[MNG-3286] Fixing inherited flag for plugin executions.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@638213 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2008-03-18 04:45:05 +00:00
parent 63513cb1c7
commit b1f048aed7
8 changed files with 375 additions and 2 deletions

View File

@ -1161,6 +1161,8 @@ private void mergeManagedDependencies(Model model, ArtifactRepository localRepos
{
Dependency dep = (Dependency) iter.next();
depsMap.put( dep.getManagementKey(), dep );
// FIXME: Add scope-check for 'import'
if (dep.getType().equals("pom"))
{
doInclude = true;
@ -1173,6 +1175,8 @@ private void mergeManagedDependencies(Model model, ArtifactRepository localRepos
while (iter.hasNext())
{
Dependency dep = (Dependency)iter.next();
// FIXME: Add scope-check for 'import'
if (dep.getType().equals("pom"))
{
Artifact artifact = artifactFactory.createProjectArtifact( dep.getGroupId(), dep.getArtifactId(),

View File

@ -370,7 +370,11 @@ public static void mergePluginDefinitions( Plugin child, Plugin parent, boolean
{
PluginExecution parentExecution = (PluginExecution) it.next();
if ( !handleAsInheritance || parentIsInherited )
String inherited = parentExecution.getInherited();
boolean parentExecInherited = parentIsInherited && ( ( inherited == null ) || Boolean.valueOf( inherited ).booleanValue() );
if ( !handleAsInheritance || parentExecInherited )
{
PluginExecution assembled = parentExecution;

View File

@ -355,6 +355,7 @@ private void assembleBuildInheritance( Model child, Model parent )
if ( ( dominantPM == null ) && ( recessivePM != null ) )
{
// FIXME: Filter out the inherited == false stuff!
childBuild.setPluginManagement( recessivePM );
}
else

View File

@ -514,4 +514,125 @@ public void testShouldMergeTwoPluginDependenciesOnMergeDupePluginDefs()
assertEquals( 2, ((Plugin)first.getPlugins().get( 0 ) ).getDependencies().size() );
}
public void testShouldNotMergePluginExecutionWhenExecInheritedIsFalseAndTreatAsInheritanceIsTrue()
{
String gid = "group";
String aid = "artifact";
String ver = "1";
PluginContainer parent = new PluginContainer();
Plugin pParent = createPlugin( gid, aid, ver, Collections.EMPTY_MAP );
pParent.setInherited( Boolean.toString( true ) );
PluginExecution eParent = new PluginExecution();
String testId = "test";
eParent.setId( testId );
eParent.addGoal( "run" );
eParent.setPhase( "initialize" );
eParent.setInherited( Boolean.toString( false ) );
pParent.addExecution( eParent );
parent.addPlugin( pParent );
PluginContainer child = new PluginContainer();
Plugin pChild = createPlugin( gid, aid, ver, Collections.EMPTY_MAP );
PluginExecution eChild = new PluginExecution();
eChild.setId( "child-specified" );
eChild.addGoal( "child" );
eChild.setPhase( "compile" );
pChild.addExecution( eChild );
child.addPlugin( pChild );
ModelUtils.mergePluginDefinitions( pChild, pParent, true );
Map executionMap = pChild.getExecutionsAsMap();
assertNull( "test execution should not be inherited from parent.", executionMap.get( testId ) );
}
public void testShouldNotMergePluginExecutionWhenPluginInheritedIsFalseAndTreatAsInheritanceIsTrue()
{
String gid = "group";
String aid = "artifact";
String ver = "1";
PluginContainer parent = new PluginContainer();
Plugin pParent = createPlugin( gid, aid, ver, Collections.EMPTY_MAP );
pParent.setInherited( Boolean.toString( false ) );
PluginExecution eParent = new PluginExecution();
String testId = "test";
eParent.setId( testId );
eParent.addGoal( "run" );
eParent.setPhase( "initialize" );
eParent.setInherited( Boolean.toString( true ) );
pParent.addExecution( eParent );
parent.addPlugin( pParent );
PluginContainer child = new PluginContainer();
Plugin pChild = createPlugin( gid, aid, ver, Collections.EMPTY_MAP );
PluginExecution eChild = new PluginExecution();
eChild.setId( "child-specified" );
eChild.addGoal( "child" );
eChild.setPhase( "compile" );
pChild.addExecution( eChild );
child.addPlugin( pChild );
ModelUtils.mergePluginDefinitions( pChild, pParent, true );
Map executionMap = pChild.getExecutionsAsMap();
assertNull( "test execution should not be inherited from parent.", executionMap.get( testId ) );
}
public void testShouldMergePluginExecutionWhenExecInheritedIsTrueAndTreatAsInheritanceIsTrue()
{
String gid = "group";
String aid = "artifact";
String ver = "1";
PluginContainer parent = new PluginContainer();
Plugin pParent = createPlugin( gid, aid, ver, Collections.EMPTY_MAP );
pParent.setInherited( Boolean.toString( true ) );
PluginExecution eParent = new PluginExecution();
String testId = "test";
eParent.setId( testId );
eParent.addGoal( "run" );
eParent.setPhase( "initialize" );
eParent.setInherited( Boolean.toString( true ) );
pParent.addExecution( eParent );
parent.addPlugin( pParent );
PluginContainer child = new PluginContainer();
Plugin pChild = createPlugin( gid, aid, ver, Collections.EMPTY_MAP );
PluginExecution eChild = new PluginExecution();
eChild.setId( "child-specified" );
eChild.addGoal( "child" );
eChild.setPhase( "compile" );
pChild.addExecution( eChild );
child.addPlugin( pChild );
ModelUtils.mergePluginDefinitions( pChild, pParent, true );
Map executionMap = pChild.getExecutionsAsMap();
assertNotNull( "test execution should be inherited from parent.", executionMap.get( testId ) );
}
}

View File

@ -19,7 +19,6 @@
* under the License.
*/
import junit.framework.TestCase;
import org.apache.maven.model.Build;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
@ -45,6 +44,8 @@
import java.util.List;
import java.util.Map;
import junit.framework.TestCase;
/**
* @author jdcasey
*/
@ -802,6 +803,124 @@ public void testReportInheritanceWhereParentReportWithFalseInheritFlagAndChildHa
assertReports( new ArrayList(), child );
}
public void testPluginExecInheritanceWhereExecInheritedSetToFalse()
{
String testId = "test";
String gid = "group";
String aid = "artifact";
String ver = "1";
Model child = makeBaseModel( "child" );
Plugin pChild = new Plugin();
pChild.setGroupId( gid );
pChild.setArtifactId( aid );
pChild.setVersion( ver );
PluginExecution eChild = new PluginExecution();
eChild.setId( "normal" );
eChild.addGoal( "run" );
pChild.addExecution( eChild );
Build bChild = new Build();
bChild.addPlugin( pChild );
child.setBuild( bChild );
Model parent = makeBaseModel( "parent" );
Plugin pParent = new Plugin();
pParent.setGroupId( gid );
pParent.setArtifactId( aid );
pParent.setVersion( ver );
pParent.setInherited( Boolean.toString( true ) );
PluginExecution eParent = new PluginExecution();
eParent.setId( testId );
eParent.addGoal( "test" );
eParent.setInherited( Boolean.toString( false ) );
pParent.addExecution( eParent );
Build bParent = new Build();
bParent.addPlugin( pParent );
parent.setBuild( bParent );
assembler.assembleModelInheritance( child, parent );
Map pluginMap = bChild.getPluginsAsMap();
assertNotNull( pluginMap );
Plugin plugin = (Plugin) pluginMap.get( gid + ":" + aid );
assertNotNull( plugin );
Map executionMap = plugin.getExecutionsAsMap();
assertNotNull( executionMap );
assertNull( "test execution with inherited == false should NOT be inherited to child model.", executionMap.get( testId ) );
}
public void testPluginExecInheritanceWhereExecInheritedSetToFalseAndPluginInheritedNotSet()
{
String testId = "test";
String gid = "group";
String aid = "artifact";
String ver = "1";
Model child = makeBaseModel( "child" );
Plugin pChild = new Plugin();
pChild.setGroupId( gid );
pChild.setArtifactId( aid );
pChild.setVersion( ver );
PluginExecution eChild = new PluginExecution();
eChild.setId( "normal" );
eChild.addGoal( "run" );
pChild.addExecution( eChild );
Build bChild = new Build();
bChild.addPlugin( pChild );
child.setBuild( bChild );
Model parent = makeBaseModel( "parent" );
Plugin pParent = new Plugin();
pParent.setGroupId( gid );
pParent.setArtifactId( aid );
pParent.setVersion( ver );
PluginExecution eParent = new PluginExecution();
eParent.setId( testId );
eParent.addGoal( "test" );
eParent.setInherited( Boolean.toString( false ) );
pParent.addExecution( eParent );
Build bParent = new Build();
bParent.addPlugin( pParent );
parent.setBuild( bParent );
assembler.assembleModelInheritance( child, parent );
Map pluginMap = bChild.getPluginsAsMap();
assertNotNull( pluginMap );
Plugin plugin = (Plugin) pluginMap.get( gid + ":" + aid );
assertNotNull( plugin );
Map executionMap = plugin.getExecutionsAsMap();
assertNotNull( executionMap );
assertNull( "test execution with inherited == false should NOT be inherited to child model.", executionMap.get( testId ) );
}
private void assertReports( List expectedPlugins, Model child )
{
Reporting childBuild = child.getReporting();

View File

@ -0,0 +1,65 @@
package org.apache.maven.project.inheritance.t12;
/*
* 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.
*/
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.inheritance.AbstractProjectInheritanceTestCase;
import java.io.File;
import java.util.Map;
/**
* Verifies that plugin execution sections in the parent POM that have
* inherit == false are not inherited to the child POM.
*/
public class ProjectInheritanceTest extends AbstractProjectInheritanceTestCase
{
// ----------------------------------------------------------------------
//
// p1 inherits from p0
// p0 inherits from super model
//
// or we can show it graphically as:
//
// p1 ---> p0 --> super model
//
// ----------------------------------------------------------------------
public void testFalsePluginExecutionInheritValue() throws Exception
{
File localRepo = getLocalRepositoryPath();
File pom0 = new File( localRepo, "p0/pom.xml" );
File pom0Basedir = pom0.getParentFile();
File pom1 = new File( pom0Basedir, "p1/pom.xml" );
getProjectWithDependencies( pom0 );
MavenProject project1 = getProjectWithDependencies( pom1 );
Map pluginMap = project1.getBuild().getPluginsAsMap();
Plugin compilerPlugin = (Plugin) pluginMap.get( "org.apache.maven.plugins:maven-compiler-plugin" );
assertNotNull( compilerPlugin );
Map executionMap = compilerPlugin.getExecutionsAsMap();
assertNull( "Plugin execution: \'test\' should NOT exist in the compiler plugin specification for the child project!", executionMap.get( "test" ) );
}
}

View File

@ -0,0 +1,29 @@
<project>
<parent>
<artifactId>p0</artifactId>
<groupId>maven</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>p1</artifactId>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>normal</id>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,30 @@
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>maven</groupId>
<artifactId>p0</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<!-- The key to this test... -->
<inherited>false</inherited>
<goals>
<goal>compile</goal>
</goals>
<phase>install</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>