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 391ab0100a..546b8670ca 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 @@ -43,6 +43,7 @@ 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.ResolutionErrorHandler; import org.apache.maven.model.Build; import org.apache.maven.model.Model; import org.apache.maven.model.Profile; @@ -90,6 +91,9 @@ import org.codehaus.plexus.util.xml.pull.XmlSerializer; public class DefaultMavenProjectBuilder implements MavenProjectBuilder { + @Requirement + private Logger logger; + @Requirement private ModelValidator validator; @@ -101,9 +105,9 @@ public class DefaultMavenProjectBuilder @Requirement List listeners; - + @Requirement - private Logger logger; + private ResolutionErrorHandler resolutionErrorHandler; //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. @@ -172,32 +176,25 @@ public class DefaultMavenProjectBuilder return project; } - File f = ( artifact.getFile() != null ) ? artifact.getFile() : new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) ); - + ArtifactResolutionRequest request = new ArtifactResolutionRequest( artifact, localRepository, remoteRepositories ); + ArtifactResolutionResult result = repositorySystem.resolve( request ); + try { - repositorySystem.findModelFromRepository( artifact, remoteRepositories, localRepository ); + resolutionErrorHandler.throwErrors( request, result ); } catch ( ArtifactResolutionException e ) { throw new ProjectBuildingException( artifact.getId(), "Error resolving project artifact.", e ); } - catch ( ArtifactNotFoundException e ) - { - throw new ProjectBuildingException( artifact.getId(), "Error finding project artifact.", e ); - } - catch ( InvalidRepositoryException e ) - { - throw new ProjectBuildingException( artifact.getId(), "Error with repository specified in project.", e ); - } - + ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration() .setLocalRepository( localRepository ) .setRemoteRepositories( remoteRepositories ); project = readModelFromLocalPath( "unknown", artifact.getFile(), config.getLocalRepository(), remoteRepositories, config ); project = buildWithProfiles( project.getModel(), config, artifact.getFile(), project.getParentFile() ); - artifact.setFile( f ); + artifact.setFile( artifact.getFile() ); project.setVersion( artifact.getVersion() ); hm.put( artifact.getId(), project ); @@ -424,15 +421,9 @@ public class DefaultMavenProjectBuilder } - private MavenProject readModelFromLocalPath( String projectId, File projectDescriptor, ArtifactRepository localRepository, List remoteRepositories, - ProjectBuilderConfiguration config ) + private MavenProject readModelFromLocalPath( String projectId, File pomFile, ArtifactRepository localRepository, List remoteRepositories, ProjectBuilderConfiguration config ) throws ProjectBuildingException { - if ( projectDescriptor == null ) - { - throw new IllegalArgumentException( "projectDescriptor: null, Project Id =" + projectId ); - } - List interpolatorProperties = new ArrayList(); interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( config.getExecutionProperties(), PomInterpolatorTag.EXECUTION_PROPERTIES.name() ) ); @@ -449,11 +440,11 @@ public class DefaultMavenProjectBuilder try { - mavenProject = buildFromLocalPath( projectDescriptor, interpolatorProperties, localRepository, remoteRepositories, config, this ); + mavenProject = buildFromLocalPath( pomFile, interpolatorProperties, localRepository, remoteRepositories, config, this ); } catch ( IOException e ) { - throw new ProjectBuildingException( projectId, "File = " + projectDescriptor.getAbsolutePath(), e ); + throw new ProjectBuildingException( projectId, "File = " + pomFile.getAbsolutePath(), e ); } return mavenProject; @@ -649,7 +640,6 @@ public class DefaultMavenProjectBuilder private static Model convertFromInputStreamToModel( InputStream inputStream ) throws IOException { - try { return new MavenXpp3Reader().read( ReaderFactory.newXmlReader( inputStream ) ); 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 0f29622720..3f24f43c39 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 @@ -70,8 +70,7 @@ public class TestArtifactResolver this.container = container; } - public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, - List remoteRepositories ) + public ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException { Model model = null; @@ -116,17 +115,7 @@ public class TestArtifactResolver throw new ArtifactMetadataRetrievalException( e ); } - List artifactRepositories; - try - { - artifactRepositories = repositorySystem.buildArtifactRepositories( model.getRepositories() ); - } - catch ( InvalidRepositoryException e ) - { - throw new ArtifactMetadataRetrievalException( e ); - } - - return new ResolutionGroup( artifact, artifacts, artifactRepositories ); + return new ResolutionGroup( artifact, artifacts, remoteRepositories ); } public List retrieveAvailableVersions( Artifact artifact, ArtifactRepository localRepository, @@ -163,13 +152,7 @@ public class TestArtifactResolver d.setScope( scope ); } - Artifact artifact = repositorySystem.createDependencyArtifact( d.getGroupId(), - d.getArtifactId(), - d.getVersion(), - d.getType(), - d.getClassifier(), - scope, - inheritedScope ); + Artifact artifact = repositorySystem.createDependencyArtifact( d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getType(), d.getClassifier(), scope, inheritedScope ); if ( artifact != null ) { projectArtifacts.add( artifact ); diff --git a/maven-project/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java b/maven-project/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java index 492dd496e3..ac9a09ed39 100644 --- a/maven-project/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java +++ b/maven-project/src/test/java/org/apache/maven/project/TestMavenRepositorySystem.java @@ -71,16 +71,6 @@ public class TestMavenRepositorySystem throw new ArtifactMetadataRetrievalException( ee ); } - List artifactRepositories; - try - { - artifactRepositories = buildArtifactRepositories( model.getRepositories() ); - } - catch ( InvalidRepositoryException e ) - { - throw new ArtifactMetadataRetrievalException( e ); - } - - return new ResolutionGroup( artifact, artifacts, artifactRepositories ); + return new ResolutionGroup( artifact, artifacts, remoteRepositories ); } } 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 b66a8a9bfa..80955f9947 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 @@ -26,7 +26,6 @@ import java.util.Map; import java.util.Set; 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.manager.WagonManager; @@ -37,8 +36,6 @@ 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.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; @@ -97,8 +94,6 @@ public class LegacyMavenRepositorySystem @Requirement private Logger logger; - private boolean interactive = true; - private TransferListener downloadMonitor; private Map proxies = new HashMap(); @@ -107,8 +102,6 @@ public class LegacyMavenRepositorySystem private Map serverPermissionsMap = new HashMap(); - private static HashMap cache = new HashMap(); - // Artifact Creation public Artifact createArtifact( String groupId, String artifactId, String version, String scope, String type ) @@ -298,29 +291,6 @@ public class LegacyMavenRepositorySystem 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. - // ---------------------------------------------------------------------------- - - public List buildArtifactRepositories( List repositories ) - throws InvalidRepositoryException - { - List repos = new ArrayList(); - - for ( Repository mavenRepo : repositories ) - { - ArtifactRepository artifactRepo = buildArtifactRepository( mavenRepo ); - - if ( !repos.contains( artifactRepo ) ) - { - repos.add( artifactRepo ); - } - } - - return repos; - } - public ArtifactRepository buildArtifactRepository( Repository repo ) throws InvalidRepositoryException { @@ -444,57 +414,6 @@ public class LegacyMavenRepositorySystem artifactRepositoryFactory.setGlobalChecksumPolicy( policy ); } - // Taken from RepositoryHelper - - public void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository ) - throws InvalidRepositoryException, ArtifactResolutionException, ArtifactNotFoundException - { - if ( cache.containsKey( artifact.getId() ) ) - { - artifact.setFile( cache.get( artifact.getId() ).getFile() ); - } - - // if the artifact is not a POM, we need to construct a POM artifact based on the artifact parameter given. - /* - if ( "pom".equals( artifact.getType() ) ) - { - projectArtifact = artifact; - } - else - { - logger.debug( "Attempting to build MavenProject instance for Artifact (" + artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion() + ") of type: " - + artifact.getType() + "; constructing POM artifact instead." ); - - projectArtifact = artifactFactory.createProjectArtifact( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(), artifact.getScope() ); - } - */ - - ArtifactResolutionRequest request = new ArtifactResolutionRequest( artifact, localRepository, remoteArtifactRepositories ); - ArtifactResolutionResult result = resolve( request ); - resolutionErrorHandler.throwErrors( request, result ); - - cache.put( artifact.getId(), artifact ); - } - - private String safeVersionlessKey( String groupId, String artifactId ) - { - String gid = groupId; - - if ( StringUtils.isEmpty( gid ) ) - { - gid = "unknown"; - } - - String aid = artifactId; - - if ( StringUtils.isEmpty( aid ) ) - { - aid = "unknown"; - } - - return ArtifactUtils.versionlessKey( gid, aid ); - } - public ArtifactResolutionResult resolve( ArtifactResolutionRequest request ) { return artifactResolver.resolve( request ); @@ -510,11 +429,6 @@ public class LegacyMavenRepositorySystem return artifactResolver.isOnline(); } - public void setInteractive( boolean interactive ) - { - this.interactive = interactive; - } - public void setDownloadMonitor( TransferListener downloadMonitor ) { this.downloadMonitor = downloadMonitor; @@ -593,11 +507,6 @@ public class LegacyMavenRepositorySystem mirrorBuilder.addMirror( id, mirrorOf, url ); } - public ArtifactRepository getMirror( ArtifactRepository repository ) - { - return mirrorBuilder.getMirror( repository ); - } - public List getMirrors( List repositories ) { return mirrorBuilder.getMirrors( repositories ); 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 edac83f5ee..3ca81e23b7 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 @@ -66,10 +66,6 @@ public interface MavenRepositorySystem // Repository creation - // maven model - List buildArtifactRepositories( List repositories ) - throws InvalidRepositoryException; - // maven model ArtifactRepository buildArtifactRepository( Repository repository ) throws InvalidRepositoryException; @@ -91,9 +87,6 @@ public interface MavenRepositorySystem // Metadata - void findModelFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository ) - throws InvalidRepositoryException, ArtifactResolutionException, ArtifactNotFoundException; - ResolutionGroup retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException; @@ -113,9 +106,6 @@ public interface MavenRepositorySystem 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 ); @@ -127,9 +117,6 @@ public interface MavenRepositorySystem // Mirrors void addMirror( String id, String mirrorOf, String url ); - - ArtifactRepository getMirror( ArtifactRepository repository ); - - List getMirrors( List repositories ); - + + List getMirrors( List repositories ); }