You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by st...@apache.org on 2012/08/28 00:24:52 UTC

svn commit: r1377889 - in /maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin: AbstractCompilerMojo.java CompilerMojo.java TestCompilerMojo.java

Author: struberg
Date: Mon Aug 27 22:24:52 2012
New Revision: 1377889

URL: http://svn.apache.org/viewvc?rev=1377889&view=rev
Log:
MCOMPILER-21 improve classpath detection

* By not using the projectArtifacts but the classPathEntries
we are now also able to detect changed properties and classes.

* test classes now automatically get recompiled if the projects 
classes got changed. 

Modified:
    maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java
    maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java
    maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/TestCompilerMojo.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=1377889&r1=1377888&r2=1377889&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 Aug 27 22:24:52 2012
@@ -19,7 +19,6 @@ package org.apache.maven.plugin;
  * under the License.
  */
 
-import org.apache.maven.artifact.Artifact;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
@@ -43,7 +42,6 @@ import org.codehaus.plexus.util.StringUt
 import java.io.File;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Date;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -568,10 +566,10 @@ public abstract class AbstractCompilerMo
 
             if ( ( compiler.getCompilerOutputStyle().equals( CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES )
                    && !canUpdateTarget )
-                 || isDependencyChanged( getArtifacts() )
-                 || isSourceChanged( compilerConfiguration, compiler) )
+                 || isDependencyChanged()
+                 || isSourceChanged(compilerConfiguration, compiler) )
             {
-                getLog().info( "Recompiling the module!" );
+                getLog().info( "Changes detected - recompiling the module!" );
                 Set<File> sources = getCompileSources( compiler, compilerConfiguration );
 
                 compilerConfiguration.setSourceFiles( sources );
@@ -771,11 +769,6 @@ public abstract class AbstractCompilerMo
 
 
     /**
-     * Get all the project artifacts for the current scope
-     */
-    protected abstract Collection<Artifact> getArtifacts();
-
-    /**
      * 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
@@ -953,12 +946,13 @@ public abstract class AbstractCompilerMo
 
     /**
      * We just compare the timestamps of all local dependency files (inter-module dependency classpath)
+     * and the own generated classes
      * and if we got a file which is >= the buid-started timestamp, then we catched a file which got
      * changed during this build.
      *
      * @return <code>true</code> if at least one single dependency has changed.
      */
-    protected boolean isDependencyChanged( Collection<Artifact> artifacts )
+    protected boolean isDependencyChanged()
     {
         if ( mavenSession == null )
         {
@@ -969,12 +963,12 @@ public abstract class AbstractCompilerMo
 
         Date buildStartTime = getBuildStartTime();
 
-        for ( Artifact artifact : artifacts )
+        for ( String classPathElement : getClasspathElements() )
         {
             // ProjectArtifacts are artifacts which are available in the local project
             // that's the only ones we are interested in now.
-            File artifactPath = artifact.getFile();
-            if ( artifactPath != null && artifactPath.isDirectory() )
+            File artifactPath = new File( classPathElement );
+            if ( artifactPath.isDirectory() )
             {
                 if ( hasNewFile( artifactPath, buildStartTime ) )
                 {

Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java?rev=1377889&r1=1377888&r2=1377889&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/CompilerMojo.java Mon Aug 27 22:24:52 2012
@@ -28,7 +28,6 @@ import org.codehaus.plexus.compiler.util
 import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
 
 import java.io.File;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -74,12 +73,6 @@ public class CompilerMojo
     private Artifact projectArtifact;
 
     /**
-     * We need all the projects artifacts to determine whether we shall force a re-compile.
-     */
-    @Parameter( defaultValue = "${project.artifacts}", readonly = true, required = true )
-    private Set<Artifact> projectArtifacts;
-
-    /**
      * A list of inclusion filters for the compiler.
      */
     @Parameter
@@ -149,12 +142,6 @@ public class CompilerMojo
         return scanner;
     }
 
-    @Override
-    protected Collection<Artifact> getArtifacts()
-    {
-        return projectArtifacts;
-    }
-
     protected SourceInclusionScanner getSourceInclusionScanner( String inputFileEnding )
     {
         SourceInclusionScanner scanner = null;

Modified: maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/TestCompilerMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/TestCompilerMojo.java?rev=1377889&r1=1377888&r2=1377889&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/TestCompilerMojo.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/TestCompilerMojo.java Mon Aug 27 22:24:52 2012
@@ -19,7 +19,6 @@ package org.apache.maven.plugin;
  * under the License.
  */
 
-import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugins.annotations.ResolutionScope;
 import org.apache.maven.plugins.annotations.LifecyclePhase;
 import org.apache.maven.plugins.annotations.Parameter;
@@ -28,7 +27,6 @@ import org.codehaus.plexus.compiler.util
 import org.codehaus.plexus.compiler.util.scan.StaleSourceScanner;
 
 import java.io.File;
-import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
@@ -141,13 +139,6 @@ public class TestCompilerMojo
     private File generatedTestSourcesDirectory;
 
 
-    /**
-     * We need all the projects test artifacts to determine whether we shall force a re-compile.
-     */
-    @Parameter( defaultValue = "${project.testArtifacts}", readonly = true, required = true )
-    private List<Artifact> testArtifacts;
-
-
     public void execute()
         throws MojoExecutionException, CompilationFailureException
     {
@@ -218,12 +209,6 @@ public class TestCompilerMojo
         return scanner;
     }
 
-    @Override
-    protected Collection<Artifact> getArtifacts()
-    {
-        return testArtifacts;
-    }
-
     protected String getSource()
     {
         return testSource == null ? source : testSource;