Author: kenney
Date: Tue Jun  5 12:36:11 2007
New Revision: 544607

URL: http://svn.apache.org/viewvc?view=rev&rev=544607
Log:
upgrade to use maven 2.1 embedder - it's been dropped out of 2.0.5 and later, 
so this plugin is only  usable in 2.1 anyway.

Modified:
    maven/sandbox/trunk/plugins/maven-it-plugin/pom.xml
    
maven/sandbox/trunk/plugins/maven-it-plugin/src/main/java/org/apache/maven/plugin/it/ForkMojo.java

Modified: maven/sandbox/trunk/plugins/maven-it-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-it-plugin/pom.xml?view=diff&rev=544607&r1=544606&r2=544607
==============================================================================
--- maven/sandbox/trunk/plugins/maven-it-plugin/pom.xml (original)
+++ maven/sandbox/trunk/plugins/maven-it-plugin/pom.xml Tue Jun  5 12:36:11 2007
@@ -17,25 +17,25 @@
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-embedder</artifactId>
-      <version>2.0.1</version>
+      <version>2.1-SNAPSHOT</version>
     </dependency>
 
-    <dependency> <!-- for MavenSession, since session.container doesn't work 
-->
+    <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-core</artifactId>
-      <version>2.0.1</version>
+      <version>2.1-SNAPSHOT</version>
     </dependency>
 
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-project</artifactId>
-      <version>2.0.1</version>
+      <version>2.1-SNAPSHOT</version>
     </dependency>
     
     <dependency>
       <groupId>org.apache.maven</groupId>
       <artifactId>maven-artifact</artifactId>
-      <version>2.0.1</version>
+      <version>2.1-SNAPSHOT</version>
     </dependency>
   </dependencies>
 </project>

Modified: 
maven/sandbox/trunk/plugins/maven-it-plugin/src/main/java/org/apache/maven/plugin/it/ForkMojo.java
URL: 
http://svn.apache.org/viewvc/maven/sandbox/trunk/plugins/maven-it-plugin/src/main/java/org/apache/maven/plugin/it/ForkMojo.java?view=diff&rev=544607&r1=544606&r2=544607
==============================================================================
--- 
maven/sandbox/trunk/plugins/maven-it-plugin/src/main/java/org/apache/maven/plugin/it/ForkMojo.java
 (original)
+++ 
maven/sandbox/trunk/plugins/maven-it-plugin/src/main/java/org/apache/maven/plugin/it/ForkMojo.java
 Tue Jun  5 12:36:11 2007
@@ -18,16 +18,21 @@
 
 import org.apache.maven.BuildFailureException;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.embedder.DefaultConfiguration;
 import org.apache.maven.embedder.MavenEmbedder;
 import org.apache.maven.embedder.MavenEmbedderException;
 import org.apache.maven.embedder.MavenEmbedderLogger;
+import org.apache.maven.execution.DefaultMavenExecutionRequest;
+import org.apache.maven.execution.MavenExecutionRequest;
 import org.apache.maven.lifecycle.LifecycleExecutionException;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.DuplicateProjectException;
 import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingException;
 import org.apache.maven.project.ProjectSorter;
+import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.dag.CycleDetectedException;
 
 import java.io.BufferedReader;
@@ -42,11 +47,10 @@
 import java.util.StringTokenizer;
 
 /**
- * Searches for integration test Maven projects, and executes each, collecting 
a log in the project directory, and outputting
- * the results to the screen.
- * 
- * @goal test
+ * Searches for integration test Maven projects, and executes each, collecting 
a log in the project directory, and
+ * outputting the results to the screen.
  *
+ * @goal test
  * @author <a href="mailto:[EMAIL PROTECTED]">Kenney Westerhof</a>
  * @author <a href="mailto:[EMAIL PROTECTED]">John Casey</a>
  */
@@ -55,7 +59,7 @@
 {
     /**
      * The local repository for caching artifacts.
-     * 
+     *
      * @parameter default-value="${localRepository}"
      * @required
      * @readonly
@@ -64,92 +68,118 @@
 
     /**
      * Directory to search for integration tests.
+     *
      * @parameter default-value="${basedir}/src/it/" expression="${it.testDir}"
      */
     private File integrationTestsDirectory;
-    
+
     /**
      * Comma-separated includes for searching the integration test directory, 
meant for specifying on the command-line.
-     * 
+     *
      * @parameter expression="${it.includes}
      */
     private String includesPattern;
 
     /**
      * Comma-separated excludes for searching the integration test directory, 
meant for specifying on the command-line.
-     * 
+     *
      * @parameter expression="${it.excludes}"
      */
     private String excludesPattern;
 
     /**
      * Includes for searching the integration test directory. This parameter 
is meant to be set from the POM.
-     * 
+     *
      * @parameter
      */
     private String[] includes = new String[] { "*/pom.xml" };
 
     /**
      * Excludes for searching the integration test directory. This parameter 
is meant to be set from the POM.
-     * 
+     *
      * @parameter
      */
     private String[] excludes = new String[0];
-    
+
     /**
      * The comma-separated list of goals to execute on each project.
-     * 
+     *
      * @parameter expression="${it.goals}" default-value="package"
      */
     private String goals;
-    
+
     /**
      * The name of the project-specific file that contains the enumeration of 
goals to execute for that test.
-     * 
+     *
      * @parameter
      */
     private String goalFile;
 
     public void execute()
-        throws MojoExecutionException, MojoFailureException
+        throws MojoExecutionException,
+            MojoFailureException
     {
-        // 
----------------------------------------------------------------------
-        // Here we will try to use the embedder
-        // 
----------------------------------------------------------------------
-        //
-         ClassLoader classLoader = 
Thread.currentThread().getContextClassLoader();
-        
-         MavenEmbedder maven = new MavenEmbedder();
-        
-         maven.setClassLoader( classLoader );
-        
+        DefaultConfiguration embedderConfig = new DefaultConfiguration();
+
+        embedderConfig.setClassLoader( 
Thread.currentThread().getContextClassLoader() );
+        embedderConfig.setLocalRepository( new File( 
localRepository.getBasedir() ) );
+
+        MavenEmbedder maven;
         try
         {
-            maven.start();
+            maven = new MavenEmbedder( embedderConfig );
         }
         catch ( MavenEmbedderException e )
         {
-            throw new MojoExecutionException( "Cannot start embedder.", e );
+            throw new MojoExecutionException( "Failed to create the embedder", 
e );
         }
-        
+
+        // maven.setClassLoader( 
Thread.currentThread().getContextClassLoader() );
+        // maven.setLocalRepositoryDirectory( new File( 
localRepository.getBasedir() ) );
+
+        /*
+         * try { maven.start(); } catch ( MavenEmbedderException e ) { throw 
new MojoExecutionException( "Cannot start
+         * embedder.", e ); }
+         */
+
         String[] include = collectPatterns( includesPattern, includes );
         String[] exclude = collectPatterns( excludesPattern, excludes );
-        
-        List projects = maven.collectProjects( integrationTestsDirectory, 
include, exclude );
-        
+
+        // List projects = maven.collectProjects( integrationTestsDirectory, 
include, exclude );
+
+        DirectoryScanner scanner = new DirectoryScanner();
+        scanner.setBasedir( integrationTestsDirectory );
+        scanner.setIncludes( include );
+        scanner.setExcludes( exclude );
+        scanner.scan();
+        String[] files = scanner.getIncludedFiles();
+        List projects = new ArrayList();
+        for ( int i = 0; i < files.length; i++ )
+        {
+            File pomFile = new File( integrationTestsDirectory, files[i] );
+            try
+            {
+                projects.add( maven.readProject( pomFile ) );
+            }
+            catch ( ProjectBuildingException e )
+            {
+                throw new MojoExecutionException( "Error reading project " + 
files[i], e );
+            }
+        }
+
         try
         {
             projects = new ProjectSorter( projects ).getSortedProjects();
         }
         catch ( CycleDetectedException e )
         {
-            throw new MojoExecutionException( "Failed to sort integration-test 
projects. Reason: " + e.getMessage() , e );
+            throw new MojoExecutionException( "Failed to sort integration-test 
projects. Reason: " + e.getMessage(), e );
         }
         catch ( DuplicateProjectException e )
         {
-            throw new MojoExecutionException( "Failed to sort integration-test 
projects. Reason: " + e.getMessage() , e );
+            throw new MojoExecutionException( "Failed to sort integration-test 
projects. Reason: " + e.getMessage(), e );
         }
-        
+
         if ( projects.isEmpty() )
         {
             getLog().info( "No test-projects were selected for execution." );
@@ -157,31 +187,31 @@
         }
 
         List goalList = collectListFromCSV( goals );
-        
+
         if ( goalList.isEmpty() )
         {
             goalList.add( "package" );
         }
-        
+
         Properties buildProperties = new Properties();
 
         List failures = new ArrayList();
-        
+
         for ( Iterator it = projects.iterator(); it.hasNext(); )
         {
             // run each one, so we can get a separate report.
             MavenProject project = (MavenProject) it.next();
-            
+
             List projectGoals = goalList;
-            
+
             if ( goalFile != null )
             {
                 File projectGoalList = new File( 
project.getFile().getParentFile(), goalFile );
-                
+
                 if ( projectGoalList.exists() )
                 {
                     List goals = readFromFile( projectGoalList );
-                    
+
                     if ( goals != null && !goals.isEmpty() )
                     {
                         getLog().info( "Using goals specified in file: " + 
projectGoalList );
@@ -189,60 +219,69 @@
                     }
                 }
             }
-            
+
             String defaultGoal = project.getDefaultGoal();
-            
+
             if ( defaultGoal != null && defaultGoal.trim().length() > 0 )
             {
                 getLog().info( "Executing default goal: " + defaultGoal + " 
for project: " + project.getId() );
-                
+
                 projectGoals = Collections.singletonList( defaultGoal );
             }
             else
             {
                 getLog().info( "Executing goals: " + projectGoals + " for 
project: " + project.getId() );
             }
-            
+
             getLog().info( "Running test: " + project.getId() + "..." );
-            
-            maven.setInteractiveMode(false);
-            maven.setLocalRepositoryDirectory( new File( 
localRepository.getBasedir() ) );
-            maven.setCheckLatestPluginVersion(false);
-            
+
             File outputLog = new File( project.getBasedir(), "build.log" );
-            
+
             MavenEmbedderLogger logger = new ToFileEmbedderLogger( outputLog );
-            
+
             maven.setLogger( logger );
-            
+
             try
             {
-                maven.execute( Collections.singletonList( project ), 
projectGoals, new EmbedderEventMonitor( logger ), new EmbedderTransferListener( 
logger ), buildProperties, project.getBasedir() );
-                
+                // maven.setCheckLatestPluginVersion(false);
+                // maven.setInteractiveMode(false);
+                DefaultMavenExecutionRequest req = new 
DefaultMavenExecutionRequest();
+                req.setBaseDirectory( project.getBasedir() );
+                req.setInteractiveMode( false );
+                req.setGoals( projectGoals );
+                req.setProperties( buildProperties );
+                maven.execute( req );
+
+                // maven.execute( Collections.singletonList( project ), 
projectGoals, new EmbedderEventMonitor( logger
+                // ), new EmbedderTransferListener( logger ), buildProperties, 
project.getBasedir() );
+
                 getLog().info( "...SUCCESS." );
             }
-            catch ( CycleDetectedException e )
-            {
-                getLog().info( "...FAILED: ", e );
-                failures.add( project.getId() );
-            }
-            catch ( LifecycleExecutionException e )
-            {
-                getLog().info( "...FAILED: ", e );
-                failures.add( project.getId() );
-            }
-            catch ( BuildFailureException e )
-            {
-                getLog().info( "...FAILED. See " + outputLog.getAbsolutePath() 
+ " for details." );
-                failures.add( project.getId() );
-            }
-            catch ( DuplicateProjectException e )
+            finally
             {
-                getLog().info( "...FAILED: ", e );
-                failures.add( project.getId() );
             }
+            // catch ( CycleDetectedException e )
+            // {
+            // getLog().info( "...FAILED: ", e );
+            // failures.add( project.getId() );
+            // }
+            // catch ( LifecycleExecutionException e )
+            // {
+            // getLog().info( "...FAILED: ", e );
+            // failures.add( project.getId() );
+            // }
+            // catch ( BuildFailureException e )
+            // {
+            // getLog().info( "...FAILED. See " + outputLog.getAbsolutePath() 
+ " for details." );
+            // failures.add( project.getId() );
+            // }
+            // catch ( DuplicateProjectException e )
+            // {
+            // getLog().info( "...FAILED: ", e );
+            // failures.add( project.getId() );
+            // }
         }
-        
+
         StringBuffer summary = new StringBuffer();
         summary.append( "\n\n" );
         summary.append( "---------------------------------------\n" );
@@ -250,23 +289,22 @@
         summary.append( "Tests Passing: " ).append( projects.size() - 
failures.size() ).append( "\n" );
         summary.append( "Tests Failing: " ).append( failures.size() ).append( 
"\n" );
         summary.append( "---------------------------------------\n" );
-        
+
         if ( !failures.isEmpty() )
         {
             summary.append( "\nThe following tests failed:\n" );
-            
+
             for ( Iterator it = failures.iterator(); it.hasNext(); )
             {
                 String projectId = (String) it.next();
                 summary.append( "\n*  " ).append( projectId );
             }
-            
+
             summary.append( "\n" );
         }
-        
+
         getLog().info( summary.toString() );
 
-        
         if ( !failures.isEmpty() )
         {
             throw new MojoFailureException( this, "There were test failures.", 
failures.size() + " tests failed." );
@@ -276,24 +314,26 @@
     private List readFromFile( File projectGoalList )
     {
         BufferedReader reader = null;
-        
+
         List result = null;
-        
+
         try
         {
             reader = new BufferedReader( new FileReader( projectGoalList ) );
-            
+
             result = new ArrayList();
-            
+
             String line = null;
-            while( ( line = reader.readLine() ) != null )
+            while ( ( line = reader.readLine() ) != null )
             {
                 result.addAll( collectListFromCSV( line ) );
             }
         }
-        catch( IOException e )
+        catch ( IOException e )
         {
-            getLog().warn( "Failed to load goal list from file: " + 
projectGoalList + ". Using 'goal' parameter configured on this plugin instead." 
);
+            getLog().warn(
+                "Failed to load goal list from file: " + projectGoalList
+                    + ". Using 'goal' parameter configured on this plugin 
instead." );
             getLog().debug( "Error reading goals file: " + projectGoalList, e 
);
         }
         finally
@@ -309,39 +349,39 @@
                 }
             }
         }
-        
+
         return result;
     }
 
     private List collectListFromCSV( String csv )
     {
         List result = new ArrayList();
-        
+
         if ( csv != null && csv.trim().length() > 0 )
         {
             StringTokenizer st = new StringTokenizer( csv, "," );
-            
-            while( st.hasMoreTokens() )
+
+            while ( st.hasMoreTokens() )
             {
                 result.add( st.nextToken().trim() );
             }
         }
-        
+
         return result;
     }
 
     private String[] collectPatterns( String pattern, String[] array )
     {
         String[] result;
-        
+
         if ( pattern != null && pattern.trim().length() > 0 )
         {
             StringTokenizer st = new StringTokenizer( pattern, "," );
-            
+
             int tokenCount = st.countTokens();
-            
+
             result = new String[tokenCount];
-            
+
             for ( int i = 0; i < result.length; i++ )
             {
                 result[i] = st.nextToken().trim();
@@ -351,7 +391,7 @@
         {
             result = array;
         }
-        
+
         return result;
     }
 


Reply via email to