From fd1d9855df1ddbc72ed7e4ee236fb784e8dd995e Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Tue, 17 Feb 2009 14:56:24 +0000 Subject: [PATCH] [MNG-4034] - dependency version is not inherited from parent dependencyManagement git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@745110 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/project/builder/PomTransformer.java | 33 ++++++++++--------- .../maven/project/builder/ProjectUri.java | 2 +- .../builder/PomClassicDomainModel.java | 6 +++- .../builder/impl/DefaultProjectBuilder.java | 10 ++++-- .../project/builder/PomConstructionTest.java | 4 +-- 5 files changed, 33 insertions(+), 22 deletions(-) diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java index 940ae20870..1eadbc7b74 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java @@ -530,24 +530,27 @@ public class PomTransformer List clearedProperties = new ArrayList(); //Default Dependency Scope Rule - ModelDataSource s = new DefaultModelDataSource( tmp, Arrays.asList( new ArtifactModelContainerFactory()) ); - for(ModelContainer mc : s.queryFor(ProjectUri.Dependencies.Dependency.xUri)) + if(domainModelIndex == 0) { - boolean containsScope = false; - for(ModelProperty mp :mc.getProperties()) - { - if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.scope)) { - containsScope = true; - break; - } - } + ModelDataSource s = new DefaultModelDataSource( tmp, Arrays.asList( new ArtifactModelContainerFactory()) ); + for(ModelContainer mc : s.queryFor(ProjectUri.Dependencies.Dependency.xUri)) + { + boolean containsScope = false; + for(ModelProperty mp :mc.getProperties()) + { + if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.scope)) { + containsScope = true; + break; + } + } - if(!containsScope) - { - tmp.add(tmp.indexOf(mc.getProperties().get(0)) + 1, new ModelProperty(ProjectUri.Dependencies.Dependency.scope, "compile")); - } + if(!containsScope) + { + tmp.add(tmp.indexOf(mc.getProperties().get(0)) + 1, new ModelProperty(ProjectUri.Dependencies.Dependency.scope, "compile")); + } + } } - + //Remove Default Executions IDS (mng-3965) List replace = new ArrayList(); for(ModelProperty mp : tmp) diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/ProjectUri.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ProjectUri.java index 7cb20d0fb6..16c390eba7 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/ProjectUri.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/ProjectUri.java @@ -1113,7 +1113,7 @@ public class ProjectUri public static class Dependencies { - public static String xUri = "http://apache.org/maven/project/profiles#collection/profile/dependencies"; + public static String xUri = "http://apache.org/maven/project/profiles#collection/profile/dependencies#collection"; public static class Dependency { diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java index 5abb68ccce..f4923d8080 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java @@ -306,7 +306,11 @@ public final class PomClassicDomainModel s.add(ProjectUri.Reporting.Plugins.Plugin.ReportSets.xUri); s.add(ProjectUri.Reporting.Plugins.Plugin.ReportSets.ReportSet.configuration); s.add(ProjectUri.Build.Plugins.Plugin.Executions.Execution.configuration); - s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.configuration);//TODO: More profile info + //TODO: More profile info + s.add(ProjectUri.Profiles.Profile.Dependencies.xUri); + s.add(ProjectUri.Profiles.Profile.Dependencies.Dependency.Exclusions.xUri); + s.add(ProjectUri.Profiles.Profile.Build.Plugins.Plugin.configuration); + modelProperties = ModelMarshaller.marshallXmlToModelProperties( getInputStream(), ProjectUri.baseUri, s ); } diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java index 67533890bc..6d2ff7186a 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java @@ -217,6 +217,7 @@ public class DefaultProjectBuilder List domainModels = new ArrayList(); domainModels.add( domainModel ); + //Process Profile on most specialized child model ProfileContext profileContext = new ProfileContext(new DefaultModelDataSource(domainModel.getModelProperties(), PomTransformer.MODEL_CONTAINER_FACTORIES), activeProfileIds, properties); @@ -225,7 +226,7 @@ public class DefaultProjectBuilder for(ModelContainer mc : profileContainers) { List transformed = new ArrayList(); - transformed.add(new ModelProperty(ProjectUri.xUri, null)); + //transformed.add(new ModelProperty(ProjectUri.xUri, null)); for(ModelProperty mp : mc.getProperties()) { if(mp.getUri().startsWith(ProjectUri.Profiles.Profile.xUri) && !mp.getUri().equals(ProjectUri.Profiles.Profile.id) @@ -380,7 +381,8 @@ public class DefaultProjectBuilder domainModels.add( parentDomainModel ); - ProfileContext profileContext = new ProfileContext(new DefaultModelDataSource(parentDomainModel.getModelProperties(), + //Process Profiles + ProfileContext profileContext = new ProfileContext(new DefaultModelDataSource(parentDomainModel.getModelProperties(), PomTransformer.MODEL_CONTAINER_FACTORIES), activeProfileIds, properties); Collection profileContainers = profileContext.getActiveProfiles(); @@ -445,7 +447,9 @@ public class DefaultProjectBuilder PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( parentFile ); parentDomainModel.setProjectDirectory( parentFile.getParentFile() ); - ProfileContext profileContext = new ProfileContext(new DefaultModelDataSource(parentDomainModel.getModelProperties(), + + //Process Profiles + ProfileContext profileContext = new ProfileContext(new DefaultModelDataSource(parentDomainModel.getModelProperties(), PomTransformer.MODEL_CONTAINER_FACTORIES), activeProfileIds, properties); Collection profileContainers = profileContext.getActiveProfiles(); diff --git a/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java b/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java index 475047dbda..e679539593 100644 --- a/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java @@ -831,11 +831,11 @@ public class PomConstructionTest } //*/ - /** MNG-4034 + /** MNG-4034 */ public void testManagedProfileDependency() throws Exception { - PomTestWrapper pom = buildPom( "managed-profile-dependency/sub" ); + PomTestWrapper pom = this.buildPomFromMavenProject( "managed-profile-dependency/sub", "maven-core-it" ); assertEquals( 1, ( (List) pom.getValue( "dependencies" ) ).size() ); assertEquals( "org.apache.maven.its", pom.getValue( "dependencies[1]/groupId" ) ); assertEquals( "maven-core-it-support", pom.getValue( "dependencies[1]/artifactId" ) );