PR: MNG-680

find the file for a parent that was cached

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@280347 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-09-12 14:45:27 +00:00
parent 50c04ac590
commit 1398c7c6af
1 changed files with 30 additions and 10 deletions

View File

@ -272,7 +272,9 @@ public class DefaultMavenProjectBuilder
Model model = readModel( projectDescriptor ); Model model = readModel( projectDescriptor );
// Always cache files in the source tree over those in the repository // Always cache files in the source tree over those in the repository
modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), model ); MavenProject p = new MavenProject( model );
p.setFile( projectDescriptor );
modelCache.put( createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ), p );
MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository, MavenProject project = build( projectDescriptor.getAbsolutePath(), model, localRepository,
buildArtifactRepositories( getSuperModel() ), buildArtifactRepositories( getSuperModel() ),
@ -319,8 +321,10 @@ public class DefaultMavenProjectBuilder
ArtifactRepository localRepository ) ArtifactRepository localRepository )
throws ProjectBuildingException throws ProjectBuildingException
{ {
Model model = getCachedModel( artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion() ); MavenProject project = getCachedProject( artifact.getGroupId(), artifact.getArtifactId(),
if ( model == null ) artifact.getVersion() );
Model model;
if ( project == null )
{ {
// TODO: can't assume artifact is a POM // TODO: can't assume artifact is a POM
try try
@ -420,6 +424,10 @@ public class DefaultMavenProjectBuilder
*/ */
} }
} }
else
{
model = project.getModel();
}
return model; return model;
} }
@ -549,10 +557,12 @@ public class DefaultMavenProjectBuilder
{ {
Model model = project.getModel(); Model model = project.getModel();
String key = createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ); String key = createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() );
Model cachedModel = (Model) modelCache.get( key ); if ( !modelCache.containsKey( key ) )
if ( cachedModel == null )
{ {
modelCache.put( key, model ); // clone the model because the profile injection below will modify this instance
MavenProject p = new MavenProject( ModelUtils.cloneModel( model ) );
p.setFile( project.getFile() );
modelCache.put( key, project );
} }
List activeProfiles = project.getActiveProfiles(); List activeProfiles = project.getActiveProfiles();
@ -706,11 +716,21 @@ public class DefaultMavenProjectBuilder
throw new ProjectBuildingException( "Missing version element from parent element" ); throw new ProjectBuildingException( "Missing version element from parent element" );
} }
model = getCachedModel( parentModel.getGroupId(), parentModel.getArtifactId(), parentModel.getVersion() );
// the only way this will have a value is if we find the parent on disk... // the only way this will have a value is if we find the parent on disk...
File parentDescriptor = null; File parentDescriptor = null;
MavenProject p = getCachedProject( parentModel.getGroupId(), parentModel.getArtifactId(),
parentModel.getVersion() );
if ( p != null )
{
model = p.getModel();
parentDescriptor = p.getFile();
}
else
{
model = null;
}
String parentRelativePath = parentModel.getRelativePath(); String parentRelativePath = parentModel.getRelativePath();
// if we can't find a cached model matching the parent spec, then let's try to look on disk using // if we can't find a cached model matching the parent spec, then let's try to look on disk using
@ -935,9 +955,9 @@ public class DefaultMavenProjectBuilder
} }
} }
private Model getCachedModel( String groupId, String artifactId, String version ) private MavenProject getCachedProject( String groupId, String artifactId, String version )
{ {
return (Model) modelCache.get( createCacheKey( groupId, artifactId, version ) ); return (MavenProject) modelCache.get( createCacheKey( groupId, artifactId, version ) );
} }
private static String createCacheKey( String groupId, String artifactId, String version ) private static String createCacheKey( String groupId, String artifactId, String version )