From fea9f2ac5363953d7b654d956df293b33093c6ef Mon Sep 17 00:00:00 2001 From: Brett Leslie Porter Date: Wed, 16 Mar 2005 06:56:03 +0000 Subject: [PATCH] project cache repairs - must not cache models that are already interpolated, translated, etc. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163581 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/artifact/MavenMetadataSource.java | 9 ++-- .../project/DefaultMavenProjectBuilder.java | 53 ++++++++++++------- .../maven/project/MavenProjectBuilder.java | 3 +- 3 files changed, 40 insertions(+), 25 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java b/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java index 96368967ea..83c98bf54f 100644 --- a/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java +++ b/maven-core/src/main/java/org/apache/maven/artifact/MavenMetadataSource.java @@ -75,12 +75,11 @@ public class MavenMetadataSource if ( mavenProjectBuilder != null ) { - MavenProject project = mavenProjectBuilder.getCachedProject( artifact.getGroupId(), - artifact.getArtifactId(), - artifact.getVersion() ); - if ( project != null ) + Model model = mavenProjectBuilder.getCachedModel( artifact.getGroupId(), artifact.getArtifactId(), + artifact.getVersion() ); + if ( model != null ) { - dependencies = project.getDependencies(); + dependencies = model.getDependencies(); } } diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 8fc9671807..25d1164f99 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -83,7 +83,7 @@ public class DefaultMavenProjectBuilder private ArtifactRepositoryFactory artifactRepositoryFactory; - private final Map projectCache = new HashMap(); + private final Map modelCache = new HashMap(); public void initialize() { @@ -151,7 +151,15 @@ public class DefaultMavenProjectBuilder boolean resolveDependencies, boolean sourceProject ) throws ProjectBuildingException, ModelInterpolationException, ArtifactResolutionException { - Model model = modelInterpolator.interpolate( project.getModel() ); + Model model = project.getModel(); + String key = createCacheKey( model.getGroupId(), model.getArtifactId(), model.getVersion() ); + Model cachedModel = (Model) modelCache.get( key ); + if ( cachedModel == null || sourceProject ) + { + modelCache.put( key, model ); + } + + model = modelInterpolator.interpolate( model ); // interpolation is before injection, because interpolation is off-limits in the injected variables modelDefaultsInjector.injectDefaults( model ); @@ -169,13 +177,6 @@ public class DefaultMavenProjectBuilder project.setParent( parentProject ); project.setArtifacts( artifactFactory.createArtifacts( project.getDependencies(), localRepository, null ) ); - String key = createCacheKey( project.getGroupId(), project.getArtifactId(), project.getVersion() ); - MavenProject cachedProject = (MavenProject) projectCache.get( key ); - if ( cachedProject == null || sourceProject ) - { - projectCache.put( key, project ); - } - // ---------------------------------------------------------------------- // Typically when the project builder is being used from maven proper // the transitive dependencies will not be resolved here because this @@ -200,7 +201,7 @@ public class DefaultMavenProjectBuilder project.getArtifacts().addAll( result.getArtifacts().values() ); } - ModelValidationResult validationResult = validator.validate( project.getModel() ); + ModelValidationResult validationResult = validator.validate( model ); if ( validationResult.getMessageCount() > 0 ) { @@ -219,14 +220,22 @@ public class DefaultMavenProjectBuilder throws ProjectBuildingException { Model model = readModel( projectDescriptor ); + MavenProject project = assembleLineage( model, localRepository, lineage, aggregatedRemoteWagonRepositories ); + project.setFile( projectDescriptor ); + return project; + + } + + private MavenProject assembleLineage( Model model, ArtifactRepository localRepository, LinkedList lineage, + List aggregatedRemoteWagonRepositories ) + throws ProjectBuildingException + { MavenProject project = new MavenProject( model ); lineage.addFirst( project ); - project.setFile( projectDescriptor ); - - Parent parentModel = model.getParent(); + Parent parentModel = project.getModel().getParent(); if ( parentModel != null ) { @@ -252,16 +261,22 @@ public class DefaultMavenProjectBuilder // as we go in order to do this. // ---------------------------------------------------------------------- - aggregatedRemoteWagonRepositories.addAll( buildArtifactRepositories( model.getRepositories() ) ); + aggregatedRemoteWagonRepositories.addAll( + buildArtifactRepositories( project.getModel().getRepositories() ) ); - MavenProject parent = getCachedProject( parentModel.getGroupId(), parentModel.getArtifactId(), - parentModel.getVersion() ); - if ( parent == null ) + MavenProject parent; + Model cachedModel = getCachedModel( parentModel.getGroupId(), parentModel.getArtifactId(), + parentModel.getVersion() ); + if ( cachedModel == null ) { File parentPom = findParentModel( parentModel, aggregatedRemoteWagonRepositories, localRepository ); parent = assembleLineage( parentPom, localRepository, lineage, aggregatedRemoteWagonRepositories ); } + else + { + parent = assembleLineage( cachedModel, localRepository, lineage, aggregatedRemoteWagonRepositories ); + } project.setParent( parent ); } @@ -352,9 +367,9 @@ public class DefaultMavenProjectBuilder return artifact.getFile(); } - public MavenProject getCachedProject( String groupId, String artifactId, String version ) + public Model getCachedModel( String groupId, String artifactId, String version ) { - return (MavenProject) projectCache.get( createCacheKey( groupId, artifactId, version ) ); + return (Model) modelCache.get( createCacheKey( groupId, artifactId, version ) ); } private static String createCacheKey( String groupId, String artifactId, String version ) diff --git a/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java index 96431093d0..3f8b6418d3 100644 --- a/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java +++ b/maven-core/src/main/java/org/apache/maven/project/MavenProjectBuilder.java @@ -19,6 +19,7 @@ package org.apache.maven.project; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.model.Model; import java.io.File; @@ -38,5 +39,5 @@ public interface MavenProjectBuilder MavenProject buildSuperProject( ArtifactRepository localRepository ) throws ProjectBuildingException; - MavenProject getCachedProject( String groupId, String artifactId, String version ); + Model getCachedModel( String groupId, String artifactId, String version ); }