diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java b/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java index 592d70b88..29dfa1d65 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java @@ -89,7 +89,7 @@ public class ANTLR extends Task { private File outputDirectory; /** should fork ? */ - private boolean fork = false; + private final boolean fork = true; /** working directory */ private File workingdir = null; @@ -109,8 +109,13 @@ public class ANTLR extends Task { this.outputDirectory = outputDirectory; } + // we are forced to fork ANTLR since there is a call + // to System.exit() and there is nothing we can do + // right now to avoid this. :-( (SBa) + // I'm not removing this method to keep backward compatibility + // and public void setFork(boolean s) { - this.fork = s; + //this.fork = s; } /** @@ -180,31 +185,19 @@ public class ANTLR extends Task { public void execute() throws BuildException { validateAttributes(); - //TODO: use ANTLR to parse the grammer file to do this. if (target.lastModified() > getGeneratedFile().lastModified()) { commandline.createArgument().setValue("-o"); commandline.createArgument().setValue(outputDirectory.toString()); commandline.createArgument().setValue(target.toString()); - if (fork) { - log("Forking " + commandline.toString(), Project.MSG_VERBOSE); - int err = run(commandline.getCommandline()); - if (err == 1) { - throw new BuildException("ANTLR returned: "+err, location); - } - } else { - ExecuteJava exe = new ExecuteJava(); - exe.setJavaCommand(commandline.getJavaCommand()); - exe.setClasspath(commandline.getClasspath()); - try { - exe.execute(project); - } catch (ExitException e){ - if ( e.getStatus() != 0 ){ - throw new BuildException("ANTLR returned: " + e.getStatus(), location); - } - } + log("Forking " + commandline.toString(), Project.MSG_VERBOSE); + int err = run(commandline.getCommandline()); + if (err == 1) { + throw new BuildException("ANTLR returned: "+err, location); } + } else { + log("Skipped grammar file. Generated file is newer.", Project.MSG_VERBOSE); } } diff --git a/src/testcases/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java b/src/testcases/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java index 0c9e10572..8fb763133 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java @@ -57,6 +57,16 @@ package org.apache.tools.ant.taskdefs.optional; import java.io.*; import org.apache.tools.ant.BuildFileTest; /** + * If you want to run tests, it is highly recommended + * to download ANTLR (www.antlr.org), build the 'all' jar + * with the mkalljar script and drop the jar (about 300KB) into + * Ant lib. + * - Running w/ the default antlr.jar (70KB) does not work (missing class) + * - Running w/ the antlr jar made w/ mkjar (88KB) does not work (still another class missing) + * + * Unless of course you specify the ANTLR classpath in your + * system classpath. (see ANTLR install.html) + * * @author Erik Meade */ public class ANTLRTest extends BuildFileTest { @@ -91,7 +101,7 @@ public class ANTLRTest extends BuildFileTest { } public void test5() { - expectBuildException("test5", "Invalid working directory"); + executeTarget("test5"); } public void test6() {