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/09/23 01:23:25 UTC

svn commit: r1388922 - in /maven/plugins/trunk/maven-compiler-plugin: ./ src/it/mcompiler-21_class-remove/ src/it/mcompiler-21_class-remove/src/ src/it/mcompiler-21_class-remove/src/main/ src/it/mcompiler-21_class-remove/src/main/java/ src/main/java/or...

Author: struberg
Date: Sat Sep 22 23:23:24 2012
New Revision: 1388922

URL: http://svn.apache.org/viewvc?rev=1388922&view=rev
Log:
MCOMPILER-21 add handling of file deletes and incremental build

Added:
    maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/
    maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/invoker.properties   (with props)
    maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/pom.xml   (with props)
    maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/
    maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/
    maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/
    maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/BeanA.java   (with props)
    maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/BeanA2.java   (with props)
    maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/verify.groovy
Modified:
    maven/plugins/trunk/maven-compiler-plugin/pom.xml
    maven/plugins/trunk/maven-compiler-plugin/src/main/java/org/apache/maven/plugin/AbstractCompilerMojo.java
    maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/CompilerMojoTestCase.java

Modified: maven/plugins/trunk/maven-compiler-plugin/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/pom.xml?rev=1388922&r1=1388921&r2=1388922&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-compiler-plugin/pom.xml Sat Sep 22 23:23:24 2012
@@ -123,14 +123,18 @@ under the License.
       <artifactId>maven-toolchain</artifactId>
       <version>1.0</version>
     </dependency>
-
-    <!-- Plexus -->
     <dependency>
-      <groupId>org.codehaus.plexus</groupId>
-      <artifactId>plexus-utils</artifactId>
-      <version>3.0.4</version>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-shared-utils</artifactId>
+      <version>0.1-SNAPSHOT</version>
     </dependency>
     <dependency>
+      <groupId>org.apache.maven.shared</groupId>
+      <artifactId>maven-shared-incremental</artifactId>
+      <version>1.0-SNAPSHOT</version>
+    </dependency>
+
+    <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-compiler-api</artifactId>
       <version>${plexusCompilerVersion}</version>

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/invoker.properties
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/invoker.properties?rev=1388922&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/invoker.properties (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/invoker.properties Sat Sep 22 23:23:24 2012
@@ -0,0 +1,4 @@
+invoker.goals = clean compile
+invoker.goals.2 = org.codehaus.gmaven:gmaven-plugin:execute
+invoker.goals.3 = compile
+invoker.buildResult.3 = failure
\ No newline at end of file

Propchange: maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/invoker.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/pom.xml
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/pom.xml?rev=1388922&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/pom.xml (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/pom.xml Sat Sep 22 23:23:24 2012
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.compiler.its</groupId>
+  <artifactId>mcompiler-21</artifactId>
+  <version>1.0-SNAPSHOT</version>
+
+  <description>
+    This IT tests what happens if the method name in a single class BeanA gets changed.
+    In this case 'mvn compile' (without a clean) should fail as  BeanA2
+    still uses the old method of BeanA.
+  </description>
+
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-compiler-plugin</artifactId>
+          <version>@project.version@</version>
+        </plugin>      
+      </plugins>
+    </pluginManagement> 
+    <plugins>
+      <plugin>
+        <!-- Called as second invoker goal to simulate file adjustment -->
+        <groupId>org.codehaus.gmaven</groupId>
+        <artifactId>gmaven-plugin</artifactId>
+        <version>1.4</version>
+        <configuration>
+          <source>
+            def beanAFile = new File( project.basedir, 'src/main/java/BeanA.java' )
+            
+            beanAFile.delete()
+          </source>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

Propchange: maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/BeanA.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/BeanA.java?rev=1388922&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/BeanA.java (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/BeanA.java Sat Sep 22 23:23:24 2012
@@ -0,0 +1,15 @@
+/**
+ * dumb test bean
+ */
+public class BeanA {
+
+    private int i,y;
+
+    public int getI() {
+        return i;
+    }
+
+    public void setI(int i) {
+        this.i = i;
+    }
+}

Propchange: maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/BeanA.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/BeanA2.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/BeanA2.java?rev=1388922&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/BeanA2.java (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/BeanA2.java Sat Sep 22 23:23:24 2012
@@ -0,0 +1,16 @@
+/**
+ * dumb test bean
+ */
+public class BeanA2 {
+
+    private int i;
+    private BeanA beanA;
+
+    public int getI() {
+        return beanA.getI();
+    }
+
+    public void setI(int i) {
+        beanA.setI(i);
+    }
+}

Propchange: maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/src/main/java/BeanA2.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/verify.groovy?rev=1388922&view=auto
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/verify.groovy (added)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-21_class-remove/verify.groovy Sat Sep 22 23:23:24 2012
@@ -0,0 +1,24 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+def logFile = new File( basedir, 'build.log' )
+assert logFile.exists()
+content = logFile.text
+
+assert content.contains( 'COMPILATION ERROR :' )

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=1388922&r1=1388921&r2=1388922&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 Sat Sep 22 23:23:24 2012
@@ -22,6 +22,8 @@ package org.apache.maven.plugin;
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.plugins.annotations.Component;
 import org.apache.maven.plugins.annotations.Parameter;
+import org.apache.maven.shared.incremental.IncrementalBuildHelper;
+import org.apache.maven.shared.utils.StringUtils;
 import org.apache.maven.toolchain.Toolchain;
 import org.apache.maven.toolchain.ToolchainManager;
 import org.codehaus.plexus.compiler.Compiler;
@@ -37,7 +39,6 @@ import org.codehaus.plexus.compiler.util
 import org.codehaus.plexus.compiler.util.scan.mapping.SourceMapping;
 import org.codehaus.plexus.compiler.util.scan.mapping.SuffixMapping;
 import org.codehaus.plexus.util.ReaderFactory;
-import org.codehaus.plexus.util.StringUtils;
 
 import java.io.File;
 import java.lang.reflect.Method;
@@ -317,6 +318,12 @@ public abstract class AbstractCompilerMo
     private boolean skipMultiThreadWarning;
 
     /**
+     * @since 2.6 needed for storing the status for the incremental build support.
+     */
+    @Component
+    private MojoExecution mojoExecution;
+
+    /**
      * We need this to determine the start timestamp of the build.
      * @since 2.6
      */
@@ -560,17 +567,20 @@ public abstract class AbstractCompilerMo
 
         boolean canUpdateTarget;
 
+        IncrementalBuildHelper incrementalBuildHelper = new IncrementalBuildHelper( mojoExecution, mavenSession );
+
         try
         {
             canUpdateTarget = compiler.canUpdateTarget( compilerConfiguration );
+            Set<File> sources = getCompileSources( compiler, compilerConfiguration );
 
             if ( ( compiler.getCompilerOutputStyle().equals( CompilerOutputStyle.ONE_OUTPUT_FILE_FOR_ALL_INPUT_FILES )
                    && !canUpdateTarget )
                  || isDependencyChanged()
-                 || isSourceChanged(compilerConfiguration, compiler) )
+                 || isSourceChanged( compilerConfiguration, compiler )
+                 || incrementalBuildHelper.inputFileTreeChanged( sources ) )
             {
                 getLog().info( "Changes detected - recompiling the module!" );
-                Set<File> sources = getCompileSources( compiler, compilerConfiguration );
 
                 compilerConfiguration.setSourceFiles( sources );
             }
@@ -650,6 +660,9 @@ public abstract class AbstractCompilerMo
 
         List<CompilerError> messages;
 
+
+        incrementalBuildHelper.beforeRebuildExecution( getOutputDirectory() );
+
         try
         {
             messages = compiler.compile( compilerConfiguration );
@@ -660,6 +673,9 @@ public abstract class AbstractCompilerMo
             throw new MojoExecutionException( "Fatal error compiling", e );
         }
 
+        // now scan the same directory again and create a diff
+        incrementalBuildHelper.afterRebuildExecution();
+
         List<CompilerError> warnings = new ArrayList<CompilerError>();
         List<CompilerError> errors = new ArrayList<CompilerError>();
         if ( messages != null )

Modified: maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/CompilerMojoTestCase.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/CompilerMojoTestCase.java?rev=1388922&r1=1388921&r2=1388922&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/CompilerMojoTestCase.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/CompilerMojoTestCase.java Sat Sep 22 23:23:24 2012
@@ -27,10 +27,14 @@ import java.util.List;
 import java.util.Set;
 
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.plugin.descriptor.MojoDescriptor;
+import org.apache.maven.plugin.descriptor.PluginDescriptor;
 import org.apache.maven.plugin.stubs.CompilerManagerStub;
 import org.apache.maven.plugin.stubs.DebugEnabledLog;
 import org.apache.maven.plugin.testing.AbstractMojoTestCase;
 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
+import org.apache.maven.project.MavenProject;
 
 public class CompilerMojoTestCase
     extends AbstractMojoTestCase
@@ -288,6 +292,8 @@ public class CompilerMojoTestCase
         setVariableValueToObject( mojo, "log", new DebugEnabledLog() );
         setVariableValueToObject( mojo, "projectArtifact", new ArtifactStub() );
         setVariableValueToObject( mojo, "classpathElements", Collections.EMPTY_LIST );
+        setVariableValueToObject( mojo, "mavenSession", getMockMavenSession() );
+        setVariableValueToObject( mojo, "mojoExecution", getMockMojoExecution() );
 
         assertNotNull( mojo );
 
@@ -315,6 +321,40 @@ public class CompilerMojoTestCase
         String testSourceRoot = testPom.getParent() + "/src/test/java";
         setVariableValueToObject( mojo, "compileSourceRoots", Collections.singletonList( testSourceRoot ) );
 
+        setVariableValueToObject( mojo, "mavenSession", getMockMavenSession() );
+        setVariableValueToObject( mojo, "mojoExecution", getMockMojoExecution() );
+
         return mojo;
     }
+
+    private MavenProject getMockMavenProject()
+    {
+        MavenProject mp = new MavenProject();
+        mp.getBuild().setDirectory( "target" );
+
+        return mp;
+    }
+
+    private MavenSession getMockMavenSession()
+    {
+        //X MavenExecutionRequest er = new DefaultMavenExecutionRequest();
+        MavenSession ms = new MavenSession( null, null, null, null, null, null, null, null, null );
+        ms.setCurrentProject( getMockMavenProject() );
+
+        return ms;
+    }
+
+    private MojoExecution getMockMojoExecution()
+    {
+        MojoDescriptor md = new MojoDescriptor();
+        md.setGoal( "compile" );
+
+        MojoExecution me = new MojoExecution( md );
+
+        PluginDescriptor pd = new PluginDescriptor();
+        pd.setArtifactId( "maven-compiler-plugin" );
+        md.setPluginDescriptor( pd );
+
+        return me;
+    }
 }