mirror of https://github.com/apache/maven.git
o create some standard test tools for the lifecycle executor
git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@757434 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0a18feb00e
commit
881bebd552
|
@ -27,7 +27,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import org.apache.maven.artifact.repository.ArtifactRepository;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
|
@ -127,8 +126,7 @@ public class MavenSession
|
|||
return container.lookup( role );
|
||||
}
|
||||
|
||||
public Object lookup( String role,
|
||||
String roleHint )
|
||||
public Object lookup( String role, String roleHint )
|
||||
throws ComponentLookupException
|
||||
{
|
||||
return container.lookup( role, roleHint );
|
||||
|
@ -146,13 +144,13 @@ public class MavenSession
|
|||
return container.lookup( type, roleHint );
|
||||
}
|
||||
|
||||
public List lookupList( String role )
|
||||
public List<Object> lookupList( String role )
|
||||
throws ComponentLookupException
|
||||
{
|
||||
return container.lookupList( role );
|
||||
}
|
||||
|
||||
public Map lookupMap( String role )
|
||||
public Map<String,Object> lookupMap( String role )
|
||||
throws ComponentLookupException
|
||||
{
|
||||
return container.lookupMap( role );
|
||||
|
|
|
@ -59,7 +59,6 @@ import org.apache.maven.model.Model;
|
|||
import org.apache.maven.model.Plugin;
|
||||
import org.apache.maven.model.PluginExecution;
|
||||
import org.apache.maven.model.ReportPlugin;
|
||||
import org.apache.maven.monitor.event.EventDispatcher;
|
||||
import org.apache.maven.monitor.event.MavenEvents;
|
||||
import org.apache.maven.monitor.logging.DefaultLog;
|
||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||
|
@ -353,7 +352,7 @@ public class DefaultPluginManager
|
|||
}
|
||||
|
||||
/* get plugin managed versions */
|
||||
Map pluginManagedDependencies = new HashMap();
|
||||
Map<String,Artifact> pluginManagedDependencies = new HashMap<String,Artifact>();
|
||||
|
||||
// This is really crappy that we have to do this. The repository system should deal with this. The retrieval of the transitive dependencies.
|
||||
|
||||
|
@ -559,8 +558,6 @@ public class DefaultPluginManager
|
|||
|
||||
// Event monitoring.
|
||||
String event = MavenEvents.MOJO_EXECUTION;
|
||||
EventDispatcher dispatcher = session.getEventDispatcher();
|
||||
|
||||
String goalExecId = goalName;
|
||||
if ( mojoExecution.getExecutionId() != null )
|
||||
{
|
||||
|
|
|
@ -73,7 +73,16 @@ public class LifecycleExecutorTest
|
|||
assertNotNull( lifecycleExecutor.getLifecyclePhases() );
|
||||
}
|
||||
|
||||
public void testStandardLifecycle()
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
// Tests which exercise the lifecycle executor when it is dealing with default lifecycle phases.
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
public void testLifecycleQueryingUsingADefaultLifecyclePhase()
|
||||
throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void testLifecycleExecutionUsingADefaultLifecyclePhase()
|
||||
throws Exception
|
||||
{
|
||||
String base = "projects/lifecycle-executor/project-with-additional-lifecycle-elements";
|
||||
|
@ -82,6 +91,88 @@ public class LifecycleExecutorTest
|
|||
FileUtils.copyDirectoryStructure( sourceDirectory, targetDirectory );
|
||||
File targetPom = new File( targetDirectory, "pom.xml" );
|
||||
|
||||
MavenSession session = createMavenSession( targetPom );
|
||||
|
||||
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.
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
public void testRemoteResourcesPlugin()
|
||||
throws Exception
|
||||
{
|
||||
MavenSession session = createMavenSession( targetPom );
|
||||
|
||||
String pluginArtifactId = "remote-resources";
|
||||
String goal = "process";
|
||||
MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, session.getCurrentProject() );
|
||||
|
||||
PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
|
||||
assertNotNull( pd );
|
||||
assertEquals( "org.apache.maven.plugins", pd.getGroupId() );
|
||||
assertEquals( "maven-remote-resources-plugin", pd.getArtifactId() );
|
||||
assertEquals( "1.0", pd.getVersion() );
|
||||
|
||||
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
|
||||
|
||||
pluginManager.executeMojo( session.getCurrentProject(), mojoExecution, session );
|
||||
}
|
||||
|
||||
public void testSurefirePlugin()
|
||||
throws Exception
|
||||
{
|
||||
MavenSession session = createMavenSession( targetPom );
|
||||
|
||||
String pluginArtifactId = "surefire";
|
||||
String goal = "test";
|
||||
MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, session.getCurrentProject() );
|
||||
assertNotNull( mojoDescriptor );
|
||||
|
||||
PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
|
||||
assertNotNull( pd );
|
||||
assertEquals( "org.apache.maven.plugins", pd.getGroupId() );
|
||||
assertEquals( "maven-surefire-plugin", pd.getArtifactId() );
|
||||
assertEquals( "2.4.2", pd.getVersion() );
|
||||
|
||||
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
|
||||
|
||||
pluginManager.executeMojo( session.getCurrentProject(), mojoExecution, session );
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
// Testing help
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* We need to customize the standard Plexus container with the plugin discovery listener which
|
||||
* is what looks for the META-INF/maven/plugin.xml resources that enter the system when a
|
||||
* Maven plugin is loaded.
|
||||
*
|
||||
* We also need to customize the Plexus container with a standard plugin discovery listener
|
||||
* which is the MavenPluginCollector. When a Maven plugin is discovered the MavenPluginCollector
|
||||
* collects the plugin descriptors which are found.
|
||||
*/
|
||||
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
|
||||
{
|
||||
containerConfiguration.addComponentDiscoverer( new MavenPluginDiscoverer() );
|
||||
containerConfiguration.addComponentDiscoveryListener( new MavenPluginCollector() );
|
||||
}
|
||||
|
||||
//!!jvz The repository system needs to know about the defaults for Maven, it's tied up in the embedder right now.
|
||||
protected ArtifactRepository getLocalRepository()
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
return repositorySystem.createLocalRepository( new File( "/Users/jvanzyl/.m2/repository" ) );
|
||||
}
|
||||
|
||||
protected MavenSession createMavenSession( File pom )
|
||||
throws Exception
|
||||
{
|
||||
ArtifactRepository localRepository = getLocalRepository();
|
||||
|
||||
Repository repository = new Repository();
|
||||
|
@ -92,9 +183,7 @@ public class LifecycleExecutorTest
|
|||
.setLocalRepository( localRepository )
|
||||
.setRemoteRepositories( Arrays.asList( repositorySystem.buildArtifactRepository( repository ) ) );
|
||||
|
||||
MavenProject project = projectBuilder.build( targetPom, configuration );
|
||||
assertEquals( "project-with-additional-lifecycle-elements", project.getArtifactId() );
|
||||
assertEquals( "1.0-SNAPSHOT", project.getVersion() );
|
||||
MavenProject project = projectBuilder.build( pom, configuration );
|
||||
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest()
|
||||
.setProjectPresent( true )
|
||||
|
@ -116,126 +205,6 @@ public class LifecycleExecutorTest
|
|||
//!!jvz This is not really quite right, take a look at how this actually works.
|
||||
session.setCurrentProject( project );
|
||||
|
||||
|
||||
lifecycleExecutor.execute( session );
|
||||
}
|
||||
|
||||
public void testRemoteResourcesPlugin()
|
||||
throws Exception
|
||||
{
|
||||
// - find the plugin [extension point: any client may wish to do whatever they choose]
|
||||
// - load the plugin into a classloader [extension point: we want to take them from a repository, some may take from disk or whatever]
|
||||
// - configure the plugin [extension point]
|
||||
// - execute the plugin
|
||||
|
||||
if ( !targetPom.getParentFile().exists() )
|
||||
{
|
||||
targetPom.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
ArtifactRepository localRepository = getLocalRepository();
|
||||
|
||||
Repository repository = new Repository();
|
||||
repository.setUrl( "http://repo1.maven.org/maven2" );
|
||||
repository.setId( "central" );
|
||||
|
||||
ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration()
|
||||
.setLocalRepository( localRepository ).setRemoteRepositories( Arrays.asList( repositorySystem.buildArtifactRepository( repository ) ) );
|
||||
|
||||
MavenProject project = projectBuilder.build( targetPom, configuration );
|
||||
assertEquals( "maven", project.getArtifactId() );
|
||||
assertEquals( "3.0-SNAPSHOT", project.getVersion() );
|
||||
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setProjectPresent( true ).setPluginGroups( Arrays.asList( new String[] { "org.apache.maven.plugins" } ) )
|
||||
.setLocalRepository( localRepository ).setRemoteRepositories( Arrays.asList( repositorySystem.buildArtifactRepository( repository ) ) ).setProperties( new Properties() );
|
||||
|
||||
MavenSession session = new MavenSession( getContainer(), request, null );
|
||||
//!!jvz This is not really quite right, take a look at how this actually works.
|
||||
session.setCurrentProject( project );
|
||||
|
||||
String pluginArtifactId = "remote-resources";
|
||||
String goal = "process";
|
||||
MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, project );
|
||||
|
||||
PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
|
||||
assertNotNull( pd );
|
||||
assertEquals( "org.apache.maven.plugins", pd.getGroupId() );
|
||||
assertEquals( "maven-remote-resources-plugin", pd.getArtifactId() );
|
||||
assertEquals( "1.0", pd.getVersion() );
|
||||
|
||||
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
|
||||
|
||||
// Need some xpath action in here. Make sure the mojoExecution configuration is intact
|
||||
|
||||
// Now the magical mojo descriptor is complete and I can execute the mojo.
|
||||
pluginManager.executeMojo( project, mojoExecution, session );
|
||||
}
|
||||
|
||||
public void testSurefirePlugin()
|
||||
throws Exception
|
||||
{
|
||||
// - find the plugin [extension point: any client may wish to do whatever they choose]
|
||||
// - load the plugin into a classloader [extension point: we want to take them from a repository, some may take from disk or whatever]
|
||||
// - configure the plugin [extension point]
|
||||
// - execute the plugin
|
||||
|
||||
if ( !targetPom.getParentFile().exists() )
|
||||
{
|
||||
targetPom.getParentFile().mkdirs();
|
||||
}
|
||||
|
||||
ArtifactRepository localRepository = getLocalRepository();
|
||||
|
||||
Repository repository = new Repository();
|
||||
repository.setUrl( "http://repo1.maven.org/maven2" );
|
||||
repository.setId( "central" );
|
||||
|
||||
ProjectBuilderConfiguration configuration = new DefaultProjectBuilderConfiguration()
|
||||
.setLocalRepository( localRepository )
|
||||
.setRemoteRepositories( Arrays.asList( repositorySystem.buildArtifactRepository( repository ) ) );
|
||||
|
||||
MavenProject project = projectBuilder.build( targetPom, configuration );
|
||||
assertEquals( "maven", project.getArtifactId() );
|
||||
assertEquals( "3.0-SNAPSHOT", project.getVersion() );
|
||||
|
||||
MavenExecutionRequest request = new DefaultMavenExecutionRequest().setProjectPresent( true ).setPluginGroups( Arrays.asList( new String[] { "org.apache.maven.plugins" } ) )
|
||||
.setLocalRepository( localRepository )
|
||||
.setRemoteRepositories( Arrays.asList( repositorySystem.buildArtifactRepository( repository ) ) )
|
||||
.setProperties( new Properties() );
|
||||
|
||||
MavenSession session = new MavenSession( getContainer(), request, null );
|
||||
//!!jvz This is not really quite right, take a look at how this actually works.
|
||||
session.setCurrentProject( project );
|
||||
|
||||
String pluginArtifactId = "surefire";
|
||||
String goal = "test";
|
||||
MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, project );
|
||||
assertNotNull( mojoDescriptor );
|
||||
|
||||
PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
|
||||
assertNotNull( pd );
|
||||
assertEquals( "org.apache.maven.plugins", pd.getGroupId() );
|
||||
assertEquals( "maven-surefire-plugin", pd.getArtifactId() );
|
||||
assertEquals( "2.4.2", pd.getVersion() );
|
||||
|
||||
MojoExecution mojoExecution = new MojoExecution( mojoDescriptor );
|
||||
|
||||
// Need some xpath action in here. Make sure the mojoExecution configuration is intact
|
||||
|
||||
// Now the magical mojo descriptor is complete and I can execute the mojo.
|
||||
pluginManager.executeMojo( project, mojoExecution, session );
|
||||
}
|
||||
|
||||
protected void customizeContainerConfiguration( ContainerConfiguration containerConfiguration )
|
||||
{
|
||||
containerConfiguration.addComponentDiscoverer( new MavenPluginDiscoverer() );
|
||||
containerConfiguration.addComponentDiscoveryListener( new MavenPluginCollector() );
|
||||
}
|
||||
|
||||
//!!jvz The repository system needs to know about the defaults for Maven, it's tied up in the embedder right now.
|
||||
protected ArtifactRepository getLocalRepository()
|
||||
throws InvalidRepositoryException
|
||||
{
|
||||
return repositorySystem.createLocalRepository( new File( "/Users/jvanzyl/.m2/repository" ) );
|
||||
return session;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue