[MNG-4129] Execution's inherited is not working as expected.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@777205 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benjamin Bentmann 2009-05-21 18:19:22 +00:00
parent aaf01a7495
commit efb59873a5
5 changed files with 202 additions and 12 deletions

View File

@ -27,6 +27,7 @@
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.project.harness.PomTestWrapper;
import org.codehaus.plexus.PlexusTestCase;
@ -1437,6 +1438,27 @@ public void testInterpolationWithSystemProperty()
assertEquals( "PASSED", pom.getValue( "name" ) );
}
/* MNG-4129 */
public void testPluginExecutionInheritanceWhenChildDoesNotDeclarePlugin()
throws Exception
{
PomTestWrapper pom = buildPom( "plugin-exec-inheritance/wo-merge" );
List<PluginExecution> executions =
(List<PluginExecution>) pom.getValue( "build/pluginsAsMap[@name='org.apache.maven.its.plugins:maven-it-plugin-log-file']/executions" );
assertEquals( 1, executions.size() );
assertEquals( "inherited-execution", executions.get( 0 ).getId() );
}
public void testPluginExecutionInheritanceWhenChildDoesDeclarePluginAsWell()
throws Exception
{
PomTestWrapper pom = buildPom( "plugin-exec-inheritance/w-merge" );
List<PluginExecution> executions =
(List<PluginExecution>) pom.getValue( "build/pluginsAsMap[@name='org.apache.maven.its.plugins:maven-it-plugin-log-file']/executions" );
assertEquals( 1, executions.size() );
assertEquals( "inherited-execution", executions.get( 0 ).getId() );
}
private void assertPathSuffixEquals( String expected, Object actual )
{
String a = actual.toString();

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>
<groupId>org.apache.maven.its.mng4129</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
<packaging>pom</packaging>
<name>Maven Integration Test :: MNG-4129</name>
<description>
Verify that plugin executions defined in the parent with inherited=false are not executed in child modules.
</description>
<modules>
<module>child-1</module>
<module>child-2</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-log-file</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<id>inherited-execution</id>
<inherited>true</inherited>
<phase>validate</phase>
<goals>
<goal>log-string</goal>
</goals>
<configuration>
<logFile>target/executions.txt</logFile>
<string>inherited-execution</string>
</configuration>
</execution>
<execution>
<id>non-inherited-execution</id>
<inherited>false</inherited>
<phase>validate</phase>
<goals>
<goal>log-string</goal>
</goals>
<configuration>
<logFile>target/executions.txt</logFile>
<string>non-inherited-execution</string>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,48 @@
<?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.mng4129</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
</parent>
<artifactId>child-1</artifactId>
<name>Maven Integration Test :: MNG-4129 :: Child-1</name>
<description>
Verify that plugin executions defined in the parent with inherited=false are not executed in child modules.
</description>
<build>
<plugins>
<!-- NOTE: It's essential part of this test variant to redefine the test plugin again, i.e. trigger plugin merging -->
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-log-file</artifactId>
<version>2.1-SNAPSHOT</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,43 @@
<?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.mng4129</groupId>
<artifactId>parent</artifactId>
<version>0.1</version>
</parent>
<artifactId>child-2</artifactId>
<name>Maven Integration Test :: MNG-4129 :: Child-2</name>
<description>
Verify that plugin executions defined in the parent with inherited=false are not executed in child modules.
</description>
<build>
<plugins>
<!-- NOTE: It's essential part of this test variant to *not* define the test plugin again, i.e. bypass plugin merging -->
</plugins>
</build>
</project>

View File

@ -412,14 +412,15 @@ protected void mergePluginContainer_Plugins( PluginContainer target, PluginConta
Plugin element = it.next();
Object key = getPluginKey( element );
Plugin existing = merged.get( key );
if ( existing != null )
if ( existing == null )
{
mergePlugin( existing, element, sourceDominant, context );
}
else
{
merged.put( key, element );
// NOTE: Enforce recursive merge to trigger merging/inheritance logic for executions as well
existing = new Plugin();
existing.setGroupId( element.getGroupId() );
existing.setArtifactId( element.getArtifactId() );
merged.put( key, existing );
}
mergePlugin( existing, element, sourceDominant, context );
}
target.setPlugins( new ArrayList<Plugin>( merged.values() ) );
@ -449,14 +450,15 @@ protected void mergeReporting_Plugins( Reporting target, Reporting source, boole
ReportPlugin element = it.next();
Object key = getReportPluginKey( element );
ReportPlugin existing = merged.get( key );
if ( existing != null )
if ( existing == null )
{
mergeReportPlugin( existing, element, sourceDominant, context );
}
else
{
merged.put( key, element );
// NOTE: Enforce recursive merge to trigger merging/inheritance logic for executions as well
existing = new ReportPlugin();
existing.setGroupId( element.getGroupId() );
existing.setArtifactId( element.getArtifactId() );
merged.put( key, existing );
}
mergeReportPlugin( existing, element, sourceDominant, context );
}
target.setPlugins( new ArrayList<ReportPlugin>( merged.values() ) );