Browse Source

Update ANTLR to revert to forked-mode only.

Comments in code should be self explanatory for the
next person who have to deal with it.

Testcase is updated (working dir is no more mandatory)
and I added a note in case someone wants to run
the tests... I should probably add a mention to
this in the ANTLR docs.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270161 13f79535-47bb-0310-9956-ffa450edef68
master
Stephane Bailliez 23 years ago
parent
commit
488529801c
2 changed files with 24 additions and 21 deletions
  1. +13
    -20
      src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java
  2. +11
    -1
      src/testcases/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java

+ 13
- 20
src/main/org/apache/tools/ant/taskdefs/optional/ANTLR.java View File

@@ -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);
}
}



+ 11
- 1
src/testcases/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java View File

@@ -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 <emeade@geekfarm.org>
*/
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() {


Loading…
Cancel
Save