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 35710a3087..98b4bfb567 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 @@ -132,11 +132,7 @@ public class DefaultMavenProjectBuilder public MavenProject build( File projectDescriptor, ProjectBuilderConfiguration config ) throws ProjectBuildingException { - MavenProject project = projectWorkspace.getProject( projectDescriptor ); - - if ( project == null ) - { - project = readModelFromLocalPath( "unknown", projectDescriptor, new PomArtifactResolver( + MavenProject project = readModelFromLocalPath( "unknown", projectDescriptor, new PomArtifactResolver( config.getLocalRepository(), repositoryHelper.buildArtifactRepositories( getSuperProject( config, projectDescriptor, true ).getModel() ), artifactResolver ), config ); @@ -152,8 +148,6 @@ public class DefaultMavenProjectBuilder project.setFile( projectDescriptor ); setBuildOutputDirectoryOnParent( project ); - - } return project; } @@ -170,21 +164,11 @@ public class DefaultMavenProjectBuilder return buildFromRepository( artifact, remoteArtifactRepositories, localRepository ); } - public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository ) throws ProjectBuildingException { - MavenProject project = null; - if ( !Artifact.LATEST_VERSION.equals( artifact.getVersion() ) && - !Artifact.RELEASE_VERSION.equals( artifact.getVersion() ) ) - { - project = - projectWorkspace.getProject( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); - } File f = artifact.getFile(); - if ( project == null ) - { repositoryHelper.findModelFromRepository( artifact, remoteArtifactRepositories, localRepository ); ProjectBuilderConfiguration config = @@ -195,10 +179,9 @@ public class DefaultMavenProjectBuilder artifactRepositories.addAll( repositoryHelper.buildArtifactRepositories( getSuperProject( config, artifact.getFile(), false ).getModel() ) ); - project = readModelFromLocalPath( "unknown", artifact.getFile(), new PomArtifactResolver( + MavenProject project = readModelFromLocalPath( "unknown", artifact.getFile(), new PomArtifactResolver( config.getLocalRepository(), artifactRepositories, artifactResolver ), config ); project = buildInternal( project.getModel(), config, artifact.getFile(), project.getParentFile(), false ); - } artifact.setFile( f ); project.setVersion( artifact.getVersion() ); @@ -440,9 +423,6 @@ public class DefaultMavenProjectBuilder externalProfileManager ) ); project.setActiveProfiles( projectProfiles ); - projectWorkspace.storeProjectByCoordinate( project ); - projectWorkspace.storeProjectByFile( project ); - return project; } 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 385291ead4..efd3f23d7a 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 @@ -56,12 +56,7 @@ import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable; import org.codehaus.plexus.util.StringUtils; import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * @author Jason van Zyl @@ -149,6 +144,8 @@ public class MavenMetadataSource return artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion(); } + private HashMap hm = new HashMap(); + private ProjectRelocation retrieveRelocatedProject( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories ) throws ArtifactMetadataRetrievalException @@ -184,45 +181,56 @@ public class MavenMetadataSource } else { - try - { - project = - mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository ); - } - catch ( InvalidProjectModelException e ) - { - handleInvalidOrMissingMavenPOM( artifact, e ); - if ( getLogger().isDebugEnabled() ) + if(hm.containsKey(pomArtifact.getId())) + { + project = hm.get(pomArtifact.getId()); + } + else + { + try { - getLogger().debug( "Reason: " + e.getMessage() ); + project = + mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository ); + hm.put(pomArtifact.getId(), project); - ModelValidationResult validationResult = e.getValidationResult(); - - if ( validationResult != null ) - { - getLogger().debug( "\nValidation Errors:" ); - for ( Iterator i = validationResult.getMessages().iterator(); i.hasNext(); ) - { - getLogger().debug( i.next().toString() ); - } - getLogger().debug( "\n" ); - } - else - { - getLogger().debug( "", e ); - } } + catch ( InvalidProjectModelException e ) + { + handleInvalidOrMissingMavenPOM( artifact, e ); - project = null; - } - catch ( ProjectBuildingException e ) - { - handleInvalidOrMissingMavenPOM( artifact, e ); + if ( getLogger().isDebugEnabled() ) + { + getLogger().debug( "Reason: " + e.getMessage() ); - project = null; + ModelValidationResult validationResult = e.getValidationResult(); + + if ( validationResult != null ) + { + getLogger().debug( "\nValidation Errors:" ); + for ( Iterator i = validationResult.getMessages().iterator(); i.hasNext(); ) + { + getLogger().debug( i.next().toString() ); + } + getLogger().debug( "\n" ); + } + else + { + getLogger().debug( "", e ); + } + } + + project = null; + } + catch ( ProjectBuildingException e ) + { + handleInvalidOrMissingMavenPOM( artifact, e ); + + project = null; + } } + if ( project != null ) { Relocation relocation = null;