From 8831e55e789d87095167869e84c0fe7672d6a2d7 Mon Sep 17 00:00:00 2001 From: John Dennis Casey Date: Wed, 24 Jan 2007 22:53:00 +0000 Subject: [PATCH] Fixing project inheritance and profile-injection now that we've moved to the model lineage builder. Iteration was backward. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@499603 13f79535-47bb-0310-9956-ffa450edef68 --- .../project/DefaultMavenProjectBuilder.java | 24 ++++++++----------- .../model/DefaultModelLineageBuilder.java | 9 ++++++- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java index 32d66e24b8..ff96c4533e 100644 --- a/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/DefaultMavenProjectBuilder.java @@ -25,7 +25,6 @@ import org.apache.maven.artifact.factory.ArtifactFactory; import org.apache.maven.artifact.manager.WagonManager; import org.apache.maven.artifact.metadata.ArtifactMetadataSource; import org.apache.maven.artifact.repository.ArtifactRepository; -import org.apache.maven.artifact.repository.ArtifactRepositoryFactory; import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy; import org.apache.maven.artifact.resolver.ArtifactNotFoundException; import org.apache.maven.artifact.resolver.ArtifactResolutionException; @@ -52,10 +51,10 @@ import org.apache.maven.project.build.ProjectBuildContext; import org.apache.maven.project.build.model.DefaultModelLineage; import org.apache.maven.project.build.model.ModelLineage; import org.apache.maven.project.build.model.ModelLineageBuilder; +import org.apache.maven.project.build.model.ModelLineageIterator; import org.apache.maven.project.build.profile.ProfileAdvisor; import org.apache.maven.project.inheritance.ModelInheritanceAssembler; import org.apache.maven.project.injection.ModelDefaultsInjector; -import org.apache.maven.project.injection.ProfileInjector; import org.apache.maven.project.interpolation.ModelInterpolationException; import org.apache.maven.project.interpolation.ModelInterpolator; import org.apache.maven.project.path.PathTranslator; @@ -1031,14 +1030,11 @@ public class DefaultMavenProjectBuilder explicitlyInactive = Collections.EMPTY_LIST; } - List models = modelLineage.getModelsInDescendingOrder(); - List poms = modelLineage.getFilesInDescendingOrder(); - MavenProject lastProject = null; - for( int i = 0; i < models.size(); i++ ) + for ( ModelLineageIterator it = modelLineage.lineageIterator(); it.hasNext(); ) { - Model currentModel = (Model) models.get( i ); - File currentPom = (File) poms.get( i ); + Model currentModel = (Model) it.next(); + File currentPom = it.getPOMFile(); MavenProject project = new MavenProject( currentModel ); project.setFile( currentPom ); @@ -1046,23 +1042,23 @@ public class DefaultMavenProjectBuilder projectContext.setCurrentProject( project ); projectContext.store( buildContextManager ); - project.setActiveProfiles( profileAdvisor.applyActivatedProfiles( model, projectDir, explicitlyActive, + project.setActiveProfiles( profileAdvisor.applyActivatedProfiles( currentModel, projectDir, explicitlyActive, explicitlyInactive ) ); if ( lastProject != null ) { - project.setParent( lastProject ); + lastProject.setParent( project ); - project.setParentArtifact( artifactFactory.createParentArtifact( lastProject.getGroupId(), lastProject - .getArtifactId(), lastProject.getVersion() ) ); + lastProject.setParentArtifact( artifactFactory.createParentArtifact( project.getGroupId(), project + .getArtifactId(), project.getVersion() ) ); } - lineage.addLast( project ); + lineage.addFirst( project ); lastProject = project; } - MavenProject result = (MavenProject) lineage.get( lineage.size() - 1 ); + MavenProject result = (MavenProject) lineage.getLast(); if ( externalProfileManager != null ) { diff --git a/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java b/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java index 16fffa4635..19821c700d 100644 --- a/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/build/model/DefaultModelLineageBuilder.java @@ -157,9 +157,16 @@ public class DefaultModelLineageBuilder * Model instance in the given Map before returning it. The skipCache flag controls whether the * Model instance is actually cached. */ - private Model readModel( File pomFile, Map cachedPomFilesByModelId, boolean skipCache ) + private Model readModel( File pom, Map cachedPomFilesByModelId, boolean skipCache ) throws ProjectBuildingException { + File pomFile = pom; + if ( pom.isDirectory() ) + { + pomFile = new File( pom, "pom.xml" ); + getLogger().debug( "readModel(..): POM: " + pom + " is a directory. Trying: " + pomFile + " instead." ); + } + Model model; FileReader reader = null;