diff --git a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java index 645f358b0c..7717000455 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/version/DefaultPluginVersionManager.java @@ -19,11 +19,13 @@ package org.apache.maven.plugin.version; * under the License. */ +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.MavenTools; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; -import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.versioning.ArtifactVersion; @@ -43,20 +45,14 @@ import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; import org.codehaus.plexus.util.StringUtils; -import java.util.Iterator; -import java.util.List; - @Component(role = PluginVersionManager.class) public class DefaultPluginVersionManager extends AbstractLogEnabled implements PluginVersionManager { @Requirement - private ArtifactFactory artifactFactory; - - @Requirement - private ArtifactMetadataSource artifactMetadataSource; - + private MavenTools repositoryTools; + @Requirement private MavenProjectBuilder mavenProjectBuilder; @@ -188,7 +184,7 @@ public class DefaultPluginVersionManager { getLogger().info( "Attempting to resolve a version for plugin: " + groupId + ":" + artifactId + " using meta-version: " + metaVersionId ); - Artifact artifact = artifactFactory.createProjectArtifact( groupId, artifactId, metaVersionId ); + Artifact artifact = repositoryTools.createProjectArtifact( groupId, artifactId, metaVersionId ); String key = artifact.getDependencyConflictId(); @@ -198,7 +194,7 @@ public class DefaultPluginVersionManager try { ResolutionGroup resolutionGroup = - artifactMetadataSource.retrieve( artifact, localRepository, project.getRemoteArtifactRepositories() ); + repositoryTools.retrieve( artifact, localRepository, project.getRemoteArtifactRepositories() ); // switching this out with the actual resolved artifact instance, since the MMSource re-creates the pom // artifact. @@ -222,7 +218,7 @@ public class DefaultPluginVersionManager MavenProject pluginProject; try { - artifact = artifactFactory.createProjectArtifact( groupId, artifactId, artifactVersion ); + artifact = repositoryTools.createProjectArtifact( groupId, artifactId, artifactVersion ); pluginProject = mavenProjectBuilder.buildFromRepository( artifact, project.getRemoteArtifactRepositories(), localRepository ); } @@ -283,7 +279,7 @@ public class DefaultPluginVersionManager getLogger().debug( "Trying " + vr ); try { - List versions = artifactMetadataSource.retrieveAvailableVersions( artifact, localRepository, + List versions = repositoryTools.retrieveAvailableVersions( artifact, localRepository, project.getRemoteArtifactRepositories() ); ArtifactVersion v = vr.matchVersion( versions ); artifactVersion = v != null ? v.toString() : null; diff --git a/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java b/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java index d651e1812b..feb3e898f6 100644 --- a/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java +++ b/maven-project/src/main/java/org/apache/maven/DefaultMavenTools.java @@ -36,6 +36,9 @@ import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.manager.WagonManager; +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; +import org.apache.maven.artifact.metadata.ArtifactMetadataSource; +import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; @@ -44,6 +47,7 @@ import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.model.DeploymentRepository; import org.apache.maven.model.Model; import org.apache.maven.model.Repository; @@ -81,6 +85,9 @@ public class DefaultMavenTools @Requirement private WagonManager wagonManager; + @Requirement + private ArtifactMetadataSource artifactMetadataSource; + @Requirement private Logger logger; @@ -98,6 +105,25 @@ public class DefaultMavenTools return artifactFactory.createArtifactWithClassifier(groupId, artifactId, version, type, classifier); } + public Artifact createProjectArtifact( String groupId, String artifactId, String metaVersionId ) + { + return artifactFactory.createProjectArtifact(groupId, artifactId, metaVersionId ); + } + + public List retrieveAvailableVersions(Artifact artifact, + ArtifactRepository localRepository, + List remoteRepositories) + throws ArtifactMetadataRetrievalException + { + return artifactMetadataSource.retrieveAvailableVersions(artifact, localRepository, remoteRepositories); + } + + public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + throws ArtifactMetadataRetrievalException + { + return artifactMetadataSource.retrieve(artifact, localRepository, remoteRepositories); + } + // ---------------------------------------------------------------------------- // Code snagged from ProjectUtils: this will have to be moved somewhere else // but just trying to collect it all in one place right now. diff --git a/maven-project/src/main/java/org/apache/maven/MavenTools.java b/maven-project/src/main/java/org/apache/maven/MavenTools.java index 3499659d56..ca2b7be619 100644 --- a/maven-project/src/main/java/org/apache/maven/MavenTools.java +++ b/maven-project/src/main/java/org/apache/maven/MavenTools.java @@ -24,15 +24,20 @@ import java.util.List; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.InvalidRepositoryException; +import org.apache.maven.artifact.factory.ArtifactFactory; +import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; +import org.apache.maven.artifact.metadata.ResolutionGroup; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; 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.model.DeploymentRepository; import org.apache.maven.model.Model; import org.apache.maven.model.Repository; import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.wagon.events.TransferListener; +import org.codehaus.plexus.component.annotations.Requirement; /** * @author Jason van Zyl @@ -76,6 +81,14 @@ public interface MavenTools Artifact createArtifactWithClassifier(String groupId, String artifactId, String version, String type, String classifier); + Artifact createProjectArtifact( String groupId, String artifactId, String metaVersionId ); + + List retrieveAvailableVersions(Artifact artifact, ArtifactRepository localRepository, List remoteRepositories) + throws ArtifactMetadataRetrievalException; + + ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + throws ArtifactMetadataRetrievalException; + // WagonManager ArtifactRepository getMirrorRepository( ArtifactRepository repository );