Browse Source

Enhance lookup path so that it works automagically with 1.x and 2.x versions...

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271824 13f79535-47bb-0310-9956-ffa450edef68
master
Stephane Bailliez 23 years ago
parent
commit
0e900607a6
2 changed files with 30 additions and 11 deletions
  1. +3
    -6
      src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java
  2. +27
    -5
      src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java

+ 3
- 6
src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java View File

@@ -196,12 +196,9 @@ public class JJTree extends Task {
}
cmdl.createArgument().setValue(target.getAbsolutePath());

if (javaccHome == null || !javaccHome.isDirectory()) {
throw new BuildException("Javacchome not set.");
}
final Path classpath = cmdl.createClasspath(project);
classpath.createPathElement().setPath(javaccHome.getAbsolutePath() +
"/JavaCC.zip");
final File javaccJar = JavaCC.getArchiveFile(javaccHome);
classpath.createPathElement().setPath( javaccJar.getAbsolutePath() );
classpath.addJavaRuntime();

final Commandline.Argument arg = cmdl.createVmArgument();
@@ -222,7 +219,7 @@ public class JJTree extends Task {
}
}
catch (IOException e) {
throw new BuildException("Failed to launch JJTree: " + e);
throw new BuildException("Failed to launch JJTree", e);
}
}
}

+ 27
- 5
src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java View File

@@ -239,12 +239,9 @@ public class JavaCC extends Task {
}
cmdl.createArgument().setValue(target.getAbsolutePath());

if (javaccHome == null || !javaccHome.isDirectory()) {
throw new BuildException("Javacchome not set.");
}
final Path classpath = cmdl.createClasspath(project);
classpath.createPathElement().setPath(javaccHome.getAbsolutePath() +
"/JavaCC.zip");
final File javaccJar = JavaCC.getArchiveFile(javaccHome);
classpath.createPathElement().setPath( javaccJar.getAbsolutePath() );
classpath.addJavaRuntime();

final Commandline.Argument arg = cmdl.createVmArgument();
@@ -254,6 +251,31 @@ public class JavaCC extends Task {
Execute.runCommand(this, cmdl.getCommandline());
}

/**
* Helper class to retrieve the path used to store the JavaCC.zip which is
* different from versions.
* @param home the javacc home path directory.
* @throws BuildException thrown if the home directory is invalid or if the archive
* could not be found despite attemps to do so.
* @return the file object pointing to the JavaCC archive.
*/
protected static File getArchiveFile(File home) throws BuildException {
if (home == null || !home.isDirectory()) {
throw new BuildException("JavaCC home must be a valid directory.");
}
// javacc prior to 2.0
File f = new File(home, "JavaCC.zip");
if ( f.exists() ){
return f;
}
// javacc install 2.0+
f = new File(home, "bin/lib/JavaCC.zip");
if ( f.exists() ){
return f;
}
throw new BuildException("Could not find a path to JavaCC.zip from '" + home + "'.");
}

/**
* Determines the output Java file to be generated by the given grammar
* file.


Loading…
Cancel
Save