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 2019/02/08 09:30:29 UTC

[maven-javadoc-plugin] 01/01: [MJAVADOC-575] 8 fails when module-info.java exists

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

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

commit 1fe0654bfe1ca550219f428c0dd767a3e70dab69
Author: rfscholte <rf...@apache.org>
AuthorDate: Fri Feb 8 10:30:22 2019 +0100

    [MJAVADOC-575] <source>8</source> fails when module-info.java exists
---
 .../invoker.properties                             | 17 +++++
 .../MJAVADOC-575_source8-module-info/pom.xml       | 74 +++++++++++++++++++++
 .../src/main/java/com/foo/MyClass.java             | 25 +++++++
 .../src/main/java/module-info.java                 | 22 +++++++
 .../MJAVADOC-575_source8-module-info/verify.groovy | 20 ++++++
 .../maven/plugins/javadoc/AbstractJavadocMojo.java | 76 +++++++++++++---------
 6 files changed, 202 insertions(+), 32 deletions(-)

diff --git a/src/it/projects/MJAVADOC-575_source8-module-info/invoker.properties b/src/it/projects/MJAVADOC-575_source8-module-info/invoker.properties
new file mode 100644
index 0000000..8905d6b
--- /dev/null
+++ b/src/it/projects/MJAVADOC-575_source8-module-info/invoker.properties
@@ -0,0 +1,17 @@
+# 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 = 1.8+
diff --git a/src/it/projects/MJAVADOC-575_source8-module-info/pom.xml b/src/it/projects/MJAVADOC-575_source8-module-info/pom.xml
new file mode 100644
index 0000000..85ae725
--- /dev/null
+++ b/src/it/projects/MJAVADOC-575_source8-module-info/pom.xml
@@ -0,0 +1,74 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.javadoc.it</groupId>
+  <artifactId>mjavadoc575</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <url>https://issues.apache.org/jira/browse/MJAVADOC-575</url>
+
+  <properties>
+    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>3.6</version>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.8.0</version>
+        <configuration>
+          <excludes>
+            <exclude>module-info.java</exclude>
+          </excludes>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <version>@project.version@</version>
+        <executions>
+          <execution>
+            <goals>
+              <goal>jar</goal> 
+            </goals>
+          </execution>
+        </executions>
+        <configuration>
+          <source>8</source>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>
diff --git a/src/it/projects/MJAVADOC-575_source8-module-info/src/main/java/com/foo/MyClass.java b/src/it/projects/MJAVADOC-575_source8-module-info/src/main/java/com/foo/MyClass.java
new file mode 100644
index 0000000..7370ac0
--- /dev/null
+++ b/src/it/projects/MJAVADOC-575_source8-module-info/src/main/java/com/foo/MyClass.java
@@ -0,0 +1,25 @@
+package com.foo;
+
+/*
+ * 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 class MyClass
+{
+
+}
diff --git a/src/it/projects/MJAVADOC-575_source8-module-info/src/main/java/module-info.java b/src/it/projects/MJAVADOC-575_source8-module-info/src/main/java/module-info.java
new file mode 100644
index 0000000..45f7f3d
--- /dev/null
+++ b/src/it/projects/MJAVADOC-575_source8-module-info/src/main/java/module-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 M.N {
+    requires org.apache.commons.lang3;
+}
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-575_source8-module-info/verify.groovy b/src/it/projects/MJAVADOC-575_source8-module-info/verify.groovy
new file mode 100644
index 0000000..a38349a
--- /dev/null
+++ b/src/it/projects/MJAVADOC-575_source8-module-info/verify.groovy
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+ 
+assert new File( basedir, 'target/apidocs/com/foo/MyClass.html').exists()
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 f77a541..1fb2fc9 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -2229,6 +2229,12 @@ public abstract class AbstractJavadocMojo
                 File sourceDirectory = sourcePath.toFile();
                 files.addAll( JavadocUtil.getFilesFromSource( sourceDirectory, sourceFileIncludes, sourceFileExcludes,
                                                               excludedPackages ) );
+                
+                if ( source != null && JavaVersion.parse( source ).isBefore( "9" )
+                    && files.remove( "module-info.java" ) )
+                {
+                    getLog().debug( "Auto exclude module-info.java due to source value" );
+                }
                 mappedFiles.put( sourcePath, files );
             }
         }
@@ -4896,41 +4902,47 @@ public abstract class AbstractJavadocMojo
         
         Map<String, JavaModuleDescriptor> allModuleDescriptors = new HashMap<>();
         
-        for ( Map.Entry<String, Collection<Path>> entry : allSourcePaths.entrySet() )
+        boolean supportModulePath = javadocRuntimeVersion.isAtLeast( "9" )
+            && ( source == null || JavaVersion.parse( source ).isAtLeast( "9" ) );
+        
+        if ( supportModulePath )
         {
-            MavenProject entryProject = reactorKeys.get( entry.getKey() );
-            
-            File artifactFile;
-            if ( entryProject != null )
-            {
-                artifactFile = getArtifactFile( entryProject );
-            }
-            else
-            {
-                artifactFile = project.getArtifactMap().get( entry.getKey() ).getFile();
-            }
-            ResolvePathResult resolvePathResult = getResolvePathResult( artifactFile );
-            
-            if ( resolvePathResult == null || resolvePathResult.getModuleNameSource() == ModuleNameSource.FILENAME )
+            for ( Map.Entry<String, Collection<Path>> entry : allSourcePaths.entrySet() )
             {
-                File moduleDescriptor = findMainDescriptor( entry.getValue() );
+                MavenProject entryProject = reactorKeys.get( entry.getKey() );
                 
-                if ( moduleDescriptor != null )
+                File artifactFile;
+                if ( entryProject != null )
                 {
-                    try
-                    {
-                        allModuleDescriptors.put( entry.getKey(),
-                                  locationManager.parseModuleDescriptor( moduleDescriptor ).getModuleDescriptor() );
-                    }
-                    catch ( IOException e )
+                    artifactFile = getArtifactFile( entryProject );
+                }
+                else
+                {
+                    artifactFile = project.getArtifactMap().get( entry.getKey() ).getFile();
+                }
+                ResolvePathResult resolvePathResult = getResolvePathResult( artifactFile );
+                
+                if ( resolvePathResult == null || resolvePathResult.getModuleNameSource() == ModuleNameSource.FILENAME )
+                {
+                    File moduleDescriptor = findMainDescriptor( entry.getValue() );
+                    
+                    if ( moduleDescriptor != null )
                     {
-                        throw new MavenReportException( e.getMessage(), e );
+                        try
+                        {
+                            allModuleDescriptors.put( entry.getKey(),
+                                      locationManager.parseModuleDescriptor( moduleDescriptor ).getModuleDescriptor() );
+                        }
+                        catch ( IOException e )
+                        {
+                            throw new MavenReportException( e.getMessage(), e );
+                        }
                     }
                 }
-            }
-            else
-            {
-                allModuleDescriptors.put( entry.getKey(), resolvePathResult.getModuleDescriptor() );
+                else
+                {
+                    allModuleDescriptors.put( entry.getKey(), resolvePathResult.getModuleDescriptor() );
+                }
             }
         }
 
@@ -4939,7 +4951,7 @@ public abstract class AbstractJavadocMojo
         ResolvePathResult mainResolvePathResult = null;
         
         Path moduleSourceDir = null;
-        if ( javadocRuntimeVersion.isAtLeast( "9" ) && !allModuleDescriptors.isEmpty() )
+        if ( supportModulePath && !allModuleDescriptors.isEmpty() )
         {
             Collection<String> unnamedProjects = new ArrayList<>();
             for ( Map.Entry<String, Collection<Path>> projectSourcepaths : allSourcePaths.entrySet() )
@@ -5061,7 +5073,7 @@ public abstract class AbstractJavadocMojo
             }
         }
         
-        if ( javadocRuntimeVersion.isAtLeast( "9" )
+        if ( supportModulePath
             && ( isAggregator() || ( mainResolvePathResult != null
                 && ModuleNameSource.MODULEDESCRIPTOR.equals( mainResolvePathResult.getModuleNameSource() ) ) )
             && !isTest() )
@@ -5110,7 +5122,7 @@ public abstract class AbstractJavadocMojo
                 throw new MavenReportException( e.getMessage(), e );
             }
         }
-        else if ( javadocRuntimeVersion.isAtLeast( "9" ) && ( mainResolvePathResult != null
+        else if ( supportModulePath && ( mainResolvePathResult != null
             && ModuleNameSource.MANIFEST.equals( mainResolvePathResult.getModuleNameSource() ) ) && !isTest() )
         {
             List<File> modulePathFiles = new ArrayList<>( getPathElements() );
@@ -5118,7 +5130,7 @@ public abstract class AbstractJavadocMojo
             String modulepath = StringUtils.join( modulePathFiles.iterator(), File.pathSeparator );
             addArgIfNotEmpty( arguments, "--module-path", JavadocUtil.quotedPathArgument( modulepath ) , false, false );
         }
-        else if ( javadocRuntimeVersion.isAtLeast( "9" ) && moduleDescriptorSource && !isTest() )
+        else if ( supportModulePath && moduleDescriptorSource && !isTest() )
         {
             String modulepath = StringUtils.join( getPathElements().iterator(), File.pathSeparator );
             addArgIfNotEmpty( arguments, "--module-path", JavadocUtil.quotedPathArgument( modulepath ) , false, false );