jvanzyl     2004/05/07 18:28:51

  Modified:    maven-core project.xml
  Added:       maven-core/src/main/java/org/apache/maven/plugin
                        IntegratedPluginGoalTestCase.java
  Log:
  o moving the integrated plugin test case to the core so it can be used
    in all the core plugins.
  
  Revision  Changes    Path
  1.10      +6 -0      maven-components/maven-core/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/maven-components/maven-core/project.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- project.xml       19 Apr 2004 13:34:04 -0000      1.9
  +++ project.xml       8 May 2004 01:28:51 -0000       1.10
  @@ -81,5 +81,11 @@
         <artifactId>wagon-http</artifactId>
         <version>0.9-SNAPSHOT</version>
       </dependency>
  +    <!-- For the abstract integrated plugin test case -->
  +    <dependency>
  +      <groupId>junit</groupId>
  +      <artifactId>junit</artifactId>
  +      <version>3.8.1</version>
  +    </dependency>
     </dependencies>
   </project>
  
  
  
  1.1                  
maven-components/maven-core/src/main/java/org/apache/maven/plugin/IntegratedPluginGoalTestCase.java
  
  Index: IntegratedPluginGoalTestCase.java
  ===================================================================
  package org.apache.maven.plugin;
  
  import org.apache.maven.plugin.descriptor.GoalDescriptor;
  import org.apache.maven.plugin.descriptor.PluginDescriptor;
  import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
  import org.apache.maven.plugin.manager.DefaultPluginManagerManager;
  import org.apache.maven.plugin.manager.executor.IntegratedPluginExecutor;
  import org.apache.maven.project.MavenProject;
  import org.apache.maven.project.MavenProjectBuilder;
  import org.codehaus.plexus.PlexusTestCase;
  
  import java.io.File;
  import java.io.InputStreamReader;
  import java.util.Iterator;
  import java.util.Map;
  
  /**
   * @author <a href="mailto:[EMAIL PROTECTED]">Jason van Zyl</a>
   * @version $Id: IntegratedPluginGoalTestCase.java,v 1.1 2004/05/08 01:28:51 jvanzyl 
Exp $
   */
  public abstract class IntegratedPluginGoalTestCase
      extends PlexusTestCase
  {
      protected static String PLUGIN_DESCRIPTOR = "META-INF/maven/plugin.xml";
  
      public IntegratedPluginGoalTestCase( String s )
      {
          super( s );
      }
  
      public abstract String getPluginId();
  
      public abstract String getGoal();
  
      protected void setUp()
          throws Exception
      {
          super.setUp();
  
          PluginDescriptor pluginDescriptor = findPluginDescriptor();
  
          getContainer().addComponentDescriptor( pluginDescriptor );
      }
  
      public void testIntegratedPlugin()
          throws Exception
      {
          MavenProjectBuilder builder = (MavenProjectBuilder) lookup( 
MavenProjectBuilder.ROLE );
  
          MavenProject project = builder.build( new File( basedir, "project.xml" ) );
  
          Plugin plugin = (Plugin) lookup( Plugin.ROLE, getPluginId() );
  
          PluginExecutionResponse response = executePlugin( plugin, getGoal(), project 
);
  
          if ( response.exceptionOccurred() )
          {
              throw new Exception( response.getException() );
          }
      }
  
      protected PluginExecutionResponse executePlugin( Plugin plugin, String goal, 
MavenProject project )
          throws Exception
      {
          IntegratedPluginExecutor executor = new IntegratedPluginExecutor();
  
          PluginExecutionRequest request = createPluginExecutionRequest( goal, project 
);
  
          request.setPlugin( plugin );
  
          PluginExecutionResponse response = new PluginExecutionResponse();
  
          executor.execute( request, response );
  
          return response;
      }
  
      protected PluginExecutionRequest createPluginExecutionRequest( String goal, 
MavenProject project )
          throws Exception
      {
          PluginDescriptor pluginDescriptor = findPluginDescriptor();
  
          GoalDescriptor goalDescriptor = findGoalDescriptor( pluginDescriptor, goal );
  
          Map parameters = DefaultPluginManagerManager.createParameters( 
goalDescriptor, project );
  
          PluginExecutionRequest request = new PluginExecutionRequest( parameters );
  
          return request;
      }
  
      protected GoalDescriptor findGoalDescriptor( PluginDescriptor pluginDescriptor, 
String goal )
      {
          GoalDescriptor goalDescriptor = null;
  
          for ( Iterator iterator = pluginDescriptor.getGoals().iterator(); 
iterator.hasNext(); )
          {
              GoalDescriptor gd = (GoalDescriptor) iterator.next();
  
              if ( gd.getName().equals( goal ) )
              {
                  goalDescriptor = gd;
  
                  break;
              }
          }
  
          return goalDescriptor;
      }
  
      protected PluginDescriptor findPluginDescriptor()
          throws Exception
      {
          PluginDescriptorBuilder builder = new PluginDescriptorBuilder();
  
          ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  
          PluginDescriptor pluginDescriptor =
              builder.build( new InputStreamReader( classLoader.getResourceAsStream( 
PLUGIN_DESCRIPTOR ) ) );
  
          return pluginDescriptor;
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to