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:18 UTC

[maven-javadoc-plugin] branch MJAVADOC-556 created (now d3918a3)

This is an automated email from the ASF dual-hosted git repository.

rfscholte pushed a change to branch MJAVADOC-556
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git.


      at d3918a3  Added integration test. Implementation now only calculates exports once per module.

This branch includes the following new commits:

     new eb37e8e  Exclude non-exported packages when Java Modules are present.
     new d3918a3  Added integration test. Implementation now only calculates exports once per module.

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[maven-javadoc-plugin] 02/02: Added integration test. Implementation now only calculates exports once per module.

Posted by rf...@apache.org.
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 );
                             }
                         }


[maven-javadoc-plugin] 01/02: Exclude non-exported packages when Java Modules are present.

Posted by rf...@apache.org.
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 eb37e8e880ac067fe199efb71934a772a76f1a6b
Author: Gili Tzabari <a-...@expedia.com>
AuthorDate: Sun Dec 23 21:31:11 2018 -0500

    Exclude non-exported packages when Java Modules are present.
---
 .../maven/plugins/javadoc/AbstractJavadocMojo.java | 113 ++++++++++++++++++++-
 1 file changed, 109 insertions(+), 4 deletions(-)

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 1e79932..44750de 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -82,6 +82,7 @@ import org.codehaus.plexus.archiver.UnArchiver;
 import org.codehaus.plexus.archiver.manager.ArchiverManager;
 import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
 import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector;
+import org.codehaus.plexus.languages.java.jpms.JavaModuleDescriptor;
 import org.codehaus.plexus.languages.java.jpms.LocationManager;
 import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest;
 import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult;
@@ -1997,9 +1998,6 @@ public abstract class AbstractJavadocMojo
             return;
         }
 
-        List<String> packageNames = getPackageNames( collectedSourcePaths, files );
-        List<String> filesWithUnnamedPackages = getFilesWithUnnamedPackages( collectedSourcePaths, files );
-
         // ----------------------------------------------------------------------
         // Find the javadoc executable and version
         // ----------------------------------------------------------------------
@@ -2015,6 +2013,17 @@ public abstract class AbstractJavadocMojo
         }
         setFJavadocVersion( new File( jExecutable ) );
 
+        List<String> packageNames;
+        if ( javadocRuntimeVersion.isAtLeast( "9" ) )
+        {
+            packageNames = getPackageNamesRespectingJavaModules( sourcePaths );
+        }
+        else
+        {
+            packageNames = getPackageNames( collectedSourcePaths, files );
+        }
+        List<String> filesWithUnnamedPackages = getFilesWithUnnamedPackages( collectedSourcePaths, files );
+
         // ----------------------------------------------------------------------
         // Javadoc output directory as File
         // ----------------------------------------------------------------------
@@ -2514,7 +2523,7 @@ public abstract class AbstractJavadocMojo
      * Method to get the excluded source files from the javadoc and create the argument string
      * that will be included in the javadoc commandline execution.
      *
-     * @param sourcePaths the collection of paths to the source files
+     * @param sourceFolders the collection of paths to the source files
      * @return a String that contains the exclude argument that will be used by javadoc
      * @throws MavenReportException
      */
@@ -4343,6 +4352,102 @@ public abstract class AbstractJavadocMojo
     }
 
     /**
+     * @param allSourcePaths     not null, containing absolute and relative paths
+     * @return a list of exported package names for files in allSourcePaths
+     * @throws MavenReportException if any
+     * @see #getFiles
+     * @see #getSourcePaths()
+     */
+    private List<String> getPackageNamesRespectingJavaModules( Map<String, Collection<String>> allSourcePaths )
+            throws MavenReportException
+    {
+        List<String> returnList = new ArrayList<>();
+
+        if ( !StringUtils.isEmpty( sourcepath ) )
+        {
+            return returnList;
+        }
+        // Avoid checking non-exported packages multiple times
+        Set<String> packagesChecked = new HashSet<>();
+        LocationManager locationManager = new LocationManager();
+
+        for ( Collection<String> artifactSourcePaths: allSourcePaths.values() )
+        {
+            for ( String currentFile : getFiles( artifactSourcePaths ) )
+            {
+                currentFile = currentFile.replace( '\\', '/' );
+
+                for ( String currentSourcePath : artifactSourcePaths )
+                {
+                    currentSourcePath = currentSourcePath.replace( '\\', '/' );
+
+                    if ( currentFile.contains( currentSourcePath ) )
+                    {
+                        if ( !currentSourcePath.endsWith( "/" ) )
+                        {
+                            currentSourcePath += "/";
+                        }
+                        String packagename = currentFile.substring( currentSourcePath.length() + 1 );
+
+                        /*
+                         * Remove the miscellaneous files
+                         * http://docs.oracle.com/javase/1.4.2/docs/tooldocs/solaris/javadoc.html#unprocessed
+                         */
+                        if ( packagename.contains( "doc-files" ) )
+                        {
+                            continue;
+                        }
+
+                        if ( packagename.lastIndexOf( "/" ) != -1 )
+                        {
+                            packagename = packagename.substring( 0, packagename.lastIndexOf( "/" ) );
+                            packagename = packagename.replace( '/', '.' );
+
+                            if ( !packagesChecked.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 );
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        return returnList;
+    }
+
+    /**
      * @param sourcePaths could be null
      * @param files       not null
      * @return a list files with unnamed package names for files in the sourcePaths