You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by rf...@apache.org on 2018/12/26 10:45:20 UTC
[maven-javadoc-plugin] 02/02: Added integration test.
Implementation now only calculates exports once per module.
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MJAVADOC-556
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
commit d3918a369ba1565318cf170c20103bceaab27f7c
Author: Gili Tzabari <a-...@expedia.com>
AuthorDate: Mon Dec 24 20:23:57 2018 -0500
Added integration test. Implementation now only calculates exports once per module.
---
pom.xml | 2 +-
.../invoker.properties | 19 ++++++
.../module/pom.xml | 44 ++++++++++++++
.../module/src/main/java/module-info.java | 23 ++++++++
.../module/src/main/java/package1/Main1.java | 24 ++++++++
.../module/src/main/java/package2/Main2.java | 24 ++++++++
.../pom.xml | 49 ++++++++++++++++
.../maven/plugins/javadoc/AbstractJavadocMojo.java | 68 +++++++++++-----------
8 files changed, 218 insertions(+), 35 deletions(-)
diff --git a/pom.xml b/pom.xml
index dbead88..bba7bfa 100644
--- a/pom.xml
+++ b/pom.xml
@@ -536,7 +536,7 @@ under the License.
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
- <exlude>**/*Test*.java</exlude>
+ <exclude>**/*Test*.java</exclude>
</excludes>
</configuration>
</plugin>
diff --git a/src/it/projects/MJAVADOC-556_hide-non-exported-packages/invoker.properties b/src/it/projects/MJAVADOC-556_hide-non-exported-packages/invoker.properties
new file mode 100644
index 0000000..81ca246
--- /dev/null
+++ b/src/it/projects/MJAVADOC-556_hide-non-exported-packages/invoker.properties
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.java.version=9+
+invoker.goals=javadoc:aggregate
diff --git a/src/it/projects/MJAVADOC-556_hide-non-exported-packages/module/pom.xml b/src/it/projects/MJAVADOC-556_hide-non-exported-packages/module/pom.xml
new file mode 100644
index 0000000..e5bea45
--- /dev/null
+++ b/src/it/projects/MJAVADOC-556_hide-non-exported-packages/module/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.maven.plugins.maven-javadoc-plugin.it</groupId>
+ <artifactId>MJAVADOC-556</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>module</artifactId>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.0</version>
+ <configuration>
+ <source>9</source>
+ <target>9</target>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-556_hide-non-exported-packages/module/src/main/java/module-info.java b/src/it/projects/MJAVADOC-556_hide-non-exported-packages/module/src/main/java/module-info.java
new file mode 100644
index 0000000..ccb7c17
--- /dev/null
+++ b/src/it/projects/MJAVADOC-556_hide-non-exported-packages/module/src/main/java/module-info.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+module module
+{
+ exports package1;
+}
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-556_hide-non-exported-packages/module/src/main/java/package1/Main1.java b/src/it/projects/MJAVADOC-556_hide-non-exported-packages/module/src/main/java/package1/Main1.java
new file mode 100644
index 0000000..f380ab9
--- /dev/null
+++ b/src/it/projects/MJAVADOC-556_hide-non-exported-packages/module/src/main/java/package1/Main1.java
@@ -0,0 +1,24 @@
+package package1;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public final class Main1
+{
+}
diff --git a/src/it/projects/MJAVADOC-556_hide-non-exported-packages/module/src/main/java/package2/Main2.java b/src/it/projects/MJAVADOC-556_hide-non-exported-packages/module/src/main/java/package2/Main2.java
new file mode 100644
index 0000000..22de4c5
--- /dev/null
+++ b/src/it/projects/MJAVADOC-556_hide-non-exported-packages/module/src/main/java/package2/Main2.java
@@ -0,0 +1,24 @@
+package package2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+public final class Main2
+{
+}
diff --git a/src/it/projects/MJAVADOC-556_hide-non-exported-packages/pom.xml b/src/it/projects/MJAVADOC-556_hide-non-exported-packages/pom.xml
new file mode 100644
index 0000000..7a12e5f
--- /dev/null
+++ b/src/it/projects/MJAVADOC-556_hide-non-exported-packages/pom.xml
@@ -0,0 +1,49 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.apache.maven.plugins.maven-javadoc-plugin.it</groupId>
+ <artifactId>MJAVADOC-556</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <url>https://issues.apache.org/jira/browse/MJAVADOC-556</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>@project.version@</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+ <modules>
+ <module>module</module>
+ </modules>
+</project>
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
index 44750de..e7c8bbc 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -4367,12 +4367,43 @@ public abstract class AbstractJavadocMojo
{
return returnList;
}
- // Avoid checking non-exported packages multiple times
- Set<String> packagesChecked = new HashSet<>();
LocationManager locationManager = new LocationManager();
for ( Collection<String> artifactSourcePaths: allSourcePaths.values() )
{
+ Set<String> exportedPackages = new HashSet<>();
+ boolean exportAllPackages;
+ File mainDescriptor = findMainDescriptor( artifactSourcePaths );
+ if ( mainDescriptor != null && !isTest() )
+ {
+ ResolvePathsRequest<File> request =
+ ResolvePathsRequest.withFiles( Collections.<File>emptyList() ).
+ setMainModuleDescriptor( mainDescriptor );
+
+ try
+ {
+ Set<JavaModuleDescriptor.JavaExports> exports = locationManager.resolvePaths( request ).
+ getMainModuleDescriptor().exports();
+ if ( exports.isEmpty() )
+ {
+ continue;
+ }
+ for ( JavaModuleDescriptor.JavaExports export : exports )
+ {
+ exportedPackages.add( export.source() );
+ }
+ }
+ catch ( IOException e )
+ {
+ throw new MavenReportException( e.getMessage(), e );
+ }
+ exportAllPackages = false;
+ }
+ else
+ {
+ exportAllPackages = true;
+ }
+
for ( String currentFile : getFiles( artifactSourcePaths ) )
{
currentFile = currentFile.replace( '\\', '/' );
@@ -4403,39 +4434,8 @@ public abstract class AbstractJavadocMojo
packagename = packagename.substring( 0, packagename.lastIndexOf( "/" ) );
packagename = packagename.replace( '/', '.' );
- if ( !packagesChecked.contains( packagename ) )
+ if ( exportAllPackages || exportedPackages.contains( packagename ) )
{
- packagesChecked.add( packagename );
- File mainDescriptor = findMainDescriptor( artifactSourcePaths );
- if ( mainDescriptor != null && !isTest() )
- {
- ResolvePathsRequest<File> request =
- ResolvePathsRequest.withFiles( Collections.<File>emptyList() ).
- setMainModuleDescriptor( mainDescriptor );
-
- try
- {
- boolean packageExported = false;
- for ( JavaModuleDescriptor.JavaExports export : locationManager.
- resolvePaths( request ).getMainModuleDescriptor().exports() )
- {
- if ( export.source().equals( packagename ) )
- {
- // Only add exported packages
- packageExported = true;
- break;
- }
- }
- if ( !packageExported )
- {
- continue;
- }
- }
- catch ( IOException e )
- {
- throw new MavenReportException( e.getMessage(), e );
- }
- }
returnList.add( packagename );
}
}