You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2012/05/07 11:57:31 UTC

svn commit: r1334946 - /maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java

Author: olamy
Date: Mon May  7 09:57:31 2012
New Revision: 1334946

URL: http://svn.apache.org/viewvc?rev=1334946&view=rev
Log:
[MCOMPILER-170] add warning message for multi thread build and reuseSame strategy.

Modified:
    maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java

Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java?rev=1334946&r1=1334945&r2=1334946&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java Mon May  7 09:57:31 2012
@@ -38,6 +38,7 @@ import org.codehaus.plexus.util.ReaderFa
 import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -319,6 +320,12 @@ public abstract class AbstractCompilerMo
      */
     private String compilerReuseStrategy = "reuseCreated";
 
+    /**
+     * @parameter default-value="${false}" expression="${maven.compiler.skipMultiThreadWarning}"
+     * @since 2.5
+     */
+    private boolean skipMultiThreadWarning;
+
     protected abstract SourceInclusionScanner getSourceInclusionScanner( int staleMillis );
 
     protected abstract SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding );
@@ -533,6 +540,14 @@ public abstract class AbstractCompilerMo
         else if ( CompilerConfiguration.CompilerReuseStrategy.ReuseSame.getStrategy().equals(
             this.compilerReuseStrategy ) )
         {
+            if ( getRequestThreadCount() > 1 )
+            {
+                if ( !skipMultiThreadWarning )
+                {
+                    getLog().warn(
+                        "You are in a multi thread build and use reuseSame strategy this can issues on some os/jdk, consider using reuseCreated strategy" );
+                }
+            }
             compilerConfiguration.setCompilerReuseStrategy( CompilerConfiguration.CompilerReuseStrategy.ReuseSame );
         }
         else
@@ -711,6 +726,28 @@ public abstract class AbstractCompilerMo
         }
     }
 
+    /**
+     * try to get thread count if a maven 3 build, using reflection as the plugin must not be maven3 api dependant
+     *
+     * @return number of thread for this build or 1 if not multi thread build
+     */
+    protected int getRequestThreadCount()
+    {
+        try
+        {
+            Method getRequestMethod = this.session.getClass().getMethod( "getRequest", null );
+            Object mavenExecutionRequest = getRequestMethod.invoke( this.session, null );
+            Method getThreadCountMethod = mavenExecutionRequest.getClass().getMethod( "getThreadCount" );
+            String threadCount = (String) getThreadCountMethod.invoke( mavenExecutionRequest, null );
+            return Integer.valueOf( threadCount );
+        }
+        catch ( Exception e )
+        {
+            getLog().debug( "impossible to get threadCount for the current build:" + e.getMessage() );
+        }
+        return 1;
+    }
+
     private String getMemoryValue( String setting )
     {
         String value = null;