You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by vs...@apache.org on 2006/09/14 14:52:28 UTC

svn commit: r443333 - /maven/plugins/trunk/maven-antlr-plugin/src/main/java/org/apache/maven/plugin/antlr/AbstractAntlrMojo.java

Author: vsiveton
Date: Thu Sep 14 05:52:27 2006
New Revision: 443333

URL: http://svn.apache.org/viewvc?view=rev&rev=443333
Log:
MANTLR-10: Build should fail if antlr fails

o handle System.err for antlr.Tool#main()

Modified:
    maven/plugins/trunk/maven-antlr-plugin/src/main/java/org/apache/maven/plugin/antlr/AbstractAntlrMojo.java

Modified: maven/plugins/trunk/maven-antlr-plugin/src/main/java/org/apache/maven/plugin/antlr/AbstractAntlrMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-antlr-plugin/src/main/java/org/apache/maven/plugin/antlr/AbstractAntlrMojo.java?view=diff&rev=443333&r1=443332&r2=443333
==============================================================================
--- maven/plugins/trunk/maven-antlr-plugin/src/main/java/org/apache/maven/plugin/antlr/AbstractAntlrMojo.java (original)
+++ maven/plugins/trunk/maven-antlr-plugin/src/main/java/org/apache/maven/plugin/antlr/AbstractAntlrMojo.java Thu Sep 14 05:52:27 2006
@@ -20,6 +20,8 @@
 import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.StringTokenizer;
@@ -27,6 +29,7 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.StringOutputStream;
 import org.codehaus.plexus.util.StringUtils;
 
 import antlr.Tool;
@@ -157,6 +160,12 @@
 
             File grammar = new File( sourceDirectory, eachGrammar );
 
+            if ( !grammar.exists() )
+            {
+                throw new MojoExecutionException( "The grammar '" + grammar.getAbsolutePath()
+                    + "' doesnt exist." );
+            }
+
             getLog().info( "grammar: " + grammar );
 
             File generated = null;
@@ -209,14 +218,18 @@
                 getLog().debug( "antlr args=\n" + StringUtils.join( args, "\n" ) );
             }
 
-            SecurityManager oldSm = System.getSecurityManager();
-
-            System.setSecurityManager( NoExitSecurityManager.INSTANCE );
-
             // ----------------------------------------------------------------------
             // Call Antlr
             // ----------------------------------------------------------------------
 
+            SecurityManager oldSm = System.getSecurityManager();
+            PrintStream oldErr = System.err;
+
+            System.setSecurityManager( NoExitSecurityManager.INSTANCE );
+            OutputStream errOS = new StringOutputStream();
+            PrintStream err = new PrintStream( errOS );
+            System.setErr( err );
+
             try
             {
                 Tool.main( (String[]) arguments.toArray( new String[0] ) );
@@ -225,12 +238,21 @@
             {
                 if ( !e.getMessage().equals( "exitVM-0" ) )
                 {
-                    throw new MojoExecutionException( "Execution failed", e );
+                    throw new MojoExecutionException( "Antlr execution failed: " + e.getMessage(), e );
+                }
+
+                if ( ( errOS.toString().indexOf( "exitVM-" ) != -1 ) &&
+                    ( errOS.toString().indexOf( "exitVM-0" ) == -1 ) )
+                {
+                    throw new MojoExecutionException( "Antlr execution failed. Error output:\n" + errOS, e );
                 }
             }
             finally
             {
                 System.setSecurityManager( oldSm );
+                System.setErr( oldErr );
+
+                System.err.println( errOS.toString() );
             }
         }