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 2021/04/30 10:47:08 UTC
[maven-javadoc-plugin] 01/07: Introduce JavadocModule
This is an automated email from the ASF dual-hosted git repository.
rfscholte pushed a commit to branch MJAVADOC-634
in repository https://gitbox.apache.org/repos/asf/maven-javadoc-plugin.git
commit 561c2eb43e40b1287593ba777135d1604c86a387
Author: rfscholte <rf...@apache.org>
AuthorDate: Wed Apr 28 20:08:56 2021 +0200
Introduce JavadocModule
---
.../maven/plugins/javadoc/AbstractJavadocMojo.java | 87 +++++++++++-----------
.../maven/plugins/javadoc/JavadocModule.java | 51 +++++++++++++
.../maven/plugins/javadoc/JavadocReport.java | 5 +-
.../plugins/javadoc/resolver/ResourceResolver.java | 36 ++++-----
4 files changed, 113 insertions(+), 66 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 2625251..730b6c4 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java
@@ -134,6 +134,7 @@ import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
+import java.util.stream.Collectors;
import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast;
import static org.apache.maven.plugins.javadoc.JavadocUtil.toRelative;
@@ -2018,9 +2019,11 @@ public abstract class AbstractJavadocMojo
throw new MavenReportException( "Failed to generate javadoc options file: " + e.getMessage(), e );
}
- Map<String, Collection<Path>> sourcePaths = getSourcePaths();
+ Collection<JavadocModule> sourcePaths = getSourcePaths();
- Collection<Path> collectedSourcePaths = collect( sourcePaths.values() );
+ Collection<Path> collectedSourcePaths = sourcePaths.stream()
+ .flatMap( e -> e.getSourcePaths().stream() )
+ .collect( Collectors.toList() );
Map<Path, Collection<String>> files = getFiles( collectedSourcePaths );
if ( !canGenerateReport( files ) )
@@ -2249,16 +2252,6 @@ public abstract class AbstractJavadocMojo
}
}
- protected final <T> Collection<T> collect( Collection<Collection<T>> sourcePaths )
- {
- Collection<T> collectedSourcePaths = new LinkedHashSet<>();
- for ( Collection<T> sp : sourcePaths )
- {
- collectedSourcePaths.addAll( sp );
- }
- return collectedSourcePaths;
- }
-
/**
* Method to get the files on the specified source paths
*
@@ -2301,10 +2294,10 @@ public abstract class AbstractJavadocMojo
* @throws MavenReportException {@link MavenReportException} issue while generating report
* @see JavadocUtil#pruneDirs(MavenProject, Collection)
*/
- protected Map<String, Collection<Path>> getSourcePaths()
+ protected Collection<JavadocModule> getSourcePaths()
throws MavenReportException
{
- Map<String, Collection<Path>> mappedSourcePaths = new LinkedHashMap<>();
+ Collection<JavadocModule> mappedSourcePaths = new ArrayList<>();
if ( StringUtils.isEmpty( sourcepath ) )
{
@@ -2336,17 +2329,12 @@ public abstract class AbstractJavadocMojo
}
if ( !sourcePaths.isEmpty() )
{
- mappedSourcePaths.put( ArtifactUtils.versionlessKey( project.getGroupId(),
- project.getArtifactId() ),
- sourcePaths );
+ mappedSourcePaths.add( new JavadocModule( ArtifactUtils.versionlessKey( project.getGroupId(),
+ project.getArtifactId() ),
+ sourcePaths ) );
}
}
- if ( includeDependencySources )
- {
- mappedSourcePaths.putAll( getDependencySourcePaths() );
- }
-
if ( isAggregator() )
{
for ( MavenProject subProject : getAggregatedProjects() )
@@ -2384,13 +2372,19 @@ public abstract class AbstractJavadocMojo
if ( !additionalSourcePaths.isEmpty() )
{
- mappedSourcePaths.put( ArtifactUtils.versionlessKey( subProject.getGroupId(),
- subProject.getArtifactId() ),
- additionalSourcePaths );
+ mappedSourcePaths.add( new JavadocModule(
+ ArtifactUtils.versionlessKey( subProject.getGroupId(),
+ subProject.getArtifactId() ),
+ additionalSourcePaths ) );
}
}
}
}
+
+ if ( includeDependencySources )
+ {
+ mappedSourcePaths.addAll( getDependencySourcePaths() );
+ }
}
else
{
@@ -2406,8 +2400,9 @@ public abstract class AbstractJavadocMojo
if ( !sourcePaths.isEmpty() )
{
- mappedSourcePaths.put( ArtifactUtils.versionlessKey( project.getGroupId(), project.getArtifactId() ),
- sourcePaths );
+ mappedSourcePaths.add( new JavadocModule( ArtifactUtils.versionlessKey( project.getGroupId(),
+ project.getArtifactId() ),
+ sourcePaths ) );
}
}
@@ -2471,7 +2466,7 @@ public abstract class AbstractJavadocMojo
* @return List of source paths.
* @throws MavenReportException {@link MavenReportException}
*/
- protected final Map<String, Collection<Path>> getDependencySourcePaths()
+ protected final Collection<JavadocModule> getDependencySourcePaths()
throws MavenReportException
{
try
@@ -4521,7 +4516,7 @@ public abstract class AbstractJavadocMojo
* @see #getFiles
* @see #getSourcePaths()
*/
- private List<String> getPackageNamesRespectingJavaModules( Map<String, Collection<Path>> allSourcePaths )
+ private List<String> getPackageNamesRespectingJavaModules( Collection<JavadocModule> javadocModules )
throws MavenReportException
{
List<String> returnList = new ArrayList<>();
@@ -4531,8 +4526,9 @@ public abstract class AbstractJavadocMojo
return returnList;
}
- for ( Collection<Path> artifactSourcePaths: allSourcePaths.values() )
+ for ( JavadocModule javadocModule : javadocModules )
{
+ Collection<Path> artifactSourcePaths = javadocModule.getSourcePaths();
Set<String> exportedPackages = new HashSet<>();
boolean exportAllPackages;
File mainDescriptor = findMainDescriptor( artifactSourcePaths );
@@ -4967,11 +4963,13 @@ public abstract class AbstractJavadocMojo
*/
private void addJavadocOptions( File javadocOutputDirectory,
List<String> arguments,
- Map<String, Collection<Path>> allSourcePaths,
+ Collection<JavadocModule> allSourcePaths,
Set<OfflineLink> offlineLinks )
throws MavenReportException
{
- Collection<Path> sourcePaths = collect( allSourcePaths.values() );
+ Collection<Path> sourcePaths = allSourcePaths.stream()
+ .flatMap( e -> e.getSourcePaths().stream() )
+ .collect( Collectors.toList() );
validateJavadocOptions();
@@ -5015,9 +5013,9 @@ public abstract class AbstractJavadocMojo
if ( supportModulePath )
{
- for ( Map.Entry<String, Collection<Path>> entry : allSourcePaths.entrySet() )
+ for ( JavadocModule entry : allSourcePaths )
{
- MavenProject entryProject = reactorKeys.get( entry.getKey() );
+ MavenProject entryProject = reactorKeys.get( entry.getGa() );
File artifactFile;
if ( entryProject != null )
@@ -5026,19 +5024,20 @@ public abstract class AbstractJavadocMojo
}
else
{
- artifactFile = project.getArtifactMap().get( entry.getKey() ).getFile();
+ artifactFile = project.getArtifactMap().get( entry.getGa() ).getFile();
}
+
ResolvePathResult resolvePathResult = getResolvePathResult( artifactFile );
if ( resolvePathResult == null || resolvePathResult.getModuleNameSource() == ModuleNameSource.FILENAME )
{
- File moduleDescriptor = findMainDescriptor( entry.getValue() );
+ File moduleDescriptor = findMainDescriptor( entry.getSourcePaths() );
if ( moduleDescriptor != null )
{
try
{
- allModuleDescriptors.put( entry.getKey(),
+ allModuleDescriptors.put( entry.getGa(),
locationManager.parseModuleDescriptor( moduleDescriptor ).getModuleDescriptor() );
}
catch ( IOException e )
@@ -5049,7 +5048,7 @@ public abstract class AbstractJavadocMojo
}
else
{
- allModuleDescriptors.put( entry.getKey(), resolvePathResult.getModuleDescriptor() );
+ allModuleDescriptors.put( entry.getGa(), resolvePathResult.getModuleDescriptor() );
}
}
}
@@ -5064,9 +5063,9 @@ public abstract class AbstractJavadocMojo
if ( supportModulePath && !allModuleDescriptors.isEmpty() )
{
Collection<String> unnamedProjects = new ArrayList<>();
- for ( Map.Entry<String, Collection<Path>> projectSourcepaths : allSourcePaths.entrySet() )
+ for ( JavadocModule javadocModule : allSourcePaths )
{
- MavenProject aggregatedProject = reactorKeys.get( projectSourcepaths.getKey() );
+ MavenProject aggregatedProject = reactorKeys.get( javadocModule.getGa() );
if ( aggregatedProject != null && !"pom".equals( aggregatedProject.getPackaging() ) )
{
ResolvePathResult result = null;
@@ -5095,7 +5094,7 @@ public abstract class AbstractJavadocMojo
}
else
{
- File moduleDescriptor = findMainDescriptor( projectSourcepaths.getValue() );
+ File moduleDescriptor = findMainDescriptor( javadocModule.getSourcePaths() );
if ( moduleDescriptor != null )
{
@@ -5119,7 +5118,7 @@ public abstract class AbstractJavadocMojo
additionalModules.add( result.getModuleDescriptor().name() );
- patchModules.put( result.getModuleDescriptor().name(), projectSourcepaths.getValue() );
+ patchModules.put( result.getModuleDescriptor().name(), javadocModule.getSourcePaths() );
Path modulePath = moduleSourceDir.resolve( result.getModuleDescriptor().name() );
if ( !Files.isDirectory( modulePath ) )
@@ -5134,7 +5133,7 @@ public abstract class AbstractJavadocMojo
}
else
{
- unnamedProjects.add( projectSourcepaths.getKey() );
+ unnamedProjects.add( javadocModule.getGa() );
}
if ( aggregatedProject.equals( getProject() ) )
@@ -5145,7 +5144,7 @@ public abstract class AbstractJavadocMojo
else
{
// todo
- getLog().error( "no reactor project: " + projectSourcepaths.getKey() );
+ getLog().error( "no reactor project: " + javadocModule.getGa() );
}
}
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocModule.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocModule.java
new file mode 100644
index 0000000..72b2308
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocModule.java
@@ -0,0 +1,51 @@
+package org.apache.maven.plugins.javadoc;
+
+/*
+ * 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.
+ */
+
+import java.nio.file.Path;
+import java.util.Collection;
+
+/**
+ * Represents a unit of Javadoc referring to the binary and java source paths
+ *
+ * @since 3.3.0
+ */
+public class JavadocModule
+{
+ private final String ga;
+
+ private final Collection<Path> sourcePaths;
+
+ public JavadocModule( String ga, Collection<Path> sourcePaths )
+ {
+ this.ga = ga;
+ this.sourcePaths = sourcePaths;
+ }
+
+ public String getGa()
+ {
+ return ga;
+ }
+
+ public Collection<Path> getSourcePaths()
+ {
+ return sourcePaths;
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java b/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java
index feeec56..7b10170 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/JavadocReport.java
@@ -25,6 +25,7 @@ import java.util.Collection;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
+import java.util.stream.Collectors;
import org.apache.maven.doxia.siterenderer.RenderingContext;
import org.apache.maven.doxia.siterenderer.sink.SiteRendererSink;
@@ -232,7 +233,9 @@ public class JavadocReport
Map<Path, Collection<String>> files;
try
{
- sourcePaths = collect( getSourcePaths().values() );
+ sourcePaths = getSourcePaths().stream()
+ .flatMap( e -> e.getSourcePaths().stream() )
+ .collect( Collectors.toList() );
files = getFiles( sourcePaths );
}
catch ( MavenReportException e )
diff --git a/src/main/java/org/apache/maven/plugins/javadoc/resolver/ResourceResolver.java b/src/main/java/org/apache/maven/plugins/javadoc/resolver/ResourceResolver.java
index d128648..f982192 100644
--- a/src/main/java/org/apache/maven/plugins/javadoc/resolver/ResourceResolver.java
+++ b/src/main/java/org/apache/maven/plugins/javadoc/resolver/ResourceResolver.java
@@ -19,22 +19,18 @@ package org.apache.maven.plugins.javadoc.resolver;
* under the License.
*/
-
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Path;
-import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Set;
import org.apache.maven.artifact.Artifact;
@@ -45,6 +41,7 @@ import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.plugins.javadoc.AbstractJavadocMojo;
+import org.apache.maven.plugins.javadoc.JavadocModule;
import org.apache.maven.plugins.javadoc.JavadocUtil;
import org.apache.maven.plugins.javadoc.ResourcesBundleMojo;
import org.apache.maven.plugins.javadoc.options.JavadocOptions;
@@ -148,10 +145,10 @@ public final class ResourceResolver extends AbstractLogEnabled
* @throws ArtifactResolutionException {@link ArtifactResolutionException}
* @throws ArtifactNotFoundException {@link ArtifactNotFoundException}
*/
- public Map<String, Collection<Path>> resolveDependencySourcePaths( final SourceResolverConfig config )
+ public Collection<JavadocModule> resolveDependencySourcePaths( final SourceResolverConfig config )
throws ArtifactResolutionException, ArtifactNotFoundException
{
- final Map<String, Collection<Path>> mappedDirs = new LinkedHashMap<>();
+ final Collection<JavadocModule> mappedDirs = new ArrayList<>();
final Map<String, MavenProject> projectMap = new HashMap<>();
if ( config.reactorProjects() != null )
@@ -171,7 +168,7 @@ public final class ResourceResolver extends AbstractLogEnabled
final MavenProject p = projectMap.get( key );
if ( p != null )
{
- mappedDirs.put( key, resolveFromProject( config, p, artifact ) );
+ mappedDirs.add( new JavadocModule( key, resolveFromProject( config, p, artifact ) ) );
}
else
{
@@ -179,10 +176,7 @@ public final class ResourceResolver extends AbstractLogEnabled
}
}
- for ( Map.Entry<String, Path> entry : resolveFromArtifacts( config, forResourceResolution ) )
- {
- mappedDirs.put( entry.getKey(), Collections.singletonList( entry.getValue() ) );
- }
+ mappedDirs.addAll( resolveFromArtifacts( config, forResourceResolution ) );
return mappedDirs;
}
@@ -261,13 +255,13 @@ public final class ResourceResolver extends AbstractLogEnabled
}
}
- List<String> dirs = new ArrayList<>( toResolve.size() );
+ List<Path> dirs = new ArrayList<>( toResolve.size() );
try
{
- for ( Map.Entry<String, Path> entry : resolveAndUnpack( toResolve, config, RESOURCE_VALID_CLASSIFIERS,
+ for ( JavadocModule entry : resolveAndUnpack( toResolve, config, RESOURCE_VALID_CLASSIFIERS,
false ) )
{
- dirs.add( entry.getValue().toString() );
+ dirs.addAll( entry.getSourcePaths() );
}
}
catch ( ArtifactResolutionException | ArtifactNotFoundException e )
@@ -280,9 +274,9 @@ public final class ResourceResolver extends AbstractLogEnabled
List<JavadocBundle> result = new ArrayList<>();
- for ( String d : dirs )
+ for ( Path d : dirs )
{
- File dir = new File( d );
+ File dir = d.toFile();
File resources = new File( dir, ResourcesBundleMojo.RESOURCES_DIR_PATH );
JavadocOptions options = null;
@@ -306,7 +300,7 @@ public final class ResourceResolver extends AbstractLogEnabled
return result;
}
- private Collection<Entry<String, Path>> resolveFromArtifacts( final SourceResolverConfig config,
+ private Collection<JavadocModule> resolveFromArtifacts( final SourceResolverConfig config,
final List<Artifact> artifacts )
throws ArtifactResolutionException, ArtifactNotFoundException
{
@@ -358,7 +352,7 @@ public final class ResourceResolver extends AbstractLogEnabled
* @throws ArtifactResolutionException if an exception occurs
* @throws ArtifactNotFoundException if an exception occurs
*/
- private Collection<Map.Entry<String, Path>> resolveAndUnpack( final List<Artifact> artifacts,
+ private Collection<JavadocModule> resolveAndUnpack( final List<Artifact> artifacts,
final SourceResolverConfig config,
final List<String> validClassifiers,
final boolean propagateErrors )
@@ -379,7 +373,7 @@ public final class ResourceResolver extends AbstractLogEnabled
filter = null;
}
- final List<Map.Entry<String, Path>> result = new ArrayList<>( artifacts.size() );
+ final List<JavadocModule> result = new ArrayList<>( artifacts.size() );
for ( final Artifact a : artifactSet )
{
if ( !validClassifiers.contains( a.getClassifier() ) || ( filter != null && !filter.include( a ) ) )
@@ -414,8 +408,8 @@ public final class ResourceResolver extends AbstractLogEnabled
unArchiver.extract();
- result.add( new AbstractMap.SimpleEntry<>( key( a.getGroupId(), a.getArtifactId() ),
- d.toPath().toAbsolutePath() ) );
+ result.add( new JavadocModule( key( a.getGroupId(), a.getArtifactId() ),
+ Collections.singleton( d.toPath().toAbsolutePath() ) ) );
}
catch ( final NoSuchArchiverException e )
{