From 5678f1719884c253f331d688d11274c43d790e3d Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Fri, 6 Mar 2009 18:57:41 +0000 Subject: [PATCH] o nuke another big chunk of the old code, looking for available versions is used internally and once all the methods are shed we'll supply a pure metadata resolution for clients, like IDEs, that need to nicely show versions. we'll also provide a graph too so people aren't going to have to do all the extra crap to get decent information. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@751036 13f79535-47bb-0310-9956-ffa450edef68 --- .../resolver/DefaultArtifactResolver.java | 20 +++++++ .../maven/plugin/DefaultPluginManager.java | 15 +++-- .../project/DefaultMavenProjectBuilder.java | 3 +- .../project/artifact/MavenMetadataSource.java | 59 ------------------- .../LegacyMavenRepositorySystem.java | 15 ----- .../repository/MavenRepositorySystem.java | 12 +--- 6 files changed, 33 insertions(+), 91 deletions(-) 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 4c50e8789a..4aa8eca016 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 @@ -39,8 +39,10 @@ import org.apache.maven.artifact.transform.ArtifactTransformationManager; import org.apache.maven.wagon.ResourceDoesNotExistException; import org.apache.maven.wagon.TransferFailedException; import org.apache.maven.wagon.events.TransferListener; +import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.component.repository.exception.ComponentLookupException; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.FileUtils; @@ -76,6 +78,12 @@ public class DefaultArtifactResolver @Requirement private ResolutionErrorHandler resolutionErrorHandler; + @Requirement + private PlexusContainer container; + + //@Requirement + private ArtifactMetadataSource metadataSource; + // ---------------------------------------------------------------------- // Implementation // ---------------------------------------------------------------------- @@ -350,6 +358,18 @@ public class DefaultArtifactResolver List listeners = request.getListeners(); ArtifactFilter filter = request.getFilter(); + if ( source == null ) + { + try + { + source = container.lookup( ArtifactMetadataSource.class ); + } + catch ( ComponentLookupException e ) + { + // Won't happen + } + } + if ( listeners == null ) { listeners = new ArrayList(); diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 7149461e8e..d27ccdee33 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -404,8 +404,13 @@ public class DefaultPluginManager // followed by the plugin's default artifact set dependencies.addAll( resolutionGroup.getArtifacts() ); - ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact( pluginArtifact ).setArtifactDependencies( dependencies ).setLocalRepository( localRepository ) - .setRemoteRepostories( project.getRemoteArtifactRepositories() ).setManagedVersionMap( pluginManagedDependencies ).setFilter( filter ).setMetadataSource( repositorySystem ); + ArtifactResolutionRequest request = new ArtifactResolutionRequest() + .setArtifact( pluginArtifact ) + .setArtifactDependencies( dependencies ) + .setLocalRepository( localRepository ) + .setRemoteRepostories( project.getRemoteArtifactRepositories() ) + .setManagedVersionMap( pluginManagedDependencies ) + .setFilter( filter ); ArtifactResolutionResult result = repositorySystem.resolve( request ); resolutionErrorHandler.throwErrors( request, result ); @@ -1348,8 +1353,10 @@ public class DefaultPluginManager ArtifactFilter filter = new ScopeArtifactFilter( scope ); ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact( artifact ).setResolveRoot( false ).setArtifactDependencies( project.getDependencyArtifacts() ) - .setLocalRepository( context.getLocalRepository() ).setRemoteRepostories( project.getRemoteArtifactRepositories() ).setManagedVersionMap( project.getManagedVersionMap() ) - .setFilter( filter ).setMetadataSource( repositorySystem ); + .setLocalRepository( context.getLocalRepository() ) + .setRemoteRepostories( project.getRemoteArtifactRepositories() ) + .setManagedVersionMap( project.getManagedVersionMap() ) + .setFilter( filter ); ArtifactResolutionResult result = repositorySystem.resolve( request ); diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 6fdd164768..954c45ef7d 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -260,8 +260,7 @@ public class DefaultMavenProjectBuilder ArtifactResolutionRequest request = new ArtifactResolutionRequest().setArtifact( pomArtifact ).setArtifactDependencies( project.getDependencyArtifacts() ) .setLocalRepository( configuration.getLocalRepository() ) .setRemoteRepostories( project.getRemoteArtifactRepositories() ) - .setManagedVersionMap( project.getManagedVersionMap() ) - .setMetadataSource( repositorySystem ); + .setManagedVersionMap( project.getManagedVersionMap() ); ArtifactResolutionResult result = repositorySystem.resolve( request ); diff --git a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java index 82eed72366..298d910b19 100644 --- a/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java +++ b/maven-project/src/main/java/org/apache/maven/project/artifact/MavenMetadataSource.java @@ -388,65 +388,6 @@ public class MavenMetadataSource } } - /* - private List aggregateRepositoryLists( List remoteRepositories, List remoteArtifactRepositories ) - throws ArtifactMetadataRetrievalException - { - if ( superProject == null ) - { - try - { - superProject = mavenProjectBuilder.buildStandaloneSuperProject( new DefaultProjectBuilderConfiguration() ); - } - catch ( ProjectBuildingException e ) - { - throw new ArtifactMetadataRetrievalException( - "Unable to parse the Maven built-in model: " + e.getMessage(), e ); - } - } - - List repositories = new ArrayList(); - - repositories.addAll( remoteRepositories ); - - // ensure that these are defined - for ( Iterator it = superProject.getRemoteArtifactRepositories().iterator(); it.hasNext(); ) - { - ArtifactRepository superRepo = (ArtifactRepository) it.next(); - - for ( Iterator aggregatedIterator = repositories.iterator(); aggregatedIterator.hasNext(); ) - { - ArtifactRepository repo = (ArtifactRepository) aggregatedIterator.next(); - - // if the repository exists in the list and was introduced by another POM's super-pom, - // remove it...the repository definitions from the super-POM should only be at the end of - // the list. - // if the repository has been redefined, leave it. - if ( repo.getId().equals( superRepo.getId() ) && repo.getUrl().equals( superRepo.getUrl() ) ) - { - aggregatedIterator.remove(); - } - } - } - - if ( remoteArtifactRepositories != null ) - { - // this list should contain the super-POM repositories, so we don't have to explicitly add them back. - for ( Iterator it = remoteArtifactRepositories.iterator(); it.hasNext(); ) - { - ArtifactRepository repository = (ArtifactRepository) it.next(); - - if ( !repositories.contains( repository ) ) - { - repositories.add( repository ); - } - } - } - - return repositories; - } - */ - public List retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException diff --git a/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java b/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java index 1cc5f83447..005d7422be 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java @@ -277,12 +277,6 @@ public class LegacyMavenRepositorySystem return projectArtifacts; } - 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 { @@ -468,15 +462,6 @@ public class LegacyMavenRepositorySystem } } - // These two methods are here so that the ArtifactMetadataSource is implemented so that I can pass this into an ArtifactResolutionRequest. - // Intermediate measure before separating the RepositorySystem out into its own module. - - public List retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository ) - throws ArtifactMetadataRetrievalException - { - return artifactMetadataSource.retrieveAvailableVersionsFromDeploymentRepository( artifact, localRepository, remoteRepository ); - } - public Artifact retrieveRelocatedArtifact( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException { diff --git a/maven-repository/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java b/maven-repository/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java index 8acbf3268d..16a2df531f 100644 --- a/maven-repository/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java +++ b/maven-repository/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java @@ -39,7 +39,6 @@ import org.apache.maven.wagon.events.TransferListener; * @author Jason van Zyl */ public interface MavenRepositorySystem - extends ArtifactMetadataSource // This needs to be removed and it's here because it's passed into the resolver. not sure why we didn't just inject the metadata source. { // Artifact creation: This needs to be reduced to fewer, if not one, method. @@ -80,16 +79,7 @@ public interface MavenRepositorySystem //MetadataResolutionResult resolveMetadata( MetadataResolutionRequest request ); ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) - throws ArtifactMetadataRetrievalException; - - // Retrieving available versions is a function of what repositories that you pass in. If you want local and remote versions then you pass - // in both those repositories. We don't need two methods here. - List retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) - throws ArtifactMetadataRetrievalException; - - // These are only showing up in tests, not called from anywhere else in the core - public List retrieveAvailableVersionsFromDeploymentRepository( Artifact artifact, ArtifactRepository localRepository, ArtifactRepository remoteRepository ) - throws ArtifactMetadataRetrievalException; + throws ArtifactMetadataRetrievalException; // Relocated artifacts are stupid. If you you want to move your shit then too bad. You have to support all your users and leave your stuff // there. This is just so problematic because it makes Maven folk responsible and makes the system complicated.