Removed use of workspace from project builder. In the build of trunk, there were about 50K of calls from MavenMetadataSource to the project builder. I put a simple hashmap cache in the metadata source to reduce calls to dozens.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@699773 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2008-09-28 04:52:53 +00:00
parent 1260ced4f5
commit 53cfcc896d
2 changed files with 47 additions and 59 deletions

View File

@ -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;
}

View File

@ -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<String, MavenProject> hm = new HashMap<String, MavenProject>();
private ProjectRelocation retrieveRelocatedProject( Artifact artifact, ArtifactRepository localRepository,
List<ArtifactRepository> 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;