o created a separate plugin manager test and we see where we've got some methods that don't belong in the lifecycle executor. need to move getMojoDescriptor to the plugin manager, just leave the parsing and construction of the lookup key in the lifecycle executor

git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@759502 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2009-03-28 16:31:54 +00:00
parent 667378b8e4
commit 6bcb9de387
5 changed files with 89 additions and 120 deletions

View File

@ -238,16 +238,8 @@ private List collectProjects( List files, MavenExecutionRequest request, boolean
{
File file = (File) iterator.next();
boolean usingReleasePom = false;
if ( RELEASE_POMv4.equals( file.getName() ) )
{
logger.info( "NOTE: Using release-pom: " + file + " in reactor build." );
usingReleasePom = true;
}
MavenProject project;
try
{
project = projectBuilder.build( file, request.getProjectBuildingConfiguration() );
@ -302,14 +294,7 @@ private List collectProjects( List files, MavenExecutionRequest request, boolean
}
else if ( moduleFile.isDirectory() )
{
if ( usingReleasePom )
{
moduleFile = new File( basedir, name + "/" + Maven.RELEASE_POMv4 );
}
else
{
moduleFile = new File( basedir, name + "/" + Maven.POMv4 );
}
moduleFile = new File( basedir, name + "/" + Maven.POMv4 );
}
if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
@ -370,14 +355,12 @@ private List getProjectFiles( MavenExecutionRequest request )
if ( request.useReactor() )
{
String includes = System.getProperty( "maven.reactor.includes", "**/" + POMv4 + ",**/" + RELEASE_POMv4 );
String includes = System.getProperty( "maven.reactor.includes", "**/" + POMv4 );
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 + "," + RELEASE_POMv4 );
String excludes = System.getProperty( "maven.reactor.excludes", POMv4 );
files = FileUtils.getFiles( userDir, includes, excludes );
filterOneProjectFilePerDirectory( files );
// make sure there is consistent ordering on all platforms, rather than using the filesystem ordering
Collections.sort( files );
}
@ -392,13 +375,8 @@ else if ( request.getPom() != null )
}
else
{
File projectFile = new File( userDir, RELEASE_POMv4 );
if ( !projectFile.exists() )
{
projectFile = new File( userDir, POMv4 );
}
File projectFile = new File( userDir, POMv4 );
if ( projectFile.exists() )
{
files = Collections.singletonList( projectFile );
@ -407,33 +385,7 @@ else if ( request.getPom() != null )
return files;
}
private void filterOneProjectFilePerDirectory( List files )
{
List releaseDirs = new ArrayList();
for ( Iterator it = files.iterator(); it.hasNext(); )
{
File projectFile = (File) it.next();
if ( RELEASE_POMv4.equals( projectFile.getName() ) )
{
releaseDirs.add( projectFile.getParentFile() );
}
}
for ( Iterator it = files.iterator(); it.hasNext(); )
{
File projectFile = (File) it.next();
// remove pom.xml files where there is a sibling release-pom.xml file...
if ( !RELEASE_POMv4.equals( projectFile.getName() ) && releaseDirs.contains( projectFile.getParentFile() ) )
{
it.remove();
}
}
}
// Lifecycle phases
public List<Lifecycle> getBuildLifecyclePhases()

View File

@ -31,14 +31,9 @@
*/
public interface Maven
{
static String ROLE = Maven.class.getName();
//jvz!! CLI pollution
String POMv4 = "pom.xml";
//!!jvz release plugin pollution
String RELEASE_POMv4 = "release-pom.xml";
MavenExecutionResult execute( MavenExecutionRequest request );
//!!jvz This should not be exposed but is as a result of the buildProjectWithDependencies

View File

@ -14,9 +14,6 @@
public class LifecycleExecutorTest
extends AbstractCoreMavenComponentTest
{
@Requirement
private PluginManager pluginManager;
@Requirement
private DefaultLifecycleExecutor lifecycleExecutor;
@ -24,7 +21,6 @@ protected void setUp()
throws Exception
{
super.setUp();
pluginManager = lookup( PluginManager.class );
lifecycleExecutor = (DefaultLifecycleExecutor) lookup( LifecycleExecutor.class );
}
@ -82,54 +78,5 @@ public void testLifecycleExecutionUsingADefaultLifecyclePhase()
assertEquals( "project-with-additional-lifecycle-elements", session.getCurrentProject().getArtifactId() );
assertEquals( "1.0-SNAPSHOT", session.getCurrentProject().getVersion() );
lifecycleExecutor.execute( session );
}
// -----------------------------------------------------------------------------------------------
// Tests which exercise the lifecycle executor when it is dealing with individual goals.
// -----------------------------------------------------------------------------------------------
//TODO: These two tests display a lack of symmetry with respect to the input which is a free form string and the
// mojo descriptor which comes back. All the free form parsing needs to be done somewhere else, this is
// really the function of the CLI, and then the pre-processing of that output still needs to be fed into
// a hinting process which helps flesh out the full specification of the plugin. The plugin manager should
// only deal in concrete terms -- all version finding mumbo jumbo is a customization to base functionality
// the plugin manager provides.
public void testRemoteResourcesPlugin()
throws Exception
{
MavenSession session = createMavenSession( getProject( "project-with-inheritance" ) );
String pluginArtifactId = "remote-resources";
String goal = "process";
MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, session.getCurrentProject() );
assertPluginDescriptor( mojoDescriptor, "org.apache.maven.plugins", "maven-remote-resources-plugin", "1.0" );
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
pluginManager.executeMojo( session.getCurrentProject(), mojoExecution, session );
}
public void testSurefirePlugin()
throws Exception
{
MavenSession session = createMavenSession( getProject( "project-with-inheritance" ) );
String pluginArtifactId = "surefire";
String goal = "test";
MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, session.getCurrentProject() );
assertPluginDescriptor( mojoDescriptor, "org.apache.maven.plugins", "maven-surefire-plugin", "2.4.2" );
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
pluginManager.executeMojo( session.getCurrentProject(), mojoExecution, session );
}
// -----------------------------------------------------------------------------------------------
// Testing help
// -----------------------------------------------------------------------------------------------
protected void assertPluginDescriptor( MojoDescriptor mojoDescriptor, String groupId, String artifactId, String version )
{
assertNotNull( mojoDescriptor );
PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
assertNotNull( pd );
assertEquals( groupId, pd.getGroupId() );
assertEquals( artifactId, pd.getArtifactId() );
assertEquals( version, pd.getVersion() );
}
}
}

View File

@ -0,0 +1,80 @@
package org.apache.maven.plugin;
import java.io.File;
import java.util.List;
import org.apache.maven.AbstractCoreMavenComponentTest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.PluginManager;
import org.apache.maven.plugin.descriptor.MojoDescriptor;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.codehaus.plexus.component.annotations.Requirement;
public class PluginManagerTest
extends AbstractCoreMavenComponentTest
{
@Requirement
private PluginManager pluginManager;
protected void setUp()
throws Exception
{
super.setUp();
pluginManager = lookup( PluginManager.class );
}
protected String getProjectsDirectory()
{
return "src/test/projects/plugin-manager";
}
// -----------------------------------------------------------------------------------------------
// Tests which exercise the lifecycle executor when it is dealing with individual goals.
// -----------------------------------------------------------------------------------------------
//TODO: These two tests display a lack of symmetry with respect to the input which is a free form string and the
// mojo descriptor which comes back. All the free form parsing needs to be done somewhere else, this is
// really the function of the CLI, and then the pre-processing of that output still needs to be fed into
// a hinting process which helps flesh out the full specification of the plugin. The plugin manager should
// only deal in concrete terms -- all version finding mumbo jumbo is a customization to base functionality
// the plugin manager provides.
public void testRemoteResourcesPlugin()
throws Exception
{
MavenSession session = createMavenSession( getProject( "project-with-inheritance" ) );
String pluginArtifactId = "remote-resources";
String goal = "process";
MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, session.getCurrentProject() );
assertPluginDescriptor( mojoDescriptor, "org.apache.maven.plugins", "maven-remote-resources-plugin", "1.0" );
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
pluginManager.executeMojo( session.getCurrentProject(), mojoExecution, session );
}
public void testSurefirePlugin()
throws Exception
{
MavenSession session = createMavenSession( getProject( "project-with-inheritance" ) );
String pluginArtifactId = "surefire";
String goal = "test";
MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, session.getCurrentProject() );
assertPluginDescriptor( mojoDescriptor, "org.apache.maven.plugins", "maven-surefire-plugin", "2.4.2" );
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
pluginManager.executeMojo( session.getCurrentProject(), mojoExecution, session );
}
// -----------------------------------------------------------------------------------------------
// Testing help
// -----------------------------------------------------------------------------------------------
protected void assertPluginDescriptor( MojoDescriptor mojoDescriptor, String groupId, String artifactId, String version )
{
assertNotNull( mojoDescriptor );
PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
assertNotNull( pd );
assertEquals( groupId, pd.getGroupId() );
assertEquals( artifactId, pd.getArtifactId() );
assertEquals( version, pd.getVersion() );
}
}

View File

@ -277,12 +277,7 @@ private void pom( MavenExecutionRequest request, Configuration configuration )
else if ( ( request.getPom() == null ) && ( request.getBaseDirectory() != null ) )
{
// Look for a release POM
File pom = new File( request.getBaseDirectory(), Maven.RELEASE_POMv4 );
if ( !pom.exists() )
{
pom = new File( request.getBaseDirectory(), Maven.POMv4 );
}
File pom = new File( request.getBaseDirectory(), Maven.POMv4 );
request.setPom( pom );
}