o changing the caching slightly to share with shane

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@699847 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2008-09-28 16:03:20 +00:00
parent 48224c4073
commit f9cb1579bb
2 changed files with 42 additions and 48 deletions

View File

@ -106,6 +106,8 @@ public class DefaultMavenProjectBuilder
private static final String MAVEN_MODEL_VERSION = "4.0.0";
private HashMap<String, MavenProject> hm = new HashMap<String, MavenProject>();
public void initialize()
{
modelReader = new MavenXpp3Reader();
@ -157,24 +159,29 @@ public class DefaultMavenProjectBuilder
public MavenProject buildFromRepository( Artifact artifact, List remoteArtifactRepositories, ArtifactRepository localRepository )
throws ProjectBuildingException
{
MavenProject project = hm.get( artifact.getId() );
if ( project != null )
{
return project;
}
File f = artifact.getFile();
repositoryHelper.findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
repositoryHelper.findModelFromRepository( artifact, remoteArtifactRepositories, localRepository );
ProjectBuilderConfiguration config =
new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository );
ProjectBuilderConfiguration config = new DefaultProjectBuilderConfiguration().setLocalRepository( localRepository );
List<ArtifactRepository> artifactRepositories =
new ArrayList<ArtifactRepository>( remoteArtifactRepositories );
artifactRepositories.addAll( repositoryHelper.buildArtifactRepositories(
getSuperProject( config, artifact.getFile(), false ).getModel() ) );
List<ArtifactRepository> artifactRepositories = new ArrayList<ArtifactRepository>( remoteArtifactRepositories );
artifactRepositories.addAll( repositoryHelper.buildArtifactRepositories( getSuperProject( config, artifact.getFile(), false ).getModel() ) );
MavenProject project = readModelFromLocalPath( "unknown", artifact.getFile(), new PomArtifactResolver(
config.getLocalRepository(), artifactRepositories, artifactResolver ), config );
project = buildInternal( project.getModel(), config, artifact.getFile(), project.getParentFile(), false );
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() );
hm.put( artifact.getId(), project );
return project;
}

View File

@ -75,9 +75,7 @@ public class MavenMetadataSource
private ArtifactFactory artifactFactory;
private RepositoryMetadataManager repositoryMetadataManager;
public HashMap<String, MavenProject> hm = new HashMap<String, MavenProject>();
// lazily instantiated and cached.
private MavenProject superProject;
@ -182,53 +180,42 @@ public class MavenMetadataSource
}
else
{
if(hm.containsKey(pomArtifact.getId()))
try
{
project = hm.get(pomArtifact.getId());
project = mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository );
}
else
catch ( InvalidProjectModelException e )
{
try
{
project =
mavenProjectBuilder.buildFromRepository( pomArtifact, remoteRepositories, localRepository );
hm.put(pomArtifact.getId(), project);
handleInvalidOrMissingMavenPOM( artifact, e );
}
catch ( InvalidProjectModelException e )
if ( getLogger().isDebugEnabled() )
{
handleInvalidOrMissingMavenPOM( artifact, e );
getLogger().debug( "Reason: " + e.getMessage() );
if ( getLogger().isDebugEnabled() )
ModelValidationResult validationResult = e.getValidationResult();
if ( validationResult != null )
{
getLogger().debug( "Reason: " + e.getMessage() );
ModelValidationResult validationResult = e.getValidationResult();
if ( validationResult != null )
getLogger().debug( "\nValidation Errors:" );
for ( Iterator i = validationResult.getMessages().iterator(); i.hasNext(); )
{
getLogger().debug( "\nValidation Errors:" );
for ( Iterator i = validationResult.getMessages().iterator(); i.hasNext(); )
{
getLogger().debug( i.next().toString() );
}
getLogger().debug( "\n" );
}
else
{
getLogger().debug( "", e );
getLogger().debug( i.next().toString() );
}
getLogger().debug( "\n" );
}
else
{
getLogger().debug( "", e );
}
project = null;
}
catch ( ProjectBuildingException e )
{
handleInvalidOrMissingMavenPOM( artifact, e );
project = null;
}
project = null;
}
catch ( ProjectBuildingException e )
{
handleInvalidOrMissingMavenPOM( artifact, e );
project = null;
}