Author: sisbell Date: Thu Mar 26 00:50:45 2009 New Revision: 758487 URL: http://svn.apache.org/viewvc?rev=758487&view=rev Log: [MNG-3899] - Inheritance does not merge extensions with same gid and aid
Added: maven/components/trunk/maven-project/src/test/resources-project-builder/build-extension-inheritance/ maven/components/trunk/maven-project/src/test/resources-project-builder/build-extension-inheritance/pom.xml maven/components/trunk/maven-project/src/test/resources-project-builder/build-extension-inheritance/sub/ maven/components/trunk/maven-project/src/test/resources-project-builder/build-extension-inheritance/sub/pom.xml Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/processor/BuildProcessor.java maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/processor/BuildProcessor.java URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/processor/BuildProcessor.java?rev=758487&r1=758486&r2=758487&view=diff ============================================================================== --- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/processor/BuildProcessor.java (original) +++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/processor/BuildProcessor.java Thu Mar 26 00:50:45 2009 @@ -25,6 +25,7 @@ import org.apache.maven.model.Build; import org.apache.maven.model.BuildBase; +import org.apache.maven.model.Dependency; import org.apache.maven.model.Extension; import org.apache.maven.model.Model; import org.apache.maven.model.Plugin; @@ -205,15 +206,50 @@ if(source.getTestSourceDirectory() != null) { target.setTestSourceDirectory( source.getTestSourceDirectory() ); - } - + } + /* + List<Dependency> childDependencies = + new ArrayList<Dependency>(dependencies.subList( length - 1 , dependencies.size() ) ); + dependencies.removeAll( childDependencies ); + dependencies.addAll( 0, childDependencies ); + */ + int i = target.getExtensions().size(); + + List<Extension> m = new ArrayList<Extension>(); for(Extension extension : source.getExtensions()) { - Extension e = new Extension(); - e.setArtifactId( extension.getArtifactId() ); - e.setGroupId( extension.getGroupId() ); - e.setVersion( extension.getVersion() ); - target.addExtension( e ); + Extension match = isMatch(extension, target.getExtensions()); + if(match != null) + { + match.setArtifactId( extension.getArtifactId() ); + match.setGroupId( extension.getGroupId() ); + match.setVersion( extension.getVersion() ); + m.add( match ); + } + else + { + Extension e = new Extension(); + e.setArtifactId( extension.getArtifactId() ); + e.setGroupId( extension.getGroupId() ); + e.setVersion( extension.getVersion() ); + m.add( e ); + // target.addExtension( e ); + } + } + target.getExtensions().removeAll( m ); + target.getExtensions().addAll( 0, m ); + } + + private static Extension isMatch(Extension extension, List<Extension> extensions) + { + for(Extension e : extensions) + { + if(e.getGroupId().equals( extension.getGroupId() ) && e.getArtifactId().equals( extension.getArtifactId() )) + { + return e; + } } + return null; } + } Modified: maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java?rev=758487&r1=758486&r2=758487&view=diff ============================================================================== --- maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java (original) +++ maven/components/trunk/maven-project/src/test/java/org/apache/maven/project/PomConstructionTest.java Thu Mar 26 00:50:45 2009 @@ -1244,6 +1244,19 @@ PomTestWrapper pom = buildPom( "boolean-interpolation" ); } */ + + /* MNG-3899 */ + public void testBuildExtensionInheritance() + throws Exception + { + PomTestWrapper pom = buildPom( "build-extension-inheritance/sub" ); + System.out.println(pom.getDomainModel().asString()); + assertEquals(3, ( (List<?>) pom.getValue( "build/extensions" )).size() ); + assertEquals("b", pom.getValue( "build/extensions[1]/artifactId" ) ); + assertEquals("a", pom.getValue( "build/extensions[2]/artifactId" ) ); + assertEquals("0.2", pom.getValue( "build/extensions[2]/version" ) ); + assertEquals("c", pom.getValue( "build/extensions[3]/artifactId" ) ); + } private void assertPathSuffixEquals( String expected, Object actual ) { Added: maven/components/trunk/maven-project/src/test/resources-project-builder/build-extension-inheritance/pom.xml URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/resources-project-builder/build-extension-inheritance/pom.xml?rev=758487&view=auto ============================================================================== --- maven/components/trunk/maven-project/src/test/resources-project-builder/build-extension-inheritance/pom.xml (added) +++ maven/components/trunk/maven-project/src/test/resources-project-builder/build-extension-inheritance/pom.xml Thu Mar 26 00:50:45 2009 @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<project> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.its.mng3899</groupId> + <artifactId>parent</artifactId> + <version>0.1</version> + <packaging>pom</packaging> + + <name>Maven Integration Test :: MNG-3899</name> + <description> + Test that build extensions are properly merged during inheritance. + </description> + + <build> + <extensions> + <extension> + <groupId>org.apache.maven.its.mng3899</groupId> + <artifactId>a</artifactId> + <version>0.1</version> + </extension> + <extension> + <groupId>org.apache.maven.its.mng3899</groupId> + <artifactId>c</artifactId> + <version>0.1</version> + </extension> + </extensions> + </build> +</project> Added: maven/components/trunk/maven-project/src/test/resources-project-builder/build-extension-inheritance/sub/pom.xml URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/test/resources-project-builder/build-extension-inheritance/sub/pom.xml?rev=758487&view=auto ============================================================================== --- maven/components/trunk/maven-project/src/test/resources-project-builder/build-extension-inheritance/sub/pom.xml (added) +++ maven/components/trunk/maven-project/src/test/resources-project-builder/build-extension-inheritance/sub/pom.xml Thu Mar 26 00:50:45 2009 @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<project> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.maven.its.mng3899</groupId> + <artifactId>parent</artifactId> + <version>0.1</version> + </parent> + + <artifactId>child</artifactId> + + <name>Maven Integration Test :: MNG-3899</name> + <description> + Test that build extensions are properly merged during inheritance. + </description> + + <build> + <!-- project extensions should precede inherited extensions --> + <extensions> + <extension> + <groupId>org.apache.maven.its.mng3899</groupId> + <artifactId>b</artifactId> + <version>0.1</version> + </extension> + <extension> + <!-- project extensions should override inherited extension with equal gid:aid --> + <groupId>org.apache.maven.its.mng3899</groupId> + <artifactId>a</artifactId> + <version>0.2</version> + </extension> + </extensions> + <plugins> + <plugin> + <groupId>org.apache.maven.its.plugins</groupId> + <artifactId>maven-it-plugin-expression</artifactId> + <version>2.1-SNAPSHOT</version> + <executions> + <execution> + <phase>validate</phase> + <goals> + <goal>eval</goal> + </goals> + <configuration> + <outputFile>target/extension.properties</outputFile> + <expressions> + <expression>project/build/extensions</expression> + </expressions> + </configuration> + </execution> + </executions> + </plugin> + </plugins> + </build> +</project>