You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2009/03/23 17:45:02 UTC

svn commit: r757434 - in /maven/components/branches/MNG-2766/maven-core/src: main/java/org/apache/maven/execution/MavenSession.java main/java/org/apache/maven/plugin/DefaultPluginManager.java test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java

Author: jvanzyl
Date: Mon Mar 23 16:45:00 2009
New Revision: 757434

URL: http://svn.apache.org/viewvc?rev=757434&view=rev
Log:
o create some standard test tools for the lifecycle executor

Modified:
    maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
    maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
    maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java

Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java?rev=757434&r1=757433&r2=757434&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/execution/MavenSession.java Mon Mar 23 16:45:00 2009
@@ -27,7 +27,6 @@
 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 @@
         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 @@
         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 );

Modified: maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java?rev=757434&r1=757433&r2=757434&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java Mon Mar 23 16:45:00 2009
@@ -59,7 +59,6 @@
 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 @@
         }
         
         /* 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 @@
 
         // Event monitoring.
         String event = MavenEvents.MOJO_EXECUTION;
-        EventDispatcher dispatcher = session.getEventDispatcher();
-
         String goalExecId = goalName;
         if ( mojoExecution.getExecutionId() != null )
         {

Modified: maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java
URL: http://svn.apache.org/viewvc/maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java?rev=757434&r1=757433&r2=757434&view=diff
==============================================================================
--- maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java (original)
+++ maven/components/branches/MNG-2766/maven-core/src/test/java/org/apache/maven/lifecycle/LifecycleExecutorTest.java Mon Mar 23 16:45:00 2009
@@ -73,7 +73,16 @@
         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,80 +91,26 @@
         FileUtils.copyDirectoryStructure( sourceDirectory, targetDirectory );
         File targetPom = new File( targetDirectory, "pom.xml" );        
         
-        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( "project-with-additional-lifecycle-elements", project.getArtifactId() );
-        assertEquals( "1.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 ) ) )
-            .setGoals( Arrays.asList( new String[] { "package" } ) )    
-            .addEventMonitor( new DefaultEventMonitor( new ConsoleLogger( 0, "" ) ) )
-            .setProperties( new Properties() );
-
-        List projects = new ArrayList();
-        projects.add( project );
-        
-        ReactorManager reactorManager = new ReactorManager( projects, request.getReactorFailureBehavior() );
+        MavenSession session = createMavenSession( targetPom );
         
-        EventDispatcher dispatcher = new DeprecationEventDispatcher( MavenEvents.DEPRECATIONS, request.getEventMonitors() );        
-        
-        MavenSession session = new MavenSession( getContainer(), request, reactorManager, dispatcher );
-        //!!jvz This is not really quite right, take a look at how this actually works.
-        session.setCurrentProject( project );
-                
+        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
     {
-        // - 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 );
+        MavenSession session = createMavenSession( targetPom );       
 
         String pluginArtifactId = "remote-resources";
         String goal = "process";
-        MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, project );
+        MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, session.getCurrentProject() );
 
         PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
         assertNotNull( pd );
@@ -165,51 +120,17 @@
 
         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 );
+        pluginManager.executeMojo( session.getCurrentProject(), 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 );
+        MavenSession session = createMavenSession( targetPom );       
 
         String pluginArtifactId = "surefire";
         String goal = "test";
-        MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, project );
+        MojoDescriptor mojoDescriptor = lifecycleExecutor.getMojoDescriptor( pluginArtifactId + ":" + goal, session, session.getCurrentProject() );
         assertNotNull( mojoDescriptor );
         
         PluginDescriptor pd = mojoDescriptor.getPluginDescriptor();
@@ -220,22 +141,70 @@
 
         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 );
+        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();
+        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( pom, configuration );
+
+        MavenExecutionRequest request = new DefaultMavenExecutionRequest()
+            .setProjectPresent( true )
+            .setPluginGroups( Arrays.asList( new String[] { "org.apache.maven.plugins" } ) )
+            .setLocalRepository( localRepository )
+            .setRemoteRepositories( Arrays.asList( repositorySystem.buildArtifactRepository( repository ) ) )
+            .setGoals( Arrays.asList( new String[] { "package" } ) )    
+            .addEventMonitor( new DefaultEventMonitor( new ConsoleLogger( 0, "" ) ) )
+            .setProperties( new Properties() );
+
+        List projects = new ArrayList();
+        projects.add( project );
+        
+        ReactorManager reactorManager = new ReactorManager( projects, request.getReactorFailureBehavior() );
+        
+        EventDispatcher dispatcher = new DeprecationEventDispatcher( MavenEvents.DEPRECATIONS, request.getEventMonitors() );        
+        
+        MavenSession session = new MavenSession( getContainer(), request, reactorManager, dispatcher );
+        //!!jvz This is not really quite right, take a look at how this actually works.
+        session.setCurrentProject( project );
+        
+        return session;
+    }
 }