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/01/06 15:04:51 UTC
[maven-javadoc-plugin] 01/04: [MJAVADOC-555] Javadoc:aggregate,
Javadoc:jar fail if one of the modules does not contain
module-info.java
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MJAVADOC-555
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
commit 444831a552835c60341bb4f856822e9daa821060
Author: rfscholte <rf...@apache.org>
AuthorDate: Fri Jan 4 16:28:47 2019 +0100
[MJAVADOC-555] Javadoc:aggregate, Javadoc:jar fail if one of the modules does not contain module-info.java
---
.../MJAVADOC-555_aggr_mixed/invoker.properties | 19 +++
.../MJAVADOC-555_aggr_mixed/module1/pom.xml | 32 ++++
.../module1/src/main/java/module-info.java | 23 +++
.../module1/src/main/java/module1/Main.java | 24 +++
.../MJAVADOC-555_aggr_mixed/module2/pom.xml | 52 +++++++
.../module2/src/main/java/module2/Main.java | 24 +++
src/it/projects/MJAVADOC-555_aggr_mixed/pom.xml | 69 +++++++++
.../projects/MJAVADOC-555_aggr_mixed/verify.groovy | 38 +++++
.../maven/plugins/javadoc/AbstractJavadocMojo.java | 168 ++++++++++++++++++---
9 files changed, 431 insertions(+), 18 deletions(-)
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/invoker.properties b/src/it/projects/MJAVADOC-555_aggr_mixed/invoker.properties
new file mode 100644
index 0000000..768d035
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/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= package javadoc:aggregate
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/module1/pom.xml b/src/it/projects/MJAVADOC-555_aggr_mixed/module1/pom.xml
new file mode 100644
index 0000000..288012b
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/module1/pom.xml
@@ -0,0 +1,32 @@
+<?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>
+ <parent>
+ <artifactId>javadoc-maven-report-exception</artifactId>
+ <groupId>testcase</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>module1</artifactId>
+</project>
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/module1/src/main/java/module-info.java b/src/it/projects/MJAVADOC-555_aggr_mixed/module1/src/main/java/module-info.java
new file mode 100644
index 0000000..0dd7ad2
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/module1/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 module1
+{
+ exports module1;
+}
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/module1/src/main/java/module1/Main.java b/src/it/projects/MJAVADOC-555_aggr_mixed/module1/src/main/java/module1/Main.java
new file mode 100644
index 0000000..e60dbdb
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/module1/src/main/java/module1/Main.java
@@ -0,0 +1,24 @@
+package module1;
+
+/*
+ * 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 Main
+{
+}
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/module2/pom.xml b/src/it/projects/MJAVADOC-555_aggr_mixed/module2/pom.xml
new file mode 100644
index 0000000..bc44c23
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/module2/pom.xml
@@ -0,0 +1,52 @@
+<?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>
+ <parent>
+ <artifactId>javadoc-maven-report-exception</artifactId>
+ <groupId>testcase</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>module2</artifactId>
+
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <archive>
+ <manifestEntries>
+ <Automatic-Module-Name>module2</Automatic-Module-Name>
+ </manifestEntries>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+</project>
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/module2/src/main/java/module2/Main.java b/src/it/projects/MJAVADOC-555_aggr_mixed/module2/src/main/java/module2/Main.java
new file mode 100644
index 0000000..b864f0e
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/module2/src/main/java/module2/Main.java
@@ -0,0 +1,24 @@
+package module2;
+
+/*
+ * 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 Main
+{
+}
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/pom.xml b/src/it/projects/MJAVADOC-555_aggr_mixed/pom.xml
new file mode 100644
index 0000000..c881914
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/pom.xml
@@ -0,0 +1,69 @@
+<?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>
+
+ <artifactId>javadoc-maven-report-exception</artifactId>
+ <groupId>testcase</groupId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <url>https://issues.apache.org/jira/browse/MJAVADOC-555</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.8.0</version>
+ <configuration>
+ <release>9</release>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>@project.version@</version>
+ <executions>
+ <execution>
+ <id>aggregate</id>
+ <goals>
+ <goal>aggregate</goal>
+ </goals>
+ <phase>site</phase>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ <modules>
+ <module>module1</module>
+ <module>module2</module>
+ </modules>
+
+</project>
\ No newline at end of file
diff --git a/src/it/projects/MJAVADOC-555_aggr_mixed/verify.groovy b/src/it/projects/MJAVADOC-555_aggr_mixed/verify.groovy
new file mode 100644
index 0000000..e75b96c
--- /dev/null
+++ b/src/it/projects/MJAVADOC-555_aggr_mixed/verify.groovy
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+int javaVersion = System.getProperty( "java.specification.version" ) as Integer
+if ( javaVersion >= 11 ) {
+ def index = new File( basedir, 'target/site/apidocs/index.html')
+
+ assert index.text =~ /<a href="module1\/module-summary\.html">module1<\/a>/
+ assert index.text =~ /<a href="module2\/module-summary\.html">module2<\/a>/
+
+ assert new File( basedir, 'target/site/apidocs/module1/module-summary.html').exists()
+ assert new File( basedir, 'target/site/apidocs/module2/module-summary.html').exists()
+}
+else {
+ def overview = new File( basedir, 'target/site/apidocs/overview-summary.html')
+
+ assert overview.text =~ /<a href="module1-summary.html">module1<\/a>/
+ assert overview.text =~ /<a href="module2-summary.html">module2<\/a>/
+
+ assert new File( basedir, 'target/site/apidocs/module1-summary.html').exists()
+ assert new File( basedir, 'target/site/apidocs/module2-summary.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 a068b74..e6cea07 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -84,6 +84,7 @@ 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.ResolvePathRequest;
import org.codehaus.plexus.languages.java.jpms.ResolvePathsRequest;
import org.codehaus.plexus.languages.java.jpms.ResolvePathsResult;
import org.codehaus.plexus.languages.java.version.JavaVersion;
@@ -1822,6 +1823,15 @@ public abstract class AbstractJavadocMojo
return Collections.singletonList( new File( p.getBuild().getOutputDirectory() ) );
}
+
+ protected File getArtifactFile( MavenProject project )
+ {
+ if ( project.getArtifact() != null )
+ {
+ return project.getArtifact().getFile();
+ }
+ return null;
+ }
/**
* @param p not null maven project
@@ -2025,7 +2035,6 @@ public abstract class AbstractJavadocMojo
{
packageNames = getPackageNames( files );
}
- List<String> filesWithUnnamedPackages = getFilesWithUnnamedPackages( files );
// ----------------------------------------------------------------------
// Javadoc output directory as File
@@ -2128,9 +2137,11 @@ public abstract class AbstractJavadocMojo
// Write argfile file and include it in the command line
// ----------------------------------------------------------------------
- if ( !filesWithUnnamedPackages.isEmpty() )
+ List<String> specialFiles = getSpecialFiles( files );
+
+ if ( !specialFiles.isEmpty() )
{
- addCommandLineArgFile( cmd, javadocOutputDirectory, filesWithUnnamedPackages );
+ addCommandLineArgFile( cmd, javadocOutputDirectory, specialFiles );
}
}
else
@@ -2689,7 +2700,15 @@ public abstract class AbstractJavadocMojo
{
if ( subProject != project )
{
- classpathElements.addAll( getProjectBuildOutputDirs( subProject ) );
+ File projectArtifactFile = getArtifactFile( subProject );
+ if ( projectArtifactFile != null )
+ {
+ classpathElements.add( projectArtifactFile );
+ }
+ else
+ {
+ classpathElements.addAll( getProjectBuildOutputDirs( subProject ) );
+ }
try
{
@@ -4515,6 +4534,70 @@ public abstract class AbstractJavadocMojo
return returnList;
}
+
+ /**
+ * Either return only the module descriptor or all sourcefiles per sourcepath
+ * @param sourcePaths could be null
+ * @param files not null
+ * @return a list of files
+ */
+ private List<String> getSpecialFiles( Map<Path, Collection<String>> sourcePaths )
+ {
+ if ( !StringUtils.isEmpty( sourcepath ) )
+ {
+ return new ArrayList<>();
+ }
+
+ boolean containsModuleDescriptor = false;
+ for ( Collection<String> sourcepathFiles : sourcePaths.values() )
+ {
+ containsModuleDescriptor = sourcepathFiles.contains( "module-info.java" );
+ if ( containsModuleDescriptor )
+ {
+ break;
+ }
+ }
+
+ if ( containsModuleDescriptor )
+ {
+ return getModuleSourcePathFiles( sourcePaths );
+ }
+ else
+ {
+ return getFilesWithUnnamedPackages( sourcePaths );
+ }
+ }
+
+ private List<String> getModuleSourcePathFiles( Map<Path, Collection<String>> sourcePaths )
+ {
+ List<String> returnList = new ArrayList<>();
+
+ for ( Entry<Path, Collection<String>> currentPathEntry : sourcePaths.entrySet() )
+ {
+ Path currentSourcePath = currentPathEntry.getKey();
+ if ( currentPathEntry.getValue().contains( "module-info.java" ) )
+ {
+ returnList.add( currentSourcePath.resolve( "module-info.java" ).toAbsolutePath().toString() );
+ }
+ else
+ {
+ for ( String currentFile : currentPathEntry.getValue() )
+ {
+ /*
+ * Remove the miscellaneous files
+ * http://docs.oracle.com/javase/1.4.2/docs/tooldocs/solaris/javadoc.html#unprocessed
+ */
+ if ( currentFile.contains( "doc-files" ) )
+ {
+ continue;
+ }
+
+ returnList.add( currentSourcePath.resolve( currentFile ).toAbsolutePath().toString() );
+ }
+ }
+ }
+ return returnList;
+ }
/**
* Generate an <code>options</code> file for all options and arguments and add the <code>@options</code> in the
@@ -4822,37 +4905,86 @@ public abstract class AbstractJavadocMojo
addArgIf( arguments, breakiterator, "-breakiterator", SINCE_JAVADOC_1_5 );
}
- Collection<String> reactorKeys = new HashSet<>( session.getProjects().size() );
+ Map<String, MavenProject> reactorKeys = new HashMap<>( session.getProjects().size() );
for ( MavenProject reactorProject : session.getProjects() )
{
- reactorKeys.add( ArtifactUtils.versionlessKey( reactorProject.getGroupId(),
- reactorProject.getArtifactId() ) );
+ reactorKeys.put( ArtifactUtils.versionlessKey( reactorProject.getGroupId(),
+ reactorProject.getArtifactId() ), reactorProject );
}
final LocationManager locationManager = new LocationManager();
Collection<String> additionalModules = new ArrayList<>();
+ boolean containsModuleDescriptor = false;
+ for ( Collection<Path> sourcepaths : allSourcePaths.values() )
+ {
+ if ( findMainDescriptor( sourcepaths ) != null )
+ {
+ containsModuleDescriptor = true;
+ }
+ }
+
+
Path moduleSourceDir = null;
- if ( allSourcePaths.size() > 1 )
+ if ( containsModuleDescriptor && allSourcePaths.size() > 1 )
{
for ( Map.Entry<String, Collection<Path>> projectSourcepaths : allSourcePaths.entrySet() )
{
- if ( reactorKeys.contains( projectSourcepaths.getKey() ) )
+ MavenProject aggregatorProject = reactorKeys.get( projectSourcepaths.getKey() );
+ if ( aggregatorProject != null )
{
- File moduleDescriptor = findMainDescriptor( projectSourcepaths.getValue() );
- if ( moduleDescriptor != null )
+ String moduleName = null;
+
+ // Prefer jar over outputDirectory, since it may may contain an automatic module name
+ File artifactFile = getArtifactFile( aggregatorProject );
+ if ( artifactFile != null )
+ {
+ ResolvePathRequest<File> request = ResolvePathRequest.ofFile( artifactFile );
+ try
+ {
+ moduleName = locationManager.resolvePath( request ).getModuleDescriptor().name();
+ }
+ catch ( RuntimeException e )
+ {
+ // most likely an invalid module name based on filename
+ if ( !"java.lang.module.FindException".equals( e.getClass().getName() ) )
+ {
+ throw e;
+ }
+ }
+ catch ( IOException e )
+ {
+ throw new MavenReportException( e.getMessage(), e );
+ }
+ }
+ else
+ {
+ File moduleDescriptor = findMainDescriptor( projectSourcepaths.getValue() );
+
+ if ( moduleDescriptor != null )
+ {
+ ResolvePathsRequest<File> request =
+ ResolvePathsRequest.ofFiles( Collections.<File>emptyList() )
+ .setMainModuleDescriptor( moduleDescriptor );
+
+ try
+ {
+ moduleName =
+ locationManager.resolvePaths( request ).getMainModuleDescriptor().name();
+ }
+ catch ( IOException e )
+ {
+ throw new MavenReportException( e.getMessage(), e );
+ }
+ }
+ }
+ if ( moduleName != null )
{
moduleSourceDir = javadocOutputDirectory.toPath().resolve( "src" );
try
{
moduleSourceDir = Files.createDirectories( moduleSourceDir );
- ResolvePathsRequest<File> request =
- ResolvePathsRequest.withFiles( Collections.<File>emptyList() )
- .setMainModuleDescriptor( moduleDescriptor );
-
- String moduleName =
- locationManager.resolvePaths( request ).getMainModuleDescriptor().name();
additionalModules.add( moduleName );
@@ -4896,7 +5028,7 @@ public abstract class AbstractJavadocMojo
if ( javadocRuntimeVersion.isAtLeast( "9" ) && ( isAggregator() || mainDescriptor != null ) && !isTest() )
{
ResolvePathsRequest<File> request =
- ResolvePathsRequest.withFiles( getPathElements() ).setAdditionalModules( additionalModules );
+ ResolvePathsRequest.ofFiles( getPathElements() ).setAdditionalModules( additionalModules );
if ( mainDescriptor != null )
{