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 bfc0b80df0..940ae20870 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 @@ -559,7 +559,6 @@ public class PomTransformer } tmp.removeAll(replace); - //Missing Version Rule if ( getPropertyFor( ProjectUri.version, tmp ) == null ) @@ -742,6 +741,27 @@ public class PomTransformer modelProperties.removeAll( clearedProperties ); } + //Rules processed on collapsed pom + + //Rule: Remove duplicate filters + List removedProperties = new ArrayList(); + List filters = new ArrayList(); + for(ModelProperty mp : modelProperties) + { + if(mp.getUri().equals(ProjectUri.Build.Filters.filter)) + { + if(filters.contains(mp.getResolvedValue())) + { + removedProperties.add(mp); + } + else + { + filters.add(mp.getResolvedValue()); + } + } + } + modelProperties.removeAll(removedProperties); + //Rule: Build plugin config overrides reporting plugin config ModelDataSource source = new DefaultModelDataSource( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); 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 aea4dc9a0a..7cb20d0fb6 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 @@ -350,7 +350,7 @@ public class ProjectUri public static class Filters { - public static String xUri = "http://apache.org/maven/project/build/filters#set"; + public static String xUri = "http://apache.org/maven/project/build/filters#collection"; public static String filter = xUri + "/filter"; } 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 5ef002d8c5..d6f577083f 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 @@ -136,6 +136,15 @@ public class PomConstructionTest } + /*MNG- 4008*/ + public void testMultipleFilters() + throws Exception + { + PomTestWrapper pom = buildPom( "multiple-filters" ); + assertEquals( 4, ( (List) pom.getValue( "build/filters" ) ).size() ); + + } + /*MNG-4005 - not implemented public void testDependenciesDifferentVersions() throws Exception @@ -748,11 +757,12 @@ public class PomConstructionTest assertPathWithNormalizedFileSeparators( pom.getValue( "reporting/outputDirectory" ) ); } - /* FIXME: cf. MNG-4008 + /* MNG-4008 */ public void testMergedFilterOrder() throws Exception { PomTestWrapper pom = buildPom( "merged-filter-order/sub" ); + System.out.println(pom.getValue( "build/filters" )); assertEquals( 7, ( (List) pom.getValue( "build/filters" ) ).size() ); assertTrue( pom.getValue( "build/filters[1]" ).toString().endsWith( "child-a.properties" ) ); @@ -763,7 +773,7 @@ public class PomConstructionTest assertTrue( pom.getValue( "build/filters[6]" ).toString().endsWith( "parent-b.properties" ) ); assertTrue( pom.getValue( "build/filters[7]" ).toString().endsWith( "parent-d.properties" ) ); } - //*/ + private void assertPathWithNormalizedFileSeparators( Object value ) { diff --git a/maven-project/src/test/resources-project-builder/multiple-filters/pom.xml b/maven-project/src/test/resources-project-builder/multiple-filters/pom.xml new file mode 100644 index 0000000000..aa61a6006b --- /dev/null +++ b/maven-project/src/test/resources-project-builder/multiple-filters/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + a + b + + + + src/main/filters/a.properties + src/main/filters/c.properties + src/main/filters/b.properties + src/main/filters/d.properties + + + + \ No newline at end of file