diff --git a/pom.xml b/pom.xml index 3b2279a1f..b3e910092 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ under the License. org.apache.maven.plugins maven-plugins - 34 + 37 @@ -71,7 +71,7 @@ under the License. 1.11.1 1.11.1 2.4 - 1.0.0.v20140518 + 1.0.0.v20140518 1.1.0 9.4.43.v20210629 @@ -171,26 +171,31 @@ under the License. org.apache.maven maven-core ${mavenVersion} + provided org.apache.maven maven-model ${mavenVersion} + provided org.apache.maven maven-settings ${mavenVersion} + provided org.apache.maven maven-plugin-api ${mavenVersion} + provided org.apache.maven maven-artifact ${mavenVersion} + provided org.apache.maven.plugin-tools @@ -198,11 +203,10 @@ under the License. provided - org.codehaus.plexus - plexus-component-annotations - provided + javax.inject + javax.inject + 1 - org.apache.maven.reporting @@ -224,11 +228,6 @@ under the License. maven-common-artifact-filters 3.1.1 - - org.apache.maven.shared - maven-artifact-transfer - 0.13.1 - @@ -412,7 +411,7 @@ under the License. org.apache.maven.plugins maven-javadoc-plugin - 3.3.1 + ${project.version} false @@ -445,16 +444,8 @@ under the License. - org.codehaus.plexus - plexus-component-metadata - - - - generate-metadata - generate-test-metadata - - - + org.eclipse.sisu + sisu-maven-plugin org.apache.maven.plugins @@ -470,19 +461,6 @@ under the License. false - - org.apache.maven.plugins - maven-plugin-plugin - 3.6.1 - - - - org.codehaus.plexus - plexus-utils - 3.1.1 - - - @@ -565,7 +543,7 @@ under the License. org.codehaus.mojo l10n-maven-plugin - 1.0-alpha-2 + 1.0.0 **/log4j.properties 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 91d734ff7..8d4f19397 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/AbstractJavadocMojo.java @@ -19,17 +19,54 @@ * under the License. */ + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.Writer; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.net.URLClassLoader; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.StandardCopyOption; +import java.time.LocalDate; +import java.time.ZoneOffset; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.Properties; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.stream.Collectors; + import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.maven.RepositoryUtils; import org.apache.maven.archiver.MavenArchiver; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.handler.ArtifactHandler; import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.resolver.ArtifactNotFoundException; -import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.DefaultArtifactVersion; import org.apache.maven.execution.MavenSession; @@ -64,18 +101,10 @@ import org.apache.maven.reporting.MavenReportException; import org.apache.maven.settings.Proxy; import org.apache.maven.settings.Settings; -import org.apache.maven.shared.transfer.artifact.DefaultArtifactCoordinate; import org.apache.maven.shared.artifact.filter.resolve.AndFilter; import org.apache.maven.shared.artifact.filter.resolve.PatternExclusionsFilter; import org.apache.maven.shared.artifact.filter.resolve.PatternInclusionsFilter; -import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter; import org.apache.maven.shared.artifact.filter.resolve.TransformableFilter; -import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver; -import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException; -import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResult; -import org.apache.maven.shared.transfer.dependencies.DefaultDependableCoordinate; -import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver; -import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolverException; import org.apache.maven.shared.invoker.MavenInvocationException; import org.apache.maven.toolchain.Toolchain; import org.apache.maven.toolchain.ToolchainManager; @@ -102,49 +131,27 @@ import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; import org.codehaus.plexus.util.xml.Xpp3Dom; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.Writer; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.StandardCopyOption; -import java.time.LocalDate; -import java.time.ZoneOffset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Optional; -import java.util.Properties; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.stream.Collectors; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.artifact.ArtifactTypeRegistry; +import org.eclipse.aether.artifact.DefaultArtifact; +import org.eclipse.aether.collection.CollectRequest; +import org.eclipse.aether.graph.DefaultDependencyNode; +import org.eclipse.aether.graph.DependencyFilter; +import org.eclipse.aether.resolution.ArtifactRequest; +import org.eclipse.aether.resolution.ArtifactResolutionException; +import org.eclipse.aether.resolution.ArtifactResult; +import org.eclipse.aether.resolution.DependencyRequest; +import org.eclipse.aether.resolution.DependencyResolutionException; +import org.eclipse.aether.util.filter.AndDependencyFilter; +import org.eclipse.aether.util.filter.PatternExclusionsDependencyFilter; +import org.eclipse.aether.util.filter.ScopeDependencyFilter; import static org.apache.commons.lang3.SystemUtils.isJavaVersionAtLeast; -import static org.apache.maven.plugins.javadoc.JavadocUtil.toRelative; -import static org.apache.maven.plugins.javadoc.JavadocUtil.toList; import static org.apache.maven.plugins.javadoc.JavadocUtil.isEmpty; import static org.apache.maven.plugins.javadoc.JavadocUtil.isNotEmpty; +import static org.apache.maven.plugins.javadoc.JavadocUtil.toList; +import static org.apache.maven.plugins.javadoc.JavadocUtil.toRelative; /** * Base class with majority of Javadoc functionalities. @@ -291,13 +298,13 @@ public abstract class AbstractJavadocMojo private ResourceResolver resourceResolver; @Component - private ArtifactResolver artifactResolver; + private RepositorySystem repoSystem; - @Component - private ArtifactHandlerManager artifactHandlerManager; + @Parameter( defaultValue = "${repositorySystemSession}", readonly = true, required = true ) + private RepositorySystemSession repoSession; @Component - private DependencyResolver dependencyResolver; + private ArtifactHandlerManager artifactHandlerManager; /** * Project builder @@ -2412,7 +2419,8 @@ protected final Collection getDependencySourcePaths() { return resourceResolver.resolveDependencySourcePaths( config ); } - catch ( final ArtifactResolutionException | ArtifactNotFoundException e ) + catch ( org.apache.maven.artifact.resolver.ArtifactResolutionException + | org.apache.maven.artifact.resolver.ArtifactNotFoundException e ) { throw new MavenReportException( "Failed to resolve one or more javadoc source/resource artifacts:\n\n" + e.getMessage(), e ); @@ -2620,6 +2628,18 @@ private static List trimValues( List items ) return result; } + private List toResolverDependencies( List dependencies ) + { + if ( dependencies == null ) + { + return null; + } + ArtifactTypeRegistry registry = RepositoryUtils.newArtifactTypeRegistry( artifactHandlerManager ); + return dependencies.stream() + .map( d -> RepositoryUtils.toDependency( d, registry ) ) + .collect( Collectors.toList() ); + } + /** * Method that gets the classpath and modulepath elements that will be specified in the javadoc * -classpath and --module-path parameter. @@ -2653,9 +2673,9 @@ private Collection getPathElements() reactorArtifacts.add( p.getGroupId() + ':' + p.getArtifactId() ); } - TransformableFilter dependencyFilter = new AndFilter( Arrays.asList( - new PatternExclusionsFilter( reactorArtifacts ), - getDependencyScopeFilter() ) ); + DependencyFilter dependencyFilter = new AndDependencyFilter( + new PatternExclusionsDependencyFilter( reactorArtifacts ), + getDependencyScopeFilter() ); for ( MavenProject subProject : aggregatorProjects ) { @@ -2680,22 +2700,23 @@ private Collection getPathElements() sb.append( subProject.getArtifactId() ).append( ":" ); sb.append( subProject.getVersion() ).append( '\n' ); - ProjectBuildingRequest buildingRequest = getProjectBuildingRequest( subProject ); - List managedDependencies = null; if ( subProject.getDependencyManagement() != null ) { managedDependencies = subProject.getDependencyManagement().getDependencies(); } + CollectRequest collRequest = new CollectRequest( + toResolverDependencies( subProject.getDependencies() ), + toResolverDependencies( managedDependencies ), + project.getRemoteProjectRepositories() ); + DependencyRequest depRequest = new DependencyRequest( collRequest, dependencyFilter ); for ( ArtifactResult artifactResult - : dependencyResolver.resolveDependencies( buildingRequest, - subProject.getDependencies(), - managedDependencies, - dependencyFilter ) ) + : repoSystem.resolveDependencies( repoSession, depRequest ).getArtifactResults() ) { - populateCompileArtifactMap( compileArtifactMap, - Collections.singletonList( artifactResult.getArtifact() ) ); + List artifacts = Collections.singletonList( + RepositoryUtils.toArtifact( artifactResult.getArtifact() ) ); + populateCompileArtifactMap( compileArtifactMap, artifacts ); sb.append( artifactResult.getArtifact().getFile() ).append( '\n' ); } @@ -2706,7 +2727,7 @@ private Collection getPathElements() } } - catch ( DependencyResolverException e ) + catch ( DependencyResolutionException e ) { throw new MavenReportException( e.getMessage(), e ); } @@ -2732,9 +2753,11 @@ private Collection getPathElements() return classpathElements; } - protected ScopeFilter getDependencyScopeFilter() + protected ScopeDependencyFilter getDependencyScopeFilter() { - return ScopeFilter.including( Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_SYSTEM ); + return new ScopeDependencyFilter( Arrays.asList( Artifact.SCOPE_COMPILE, + Artifact.SCOPE_PROVIDED, + Artifact.SCOPE_SYSTEM ), null ); } /** @@ -2745,18 +2768,14 @@ protected ScopeFilter getDependencyScopeFilter() public Artifact resolveDependency( Dependency dependency ) throws MavenReportException { - DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate(); - coordinate.setGroupId( dependency.getGroupId() ); - coordinate.setArtifactId( dependency.getArtifactId() ); - coordinate.setVersion( dependency.getVersion() ); - coordinate.setClassifier( dependency.getClassifier() ); - coordinate.setExtension( artifactHandlerManager.getArtifactHandler( dependency.getType() ).getExtension() ); - - try + ArtifactRequest req = new ArtifactRequest( RepositoryUtils.toDependency( dependency, null ).getArtifact(), + project.getRemoteProjectRepositories(), null ); + try { - return artifactResolver.resolveArtifact( getProjectBuildingRequest( project ), coordinate ).getArtifact(); - } - catch ( ArtifactResolverException e ) + ArtifactResult resolutionResult = repoSystem.resolveArtifact( repoSession, req ); + return RepositoryUtils.toArtifact( resolutionResult.getArtifact( ) ); + } + catch ( ArtifactResolutionException e ) { throw new MavenReportException( "artifact resolver problem - " + e.getMessage(), e ); } @@ -3584,14 +3603,13 @@ private List getArtifactsAbsolutePath( JavadocPathArtifact javadocArtifa Artifact artifact = createAndResolveArtifact( javadocArtifact ); path.add( artifact.getFile().getAbsolutePath() ); - DefaultDependableCoordinate coordinate = new DefaultDependableCoordinate(); - coordinate.setGroupId( javadocArtifact.getGroupId() ); - coordinate.setArtifactId( javadocArtifact.getArtifactId() ); - coordinate.setVersion( javadocArtifact.getVersion() ); - + DependencyFilter filter = new ScopeDependencyFilter( + Arrays.asList( Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED ), + Collections.emptySet() ); + DependencyRequest req = new DependencyRequest( + new DefaultDependencyNode( RepositoryUtils.toArtifact( artifact ) ), filter ); Iterable deps = - dependencyResolver.resolveDependencies( getProjectBuildingRequest( project ), coordinate, - ScopeFilter.including( "compile", "provided" ) ); + repoSystem.resolveDependencies( repoSession, req ).getArtifactResults(); for ( ArtifactResult a : deps ) { path.add( a.getArtifact().getFile().getAbsolutePath() ); @@ -3599,11 +3617,11 @@ private List getArtifactsAbsolutePath( JavadocPathArtifact javadocArtifa return path; } - catch ( ArtifactResolverException e ) + catch ( ArtifactResolutionException e ) { throw new MavenReportException( "Unable to resolve artifact:" + javadocArtifact, e ); } - catch ( DependencyResolverException e ) + catch ( DependencyResolutionException e ) { throw new MavenReportException( "Unable to resolve dependencies for:" + javadocArtifact, e ); } @@ -3614,18 +3632,20 @@ private List getArtifactsAbsolutePath( JavadocPathArtifact javadocArtifa * * @param javadocArtifact the {@link JavadocPathArtifact} to resolve * @return a resolved {@link Artifact} + * @throws org.eclipse.aether.resolution.ArtifactResolutionException * @throws ArtifactResolverException issue while resolving artifact */ - private Artifact createAndResolveArtifact( JavadocPathArtifact javadocArtifact ) - throws ArtifactResolverException + private Artifact createAndResolveArtifact( JavadocPathArtifact javadocArtifact ) + throws org.eclipse.aether.resolution.ArtifactResolutionException { - DefaultArtifactCoordinate coordinate = new DefaultArtifactCoordinate(); - coordinate.setGroupId( javadocArtifact.getGroupId() ); - coordinate.setArtifactId( javadocArtifact.getArtifactId() ); - coordinate.setVersion( javadocArtifact.getVersion() ); - coordinate.setClassifier( javadocArtifact.getClassifier() ); - - return artifactResolver.resolveArtifact( getProjectBuildingRequest( project ), coordinate ).getArtifact(); + org.eclipse.aether.artifact.Artifact artifact = + new DefaultArtifact( javadocArtifact.getGroupId(), + javadocArtifact.getArtifactId(), + javadocArtifact.getClassifier(), + "jar", + javadocArtifact.getVersion() ); + ArtifactRequest req = new ArtifactRequest( artifact, project.getRemoteProjectRepositories(), null ); + return RepositoryUtils.toArtifact( repoSystem.resolveArtifact( repoSession, req ).getArtifact() ); } /** @@ -4411,7 +4431,7 @@ private void copyAdditionalJavadocResources( File anOutputDirectory ) { artifact = createAndResolveArtifact( item ); } - catch ( ArtifactResolverException e ) + catch ( ArtifactResolutionException e ) { throw new MavenReportException( "Unable to resolve artifact:" + item, e ); } @@ -5696,7 +5716,7 @@ private void addTagletsFromTagletArtifacts( List arguments ) { artifact = createAndResolveArtifact( aTagletArtifact ); } - catch ( ArtifactResolverException e ) + catch ( ArtifactResolutionException e ) { throw new MavenReportException( "Unable to resolve artifact:" + aTagletArtifact, e ); } diff --git a/src/main/java/org/apache/maven/plugins/javadoc/TestJavadocJar.java b/src/main/java/org/apache/maven/plugins/javadoc/TestJavadocJar.java index ed725c7ce..e282d121c 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/TestJavadocJar.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/TestJavadocJar.java @@ -26,11 +26,12 @@ import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.plugins.javadoc.resolver.SourceResolverConfig; import org.apache.maven.project.MavenProject; -import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter; import org.codehaus.plexus.util.StringUtils; +import org.eclipse.aether.util.filter.ScopeDependencyFilter; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -187,10 +188,13 @@ protected List getExecutionProjectSourceRoots( MavenProject p ) } @Override - protected ScopeFilter getDependencyScopeFilter() + protected ScopeDependencyFilter getDependencyScopeFilter() { - return ScopeFilter.including( Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_SYSTEM, - Artifact.SCOPE_TEST ); + return new ScopeDependencyFilter( Arrays.asList( + Artifact.SCOPE_COMPILE, + Artifact.SCOPE_PROVIDED, + Artifact.SCOPE_SYSTEM, + Artifact.SCOPE_TEST ), null ); } /** diff --git a/src/main/java/org/apache/maven/plugins/javadoc/TestJavadocReport.java b/src/main/java/org/apache/maven/plugins/javadoc/TestJavadocReport.java index 72b1a57c2..f419f7f3a 100644 --- a/src/main/java/org/apache/maven/plugins/javadoc/TestJavadocReport.java +++ b/src/main/java/org/apache/maven/plugins/javadoc/TestJavadocReport.java @@ -28,11 +28,12 @@ import org.apache.maven.plugins.javadoc.resolver.SourceResolverConfig; import org.apache.maven.project.MavenProject; import org.apache.maven.reporting.MavenReportException; -import org.apache.maven.shared.artifact.filter.resolve.ScopeFilter; import org.codehaus.plexus.util.StringUtils; +import org.eclipse.aether.util.filter.ScopeDependencyFilter; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.LinkedList; import java.util.List; @@ -289,10 +290,13 @@ protected String getWindowtitle() } @Override - protected ScopeFilter getDependencyScopeFilter() + protected ScopeDependencyFilter getDependencyScopeFilter() { - return ScopeFilter.including( Artifact.SCOPE_COMPILE, Artifact.SCOPE_PROVIDED, Artifact.SCOPE_SYSTEM, - Artifact.SCOPE_TEST ); + return new ScopeDependencyFilter( Arrays.asList( + Artifact.SCOPE_COMPILE, + Artifact.SCOPE_PROVIDED, + Artifact.SCOPE_SYSTEM, + Artifact.SCOPE_TEST ), null ); } /** 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 01c7abc3d..a5151bb4d 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,6 +19,11 @@ * under the License. */ + +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; + import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -26,19 +31,17 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.DefaultArtifact; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; 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; @@ -47,37 +50,31 @@ import org.apache.maven.plugins.javadoc.options.io.xpp3.JavadocOptionsXpp3Reader; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.artifact.filter.resolve.transform.ArtifactIncludeFilterTransformer; -import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolver; -import org.apache.maven.shared.transfer.artifact.resolve.ArtifactResolverException; -import org.apache.maven.shared.transfer.dependencies.resolve.DependencyResolver; +import org.apache.maven.shared.artifact.filter.resolve.transform.EclipseAetherFilterTransformer; import org.codehaus.plexus.archiver.ArchiverException; import org.codehaus.plexus.archiver.UnArchiver; import org.codehaus.plexus.archiver.manager.ArchiverManager; import org.codehaus.plexus.archiver.manager.NoSuchArchiverException; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; +import org.eclipse.aether.RepositorySystem; +import org.eclipse.aether.RepositorySystemSession; +import org.eclipse.aether.graph.DefaultDependencyNode; +import org.eclipse.aether.graph.DependencyFilter; +import org.eclipse.aether.resolution.ArtifactRequest; +import org.eclipse.aether.resolution.ArtifactResult; /** * */ -@Component( role = ResourceResolver.class ) +@Named +@Singleton public final class ResourceResolver extends AbstractLogEnabled { - @Requirement - private ArtifactFactory artifactFactory; - - @Requirement - private ArtifactResolver resolver; - - @Requirement - private DependencyResolver dependencyResolver; - - @Requirement - private ArtifactMetadataSource artifactMetadataSource; - - @Requirement + @Inject + private RepositorySystem repoSystem; + + @Inject private ArchiverManager archiverManager; /** @@ -233,7 +230,7 @@ private List resolveBundlesFromArtifacts( final SourceResolverCon final List artifacts ) throws IOException { - final List toResolve = new ArrayList<>( artifacts.size() ); + final List toResolve = new ArrayList<>( artifacts.size() ); for ( final Artifact artifact : artifacts ) { @@ -303,7 +300,7 @@ private JavadocModule resolveFromArtifact( final SourceResolverConfig config, final Artifact artifact ) throws ArtifactResolutionException, ArtifactNotFoundException { - final List toResolve = new ArrayList<>( 2 ); + final List toResolve = new ArrayList<>( 2 ); if ( config.filter() != null && !new ArtifactIncludeFilterTransformer().transform( config.filter() ).include( artifact ) ) @@ -328,18 +325,15 @@ private JavadocModule resolveFromArtifact( final SourceResolverConfig config, sourcePaths ); } - private Artifact createResourceArtifact( final Artifact artifact, final String classifier, - final SourceResolverConfig config ) + private org.eclipse.aether.artifact.Artifact createResourceArtifact( final Artifact artifact, + final String classifier, + final SourceResolverConfig config ) { - final DefaultArtifact a = - (DefaultArtifact) artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), - artifact.getArtifactId(), - artifact.getVersion(), "jar", - classifier ); - - a.setRepository( artifact.getRepository() ); - - return a; + return new org.eclipse.aether.artifact.DefaultArtifact( artifact.getGroupId(), + artifact.getArtifactId(), + classifier, + "jar", + artifact.getVersion() ); } /** @@ -352,7 +346,7 @@ private Artifact createResourceArtifact( final Artifact artifact, final String c * @throws ArtifactResolutionException if an exception occurs * @throws ArtifactNotFoundException if an exception occurs */ - private Collection resolveAndUnpack( final List artifacts, + private Collection resolveAndUnpack( final List artifacts, final SourceResolverConfig config, final List validClassifiers, final boolean propagateErrors ) @@ -361,12 +355,12 @@ private Collection resolveAndUnpack( final List artifacts, // NOTE: Since these are '-sources' and '-test-sources' artifacts, they won't actually // resolve transitively...this is just used to aggregate resolution failures into a single // exception. - final Set artifactSet = new LinkedHashSet<>( artifacts ); + final Set artifactSet = new LinkedHashSet<>( artifacts ); - final ArtifactFilter filter; + final DependencyFilter filter; if ( config.filter() != null ) { - filter = new ArtifactIncludeFilterTransformer().transform( config.filter() ); + filter = new EclipseAetherFilterTransformer().transform( config.filter() ); } else { @@ -374,23 +368,26 @@ private Collection resolveAndUnpack( final List artifacts, } final List result = new ArrayList<>( artifacts.size() ); - for ( final Artifact a : artifactSet ) + for ( final org.eclipse.aether.artifact.Artifact a : artifactSet ) { - if ( !validClassifiers.contains( a.getClassifier() ) || ( filter != null && !filter.include( a ) ) ) + if ( !validClassifiers.contains( a.getClassifier() ) || ( filter != null + && !filter.accept( new DefaultDependencyNode( a ), Collections.emptyList() ) ) ) { continue; } Artifact resolvedArtifact; - try + ArtifactRequest req = new ArtifactRequest( a, config.project().getRemoteProjectRepositories(), null ); + try { - resolvedArtifact = resolver.resolveArtifact( config.getBuildingRequest(), a ).getArtifact(); + RepositorySystemSession repoSession = config.getBuildingRequest().getRepositorySession(); + ArtifactResult resolutionResult = repoSystem.resolveArtifact( repoSession, req ); + resolvedArtifact = RepositoryUtils.toArtifact( resolutionResult.getArtifact() ); } - catch ( ArtifactResolverException e1 ) + catch ( org.eclipse.aether.resolution.ArtifactResolutionException e ) { continue; } - final File d = new File( config.outputBasedir(), a.getArtifactId() + "-" + a.getVersion() + "-" + a.getClassifier() ); @@ -401,7 +398,7 @@ private Collection resolveAndUnpack( final List artifacts, try { - final UnArchiver unArchiver = archiverManager.getUnArchiver( a.getType() ); + final UnArchiver unArchiver = archiverManager.getUnArchiver( a.getExtension() ); unArchiver.setDestDirectory( d ); unArchiver.setSourceFile( resolvedArtifact.getFile() ); @@ -415,14 +412,15 @@ private Collection resolveAndUnpack( final List artifacts, if ( propagateErrors ) { throw new ArtifactResolutionException( "Failed to retrieve valid un-archiver component: " - + a.getType(), a, e ); + + a.getExtension(), RepositoryUtils.toArtifact( a ), e ); } } catch ( final ArchiverException e ) { if ( propagateErrors ) { - throw new ArtifactResolutionException( "Failed to unpack: " + a.getId(), a, e ); + throw new ArtifactResolutionException( "Failed to unpack: " + a.toString(), + RepositoryUtils.toArtifact( a ), e ); } } } diff --git a/src/test/java/org/apache/maven/plugins/javadoc/AggregatorJavadocReportTest.java b/src/test/java/org/apache/maven/plugins/javadoc/AggregatorJavadocReportTest.java index 338bdc23b..85d84305e 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/AggregatorJavadocReportTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/AggregatorJavadocReportTest.java @@ -80,7 +80,7 @@ private JavadocReport lookupMojo( File testPom ) DefaultRepositorySystemSession repoSysSession = (DefaultRepositorySystemSession) session.getRepositorySession(); repoSysSession.setLocalRepositoryManager( new SimpleLocalRepositoryManagerFactory().newInstance( repoSysSession, new LocalRepository( localRepo ) ) ); setVariableValueToObject( mojo, "session", session ); - + setVariableValueToObject( mojo, "repoSession", repoSysSession ); return mojo; } diff --git a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java index 4200ec055..845a41e06 100644 --- a/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java +++ b/src/test/java/org/apache/maven/plugins/javadoc/JavadocReportTest.java @@ -118,8 +118,9 @@ private JavadocReport lookupMojo( Path testPom ) currentProject.setGroupId( "GROUPID" ); currentProject.setArtifactId( "ARTIFACTID" ); - setVariableValueToObject( mojo, "session", newMavenSession( currentProject ) ); - + MavenSession session = newMavenSession( currentProject ); + setVariableValueToObject( mojo, "session", session ); + setVariableValueToObject( mojo, "repoSession", session.getRepositorySession() ); return mojo; } @@ -514,7 +515,7 @@ public void testDoclets() legacySupport.setSession( session ); setVariableValueToObject( mojo, "session", session ); - + setVariableValueToObject( mojo, "repoSession", repositorySession ); mojo.execute(); Path generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" ).toPath(); @@ -533,6 +534,7 @@ public void testDoclets() testPom = unit.resolve( "doclet-path-test/doclet-path-test-plugin-config.xml" ); mojo = lookupMojo( testPom ); setVariableValueToObject( mojo, "session", session ); + setVariableValueToObject( mojo, "repoSession", repositorySession ); mojo.execute(); generatedFile = new File( getBasedir(), "target/test/unit/doclet-test/target/site/apidocs/graph.dot" ).toPath(); @@ -696,6 +698,7 @@ public void testTaglets() legacySupport.setSession( session ); setVariableValueToObject( mojo, "session", session ); + setVariableValueToObject( mojo, "repoSession", repositorySession ); mojo.execute(); @@ -992,6 +995,7 @@ public void testProxy() setVariableValueToObject( mojo, "settings", settings ); setVariableValueToObject( mojo, "session", session ); + setVariableValueToObject( mojo, "repoSession", repositorySession ); mojo.execute(); Path commandLine = new File( getBasedir(), "target/test/unit/proxy-test/target/site/apidocs/javadoc." + ( SystemUtils.IS_OS_WINDOWS ? "bat" : "sh" ) ).toPath(); @@ -1033,6 +1037,7 @@ public void testProxy() mojo = lookupMojo( testPom ); setVariableValueToObject( mojo, "settings", settings ); setVariableValueToObject( mojo, "session", session ); + setVariableValueToObject( mojo, "repoSession", repositorySession ); mojo.execute(); readed = readFile( commandLine ); assertTrue( readed.contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) ); @@ -1080,6 +1085,7 @@ public void testProxy() mojo = lookupMojo( testPom ); setVariableValueToObject( mojo, "settings", settings ); setVariableValueToObject( mojo, "session", session ); + setVariableValueToObject( mojo, "repoSession", repositorySession ); mojo.execute(); readed = readFile( commandLine ); assertThat( readed ).contains( "-J-Dhttp.proxyHost=" + proxyServer.getHostName() ) @@ -1202,7 +1208,7 @@ public void testTagletArtifacts() LegacySupport legacySupport = lookup( LegacySupport.class ); legacySupport.setSession( session ); setVariableValueToObject( mojo, "session", session ); - + setVariableValueToObject( mojo, "repoSession", repositorySession ); mojo.execute(); Path optionsFile = new File( mojo.getOutputDirectory(), "options" ).toPath(); @@ -1240,6 +1246,7 @@ public void testStylesheetfile() LegacySupport legacySupport = lookup( LegacySupport.class ); legacySupport.setSession( session ); setVariableValueToObject( mojo, "session", session ); + setVariableValueToObject( mojo, "repoSession", repositorySession ); Path apidocs = new File( getBasedir(), "target/test/unit/stylesheetfile-test/target/site/apidocs" ).toPath(); @@ -1362,6 +1369,7 @@ public void testHelpfile() LegacySupport legacySupport = lookup( LegacySupport.class ); legacySupport.setSession( session ); setVariableValueToObject( mojo, "session", session ); + setVariableValueToObject( mojo, "repoSession", repositorySession ); Path apidocs = new File( getBasedir(), "target/test/unit/helpfile-test/target/site/apidocs" ).toPath(); @@ -1381,6 +1389,7 @@ public void testHelpfile() setVariableValueToObject( mojo, "helpfile", "com/mycompany/app/javadoc/helpfile/help-doc.html" ); setVariableValueToObject( mojo, "session", session ); + setVariableValueToObject( mojo, "repoSession", repositorySession ); mojo.execute();