bodewig     2003/04/01 05:47:06

  Modified:    src/main/org/apache/tools/ant/taskdefs/optional ANTLR.java
  Log:
  Fix ANTLR's test8 testcase.
  
  Revision  Changes    Path
  1.21      +26 -3     
ant/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java
  
  Index: ANTLR.java
  ===================================================================
  RCS file: 
/home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ANTLR.java        31 Mar 2003 13:46:18 -0000      1.20
  +++ ANTLR.java        1 Apr 2003 13:47:06 -0000       1.21
  @@ -55,6 +55,7 @@
   package org.apache.tools.ant.taskdefs.optional;
   
   import java.io.BufferedReader;
  +import java.io.ByteArrayOutputStream;
   import java.io.File;
   import java.io.FileReader;
   import java.io.IOException;
  @@ -63,12 +64,14 @@
   import org.apache.tools.ant.Project;
   import org.apache.tools.ant.Task;
   import org.apache.tools.ant.taskdefs.Execute;
  -import org.apache.tools.ant.taskdefs.LogStreamHandler;
  +import org.apache.tools.ant.taskdefs.LogOutputStream;
  +import org.apache.tools.ant.taskdefs.PumpStreamHandler;
   import org.apache.tools.ant.types.Commandline;
   import org.apache.tools.ant.types.CommandlineJava;
   import org.apache.tools.ant.types.Path;
   import org.apache.tools.ant.util.JavaEnvUtils;
   import org.apache.tools.ant.util.LoaderUtils;
  +import org.apache.tools.ant.util.TeeOutputStream;
   
   /**
    *  Invokes the ANTLR Translator generator on a grammar file.
  @@ -111,6 +114,9 @@
       /** working directory */
       private File workingdir = null;
   
  +    /** captures ANTLR's output */
  +    private ByteArrayOutputStream bos = new ByteArrayOutputStream();
  +
       public ANTLR() {
           commandline.setVm(JavaEnvUtils.getJreExecutable("java"));
           commandline.setClassname("antlr.Tool");
  @@ -277,6 +283,12 @@
               int err = run(commandline.getCommandline());
               if (err == 1) {
                   throw new BuildException("ANTLR returned: " + err, 
getLocation());
  +            } else {
  +                String output = bos.toString();
  +                if (output.indexOf("error:") > -1) {
  +                    throw new BuildException("ANTLR signaled an error: "
  +                                             + output, getLocation());
  +                }
               }
           } else {
               log("Skipped grammar file. Generated file is newer.", 
Project.MSG_VERBOSE);
  @@ -352,8 +364,14 @@
   
       /** execute in a forked VM */
       private int run(String[] command) throws BuildException {
  -        Execute exe = new Execute(new LogStreamHandler(this, 
Project.MSG_INFO,
  -                Project.MSG_WARN), null);
  +        PumpStreamHandler psh = 
  +            new PumpStreamHandler(new LogOutputStream(this, 
Project.MSG_INFO),
  +                                  new TeeOutputStream(
  +                                      new LogOutputStream(this, 
  +                                                          Project.MSG_WARN),
  +                                      bos)
  +                                  );
  +        Execute exe = new Execute(psh, null);
           exe.setAntRun(getProject());
           if (workingdir != null) {
               exe.setWorkingDirectory(workingdir);
  @@ -363,6 +381,11 @@
               return exe.execute();
           } catch (IOException e) {
               throw new BuildException(e, getLocation());
  +        } finally {
  +            try {
  +                bos.close();
  +            } catch (IOException e) {
  +            }
           }
       }
   }
  
  
  

Reply via email to