mirror of https://github.com/apache/maven.git
cache POMs within the reactor
git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163571 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
38add00ed4
commit
dda9fa50fb
|
@ -130,22 +130,7 @@ public class DefaultMaven
|
|||
|
||||
try
|
||||
{
|
||||
List goals;
|
||||
if ( "pom".equals( project.getPackaging() ) )
|
||||
{
|
||||
goals = new ArrayList();
|
||||
|
||||
// TODO: not required if discovered and cached
|
||||
goals.add( "pom:install" );
|
||||
|
||||
goals.addAll( request.getGoals() );
|
||||
}
|
||||
else
|
||||
{
|
||||
goals = request.getGoals();
|
||||
}
|
||||
|
||||
MavenExecutionResponse response = processProject( request, project, dispatcher, goals );
|
||||
MavenExecutionResponse response = processProject( request, project, dispatcher, request.getGoals() );
|
||||
if ( response.isExecutionFailure() )
|
||||
{
|
||||
return response;
|
||||
|
|
|
@ -29,8 +29,6 @@ import org.apache.maven.project.MavenProject;
|
|||
import org.apache.maven.project.MavenProjectBuilder;
|
||||
|
||||
import java.io.FileReader;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -57,6 +55,7 @@ public class MavenMetadataSource
|
|||
{
|
||||
// there is code in plexus that uses this (though it shouldn't) so we
|
||||
// need to be able to not have a project builder
|
||||
// TODO: remove, then remove those null checks
|
||||
this.artifactResolver = artifactResolver;
|
||||
this.mavenProjectBuilder = null;
|
||||
}
|
||||
|
@ -70,39 +69,57 @@ public class MavenMetadataSource
|
|||
public Set retrieve( Artifact artifact, ArtifactRepository localRepository, List remoteRepositories )
|
||||
throws ArtifactMetadataRetrievalException
|
||||
{
|
||||
Set artifacts;
|
||||
Artifact metadataArtifact = artifactFactory.createArtifact( artifact.getGroupId(), artifact.getArtifactId(),
|
||||
artifact.getVersion(), artifact.getScope(), "pom",
|
||||
"pom", null );
|
||||
try
|
||||
{
|
||||
artifactResolver.resolve( metadataArtifact, remoteRepositories, localRepository );
|
||||
List dependencies = null;
|
||||
|
||||
// [jdcasey/03-Feb-2005]: Replacing with ProjectBuilder, to enable
|
||||
// post-processing and inheritance calculation before retrieving the
|
||||
// associated artifacts. This should improve consistency.
|
||||
if ( mavenProjectBuilder != null )
|
||||
{
|
||||
MavenProject project = mavenProjectBuilder.build( metadataArtifact.getFile(), localRepository );
|
||||
artifacts =
|
||||
artifactFactory.createArtifacts( project.getDependencies(), localRepository, artifact.getScope() );
|
||||
MavenProject project = mavenProjectBuilder.getCachedProject( artifact.getGroupId(),
|
||||
artifact.getArtifactId(),
|
||||
artifact.getVersion() );
|
||||
if ( project != null )
|
||||
{
|
||||
dependencies = project.getDependencies();
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if ( dependencies == null )
|
||||
{
|
||||
Model model = reader.read( new FileReader( metadataArtifact.getFile() ) );
|
||||
artifacts =
|
||||
artifactFactory.createArtifacts( model.getDependencies(), localRepository, artifact.getScope() );
|
||||
Artifact metadataArtifact = artifactFactory.createArtifact( artifact.getGroupId(),
|
||||
artifact.getArtifactId(),
|
||||
artifact.getVersion(), artifact.getScope(),
|
||||
"pom", "pom", null );
|
||||
|
||||
artifactResolver.resolve( metadataArtifact, remoteRepositories, localRepository );
|
||||
|
||||
// [jdcasey/03-Feb-2005]: Replacing with ProjectBuilder, to enable
|
||||
// post-processing and inheritance calculation before retrieving the
|
||||
// associated artifacts. This should improve consistency.
|
||||
try
|
||||
{
|
||||
if ( mavenProjectBuilder != null )
|
||||
{
|
||||
MavenProject p = mavenProjectBuilder.build( metadataArtifact.getFile(), localRepository );
|
||||
dependencies = p.getDependencies();
|
||||
}
|
||||
else
|
||||
{
|
||||
Model model = reader.read( new FileReader( metadataArtifact.getFile() ) );
|
||||
dependencies = model.getDependencies();
|
||||
}
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException(
|
||||
"Cannot read artifact source: " + metadataArtifact.getPath(), e );
|
||||
}
|
||||
}
|
||||
return artifactFactory.createArtifacts( dependencies, localRepository, artifact.getScope() );
|
||||
}
|
||||
catch ( ArtifactResolutionException e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException( "Error while resolving metadata artifact", e );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
throw new ArtifactMetadataRetrievalException( "Cannot read artifact source: " + metadataArtifact.getPath(),
|
||||
e );
|
||||
}
|
||||
return artifacts;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,8 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
private ArtifactRepositoryFactory artifactRepositoryFactory;
|
||||
|
||||
private final Map projectCache = new HashMap();
|
||||
|
||||
public void initialize()
|
||||
{
|
||||
modelReader = new MavenXpp3Reader();
|
||||
|
@ -155,6 +157,9 @@ public class DefaultMavenProjectBuilder
|
|||
project.setParent( parentProject );
|
||||
project.setArtifacts( artifactFactory.createArtifacts( project.getDependencies(), localRepository, null ) );
|
||||
|
||||
projectCache.put( createCacheKey( project.getGroupId(), project.getArtifactId(), project.getVersion() ),
|
||||
project );
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Typically when the project builder is being used from maven proper
|
||||
// the transitive dependencies will not be resolved here because this
|
||||
|
@ -233,18 +238,22 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
aggregatedRemoteWagonRepositories.addAll( buildArtifactRepositories( model.getRepositories() ) );
|
||||
|
||||
File parentPom = findParentModel( parentModel, aggregatedRemoteWagonRepositories, localRepository );
|
||||
|
||||
MavenProject parent = assembleLineage( parentPom, localRepository, lineage,
|
||||
aggregatedRemoteWagonRepositories );
|
||||
MavenProject parent = getCachedProject( parentModel.getGroupId(), parentModel.getArtifactId(),
|
||||
parentModel.getVersion() );
|
||||
if ( parent == null )
|
||||
{
|
||||
File parentPom = findParentModel( parentModel, aggregatedRemoteWagonRepositories, localRepository );
|
||||
|
||||
parent = assembleLineage( parentPom, localRepository, lineage, aggregatedRemoteWagonRepositories );
|
||||
}
|
||||
project.setParent( parent );
|
||||
}
|
||||
|
||||
return project;
|
||||
}
|
||||
|
||||
private List buildArtifactRepositories( List repositories ) throws ProjectBuildingException
|
||||
private List buildArtifactRepositories( List repositories )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
UserModel userModel = null;
|
||||
|
||||
|
@ -387,6 +396,16 @@ public class DefaultMavenProjectBuilder
|
|||
return sortedProjects;
|
||||
}
|
||||
|
||||
public MavenProject getCachedProject( String groupId, String artifactId, String version )
|
||||
{
|
||||
return (MavenProject) projectCache.get( createCacheKey( groupId, artifactId, version ) );
|
||||
}
|
||||
|
||||
private static String createCacheKey( String groupId, String artifactId, String version )
|
||||
{
|
||||
return groupId + ":" + artifactId + ":" + version;
|
||||
}
|
||||
|
||||
public MavenProject buildSuperProject( ArtifactRepository localRepository )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
|
|
|
@ -43,4 +43,6 @@ public interface MavenProjectBuilder
|
|||
|
||||
List getSortedProjects( List projects )
|
||||
throws CycleDetectedException;
|
||||
|
||||
MavenProject getCachedProject( String groupId, String artifactId, String version );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue