You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kh...@apache.org on 2016/05/01 20:35:22 UTC

svn commit: r1741877 - /maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java

Author: khmarbaise
Date: Sun May  1 18:35:17 2016
New Revision: 1741877

URL: http://svn.apache.org/viewvc?rev=1741877&view=rev
Log:
[MINVOKER-147] setupIncludes / parallelThreads does not guarantee execution of setup*/pom.xml first.
 o Refactored code to execute the setup Jobs before any other job.
   Furthermore in the first step only executing single thread.

Modified:
    maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java

Modified: maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java?rev=1741877&r1=1741876&r2=1741877&view=diff
==============================================================================
--- maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java (original)
+++ maven/plugins/trunk/maven-invoker-plugin/src/main/java/org/apache/maven/plugin/invoker/AbstractInvokerMojo.java Sun May  1 18:35:17 2016
@@ -39,6 +39,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -686,14 +687,52 @@ public abstract class AbstractInvokerMoj
             getLog().warn( "Filtering of parent/child POMs is not supported without cloning the projects" );
         }
 
-        runBuilds( projectsDir, buildJobs );
+        // First run setup jobs.
+        BuildJob[] setupBuildJobs = null;
+        try
+        {
+            setupBuildJobs = getSetupBuildJobsFromFolders();
+        }
+        catch ( IOException e )
+        {
+            getLog().error( "Failure...", e );
+        }
+
+        if ( setupBuildJobs != null )
+        {
+            // parallelThreads = 1 for this call
+            // run all setup jobs only single thread.
+            //
+            // Some Idea about ordering?
+            getLog().info( "Running Setup Jobs" );
+            runBuilds( projectsDir, setupBuildJobs, 1 );
+        }
+
+        // Afterwards run all other jobs.
+        BuildJob[] nonSetupBuildJobs = getNonSetupJobs( buildJobs );
+        // parallelThreads run the rest with parallel sets...
+        runBuilds( projectsDir, nonSetupBuildJobs, parallelThreads );
 
-        writeSummaryFile( buildJobs );
+        writeSummaryFile( nonSetupBuildJobs );
 
-        processResults( new InvokerSession( buildJobs ) );
+        processResults( new InvokerSession( nonSetupBuildJobs ) );
 
     }
 
+    private BuildJob[] getNonSetupJobs( BuildJob[] buildJobs )
+    {
+        List<BuildJob> result = new LinkedList<BuildJob>();
+        for ( int i = 0; i < buildJobs.length; i++ )
+        {
+            if ( !buildJobs[i].getType().equals( BuildJob.Type.SETUP ) )
+            {
+                result.add( buildJobs[i] );
+            }
+        }
+        BuildJob[] buildNonSetupJobs = result.toArray( new BuildJob[result.size()] );
+        return buildNonSetupJobs;
+    }
+
     private void handleScriptRunnerWithScriptClassPath()
     {
         final List<String> scriptClassPath;
@@ -1085,7 +1124,7 @@ public abstract class AbstractInvokerMoj
      * @param buildJobs The build jobs to run must not be <code>null</code> nor contain <code>null</code> elements.
      * @throws org.apache.maven.plugin.MojoExecutionException If any build could not be launched.
      */
-    private void runBuilds( final File projectsDir, BuildJob[] buildJobs )
+    private void runBuilds( final File projectsDir, BuildJob[] buildJobs, int runWithParallelThreads )
         throws MojoExecutionException
     {
         if ( !localRepositoryPath.exists() )
@@ -1201,11 +1240,12 @@ public abstract class AbstractInvokerMoj
 
         try
         {
-            if ( isParallelRun() )
+            // TODO: Think about running SETUP jobs only single thread.
+            if ( runWithParallelThreads > 1 )
             {
-                getLog().info( "use parallelThreads " + parallelThreads );
+                getLog().info( "use parallelThreads " + runWithParallelThreads );
 
-                ExecutorService executorService = Executors.newFixedThreadPool( parallelThreads );
+                ExecutorService executorService = Executors.newFixedThreadPool( runWithParallelThreads );
                 for ( final BuildJob job : buildJobs )
                 {
                     executorService.execute( new Runnable()
@@ -1922,6 +1962,43 @@ public abstract class AbstractInvokerMoj
         }
     }
 
+    private List<String> calculateExcludes()
+        throws IOException
+    {
+        List<String> excludes =
+            ( pomExcludes != null ) ? new ArrayList<String>( pomExcludes ) : new ArrayList<String>();
+        if ( this.settingsFile != null )
+        {
+            String exclude = relativizePath( this.settingsFile, projectsDirectory.getCanonicalPath() );
+            if ( exclude != null )
+            {
+                excludes.add( exclude.replace( '\\', '/' ) );
+                getLog().debug( "Automatically excluded " + exclude + " from project scanning" );
+            }
+        }
+        return excludes;
+
+    }
+
+    /**
+     * @return The list of setupUp jobs.
+     * @throws IOException
+     * @see {@link #setupIncludes}
+     */
+    private BuildJob[] getSetupBuildJobsFromFolders()
+        throws IOException
+    {
+        List<String> excludes = calculateExcludes();
+
+        BuildJob[] setupPoms = scanProjectsDirectory( setupIncludes, excludes, BuildJob.Type.SETUP );
+        if ( getLog().isDebugEnabled() )
+        {
+            getLog().debug( "Setup projects: " + Arrays.asList( setupPoms ) );
+        }
+
+        return setupPoms;
+    }
+
     /**
      * Gets the build jobs that should be processed. Note that the order of the returned build jobs is significant.
      *
@@ -1935,17 +2012,7 @@ public abstract class AbstractInvokerMoj
 
         if ( invokerTest == null )
         {
-            List<String> excludes =
-                ( pomExcludes != null ) ? new ArrayList<String>( pomExcludes ) : new ArrayList<String>();
-            if ( this.settingsFile != null )
-            {
-                String exclude = relativizePath( this.settingsFile, projectsDirectory.getCanonicalPath() );
-                if ( exclude != null )
-                {
-                    excludes.add( exclude.replace( '\\', '/' ) );
-                    getLog().debug( "Automatically excluded " + exclude + " from project scanning" );
-                }
-            }
+            List<String> excludes = calculateExcludes();
 
             BuildJob[] setupPoms = scanProjectsDirectory( setupIncludes, excludes, BuildJob.Type.SETUP );
             if ( getLog().isDebugEnabled() )