diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolver.java index 6dcd5caf06..900e7c8f68 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/ArtifactResolver.java @@ -35,6 +35,8 @@ import org.apache.maven.wagon.events.TransferListener; // Just hide the one method we want behind the RepositorySystem interface. public interface ArtifactResolver { + ArtifactResolutionResult collect( ArtifactResolutionRequest request ); + ArtifactResolutionResult resolve( ArtifactResolutionRequest request ); // The rest is deprecated diff --git a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java index fae03b880d..e9bb3c1434 100644 --- a/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java +++ b/maven-compat/src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactResolver.java @@ -339,8 +339,18 @@ public class DefaultArtifactResolver // ------------------------------------------------------------------------ // // ------------------------------------------------------------------------ - + + public ArtifactResolutionResult collect( ArtifactResolutionRequest request ) + { + return resolve( request, true ); + } + public ArtifactResolutionResult resolve( ArtifactResolutionRequest request ) + { + return resolve( request, false ); + } + + private ArtifactResolutionResult resolve( ArtifactResolutionRequest request, boolean collectOnly ) { Artifact rootArtifact = request.getArtifact(); Set artifacts = request.getArtifactDependencies(); @@ -382,7 +392,7 @@ public class DefaultArtifactResolver // file reference. But this may be a Maven Plugin that we need to resolve from a remote repository // as well as its dependencies. - if ( request.isResolveRoot() /* && rootArtifact.getFile() == null */ ) + if ( !collectOnly && request.isResolveRoot() /* && rootArtifact.getFile() == null */ ) { try { @@ -457,7 +467,7 @@ public class DefaultArtifactResolver return result; } - if ( result.getArtifacts() != null ) + if ( !collectOnly && result.getArtifacts() != null ) { for ( Artifact artifact : result.getArtifacts() ) { diff --git a/maven-compat/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java b/maven-compat/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java index a1dd3b0b25..77219b6ce6 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/LegacyRepositorySystem.java @@ -260,6 +260,57 @@ public class LegacyRepositorySystem return url; } + public ArtifactResolutionResult collect( ArtifactResolutionRequest request ) + { + /* + * Probably is not worth it, but here I make sure I restore request + * to its original state. + */ + try + { + LocalArtifactRepository ideWorkspace = plexus.lookup( LocalArtifactRepository.class, LocalArtifactRepository.IDE_WORKSPACE ); + + if ( request.getLocalRepository() instanceof DelegatingLocalArtifactRepository ) + { + DelegatingLocalArtifactRepository delegatingLocalRepository = (DelegatingLocalArtifactRepository) request.getLocalRepository(); + + LocalArtifactRepository orig = delegatingLocalRepository.getIdeWorspace(); + + delegatingLocalRepository.setIdeWorkspace( ideWorkspace ); + + try + { + return artifactResolver.collect( request ); + } + finally + { + delegatingLocalRepository.setIdeWorkspace( orig ); + } + } + else + { + ArtifactRepository localRepository = request.getLocalRepository(); + DelegatingLocalArtifactRepository delegatingLocalRepository = new DelegatingLocalArtifactRepository( localRepository ); + delegatingLocalRepository.setIdeWorkspace( ideWorkspace ); + request.setLocalRepository( delegatingLocalRepository ); + try + { + return artifactResolver.collect( request ); + } + finally + { + request.setLocalRepository( localRepository ); + } + } + } + catch ( ComponentLookupException e ) + { + // no ide workspace artifact resolution + } + + return artifactResolver.resolve( request ); + } + public ArtifactResolutionResult resolve( ArtifactResolutionRequest request ) { /* diff --git a/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java b/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java index 0be35168c4..50487da7e3 100644 --- a/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java +++ b/maven-compat/src/main/java/org/apache/maven/repository/RepositorySystem.java @@ -90,6 +90,8 @@ public interface RepositorySystem */ List getEffectiveRepositories( List repositories ); + ArtifactResolutionResult collect( ArtifactResolutionRequest request ); + ArtifactResolutionResult resolve( ArtifactResolutionRequest request ); MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request );