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

svn commit: r1407231 - in /maven/plugins/trunk/maven-compiler-plugin/src: it/mcompiler-120/verify.groovy main/java/org/apache/maven/plugin/AbstractCompilerMojo.java test/java/org/apache/maven/plugin/stubs/CompilerStub.java

Author: andham
Date: Thu Nov  8 19:28:44 2012
New Revision: 1407231

URL: http://svn.apache.org/viewvc?rev=1407231&view=rev
Log:
[MCOMPILER-184] Improved usage of new plexus-compiler 2.0 API

Modified:
    maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-120/verify.groovy
    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/stubs/CompilerStub.java

Modified: maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-120/verify.groovy
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-120/verify.groovy?rev=1407231&r1=1407230&r2=1407231&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-120/verify.groovy (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/it/mcompiler-120/verify.groovy Thu Nov  8 19:28:44 2012
@@ -21,4 +21,4 @@ def logFile = new File( basedir, 'build.
 assert logFile.exists()
 content = logFile.text
 
-assert content.contains( 'COMPILATION ERROR :' )
+assert content.contains( 'Compilation failure' )

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=1407231&r1=1407230&r2=1407231&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 Thu Nov  8 19:28:44 2012
@@ -684,7 +684,7 @@ public abstract class AbstractCompilerMo
             catch ( CompilerNotImplementedException cnie )
             {
                 List<CompilerError> messages = compiler.compile( compilerConfiguration );
-                compilerResult = new CompilerResult().compilerMessages( makeCompilerMessages( messages ) );
+                compilerResult = convertToCompilerResult( messages );
             }
         }
         catch ( Exception e )
@@ -698,22 +698,19 @@ public abstract class AbstractCompilerMo
 
         List<CompilerMessage> warnings = new ArrayList<CompilerMessage>();
         List<CompilerMessage> errors = new ArrayList<CompilerMessage>();
-
-
-            for ( CompilerMessage message : compilerResult.getCompilerMessages() )
+        for ( CompilerMessage message : compilerResult.getCompilerMessages() )
+        {
+            if ( message.isError() )
             {
-                if ( message.isError() || message.getKind() == CompilerMessage.Kind.ERROR )
-                {
-                    errors.add( message );
-                }
-                else
-                {
-                    warnings.add( message );
-                }
+                errors.add( message );
             }
+            else
+            {
+                warnings.add( message );
+            }
+        }
 
-
-        if ( failOnError && !errors.isEmpty() )
+        if ( failOnError && !compilerResult.isSuccess() )
         {
             if ( !warnings.isEmpty() )
             {
@@ -728,18 +725,27 @@ public abstract class AbstractCompilerMo
                 getLog().info( "-------------------------------------------------------------" );
             }
 
-            getLog().info( "-------------------------------------------------------------" );
-            getLog().error( "COMPILATION ERROR : " );
-            getLog().info( "-------------------------------------------------------------" );
-
-            for ( CompilerMessage error : errors )
+            if ( !errors.isEmpty() )
             {
-                getLog().error( error.toString() );
+                getLog().info( "-------------------------------------------------------------" );
+                getLog().error( "COMPILATION ERROR : " );
+                getLog().info( "-------------------------------------------------------------" );
+                for ( CompilerMessage error : errors )
+                {
+                    getLog().error( error.toString() );
+                }
+                getLog().info( errors.size() + ( ( errors.size() > 1 ) ? " errors " : " error" ) );
+                getLog().info( "-------------------------------------------------------------" );
             }
-            getLog().info( errors.size() + ( ( errors.size() > 1 ) ? " errors " : " error" ) );
-            getLog().info( "-------------------------------------------------------------" );
 
-            throw new CompilationFailureException( errors );
+            if ( !errors.isEmpty() )
+            {
+                throw new CompilationFailureException( errors );
+            }
+            else
+            {
+                throw new CompilationFailureException( warnings );
+            }
         }
         else
         {
@@ -750,22 +756,27 @@ public abstract class AbstractCompilerMo
         }
     }
 
-    protected List<CompilerMessage> makeCompilerMessages( List<CompilerError> compilerErrors )
+    protected CompilerResult convertToCompilerResult( List<CompilerError> compilerErrors )
     {
         if ( compilerErrors == null )
         {
-            return Collections.emptyList();
+            return new CompilerResult();
         }
         List<CompilerMessage> messages = new ArrayList<CompilerMessage>( compilerErrors.size() );
+        boolean success = true;
         for ( CompilerError compilerError : compilerErrors )
         {
             messages.add(
                 new CompilerMessage( compilerError.getFile(), compilerError.getKind(), compilerError.getStartLine(),
                                      compilerError.getStartColumn(), compilerError.getEndLine(),
                                      compilerError.getEndColumn(), compilerError.getMessage() ) );
+            if ( compilerError.isError() )
+            {
+                success = false;
+            }
         }
 
-        return messages;
+        return new CompilerResult( success, messages );
     }
 
     /**

Modified: maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/stubs/CompilerStub.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/stubs/CompilerStub.java?rev=1407231&r1=1407230&r2=1407231&view=diff
==============================================================================
--- maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/stubs/CompilerStub.java (original)
+++ maven/plugins/trunk/maven-compiler-plugin/src/test/java/org/apache/maven/plugin/stubs/CompilerStub.java Thu Nov  8 19:28:44 2012
@@ -120,8 +120,9 @@ public class CompilerStub
         {
             throw new CompilerException( "An exception occurred while creating output file", e );
         }
-        return new CompilerResult().compilerMessages(
-            Collections.singletonList( new CompilerMessage( "message 1", shouldFail ) ) );
+        
+        return new CompilerResult( !shouldFail,
+            Collections.singletonList( new CompilerMessage( "message 1", CompilerMessage.Kind.OTHER ) ) );
     }
 
     public String[] createCommandLine( CompilerConfiguration compilerConfiguration )