[MNG-3899] - Inheritance does not merge extensions with same gid and aid

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@758487 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-03-26 00:50:45 +00:00
parent 0a68cca3ef
commit 49508f67ad
4 changed files with 181 additions and 8 deletions

View File

@ -25,6 +25,7 @@ import java.util.List;
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;
@ -206,14 +207,49 @@ public class BuildProcessor
{
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 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() );
target.addExtension( e );
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;
}
}

View File

@ -1245,6 +1245,19 @@ public class PomConstructionTest
}
*/
/* 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 )
{
String a = actual.toString();

View File

@ -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>

View File

@ -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>