diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java index 24c7d8076..a65308c95 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java @@ -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); } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java index 65c5827e4..b51f3dfc2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java @@ -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.