Fixing plugins-as-extensions when brought in from pluginManagement to a module-project's build. Unit test included.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@601013 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2007-12-04 17:22:28 +00:00
parent 1db3b755ab
commit 103a85a02b
2 changed files with 179 additions and 36 deletions

View File

@ -144,6 +144,21 @@ private void scanInternal( File pom,
String key = createKey( model );
if ( inheritedInterpolationValues == null )
{
inheritedInterpolationValues = new HashMap();
}
model = modelInterpolator.interpolate( model, inheritedInterpolationValues, false );
grabManagedPluginsWithExtensionsFlagTurnedOn( model, managedPluginsWithExtensionsFlag );
Properties modelProps = model.getProperties();
if ( modelProps != null )
{
inheritedInterpolationValues.putAll( modelProps );
}
if ( visitedModelIds.contains( key ) )
{
getLogger().debug( "Already visited: " + key + "; continuing." );
@ -156,15 +171,6 @@ private void scanInternal( File pom,
"Checking: " + model.getId() + " for extensions. (It has "
+ model.getModules().size() + " modules.)" );
if ( inheritedInterpolationValues == null )
{
inheritedInterpolationValues = new HashMap();
}
model = modelInterpolator.interpolate( model, inheritedInterpolationValues, false );
grabManagedPluginsWithExtensionsFlagTurnedOn( model, managedPluginsWithExtensionsFlag );
checkModelBuildForExtensions( model, request, inheritedRemoteRepositories, managedPluginsWithExtensionsFlag );
if ( !reactorFiles.contains( modelPom ) )
@ -182,12 +188,6 @@ private void scanInternal( File pom,
visitedModelIds,
reactorFiles );
}
Properties modelProps = model.getProperties();
if ( modelProps != null )
{
inheritedInterpolationValues.putAll( modelProps );
}
}
}
catch ( ModelInterpolationException e )

View File

@ -16,12 +16,14 @@
import org.apache.maven.project.interpolation.ModelInterpolationException;
import org.apache.maven.project.interpolation.ModelInterpolator;
import org.apache.maven.shared.tools.easymock.MockManager;
import org.apache.maven.shared.tools.easymock.TestFileManager;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.logging.console.ConsoleLogger;
import org.easymock.ArgumentsMatcher;
import org.easymock.MockControl;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import junit.framework.TestCase;
@ -32,6 +34,8 @@ public class DefaultBuildExtensionScannerTest
private MockManager mockManager;
private TestFileManager fileManager;
private MockControl extensionManagerCtl;
private ExtensionManager extensionManager;
@ -54,6 +58,7 @@ public void setUp()
super.setUp();
mockManager = new MockManager();
fileManager = new TestFileManager( "DefaultBuildExtensionScannerTest", "" );
extensionManagerCtl = MockControl.createControl( ExtensionManager.class );
mockManager.add( extensionManagerCtl );
@ -72,6 +77,14 @@ public void setUp()
modelInterpolator = (ModelInterpolator) modelInterpolatorCtl.getMock();
}
public void tearDown()
throws Exception
{
fileManager.cleanUp();
super.tearDown();
}
public void testIncludePluginWhenExtensionsFlagDirectlySet()
throws ExtensionScanningException, ProjectBuildingException, ModelInterpolationException,
ExtensionManagerException
@ -100,20 +113,20 @@ public void testIncludePluginWhenExtensionsFlagDirectlySet()
modelLineageBuilder.buildModelLineage( pomFile, null, null, null, false, true );
modelLineageBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
modelLineageBuilderCtl.setReturnValue( ml );
modelLineageBuilderCtl.setReturnValue( ml, MockControl.ZERO_OR_MORE );
modelInterpolator.interpolate( model, null, false );
modelInterpolatorCtl.setMatcher( MockControl.ALWAYS_MATCHER );
modelInterpolatorCtl.setReturnValue( model );
modelInterpolatorCtl.setReturnValue( model, MockControl.ZERO_OR_MORE );
extensionManager.addPluginAsExtension( plugin, model, Collections.EMPTY_LIST, request );
extensionManagerCtl.setVoidCallable();
extensionManagerCtl.setVoidCallable( 1 );
MavenProject superProject = new MavenProject( new Model() );
superProject.setRemoteArtifactRepositories( Collections.EMPTY_LIST );
projectBuilder.buildStandaloneSuperProject();
projectBuilderCtl.setReturnValue( superProject );
projectBuilderCtl.setReturnValue( superProject, MockControl.ZERO_OR_MORE );
mockManager.replayAll();
@ -176,34 +189,23 @@ public void testIncludePluginWhenExtensionsFlagSetInPluginManagement()
modelLineageBuilder.buildModelLineage( pomFile, null, null, null, false, true );
modelLineageBuilderCtl.setMatcher( MockControl.ALWAYS_MATCHER );
modelLineageBuilderCtl.setReturnValue( ml );
modelLineageBuilderCtl.setReturnValue( ml, MockControl.ZERO_OR_MORE );
modelInterpolator.interpolate( model, null, false );
modelInterpolatorCtl.setMatcher( new ArgumentsMatcher(){
public boolean matches( Object[] expected,
Object[] actual )
{
return expected[0].equals( actual[0] );
}
public String toString( Object[] arguments )
{
return "matcher for: " + ((Model) arguments[0]).getId();
}
} );
modelInterpolatorCtl.setReturnValue( model, 1 );
modelInterpolatorCtl.setMatcher( new FirstArgFileMatcher() );
modelInterpolatorCtl.setReturnValue( model, MockControl.ZERO_OR_MORE);
modelInterpolator.interpolate( parentModel, null, false );
modelInterpolatorCtl.setReturnValue( parentModel, 1 );
modelInterpolatorCtl.setReturnValue( parentModel, MockControl.ZERO_OR_MORE );
extensionManager.addPluginAsExtension( plugin, model, Collections.EMPTY_LIST, request );
extensionManagerCtl.setVoidCallable();
extensionManagerCtl.setVoidCallable( 1 );
MavenProject superProject = new MavenProject( new Model() );
superProject.setRemoteArtifactRepositories( Collections.EMPTY_LIST );
projectBuilder.buildStandaloneSuperProject();
projectBuilderCtl.setReturnValue( superProject );
projectBuilderCtl.setReturnValue( superProject, MockControl.ZERO_OR_MORE );
mockManager.replayAll();
@ -214,4 +216,145 @@ modelInterpolator, new ConsoleLogger( Logger.LEVEL_DEBUG,
mockManager.verifyAll();
}
public void testIncludePluginWithExtensionsFlagDeclaredInParentPluginManagementReferencedFromModule()
throws ModelInterpolationException, ProjectBuildingException, ExtensionManagerException,
ExtensionScanningException, IOException
{
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
File projectDir = fileManager.createTempDir();
File pomFile = fileManager.createFile( projectDir, "pom.xml", "Placeholder file." ).getCanonicalFile();
File modulePomFile = fileManager.createFile( projectDir,
"module/pom.xml",
"Placeholder file." ).getCanonicalFile();
Model model = new Model();
model.setGroupId( "group" );
model.setArtifactId( "artifact" );
model.setVersion( "1" );
Parent parent = new Parent();
parent.setGroupId( "group" );
parent.setArtifactId( "parent" );
parent.setVersion( "1" );
model.setParent( parent );
Model parentModel = new Model();
parentModel.setGroupId( "group" );
parentModel.setArtifactId( "parent" );
parentModel.setVersion( "1" );
Build parentBuild = new Build();
parentModel.setBuild( parentBuild );
PluginManagement pMgmt = new PluginManagement();
parentBuild.setPluginManagement( pMgmt );
Plugin parentPlugin = new Plugin();
pMgmt.addPlugin( parentPlugin );
parentPlugin.setGroupId( "test" );
parentPlugin.setArtifactId( "artifact" );
parentPlugin.setExtensions( true );
Model module = new Model();
module.setGroupId( "group" );
module.setArtifactId( "module" );
module.setVersion( "1" );
Parent moduleParent = new Parent();
moduleParent.setGroupId( model.getGroupId() );
moduleParent.setArtifactId( model.getArtifactId() );
moduleParent.setVersion( model.getVersion() );
module.setParent( moduleParent );
Build build = new Build();
module.setBuild( build );
Plugin plugin = new Plugin();
build.addPlugin( plugin );
plugin.setGroupId( "test" );
plugin.setArtifactId( "artifact" );
model.addModule( "module" );
ModelLineage ml = new DefaultModelLineage();
ml.setOrigin( model, pomFile, Collections.EMPTY_LIST, true );
ml.addParent( parentModel, pomFile, Collections.EMPTY_LIST, false );
ModelLineage moduleMl = new DefaultModelLineage();
moduleMl.setOrigin( module, modulePomFile, Collections.EMPTY_LIST, true );
moduleMl.addParent( model, pomFile, Collections.EMPTY_LIST, true );
moduleMl.addParent( parentModel, pomFile, Collections.EMPTY_LIST, false );
modelLineageBuilder.buildModelLineage( pomFile, null, null, null, false, true );
modelLineageBuilderCtl.setMatcher( new FirstArgFileMatcher() );
modelLineageBuilderCtl.setReturnValue( ml, MockControl.ZERO_OR_MORE );
modelLineageBuilder.buildModelLineage( modulePomFile, null, null, null, false, true );
modelLineageBuilderCtl.setReturnValue( moduleMl, MockControl.ZERO_OR_MORE );
modelInterpolator.interpolate( model, null, false );
modelInterpolatorCtl.setMatcher( new FirstArgModelIdMatcher() );
modelInterpolatorCtl.setReturnValue( model, MockControl.ZERO_OR_MORE );
modelInterpolator.interpolate( parentModel, null, false );
modelInterpolatorCtl.setReturnValue( parentModel, MockControl.ZERO_OR_MORE );
modelInterpolator.interpolate( module, null, false );
modelInterpolatorCtl.setReturnValue( module, MockControl.ZERO_OR_MORE );
extensionManager.addPluginAsExtension( plugin, module, Collections.EMPTY_LIST, request );
extensionManagerCtl.setVoidCallable( 1 );
MavenProject superProject = new MavenProject( new Model() );
superProject.setRemoteArtifactRepositories( Collections.EMPTY_LIST );
projectBuilder.buildStandaloneSuperProject();
projectBuilderCtl.setReturnValue( superProject, MockControl.ZERO_OR_MORE );
mockManager.replayAll();
new DefaultBuildExtensionScanner( extensionManager, projectBuilder, modelLineageBuilder,
modelInterpolator, new ConsoleLogger( Logger.LEVEL_DEBUG,
"test" ) ).scanForBuildExtensions( pomFile,
request );
mockManager.verifyAll();
}
private static final class FirstArgFileMatcher
implements ArgumentsMatcher
{
public boolean matches( Object[] expected,
Object[] actual )
{
return expected[0].equals( actual[0] );
}
public String toString( Object[] arguments )
{
return "matcher for file: " + arguments[0];
}
}
private static final class FirstArgModelIdMatcher
implements ArgumentsMatcher
{
public boolean matches( Object[] expected,
Object[] actual )
{
return ((Model)expected[0]).getId().equals( ((Model)actual[0]).getId() );
}
public String toString( Object[] arguments )
{
return "matcher for: " + ( (Model) arguments[0] ).getId();
}
}
}