From 3a2c55315c51b01a90848c963eb7c9fec30a79ed Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Fri, 6 Mar 2009 00:23:35 +0000 Subject: [PATCH] Fixed a number of element ordering problems. Matches up with latest model-builder. Suppoert for tagging elements with orginal pom id. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@750701 13f79535-47bb-0310-9956-ffa450edef68 --- .../builder/PomClassicDomainModel.java | 21 ++++++++ .../maven/project/builder/PomTransformer.java | 10 ++-- .../ArtifactModelContainerFactory.java | 4 ++ .../DependencyManagementDataSourceRule.java | 4 +- .../project/builder/rules/ExecutionRule.java | 17 ++----- .../rules/OverideConfigTransformerRule.java | 2 +- .../maven/project/PomConstructionTest.java | 17 +++++++ .../maven/project/harness/PomTestWrapper.java | 1 + .../plugin-management-duplicate/pom.xml | 50 ++----------------- pom.xml | 2 +- 10 files changed, 58 insertions(+), 70 deletions(-) diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java index ad3f09cbdd..e7cfe4fe9e 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java @@ -322,6 +322,27 @@ public class PomClassicDomainModel implements InputStreamDomainModel modelProperties = ModelMarshaller.marshallXmlToModelProperties( getInputStream(), ProjectUri.baseUri, s ); + String artifactId = null, groupId = null, version = null;//TODO Expand to full projectId + for(ModelProperty mp : modelProperties) + { + if( mp.getUri().equals(ProjectUri.artifactId)) + { + artifactId = mp.getResolvedValue(); + } + else if( mp.getUri().equals(ProjectUri.groupId)) + { + groupId = mp.getResolvedValue(); + } + else if (mp.getUri().equals(ProjectUri.version)) + { + version = mp.getResolvedValue(); + } + } + + for(ModelProperty mp : modelProperties) + { + mp.setTag(groupId + ":" + artifactId + ":" + version); + } } return new ArrayList(modelProperties); } 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 edd41471ad..278ea8ce8d 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 @@ -269,7 +269,7 @@ public class PomTransformer if(b.containerAction(c).equals(ModelContainerAction.JOIN)) { //MNG-3995 - property lost here - joinedContainers.addAll(source.join(b, c).getProperties()); + joinedContainers.addAll(source.joinWithOriginalOrder(b, c).getProperties()); joinedExecutionContainers.add(a); } } @@ -361,10 +361,9 @@ public class PomTransformer new AlwaysJoinModelContainerFactory())); for(ModelContainer es : executionSource.queryFor( ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri )) { ExecutionRule rule = new ExecutionRule(); - // List x = rule.execute(es.getProperties()); - List x = !aContainsAnyOfB(es.getProperties(), joinedContainers) ? rule.execute(es.getProperties()) : - ModelTransformerContext.sort(rule.execute(es.getProperties()), - ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri); + System.out.println("----"); + List x = !aContainsAnyOfB(es.getProperties(), joinedContainers) ? es.getProperties() : + rule.execute(es.getProperties()); dataSource.replace(es, es.createNewInstance(x)); } @@ -411,7 +410,6 @@ public class PomTransformer p.add(mp); } } - return factory.createDomainModel( p ); } diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ArtifactModelContainerFactory.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ArtifactModelContainerFactory.java index 11d420361a..f7d51c774d 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ArtifactModelContainerFactory.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ArtifactModelContainerFactory.java @@ -150,6 +150,10 @@ public final class ArtifactModelContainerFactory } else { + for(ModelProperty mp1 : properties) + { + System.out.println("----" + mp1); + } throw new IllegalArgumentException( "Properties do not contain group id. Artifact ID = " + artifactId + ", Version = " + version ); } diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyManagementDataSourceRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyManagementDataSourceRule.java index 46177b2aa9..b382896e62 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyManagementDataSourceRule.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DependencyManagementDataSourceRule.java @@ -31,11 +31,11 @@ public class DependencyManagementDataSourceRule implements DataSourceRule for(ModelContainer mc : exclusionContainers) { - for(ModelContainer mc1 : exclusionContainers) + for(ModelContainer mc1 : exclusionContainers.subList(exclusionContainers.indexOf(mc) + 1, exclusionContainers.size())) { if(!mc.equals(mc1) && mc.containerAction(mc1).equals(ModelContainerAction.JOIN)) { - exclusionSource.joinWithOriginalOrder(mc1, mc); + exclusionSource.join(mc1, mc); } } } diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java index 612072d811..87ea4943db 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java @@ -15,6 +15,7 @@ public class ExecutionRule implements ModelContainerRule { List processedProperties = new ArrayList(); for(ModelProperty mp : properties) { + System.out.println("1 - " + mp); if(mp.getUri().equals(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.goal)) { goalProperties.add(mp); } else if(mp.getUri().equals(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI)) { @@ -36,25 +37,21 @@ public class ExecutionRule implements ModelContainerRule { } else { x = true; } - } } processedProperties.removeAll(c); - if(!goalProperties.isEmpty()) { - Collections.reverse(goalProperties); List uniqueGoals = new ArrayList(); for(ModelProperty mp : goalProperties) { if(!containsProperty(mp, uniqueGoals)) { uniqueGoals.add(mp); } } - Collections.reverse(uniqueGoals); - + // Collections.reverse(uniqueGoals); processedProperties.addAll( findIndexOf(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI, processedProperties) + 1, - uniqueGoals); + uniqueGoals); } List emptyTags = new ArrayList(); @@ -65,14 +62,13 @@ public class ExecutionRule implements ModelContainerRule { } } processedProperties.removeAll(emptyTags); - return processedProperties; } private static int findIndexOf(String uri, List modelProperties) { for(ModelProperty mp : modelProperties) { - if(mp.getUri().equals(uri)) { + if(mp.getUri().equals(uri) && mp.getResolvedValue() == null) { return modelProperties.indexOf(mp); } } @@ -85,11 +81,6 @@ public class ExecutionRule implements ModelContainerRule { boolean b = (mp.getResolvedValue() == null && modelProperty.getResolvedValue() == null) || (mp.getResolvedValue() != null && !mp.getResolvedValue().trim().equals("") && mp.getResolvedValue().equals(modelProperty.getResolvedValue())); - /* - boolean b = (mp.getResolvedValue() == null && modelProperty.getResolvedValue() == null) || - (mp.getResolvedValue() != null && modelProperty.getResolvedValue() != null - && mp.getResolvedValue().equals(modelProperty.getResolvedValue())); - */ if(b) { return true; } diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/OverideConfigTransformerRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/OverideConfigTransformerRule.java index 948b5e9de5..7722f5ccd8 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/OverideConfigTransformerRule.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/OverideConfigTransformerRule.java @@ -28,7 +28,7 @@ public class OverideConfigTransformerRule implements JoinRule ModelContainerAction action = transformedReportContainer.containerAction( reportContainer ); if ( action.equals( ModelContainerAction.JOIN ) ) { - source.join( transformedReportContainer, reportContainer ); + source.join( reportContainer, transformedReportContainer ); break; } } diff --git a/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java b/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java index fcef175c9c..4c6ff655bf 100644 --- a/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java @@ -90,6 +90,21 @@ public class PomConstructionTest assertEquals( "test-prop", pom.getValue( "properties[1]/b" ) );//verifies profile applied assertEquals( "test-module", pom.getValue( "modules[1]" ) ); } + + /** + * Tests that modules is not overriden by profile + * + * @throws Exception + */ + /* + public void testPluginManagementDuplicate() + throws Exception + { + PomTestWrapper pom = buildPom( "plugin-management-duplicate"); + // assertEquals("target", pom.getValue("build/plugins[1]/configuration/domParam/copy/fileset@dir")); + System.out.println(pom.getDomainModel().asString()); + } + */ /** * Will throw exception if doesn't find parent(s) in build @@ -115,6 +130,7 @@ public class PomConstructionTest throws Exception { PomTestWrapper pom = buildPom( "plugin-config-properties" ); + System.out.println(pom.getDomainModel().asString()); assertEquals( "my.property", pom.getValue( "build/plugins[1]/configuration[1]/systemProperties[1]/property[1]/name" ) ); } @@ -277,6 +293,7 @@ public class PomConstructionTest throws Exception { PomTestWrapper pom = buildPom( "single-configuration-inheritance" ); + assertEquals( 2, ( (List) pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules" ) ).size() ); assertEquals("2.0.6", pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[1]/requireMavenVersion[1]/version" ) ); assertEquals("[2.0.6,)", pom.getValue( "build/plugins[1]/executions[1]/configuration[1]/rules[2]/requireMavenVersion[1]/version" ) ); diff --git a/maven-project/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java b/maven-project/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java index 86d3317771..0962be4f41 100644 --- a/maven-project/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java +++ b/maven-project/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java @@ -71,6 +71,7 @@ public class PomTestWrapper try { context = JXPathContext.newContext( new MavenXpp3Reader().read(domainModel.getInputStream())); } catch (XmlPullParserException e) { + e.printStackTrace(); throw new IOException(e.getMessage()); } } diff --git a/maven-project/src/test/resources-project-builder/plugin-management-duplicate/pom.xml b/maven-project/src/test/resources-project-builder/plugin-management-duplicate/pom.xml index f7df30821b..c84c7e0e7f 100644 --- a/maven-project/src/test/resources-project-builder/plugin-management-duplicate/pom.xml +++ b/maven-project/src/test/resources-project-builder/plugin-management-duplicate/pom.xml @@ -20,51 +20,7 @@ under the License. --> - 4.0.0 - - org.apache.maven.its.mng4053 - test2 - 1.0-SNAPSHOT - - Maven Integration Test :: MNG-4053 - - Verify that attributes in plugin configuration elements are not erroneously duplicated to other elements when - plugin management is used. - - - - - - - - org.apache.maven.its.plugins - maven-it-plugin-configuration - 2.1-SNAPSHOT - - - - - - org.apache.maven.its.plugins - maven-it-plugin-configuration - 2.1-SNAPSHOT - - - validate - - config - - - target/config.properties - - - - - - - - - - - + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml index 873f5461d6..d932d0b6e7 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ under the License. 1.6 1.0 1.0-beta-4 - 1.5 + 1.7-SNAPSHOT 1.0.0-alpha-4 1.0-alpha-1 1.0