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 9c821bc04a..ce339772fa 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 @@ -309,7 +309,16 @@ public class DefaultArtifactResolver ArtifactResolutionResult result; - result = artifactCollector.collect( artifacts, originatingArtifact, managedVersions, localRepository, remoteRepositories, source, filter, listeners, conflictResolvers ); + result = artifactCollector.collect( + artifacts, + originatingArtifact, + managedVersions, + localRepository, + remoteRepositories, + source, + filter, + listeners, + conflictResolvers ); // We have collected all the problems so let's mimic the way the old code worked and just blow up right here. // That's right lets just let it rip right here and send a big incomprehensible blob of text at unsuspecting @@ -391,9 +400,15 @@ public class DefaultArtifactResolver // This is an attempt to get the metadata for the artifacts we are ultimately trying to resolve. // We still - ArtifactResolutionResult result = artifactCollector.collect( artifacts, originatingArtifact, - managedVersions, localRepository, - remoteRepositories, source, filter, listeners ); + ArtifactResolutionResult result = artifactCollector.collect( + artifacts, + originatingArtifact, + managedVersions, + localRepository, + remoteRepositories, + source, + filter, + listeners ); // Let's grab all the repositories that were gleaned. This we should know up front. I'm not sure // what the metadata source is doing. Repositories in POMs are deadly. 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 6e1d84846c..fc8ee41fc2 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 @@ -105,30 +105,35 @@ public class DefaultMavenProjectBuilder public MavenProject build( File projectDescriptor, ProjectBuilderConfiguration config ) throws ProjectBuildingException { - if(projectDescriptor == null) + if ( projectDescriptor == null ) { - throw new IllegalArgumentException("projectDescriptor: null"); + throw new IllegalArgumentException( "projectDescriptor: null" ); } - if(config == null) + if ( config == null ) { - throw new IllegalArgumentException("config: null"); + throw new IllegalArgumentException( "config: null" ); + } + + List artifactRepositories = new ArrayList(); + try + { + artifactRepositories.addAll( repositorySystem.buildArtifactRepositories( projectBuilder.getSuperModel().getRepositories() ) ); + } + catch ( InvalidRepositoryException e ) + { + throw new ProjectBuildingException( "Cannot create repositories from super model.", e.getMessage() ); } - List artifactRepositories = new ArrayList( ); - artifactRepositories.addAll( repositorySystem.buildArtifactRepositories( projectBuilder.getSuperModel() ) ); - if(config.getRemoteRepositories() != null) - { - artifactRepositories.addAll(config.getRemoteRepositories()); - } - - MavenProject project = readModelFromLocalPath( "unknown", - projectDescriptor, - new DefaultPomArtifactResolver( config.getLocalRepository(), - artifactRepositories, repositorySystem ), config ); + if ( config.getRemoteRepositories() != null ) + { + artifactRepositories.addAll( config.getRemoteRepositories() ); + } + + MavenProject project = readModelFromLocalPath( "unknown", projectDescriptor, new DefaultPomArtifactResolver( config.getLocalRepository(), artifactRepositories, repositorySystem ), config ); project.setFile( projectDescriptor ); - + project = buildWithProfiles( project.getModel(), config, projectDescriptor, project.getParentFile(), true ); Build build = project.getBuild(); @@ -176,9 +181,17 @@ public class DefaultMavenProjectBuilder if ( project != null ) { return project; - } + } + List artifactRepositories = new ArrayList( remoteArtifactRepositories ); - artifactRepositories.addAll( repositorySystem.buildArtifactRepositories( projectBuilder.getSuperModel() ) ); + try + { + artifactRepositories.addAll( repositorySystem.buildArtifactRepositories( projectBuilder.getSuperModel().getRepositories() ) ); + } + catch ( InvalidRepositoryException e ) + { + throw new ProjectBuildingException( "Cannot create repositories from super model.", e.getMessage() ); + } File f = (artifact.getFile() != null) ? artifact.getFile() : new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) ); repositorySystem.findModelFromRepository( artifact, artifactRepositories, localRepository ); diff --git a/maven-project/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java b/maven-project/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java index 1288ac5a55..023316fc31 100644 --- a/maven-project/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java +++ b/maven-project/src/main/java/org/apache/maven/repository/LegacyMavenRepositorySystem.java @@ -394,21 +394,6 @@ public class LegacyMavenRepositorySystem } } - public List buildArtifactRepositories( Model model ) - throws ProjectBuildingException - { - try - { - return buildArtifactRepositories( model.getRepositories() ); - } - catch ( InvalidRepositoryException e ) - { - String projectId = safeVersionlessKey( model.getGroupId(), model.getArtifactId() ); - - throw new ProjectBuildingException( projectId, e.getMessage(), e ); - } - } - private List normalizeToArtifactRepositories( List remoteArtifactRepositories, String projectId ) throws ProjectBuildingException { 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 index d9c01858a9..74302e803f 100644 --- a/maven-project/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java +++ b/maven-project/src/main/java/org/apache/maven/repository/MavenRepositorySystem.java @@ -75,15 +75,18 @@ public interface MavenRepositorySystem // Repository creation + // maven model List buildArtifactRepositories( List repositories ) throws InvalidRepositoryException; - ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repo ) + // maven model + ArtifactRepository buildDeploymentArtifactRepository( DeploymentRepository repository ) throws InvalidRepositoryException; - ArtifactRepository buildArtifactRepository( Repository repo ) + // maven model + ArtifactRepository buildArtifactRepository( Repository repository ) throws InvalidRepositoryException; - + ArtifactRepository createLocalRepository( String url, String repositoryId ) throws IOException; @@ -91,9 +94,6 @@ public interface MavenRepositorySystem ArtifactRepository createRepository( String url, String repositoryId, ArtifactRepositoryPolicy snapshotsPolicy, ArtifactRepositoryPolicy releasesPolicy ); - List buildArtifactRepositories( Model model ) - throws ProjectBuildingException; - void setGlobalUpdatePolicy( String policy ); void setGlobalChecksumPolicy( String policy ); 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 79b9e474d9..839093d34b 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 @@ -31,6 +31,7 @@ public class TestProjectBuilder @Requirement(hint="test") private ArtifactResolver artifactResolver; - @Requirement(hint="test") - private MavenRepositorySystem repositorySystem; + // Causing problems + //@Requirement(hint="test") + //private MavenRepositorySystem repositorySystem; }