From 00c302e02158459d7c4042523581acd6a3d31a21 Mon Sep 17 00:00:00 2001 From: Jason van Zyl Date: Mon, 23 Feb 2009 00:04:14 +0000 Subject: [PATCH] o checking in so that oleg and shane can see the changes, there are three failing tests. i'm fixing in the plane and will check in when i land git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@746850 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/plugin/DefaultPluginManager.java | 8 +- .../version/DefaultPluginVersionManager.java | 4 +- .../apache/maven/embedder/MavenEmbedder.java | 6 +- ...DefaultMavenExecutionRequestPopulator.java | 4 +- .../org/apache/maven/RepositorySystem.java | 140 -------------- .../maven/profiles/MavenProfilesBuilder.java | 2 - .../profiles/build/DefaultProfileAdvisor.java | 6 +- .../project/DefaultMavenProjectBuilder.java | 54 ++---- .../project/DefaultPomArtifactResolver.java | 9 +- .../maven/project/DefaultProjectBuilder.java | 13 +- .../apache/maven/project/MavenProject.java | 33 ++-- .../LegacyMavenRepositorySystem.java} | 77 ++++++-- .../repository/MavenRepositorySystem.java | 158 +++++++++++++++ .../maven/project/ProjectClasspathTest.java | 15 +- .../maven/project/TestArtifactResolver.java | 180 ++++-------------- .../maven/project/TestProjectBuilder.java | 19 +- .../project/builder/PomConstructionTest.java | 6 +- .../maven/project/ProjectClasspathTest.xml | 102 ---------- .../canonical/CanonicalProjectBuilderTest.xml | 105 ---------- pom.xml | 1 + 20 files changed, 321 insertions(+), 621 deletions(-) delete mode 100644 maven-project/src/main/java/org/apache/maven/RepositorySystem.java rename maven-project/src/main/java/org/apache/maven/{LegacyRepositorySystem.java => repository/LegacyMavenRepositorySystem.java} (91%) create mode 100644 maven-project/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java delete mode 100644 maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml delete mode 100644 maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml 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 d1cc9b05e7..e1eeec2416 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 @@ -34,7 +34,6 @@ import java.util.Map; import java.util.Set; import org.apache.maven.ArtifactFilterManager; -import org.apache.maven.RepositorySystem; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; @@ -78,6 +77,7 @@ import org.apache.maven.project.path.PathTranslator; import org.apache.maven.realm.MavenRealmManager; import org.apache.maven.realm.RealmManagementException; import org.apache.maven.reporting.MavenReport; +import org.apache.maven.repository.MavenRepositorySystem; import org.apache.maven.shared.model.InterpolatorProperty; import org.apache.maven.shared.model.ModelMarshaller; import org.apache.maven.shared.model.ModelProperty; @@ -137,7 +137,7 @@ public class DefaultPluginManager protected PluginVersionManager pluginVersionManager; @Requirement - protected RepositorySystem repositoryTools; + protected MavenRepositorySystem repositoryTools; @Requirement protected RuntimeInformation runtimeInformation; @@ -1471,7 +1471,7 @@ public class DefaultPluginManager // ---------------------------------------------------------------------- protected void resolveTransitiveDependencies( MavenSession context, - RepositorySystem repositoryTools, + MavenRepositorySystem repositoryTools, String scope, MavenProject project, boolean isAggregator ) @@ -1582,7 +1582,7 @@ public class DefaultPluginManager private void downloadDependencies( MavenProject project, MavenSession context, - RepositorySystem repositoryTools ) + MavenRepositorySystem repositoryTools ) throws ArtifactResolutionException, ArtifactNotFoundException { ArtifactRepository localRepository = context.getLocalRepository(); 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 f43b4af3aa..651839c74f 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 @@ -22,7 +22,6 @@ package org.apache.maven.plugin.version; import java.util.Iterator; import java.util.List; -import org.apache.maven.RepositorySystem; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.metadata.ArtifactMetadataRetrievalException; @@ -40,6 +39,7 @@ import org.apache.maven.plugin.InvalidPluginException; import org.apache.maven.project.MavenProject; import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.repository.MavenRepositorySystem; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.logging.AbstractLogEnabled; @@ -51,7 +51,7 @@ public class DefaultPluginVersionManager implements PluginVersionManager { @Requirement - private RepositorySystem repositoryTools; + private MavenRepositorySystem repositoryTools; @Requirement private MavenProjectBuilder mavenProjectBuilder; diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index 9e77f737ac..ac04bdb508 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -31,7 +31,6 @@ import java.util.Iterator; import java.util.List; import org.apache.maven.Maven; -import org.apache.maven.RepositorySystem; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; @@ -73,6 +72,7 @@ import org.apache.maven.project.MavenProjectBuildingResult; import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.reactor.MavenExecutionException; import org.apache.maven.reactor.MissingModuleException; +import org.apache.maven.repository.MavenRepositorySystem; import org.apache.maven.settings.Settings; import org.apache.maven.settings.SettingsConfigurationException; import org.apache.maven.settings.io.xpp3.SettingsXpp3Reader; @@ -137,7 +137,7 @@ public class MavenEmbedder private MavenXpp3Writer modelWriter; - private RepositorySystem repositoryTools; + private MavenRepositorySystem repositoryTools; private Maven maven; @@ -659,7 +659,7 @@ public class MavenEmbedder pluginRepository = container.lookup( PluginRepository.class ); - repositoryTools = container.lookup( RepositorySystem.class ); + repositoryTools = container.lookup( MavenRepositorySystem.class ); // This is temporary as we can probably cache a single request and use it for default values and // simply cascade values in from requests used for individual executions. diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java index 9290c7e711..446700b3f0 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/execution/DefaultMavenExecutionRequestPopulator.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Properties; import org.apache.maven.Maven; -import org.apache.maven.RepositorySystem; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; @@ -44,6 +43,7 @@ import org.apache.maven.profiles.ProfileManager; import org.apache.maven.profiles.activation.DefaultProfileActivationContext; import org.apache.maven.profiles.activation.ProfileActivationContext; import org.apache.maven.realm.DefaultMavenRealmManager; +import org.apache.maven.repository.MavenRepositorySystem; import org.apache.maven.settings.MavenSettingsBuilder; import org.apache.maven.settings.Mirror; import org.apache.maven.settings.Proxy; @@ -86,7 +86,7 @@ public class DefaultMavenExecutionRequestPopulator private MavenSettingsBuilder settingsBuilder; @Requirement - private RepositorySystem mavenTools; + private MavenRepositorySystem mavenTools; // 2009-02-12 Oleg: this component is defined in maven-core components.xml // because it already has another declared (not generated) component diff --git a/maven-project/src/main/java/org/apache/maven/RepositorySystem.java b/maven-project/src/main/java/org/apache/maven/RepositorySystem.java deleted file mode 100644 index 88a77c3280..0000000000 --- a/maven-project/src/main/java/org/apache/maven/RepositorySystem.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.apache.maven; - -/* - * 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.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.Set; - -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.ArtifactMetadataSource; -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.resolver.ArtifactResolutionResult; -import org.apache.maven.artifact.resolver.ResolutionListener; -import org.apache.maven.artifact.resolver.filter.ArtifactFilter; -import org.apache.maven.artifact.versioning.ArtifactVersion; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.DeploymentRepository; -import org.apache.maven.model.Model; -import org.apache.maven.model.Repository; -import org.apache.maven.project.MavenProject; -import org.apache.maven.project.ProjectBuildingException; -import org.apache.maven.project.artifact.InvalidDependencyVersionException; -import org.apache.maven.wagon.events.TransferListener; -import org.codehaus.plexus.component.annotations.Requirement; - -/** - * @author Jason van Zyl - */ -public interface RepositorySystem -{ - List buildArtifactRepositories( List repositories ) - throws InvalidRepositoryException; - - ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo ) - throws InvalidRepositoryException; - - ArtifactRepository buildArtifactRepository( Repository repo ) - throws InvalidRepositoryException; - - ArtifactRepository createLocalRepository( String url, String repositoryId ) - throws IOException; - - ArtifactRepository createRepository( String url, String repositoryId ); - - ArtifactRepository createRepository( String url, String repositoryId, ArtifactRepositoryPolicy snapshotsPolicy, ArtifactRepositoryPolicy releasesPolicy ); - - void setGlobalUpdatePolicy( String policy ); - - void setGlobalChecksumPolicy( String policy ); - - // Taken from RepositoryHelper - - void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository ) - throws ProjectBuildingException; - - List buildArtifactRepositories( Model model ) - throws ProjectBuildingException; - - // PomArtifactResolver - - void resolve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) - throws ArtifactResolutionException, ArtifactNotFoundException; - - Artifact createArtifact(String groupId, String artifactId, String version, String scope, String type); - - Artifact createArtifactWithClassifier(String groupId, String artifactId, String version, String type, String classifier); - - Artifact createBuildArtifact(String groupId, String artifactId, String version, String packaging ); - - 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; - - public ArtifactResolutionResult resolveTransitively( - Set artifacts, Artifact originatingArtifact, - Map managedVersions, ArtifactRepository localRepository, - List remoteRepositories, - ArtifactFilter filter ) - throws ArtifactResolutionException, ArtifactNotFoundException; - - Set createArtifacts( - List dependencies, String inheritedScope, - ArtifactFilter dependencyFilter, MavenProject project) - throws InvalidDependencyVersionException; - - // WagonManager - - ArtifactRepository getMirrorRepository( ArtifactRepository repository ); - - ArtifactRepository getMirror( ArtifactRepository originalRepository ); - - boolean matchPattern( ArtifactRepository originalRepository, String pattern ); - - boolean isExternalRepo( ArtifactRepository originalRepository ); - - void addMirror( String id, String mirrorOf, String url ); - - void setOnline( boolean online ); - - boolean isOnline(); - - void setInteractive( boolean interactive ); - - void setDownloadMonitor( TransferListener downloadMonitor ); - - void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts ); - - void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey, String passphrase ); - - void addPermissionInfo( String repositoryId, String filePermissions, String directoryPermissions ); -} diff --git a/maven-project/src/main/java/org/apache/maven/profiles/MavenProfilesBuilder.java b/maven-project/src/main/java/org/apache/maven/profiles/MavenProfilesBuilder.java index 125b0b505f..a3825fbbab 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/MavenProfilesBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/MavenProfilesBuilder.java @@ -29,8 +29,6 @@ import java.io.IOException; */ public interface MavenProfilesBuilder { - String ROLE = MavenProfilesBuilder.class.getName(); - ProfilesRoot buildProfiles( File basedir ) throws IOException, XmlPullParserException; } diff --git a/maven-project/src/main/java/org/apache/maven/profiles/build/DefaultProfileAdvisor.java b/maven-project/src/main/java/org/apache/maven/profiles/build/DefaultProfileAdvisor.java index e912238c05..42d01bd74d 100644 --- a/maven-project/src/main/java/org/apache/maven/profiles/build/DefaultProfileAdvisor.java +++ b/maven-project/src/main/java/org/apache/maven/profiles/build/DefaultProfileAdvisor.java @@ -19,7 +19,6 @@ package org.apache.maven.profiles.build; * under the License. */ -import org.apache.maven.RepositorySystem; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; @@ -35,6 +34,7 @@ import org.apache.maven.profiles.activation.ProfileActivationContext; import org.apache.maven.profiles.activation.ProfileActivationException; import org.apache.maven.profiles.injection.ProfileInjector; import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.repository.MavenRepositorySystem; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.component.annotations.Component; @@ -57,10 +57,8 @@ import java.util.List; public class DefaultProfileAdvisor implements ProfileAdvisor, LogEnabled, Contextualizable { - public static final String ROLE_HINT = "default"; - @Requirement - private RepositorySystem mavenTools; + private MavenRepositorySystem mavenTools; @Requirement private MavenProfilesBuilder profilesBuilder; 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 17b4bdd326..50412959be 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 @@ -19,23 +19,20 @@ package org.apache.maven.project; * under the License. */ -import java.io.*; +import java.io.File; +import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.maven.RepositorySystem; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.InvalidRepositoryException; -import org.apache.maven.artifact.factory.ArtifactFactory; -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; -import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.model.Profile; @@ -46,9 +43,10 @@ import org.apache.maven.profiles.activation.ProfileActivationContext; import org.apache.maven.profiles.activation.ProfileActivationException; import org.apache.maven.profiles.build.ProfileAdvisor; import org.apache.maven.project.artifact.InvalidDependencyVersionException; -import org.apache.maven.project.builder.*; +import org.apache.maven.project.builder.PomInterpolatorTag; import org.apache.maven.project.validation.ModelValidationResult; import org.apache.maven.project.validation.ModelValidator; +import org.apache.maven.repository.MavenRepositorySystem; import org.apache.maven.shared.model.InterpolatorProperty; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; @@ -74,22 +72,13 @@ public class DefaultMavenProjectBuilder private ProfileAdvisor profileAdvisor; @Requirement - private RepositorySystem mavenTools; + private MavenRepositorySystem repositorySystem; @Requirement private ProjectBuilder projectBuilder; private Logger logger; - @Requirement - protected ArtifactResolver artifactResolver; - - @Requirement - protected ArtifactMetadataSource artifactMetadataSource; - - @Requirement - private ArtifactFactory artifactFactory; - //DO NOT USE, it is here only for backward compatibility reasons. The existing // maven-assembly-plugin (2.2-beta-1) is accessing it via reflection. @@ -127,7 +116,7 @@ public class DefaultMavenProjectBuilder } List artifactRepositories = new ArrayList( ); - artifactRepositories.addAll( mavenTools.buildArtifactRepositories( projectBuilder.getSuperModel() ) ); + artifactRepositories.addAll( repositorySystem.buildArtifactRepositories( projectBuilder.getSuperModel() ) ); if(config.getRemoteRepositories() != null) { artifactRepositories.addAll(config.getRemoteRepositories()); @@ -136,7 +125,7 @@ public class DefaultMavenProjectBuilder MavenProject project = readModelFromLocalPath( "unknown", projectDescriptor, new DefaultPomArtifactResolver( config.getLocalRepository(), - artifactRepositories, artifactResolver ), config ); + artifactRepositories, repositorySystem ), config ); project.setFile( projectDescriptor ); @@ -189,14 +178,14 @@ public class DefaultMavenProjectBuilder return project; } List artifactRepositories = new ArrayList( remoteArtifactRepositories ); - artifactRepositories.addAll( mavenTools.buildArtifactRepositories( projectBuilder.getSuperModel() ) ); + artifactRepositories.addAll( repositorySystem.buildArtifactRepositories( projectBuilder.getSuperModel() ) ); File f = (artifact.getFile() != null) ? artifact.getFile() : new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) ); - mavenTools.findModelFromRepository( artifact, artifactRepositories, localRepository ); + repositorySystem.findModelFromRepository( artifact, artifactRepositories, localRepository ); ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository ); - project = readModelFromLocalPath( "unknown", artifact.getFile(), new DefaultPomArtifactResolver( config.getLocalRepository(), artifactRepositories, artifactResolver ), config ); + project = readModelFromLocalPath( "unknown", artifact.getFile(), new DefaultPomArtifactResolver( config.getLocalRepository(), artifactRepositories, repositorySystem ), config ); project = buildWithProfiles( project.getModel(), config, artifact.getFile(), project.getParentFile(), false ); artifact.setFile( f ); project.setVersion( artifact.getVersion() ); @@ -221,7 +210,7 @@ public class DefaultMavenProjectBuilder try { - project = new MavenProject( superModel, artifactFactory, mavenTools, this, config ); + project = new MavenProject( superModel, repositorySystem, this, config ); } catch ( InvalidRepositoryException e ) { @@ -230,8 +219,8 @@ public class DefaultMavenProjectBuilder try { - project.setRemoteArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) ); - project.setPluginArtifactRepositories( mavenTools.buildArtifactRepositories( superModel.getRepositories() ) ); + project.setRemoteArtifactRepositories( repositorySystem.buildArtifactRepositories( superModel.getRepositories() ) ); + project.setPluginArtifactRepositories( repositorySystem.buildArtifactRepositories( superModel.getRepositories() ) ); } catch ( InvalidRepositoryException e ) { @@ -250,7 +239,7 @@ public class DefaultMavenProjectBuilder try { - project.setDependencyArtifacts( project.createArtifacts( artifactFactory, null, null ) ); + project.setDependencyArtifacts( repositorySystem.createArtifacts( project.getDependencies(), null, null, project ) ); } catch ( InvalidDependencyVersionException e ) { @@ -265,9 +254,9 @@ public class DefaultMavenProjectBuilder .setLocalRepository( config.getLocalRepository() ) .setRemoteRepostories( project.getRemoteArtifactRepositories() ) .setManagedVersionMap( project.getManagedVersionMap() ) - .setMetadataSource( artifactMetadataSource ); + .setMetadataSource( repositorySystem ); - ArtifactResolutionResult result = artifactResolver.resolve( request ); + ArtifactResolutionResult result = repositorySystem.resolve( request ); project.setArtifacts( result.getArtifacts() ); @@ -323,12 +312,11 @@ public class DefaultMavenProjectBuilder try { - project = new MavenProject( model, artifactFactory, mavenTools, this, config ); + project = new MavenProject( model, repositorySystem, this, config ); validateModel( model, projectDescriptor ); - Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(), - project.getVersion(), project.getPackaging() ); + Artifact projectArtifact = repositorySystem.createBuildArtifact( project.getGroupId(), project.getArtifactId(), project.getVersion(), project.getPackaging() ); project.setArtifact( projectArtifact ); project.setParentFile( parentDescriptor ); @@ -371,11 +359,7 @@ public class DefaultMavenProjectBuilder try { - mavenProject = projectBuilder.buildFromLocalPath( projectDescriptor, - interpolatorProperties, - resolver, - config, - this); + mavenProject = projectBuilder.buildFromLocalPath( projectDescriptor, interpolatorProperties, resolver, config, this ); } catch ( IOException e ) { diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultPomArtifactResolver.java b/maven-project/src/main/java/org/apache/maven/project/DefaultPomArtifactResolver.java index 9fbcb0c409..4d85291004 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultPomArtifactResolver.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultPomArtifactResolver.java @@ -25,6 +25,7 @@ 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.project.PomArtifactResolver; +import org.apache.maven.repository.MavenRepositorySystem; import java.io.File; import java.io.IOException; @@ -49,7 +50,7 @@ public class DefaultPomArtifactResolver /** * Artifact resolver used to resolve artifacts */ - private ArtifactResolver resolver; + private MavenRepositorySystem repositorySystem; /** * Constructor @@ -58,11 +59,11 @@ public class DefaultPomArtifactResolver * @param remoteRepositories remote repositories used in resolving artifacts * @param resolver artifact resolver used to resolve artifacts */ - public DefaultPomArtifactResolver( ArtifactRepository localRepository, List remoteRepositories, ArtifactResolver resolver ) + public DefaultPomArtifactResolver( ArtifactRepository localRepository, List remoteRepositories, MavenRepositorySystem resolver ) { this.localRepository = localRepository; this.remoteRepositories = remoteRepositories; - this.resolver = resolver; + this.repositorySystem = resolver; } /** @@ -79,7 +80,7 @@ public class DefaultPomArtifactResolver try { - resolver.resolve( artifact, remoteRepositories, localRepository ); + repositorySystem.resolve( artifact, localRepository, remoteRepositories ); } catch ( ArtifactResolutionException e ) { diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java index b80bb21925..4e1f9a5f7e 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java @@ -22,7 +22,6 @@ package org.apache.maven.project; import java.io.*; import java.util.*; -import org.apache.maven.RepositorySystem; import org.apache.maven.mercury.PomProcessor; import org.apache.maven.mercury.PomProcessorException; import org.apache.maven.mercury.MavenDomainModel; @@ -37,8 +36,8 @@ import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.project.builder.*; -import org.apache.maven.project.builder.ProjectUri; import org.apache.maven.project.builder.profile.ProfileContext; +import org.apache.maven.repository.MavenRepositorySystem; import org.apache.maven.shared.model.*; import org.apache.maven.shared.model.impl.DefaultModelDataSource; import org.codehaus.plexus.component.annotations.Component; @@ -58,10 +57,7 @@ public class DefaultProjectBuilder implements ProjectBuilder, PomProcessor, LogEnabled { @Requirement - private ArtifactFactory artifactFactory; - - @Requirement - private RepositorySystem mavenTools; + private MavenRepositorySystem repositorySystem; @Requirement List listeners; @@ -314,8 +310,7 @@ public class DefaultProjectBuilder try { MavenProject mavenProject = new MavenProject( convertFromInputStreamToModel(domainModel.getInputStream()), - artifactFactory, - mavenTools, + repositorySystem, mavenProjectBuilder, projectBuilderConfiguration ); @@ -385,7 +380,7 @@ public class DefaultProjectBuilder return domainModels; } - Artifact artifactParent = artifactFactory.createParentArtifact( domainModel.getParentGroupId(), + Artifact artifactParent = repositorySystem.createParentArtifact( domainModel.getParentGroupId(), domainModel.getParentArtifactId(), domainModel.getParentVersion() ); artifactResolver.resolve( artifactParent ); diff --git a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java index 175a741737..9118647eaf 100644 --- a/maven-project/src/main/java/org/apache/maven/project/MavenProject.java +++ b/maven-project/src/main/java/org/apache/maven/project/MavenProject.java @@ -34,7 +34,6 @@ import java.util.Properties; import java.util.Set; import java.util.Stack; -import org.apache.maven.RepositorySystem; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.ArtifactUtils; import org.apache.maven.artifact.DependencyResolutionRequiredException; @@ -75,6 +74,7 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Writer; import org.apache.maven.project.artifact.ActiveProjectArtifact; import org.apache.maven.project.artifact.InvalidDependencyVersionException; import org.apache.maven.project.artifact.MavenMetadataSource; +import org.apache.maven.repository.MavenRepositorySystem; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; @@ -163,12 +163,11 @@ public class MavenProject private Stack previousExecutionProjects = new Stack(); - //!! Components that need to be taken out of here - private ArtifactFactory artifactFactory; - private MavenProjectBuilder mavenProjectBuilder; private ProjectBuilderConfiguration projectBuilderConfiguration; + + private MavenRepositorySystem repositorySystem; // private File parentFile; @@ -213,7 +212,7 @@ public class MavenProject * @param projectBuilderConfiguration * @throws InvalidRepositoryException */ - public MavenProject( Model model, ArtifactFactory artifactFactory, RepositorySystem mavenTools, MavenProjectBuilder mavenProjectBuilder, ProjectBuilderConfiguration projectBuilderConfiguration ) + public MavenProject( Model model, MavenRepositorySystem mavenTools, MavenProjectBuilder mavenProjectBuilder, ProjectBuilderConfiguration projectBuilderConfiguration ) throws InvalidRepositoryException { if(model == null) @@ -221,11 +220,6 @@ public class MavenProject throw new IllegalArgumentException("model: null"); } - if(artifactFactory == null) - { - throw new IllegalArgumentException("artifactFactory: null"); - } - if(mavenTools == null) { throw new IllegalArgumentException("mavenTools: null"); @@ -234,7 +228,7 @@ public class MavenProject setModel( model ); this.mavenProjectBuilder = mavenProjectBuilder; this.projectBuilderConfiguration = projectBuilderConfiguration; - this.artifactFactory = artifactFactory; + this.repositorySystem = mavenTools; originalModel = model; DistributionManagement dm = model.getDistributionManagement(); @@ -1146,7 +1140,7 @@ public class MavenProject return pluginArtifacts; } pluginArtifacts = new HashSet(); - if ( artifactFactory != null ) + if ( repositorySystem != null ) { List plugins = getBuildPlugins(); for ( Iterator i = plugins.iterator(); i.hasNext(); ) @@ -1166,8 +1160,8 @@ public class MavenProject Artifact artifact; try { - artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(), - VersionRange.createFromVersionSpec( version ) ); + artifact = repositorySystem.createPluginArtifact( p.getGroupId(), p.getArtifactId(), + VersionRange.createFromVersionSpec( version ) ); } catch ( InvalidVersionSpecificationException e ) { @@ -1225,7 +1219,7 @@ public class MavenProject Artifact artifact = null; try { - artifact = artifactFactory.createPluginArtifact( p.getGroupId(), p.getArtifactId(), + artifact = repositorySystem.createPluginArtifact( p.getGroupId(), p.getArtifactId(), VersionRange.createFromVersionSpec( version ) ); } catch ( InvalidVersionSpecificationException e ) @@ -1288,8 +1282,7 @@ public class MavenProject try { VersionRange versionRange = VersionRange.createFromVersionSpec( version ); - artifact = - artifactFactory.createExtensionArtifact( ext.getGroupId(), ext.getArtifactId(), versionRange ); + artifact = repositorySystem.createExtensionArtifact( ext.getGroupId(), ext.getArtifactId(), versionRange ); } catch ( InvalidVersionSpecificationException e ) { @@ -1326,7 +1319,7 @@ public class MavenProject if ( parentArtifact == null && model.getParent() != null ) { Parent p = model.getParent(); - parentArtifact = artifactFactory.createParentArtifact( p.getGroupId(), p.getArtifactId(), p.getVersion() ); + parentArtifact = repositorySystem.createParentArtifact( p.getGroupId(), p.getArtifactId(), p.getVersion() ); } return parentArtifact; } @@ -1608,7 +1601,7 @@ public class MavenProject } Map map = null; - if ( artifactFactory != null ) + if ( repositorySystem != null ) { List deps; @@ -1625,7 +1618,7 @@ public class MavenProject { VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() ); - Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), + Artifact artifact = repositorySystem.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), versionRange, d.getType(), d.getClassifier(), d.getScope(), d.isOptional() ); diff --git a/maven-project/src/main/java/org/apache/maven/LegacyRepositorySystem.java b/maven-project/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java similarity index 91% rename from maven-project/src/main/java/org/apache/maven/LegacyRepositorySystem.java rename to maven-project/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java index addb960b15..19887d4b0e 100644 --- a/maven-project/src/main/java/org/apache/maven/LegacyRepositorySystem.java +++ b/maven-project/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java @@ -1,4 +1,4 @@ -package org.apache.maven; +package org.apache.maven.repository; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -46,10 +46,12 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository; 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.ArtifactResolutionRequest; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.model.Dependency; import org.apache.maven.model.DeploymentRepository; import org.apache.maven.model.Model; @@ -72,9 +74,9 @@ import org.codehaus.plexus.util.StringUtils; /** * @author Jason van Zyl */ -@Component(role = RepositorySystem.class) -public class LegacyRepositorySystem - implements RepositorySystem, LogEnabled +@Component(role = MavenRepositorySystem.class) +public class LegacyMavenRepositorySystem + implements MavenRepositorySystem, LogEnabled { @Requirement private ArtifactFactory artifactFactory; @@ -120,6 +122,39 @@ public class LegacyRepositorySystem { return artifactFactory.createProjectArtifact(groupId, artifactId, metaVersionId ); } + + public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, boolean optional ) + { + return artifactFactory.createDependencyArtifact( groupId, artifactId, versionRange, type, classifier, scope ); + } + + public Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, String inheritedScope ) + { + return artifactFactory.createDependencyArtifact( groupId, artifactId, versionRange, type, classifier, scope, inheritedScope ); + } + + public Artifact createExtensionArtifact( String groupId, String artifactId, VersionRange versionRange ) + { + return artifactFactory.createExtensionArtifact( groupId, artifactId, versionRange ); + } + + public Artifact createParentArtifact( String groupId, String artifactId, String version ) + { + return artifactFactory.createParentArtifact( groupId, artifactId, version ); + } + + public Artifact createPluginArtifact( String groupId, String artifactId, VersionRange versionRange ) + { + return artifactFactory.createPluginArtifact( groupId, artifactId, versionRange ); + } + + public Set createArtifacts( List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenProject project ) + throws InvalidDependencyVersionException + { + return MavenMetadataSource.createArtifacts( artifactFactory, dependencies, inheritedScope, dependencyFilter, project ); + } + + // public List retrieveAvailableVersions(Artifact artifact, ArtifactRepository localRepository, @@ -142,18 +177,7 @@ public class LegacyRepositorySystem ArtifactFilter filter ) throws ArtifactResolutionException, ArtifactNotFoundException { - return artifactResolver.resolveTransitively( artifacts, originatingArtifact, localRepository, - remoteRepositories, artifactMetadataSource, filter ); - } - - public Set createArtifacts( - List dependencies, String inheritedScope, - ArtifactFilter dependencyFilter, MavenProject project) - throws InvalidDependencyVersionException - - { - return MavenMetadataSource.createArtifacts(artifactFactory, - dependencies, inheritedScope, dependencyFilter, project); + return artifactResolver.resolveTransitively(artifacts, originatingArtifact, remoteRepositories, localRepository, artifactMetadataSource ); } // ---------------------------------------------------------------------------- @@ -464,7 +488,6 @@ public class LegacyRepositorySystem throws ArtifactResolutionException, ArtifactNotFoundException { File artifactFile = new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) ); - // FIXME: Not sure whether this is just intermediate code but the call belows wrecks havoc on system dependencies artifact.setFile( artifactFile ); artifactResolver.resolve( artifact, remoteRepositories, localRepository ); } @@ -695,6 +718,26 @@ public class LegacyRepositorySystem { serverPermissionsMap.put( repositoryId, permissions ); } + } + + public ArtifactResolutionResult resolve( ArtifactResolutionRequest request ) + { + return artifactResolver.resolve( request ); + } + + // 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 + { + return artifactMetadataSource.retrieveRelocatedArtifact( artifact, localRepository, remoteRepositories ); } // Test for this stuff diff --git a/maven-project/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java b/maven-project/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java new file mode 100644 index 0000000000..d9c01858a9 --- /dev/null +++ b/maven-project/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java @@ -0,0 +1,158 @@ +package org.apache.maven.repository; + +/* + * 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.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.InvalidRepositoryException; +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.ArtifactRepositoryPolicy; +import org.apache.maven.artifact.resolver.ArtifactNotFoundException; +import org.apache.maven.artifact.resolver.ArtifactResolutionException; +import org.apache.maven.artifact.resolver.ArtifactResolutionRequest; +import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.DeploymentRepository; +import org.apache.maven.model.Model; +import org.apache.maven.model.Repository; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.ProjectBuildingException; +import org.apache.maven.project.artifact.InvalidDependencyVersionException; +import org.apache.maven.wagon.events.TransferListener; + +/** + * @author Jason van Zyl + */ +public interface MavenRepositorySystem + extends ArtifactMetadataSource // This needs to be removed +{ + // Artifact creation: This needs to be reduced to fewer, if not one, method. We also need to get rid of the legacy + // VersionRange from the system. + + Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ); + + Artifact createArtifactWithClassifier( String groupId, String artifactId, String version, String type, String classifier ); + + Artifact createBuildArtifact( String groupId, String artifactId, String version, String packaging ); + + Artifact createProjectArtifact( String groupId, String artifactId, String metaVersionId ); + + Artifact createPluginArtifact( String groupId, String artifactId, VersionRange versionRange ); + + Artifact createExtensionArtifact( String groupId, String artifactId, VersionRange versionRange ); + + Artifact createParentArtifact( String groupId, String artifactId, String version ); + + Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, boolean optional ); + + Artifact createDependencyArtifact( String groupId, String artifactId, VersionRange versionRange, String type, String classifier, String scope, String inheritedScope ); + + Set createArtifacts( List dependencies, String inheritedScope, ArtifactFilter dependencyFilter, MavenProject project ) + throws InvalidDependencyVersionException; + + // Repository creation + + List buildArtifactRepositories( List repositories ) + throws InvalidRepositoryException; + + ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo ) + throws InvalidRepositoryException; + + ArtifactRepository buildArtifactRepository( Repository repo ) + throws InvalidRepositoryException; + + ArtifactRepository createLocalRepository( String url, String repositoryId ) + throws IOException; + + ArtifactRepository createRepository( String url, String repositoryId ); + + ArtifactRepository createRepository( String url, String repositoryId, ArtifactRepositoryPolicy snapshotsPolicy, ArtifactRepositoryPolicy releasesPolicy ); + + List buildArtifactRepositories( Model model ) + throws ProjectBuildingException; + + void setGlobalUpdatePolicy( String policy ); + + void setGlobalChecksumPolicy( String policy ); + + // Artifact resolution + + ArtifactResolutionResult resolve( ArtifactResolutionRequest request ); + + void resolve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + throws ArtifactResolutionException, ArtifactNotFoundException; + + ArtifactResolutionResult resolveTransitively( Set artifacts, Artifact originatingArtifact, Map managedVersions, ArtifactRepository localRepository, + List remoteRepositories, ArtifactFilter filter ) + throws ArtifactResolutionException, ArtifactNotFoundException; + + void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository ) + throws ProjectBuildingException; + + // Version retrieval or metadata operations + + ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + throws ArtifactMetadataRetrievalException; + + 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; + + public Artifact retrieveRelocatedArtifact( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) + throws ArtifactMetadataRetrievalException; + + // Mirrors + + ArtifactRepository getMirrorRepository( ArtifactRepository repository ); + + ArtifactRepository getMirror( ArtifactRepository originalRepository ); + + boolean matchPattern( ArtifactRepository originalRepository, String pattern ); + + boolean isExternalRepo( ArtifactRepository originalRepository ); + + void addMirror( String id, String mirrorOf, String url ); + + // Network enablement + + void setOnline( boolean online ); + + boolean isOnline(); + + // This doesn't belong here + void setInteractive( boolean interactive ); + + void setDownloadMonitor( TransferListener downloadMonitor ); + + void addProxy( String protocol, String host, int port, String username, String password, String nonProxyHosts ); + + void addAuthenticationInfo( String repositoryId, String username, String password, String privateKey, String passphrase ); + + void addPermissionInfo( String repositoryId, String filePermissions, String directoryPermissions ); +} diff --git a/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathTest.java b/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathTest.java index c6bb03730f..0f44511d4d 100644 --- a/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/ProjectClasspathTest.java @@ -24,26 +24,15 @@ import java.util.Iterator; import org.apache.maven.artifact.Artifact; -/** - * @todo relocate to maven-artifact in entirety - */ public class ProjectClasspathTest extends AbstractMavenProjectTestCase { private String dir = "projects/scope/"; - + public void testProjectClasspath() throws Exception { File f = getFileForClasspathResource( dir + "project-with-scoped-dependencies.xml" ); - -// assertEquals( TestArtifactResolver.class, getContainer().lookup( ArtifactResolver.ROLE ).getClass() ); - TestProjectBuilder builder = (TestProjectBuilder) getContainer().lookup( MavenProjectBuilder.class, "test" ); - - TestArtifactResolver testArtifactResolver = getContainer().lookup( TestArtifactResolver.class ); - - builder.setArtifactResolver( testArtifactResolver ); - builder.setArtifactMetadataSource( testArtifactResolver.source() ); MavenProject project = getProjectWithDependencies( f ); @@ -63,6 +52,8 @@ public class ProjectClasspathTest artifact = getArtifact( project, "maven-test-test", "scope-test" ); assertNull( "Check no test dependencies are transitive", artifact ); artifact = getArtifact( project, "maven-test-test", "scope-compile" ); + System.out.println( "a = " + artifact ); + System.out.println( "b = " + artifact.getScope() ); assertEquals( "Check scope", "test", artifact.getScope() ); artifact = getArtifact( project, "maven-test-test", "scope-default" ); assertEquals( "Check scope", "test", artifact.getScope() ); diff --git a/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java b/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java index 3fc2c7b069..5f8537bd60 100644 --- a/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java +++ b/maven-project/src/test/java/org/apache/maven/project/TestArtifactResolver.java @@ -19,63 +19,60 @@ package org.apache.maven.project; * under the License. */ +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + 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.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; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolutionResult; +import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.artifact.resolver.DefaultArtifactResolver; import org.apache.maven.artifact.resolver.filter.ArtifactFilter; import org.apache.maven.artifact.versioning.ArtifactVersion; import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException; import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.model.*; +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; -import org.codehaus.plexus.PlexusConstants; +import org.apache.maven.repository.MavenRepositorySystem; import org.codehaus.plexus.PlexusContainer; -import org.codehaus.plexus.context.Context; -import org.codehaus.plexus.context.ContextException; -import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.*; - +@Component(role=ArtifactResolver.class, hint="test") public class TestArtifactResolver extends DefaultArtifactResolver - implements Contextualizable { - public static final String ROLE = TestArtifactResolver.class.getName(); - - private ArtifactRepositoryFactory repositoryFactory; - + @Requirement private PlexusContainer container; + @Requirement + private MavenRepositorySystem repositorySystem; + static class Source implements ArtifactMetadataSource { - private ArtifactFactory artifactFactory; - - private final ArtifactRepositoryFactory repositoryFactory; - private final PlexusContainer container; - public Source( ArtifactFactory artifactFactory, ArtifactRepositoryFactory repositoryFactory, - PlexusContainer container ) + private MavenRepositorySystem repositorySystem; + + public Source( MavenRepositorySystem repositorySystem, PlexusContainer container ) { - this.artifactFactory = artifactFactory; - this.repositoryFactory = repositoryFactory; + this.repositorySystem = repositorySystem; this.container = container; } @@ -129,7 +126,7 @@ public class TestArtifactResolver try { artifactRepositories = - ProjectUtils.buildArtifactRepositories( model.getRepositories(), repositoryFactory, container ); + repositorySystem.buildArtifactRepositories( model.getRepositories() ); } catch ( InvalidRepositoryException e ) { @@ -174,10 +171,14 @@ public class TestArtifactResolver } VersionRange versionRange = VersionRange.createFromVersionSpec( d.getVersion() ); - Artifact artifact = artifactFactory.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), - versionRange, d.getType(), - d.getClassifier(), scope, - inheritedScope ); + + Artifact artifact = repositorySystem.createDependencyArtifact( d.getGroupId(), + d.getArtifactId(), + versionRange, + d.getType(), + d.getClassifier(), + scope, + inheritedScope ); if ( artifact != null ) { projectArtifacts.add( artifact ); @@ -198,7 +199,7 @@ public class TestArtifactResolver public Source source() { - return new Source( artifactFactory, repositoryFactory, container ); + return new Source( repositorySystem, container ); } /** @@ -218,7 +219,7 @@ public class TestArtifactResolver throws ArtifactResolutionException, ArtifactNotFoundException { return super.resolveTransitively( artifacts, originatingArtifact, localRepository, remoteRepositories, - new Source( artifactFactory, repositoryFactory, container ), filter ); + new Source( repositorySystem, container ), filter ); } @Override @@ -228,117 +229,6 @@ public class TestArtifactResolver throws ArtifactResolutionException, ArtifactNotFoundException { return super.resolveTransitively( artifacts, originatingArtifact, remoteRepositories, localRepository, - new Source( artifactFactory, repositoryFactory, container ) ); + new Source( repositorySystem, container ) ); } - - public void contextualize( Context context ) - throws ContextException - { - container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY ); - } - - public static final class ProjectUtils - { - private ProjectUtils() - { - } - - public static List buildArtifactRepositories( List repositories, - ArtifactRepositoryFactory artifactRepositoryFactory, - PlexusContainer container ) - throws InvalidRepositoryException - { - - List repos = new ArrayList(); - - for ( Iterator i = repositories.iterator(); i.hasNext(); ) - { - Repository mavenRepo = (Repository) i.next(); - - ArtifactRepository artifactRepo = - buildArtifactRepository( mavenRepo, artifactRepositoryFactory, container ); - - if ( !repos.contains( artifactRepo ) ) - { - repos.add( artifactRepo ); - } - } - return repos; - } - - public static ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo, - ArtifactRepositoryFactory artifactRepositoryFactory, - PlexusContainer container ) - throws InvalidRepositoryException - { - if ( repo != null ) - { - String id = repo.getId(); - String url = repo.getUrl(); - - return artifactRepositoryFactory.createDeploymentArtifactRepository( id, url, repo.getLayout(), - repo.isUniqueVersion() ); - } - else - { - return null; - } - } - - public static ArtifactRepository buildArtifactRepository( Repository repo, - ArtifactRepositoryFactory artifactRepositoryFactory, - PlexusContainer container ) - throws InvalidRepositoryException - { - if ( repo != null ) - { - String id = repo.getId(); - String url = repo.getUrl(); - - if ( id == null || id.trim().length() < 1 ) - { - throw new MissingRepositoryElementException( "Repository ID must not be empty (URL is: " + url + ")." ); - } - - if ( url == null || url.trim().length() < 1 ) - { - throw new MissingRepositoryElementException( "Repository URL must not be empty (ID is: " + id + ").", id ); - } - - ArtifactRepositoryPolicy snapshots = buildArtifactRepositoryPolicy( repo.getSnapshots() ); - ArtifactRepositoryPolicy releases = buildArtifactRepositoryPolicy( repo.getReleases() ); - - return artifactRepositoryFactory.createArtifactRepository( id, url, repo.getLayout(), snapshots, releases ); - } - else - { - return null; - } - } - - private static ArtifactRepositoryPolicy buildArtifactRepositoryPolicy( RepositoryPolicy policy ) - { - boolean enabled = true; - String updatePolicy = null; - String checksumPolicy = null; - - if ( policy != null ) - { - enabled = policy.isEnabled(); - if ( policy.getUpdatePolicy() != null ) - { - updatePolicy = policy.getUpdatePolicy(); - } - if ( policy.getChecksumPolicy() != null ) - { - checksumPolicy = policy.getChecksumPolicy(); - } - } - - return new ArtifactRepositoryPolicy( enabled, updatePolicy, checksumPolicy ); - } - - } - - } \ No newline at end of file diff --git a/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java b/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java index 19fe78fa1c..0fff9a6e9f 100644 --- a/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java +++ b/maven-project/src/test/java/org/apache/maven/project/TestProjectBuilder.java @@ -19,19 +19,14 @@ package org.apache.maven.project; * under the License. */ -import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.resolver.ArtifactResolver; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; -public class TestProjectBuilder extends DefaultMavenProjectBuilder +@Component(role=MavenProjectBuilder.class,hint="test") +public class TestProjectBuilder + extends DefaultMavenProjectBuilder { - - public void setArtifactResolver( ArtifactResolver resolver ) - { - artifactResolver = resolver; - } - - public void setArtifactMetadataSource( ArtifactMetadataSource metadataSource ) - { - artifactMetadataSource = metadataSource; - } + @Requirement(hint="test") + private ArtifactResolver artifactResolver; } diff --git a/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java b/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java index 10726e9312..45b83bc39d 100644 --- a/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java @@ -24,7 +24,6 @@ import java.io.IOException; import java.io.FileInputStream; import java.util.*; -import org.apache.maven.RepositorySystem; import org.apache.maven.profiles.DefaultProfileManager; import org.apache.maven.profiles.activation.DefaultProfileActivationContext; import org.apache.maven.profiles.activation.ProfileActivationContext; @@ -35,6 +34,7 @@ import org.apache.maven.artifact.repository.DefaultArtifactRepository; import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout; import org.apache.maven.project.harness.PomTestWrapper; import org.apache.maven.project.*; +import org.apache.maven.repository.MavenRepositorySystem; import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.util.xml.pull.XmlPullParserException; @@ -52,7 +52,7 @@ public class PomConstructionTest private MavenProjectBuilder mavenProjectBuilder; - private RepositorySystem mavenTools; + private MavenRepositorySystem mavenTools; private PomArtifactResolver pomArtifactResolver; @@ -67,7 +67,7 @@ public class PomConstructionTest testMixinDirectory = new File( getBasedir(), BASE_MIXIN_DIR ); mavenProjectBuilder = lookup( MavenProjectBuilder.class ); projectBuilder = lookup( ProjectBuilder.class ); - mavenTools = lookup( RepositorySystem.class ); + mavenTools = lookup( MavenRepositorySystem.class ); pomArtifactResolver = new PomArtifactResolver() { diff --git a/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml b/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml deleted file mode 100644 index 9196b8a033..0000000000 --- a/maven-project/src/test/resources/org/apache/maven/project/ProjectClasspathTest.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - org.apache.maven.profiles.injection.ProfileInjector - test - org.apache.maven.project.injection.TestProfileInjector - - - org.apache.maven.profiles.build.ProfileAdvisor - default - org.apache.maven.profiles.build.DefaultProfileAdvisor - - - org.apache.maven.RepositorySystem - - - org.apache.maven.profiles.MavenProfilesBuilder - - - org.apache.maven.profiles.injection.ProfileInjector - test - - - - - org.apache.maven.project.TestArtifactResolver - org.apache.maven.project.TestArtifactResolver - - - org.apache.maven.artifact.factory.ArtifactFactory - - - org.apache.maven.artifact.repository.ArtifactRepositoryFactory - - - org.apache.maven.artifact.resolver.ArtifactCollector - - - - - org.apache.maven.project.ProjectBuilder - default - org.apache.maven.project.DefaultProjectBuilder - - - org.apache.maven.artifact.factory.ArtifactFactory - - - org.apache.maven.RepositorySystem - - - - - org.apache.maven.project.MavenProjectBuilder - test - org.apache.maven.project.TestProjectBuilder - - - org.apache.maven.project.ProjectBuilder - - - org.apache.maven.profiles.build.ProfileAdvisor - default - - - org.apache.maven.profiles.MavenProfilesBuilder - - - org.apache.maven.project.validation.ModelValidator - - - org.apache.maven.artifact.factory.ArtifactFactory - - - org.apache.maven.artifact.resolver.ArtifactResolver - - - org.apache.maven.RepositorySystem - - - - - diff --git a/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml b/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml deleted file mode 100644 index b0128ec45f..0000000000 --- a/maven-project/src/test/resources/org/apache/maven/project/canonical/CanonicalProjectBuilderTest.xml +++ /dev/null @@ -1,105 +0,0 @@ - - - - - - org.apache.maven.profiles.injection.ProfileInjector - test - org.apache.maven.project.injection.TestProfileInjector - - - org.apache.maven.project.TestArtifactResolver - org.apache.maven.project.TestArtifactResolver - - - org.apache.maven.artifact.manager.WagonManager - - - org.apache.maven.artifact.factory.ArtifactFactory - - - org.apache.maven.artifact.repository.ArtifactRepositoryFactory - - - org.apache.maven.artifact.resolver.ArtifactCollector - - - - - org.apache.maven.profiles.build.ProfileAdvisor - default - org.apache.maven.profiles.build.DefaultProfileAdvisor - - - org.apache.maven.RepositorySystem - - - org.apache.maven.profiles.MavenProfilesBuilder - - - org.apache.maven.profiles.injection.ProfileInjector - test - - - - - org.apache.maven.project.ProjectBuilder - default - org.apache.maven.project.DefaultProjectBuilder - - - org.apache.maven.artifact.factory.ArtifactFactory - - - org.apache.maven.RepositorySystem - - - - - org.apache.maven.project.MavenProjectBuilder - test - org.apache.maven.project.TestProjectBuilder - - - org.apache.maven.project.ProjectBuilder - - - org.apache.maven.profiles.build.ProfileAdvisor - default - - - org.apache.maven.profiles.MavenProfilesBuilder - - - org.apache.maven.project.validation.ModelValidator - - - org.apache.maven.artifact.factory.ArtifactFactory - - - org.apache.maven.artifact.resolver.ArtifactResolver - - - org.apache.maven.RepositorySystem - - - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml index 7011bb78d7..0ba28c7a79 100644 --- a/pom.xml +++ b/pom.xml @@ -157,6 +157,7 @@ under the License. generate-metadata + generate-test-metadata