diff --git a/docs/manual/OptionalTasks/javacc.html b/docs/manual/OptionalTasks/javacc.html index 3b94754b3..619be888b 100644 --- a/docs/manual/OptionalTasks/javacc.html +++ b/docs/manual/OptionalTasks/javacc.html @@ -8,25 +8,25 @@

JavaCC

-

Description

+

Description

- Invokes the JavaCC compiler + Invokes the JavaCC compiler compiler on a grammar file.

- To use the javacc task, set the target attribute to the name of the - grammar file to process. You also need to specify the directory containing - the JavaCC installation using the javacchome attribute, so that ant - can find the JavaCC classes. Optionally, you can also set the + To use the javacc task, set the target attribute to the name of the + grammar file to process. You also need to specify the directory containing + the JavaCC installation using the javacchome attribute, so that ant + can find the JavaCC classes. Optionally, you can also set the outputdirectory to write the generated file to a specific directory. Otherwise javacc writes the generated files to the directory containing the grammar file.

- This task only invokes JavaCC if the grammar file is newer than the generated + This task only invokes JavaCC if the grammar file is newer than the generated Java files. javacc assumes that the Java class name of the generated parser is the same as the name of the grammar file, ignoring the .jj. - If this is not the case, the javacc task will still work, but it will always + If this is not the case, the javacc task will still work, but it will always generate the output files.

@@ -115,6 +115,11 @@ Sets the JAVA_UNICODE_ESCAPE grammar option. This is a boolean option. No + + keeplinecolumn + Sets the KEEP_LINE_COLUMN grammar option. This is a boolean option. + No + lookahead Sets the LOOKAHEAD grammar option. This is an integer option. @@ -158,10 +163,10 @@

Example

-<javacc 
-    target="src/Parser.jj" 
+<javacc
+    target="src/Parser.jj"
     outputdirectory="build/src"
-    javacchome="c:/program files/JavaCC" 
+    javacchome="c:/program files/JavaCC"
     static="true"
 />
 
@@ -172,7 +177,7 @@


-

Copyright © 2000-2001 Apache Software Foundation. +

Copyright © 2000-2001,2003 Apache Software Foundation. All rights Reserved.

diff --git a/docs/manual/OptionalTasks/jjdoc.html b/docs/manual/OptionalTasks/jjdoc.html new file mode 100644 index 000000000..e48abb59e --- /dev/null +++ b/docs/manual/OptionalTasks/jjdoc.html @@ -0,0 +1,101 @@ + + + + + + JJDoc Task + + + +

+JJDoc

+

Since Ant 1.6

+

Description

+ +

Invokes the JJDoc preprocessor +for the JavaCC compiler compiler. It takes a JavaCC parser specification +and produces documentation for the BNF grammar. +It can operate in three modes, determined by command line options. +

To use the jjdoc task, set the target attribute to the name +of the JavaCC grammar file to process. You also need to specify the directory +containing the JavaCC installation using the javacchome attribute, +so that ant can find the JavaCC classes. Optionally, you can also set the +outputfile to write the generated BNF documentation file to a specific (directory and) file. +Otherwise jjdoc writes the generated BNF documentation file as the JavaCC +grammar file with a suffix .txt or .html.

+

This task only invokes JJDoc if the grammar file is newer than the +generated BNF documentation file.

+ +

Parameters

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
targetThe javacc grammar file to process.Yes
javacchomeThe directory containing the JavaCC distribution.Yes
outputfileThe file to write the generated BNF documentation file to. If not set, +the file is written with the same name as the JavaCC grammar file but with a the suffix .html or .txt. No
textSets the TEXT BNF documentation option. This is a boolean +option.No
onetableSets the ONE_TABLE BNF documentation option. This is a boolean option.No
+ +

+Example

+ +
+
<jjdoc 
+    target="src/Parser.jj" 
+    outputfile="doc/ParserBNF.html"
+    javacchome="c:/program files/JavaCC" 
+/>
+
+This invokes JJDoc on grammar file src/Parser.jj, writing the generated +BNF documentation file, ParserBNF.html, file to doc. +
+
+

Copyright © 2003 Apache Software Foundation. All rights +Reserved.

+ + + diff --git a/docs/manual/OptionalTasks/jjtree.html b/docs/manual/OptionalTasks/jjtree.html index e66526a04..15b224231 100644 --- a/docs/manual/OptionalTasks/jjtree.html +++ b/docs/manual/OptionalTasks/jjtree.html @@ -12,18 +12,21 @@

Description

-Invokes the JJTree preprocessor +

Invokes the JJTree preprocessor for the JavaCC compiler compiler. It inserts parse tree building actions at various places in the JavaCC source that it generates. The output of JJTree is run through JavaCC to create the parser.

To use the jjtree task, set the target attribute to the name -of the jjtree grammar file to process. You also need to specify the directory +of the JJTree grammar file to process. You also need to specify the directory containing the JavaCC installation using the javacchome attribute, so that ant can find the JavaCC classes. Optionally, you can also set the outputdirectory -to write the generated file to a specific directory. Otherwise jjtree writes -the generated JavaCC grammar file to the directory containing the JJTree -grammar file.

+to write the generated JavaCC grammar and node files to a specific directory. +Otherwise jjtree writes the generated JavaCC grammar and node files to the directory +containing the JJTree grammar file. As an extra option, you can also set the +outputfile to write the generated JavaCC grammar file to a specific (directory and) file. +Otherwise jjtree writes the generated JavaCC grammar file as the JJTree +grammar file with a suffix .jj.

This task only invokes JJTree if the grammar file is newer than the generated JavaCC file.

@@ -57,8 +60,20 @@ generated JavaCC file.

outputdirectory -The directory to write the generated file to. If not set, -the files are written to the directory containing the grammar file.  +The directory to write the generated JavaCC grammar and node files to. +If not set, the files are written to the directory containing the grammar file.  + +No + + + +outputfile + +The file to write the generated JavaCC grammar file +to. If not set, the file is written with the same name as the JJTree +grammar file but with a the suffix .jj. This is a +filename relative to outputdirectory if specified, the +project's basedir. No @@ -173,7 +188,7 @@ grammar file, Parser.jj, file to build/src. The grammar option NODE_USES_PARSER is set to true when invoking JJTree.

-

Copyright © 2001-2002 Apache Software Foundation. All rights +

Copyright © 2001-2003 Apache Software Foundation. All rights Reserved.

diff --git a/docs/manual/optionaltasklist.html b/docs/manual/optionaltasklist.html index 4525ef004..95427a2a4 100644 --- a/docs/manual/optionaltasklist.html +++ b/docs/manual/optionaltasklist.html @@ -37,6 +37,7 @@ Javah
JspC
JDepend
+JJDoc
JJTree
Jlink
JProbe Coverage
diff --git a/docs/manual/tasksoverview.html b/docs/manual/tasksoverview.html index 3966aa68a..703ca0cdf 100644 --- a/docs/manual/tasksoverview.html +++ b/docs/manual/tasksoverview.html @@ -318,12 +318,12 @@ documentation.

Stylebook -

Executes the Apache Stylebook documentation generator. +

Executes the Apache Stylebook documentation generator. Unlike the command-line version of this tool, all three arguments are required to run the Stylebook task.

- +

- @@ -861,7 +861,7 @@ documentation.

@@ -870,9 +870,19 @@ documentation.

+ + + + + - @@ -1032,7 +1042,7 @@ documentation.

- @@ -1042,7 +1052,7 @@ documentation.

in the same JVM can have through-the-firewall access to remote web sites.

- +
@@ -748,7 +748,7 @@ documentation.

Script

Executes a script in a +

Executes a script in a Apache BSF-supported language.

JavaCC

Invokes the - + JavaCC compiler-compiler on a grammar file.

Generates JNI headers from a Java class.

JJDoc

Invokes the + JJDoc documentation generator for the JavaCC compiler-compiler. + JJDoc takes a JavaCC parser specification and produces documentation + for the BNF grammar. It can operate in three modes, determined by + command line options. This task only invokes JJDoc if the grammar file + is newer than the generated BNF grammar documentation.

JJTree

Invokes the +

Invokes the JJTree preprocessor for the JavaCC compiler-compiler. It inserts parse-tree building actions at various places in the JavaCC source that it generates. The output of JJTree is run through JavaCC to create the @@ -948,7 +958,7 @@ documentation.

Dirname

Sets a property to the value of the specified file up to, - but not including, the last path element. + but not including, the last path element.

Telnet

Task to automate a remote telnet session. This task uses +

Task to automate a remote telnet session. This task uses nested <read> and <write> tags to indicate strings to wait for and specify text to send.

@@ -1083,8 +1093,8 @@ documentation.

CvsTagDiff -

Generates an XML-formatted report file of the changes between - two tags or dates recorded in a

Generates an XML-formatted report file of the changes between + two tags or dates recorded in a CVS repository.

@@ -1135,7 +1145,7 @@ documentation.

Tasks to perform the StarTeam stcheckout, stcheckin, stlabel, and stlist commands. The Starteam task - is deprecated; use + is deprecated; use STCheckout instead.

diff --git a/src/main/org/apache/tools/ant/taskdefs/defaults.properties b/src/main/org/apache/tools/ant/taskdefs/defaults.properties index 8119ed6f6..76bfec588 100644 --- a/src/main/org/apache/tools/ant/taskdefs/defaults.properties +++ b/src/main/org/apache/tools/ant/taskdefs/defaults.properties @@ -103,6 +103,7 @@ cab=org.apache.tools.ant.taskdefs.optional.Cab ftp=org.apache.tools.ant.taskdefs.optional.net.FTP icontract=org.apache.tools.ant.taskdefs.optional.IContract javacc=org.apache.tools.ant.taskdefs.optional.javacc.JavaCC +jjdoc=org.apache.tools.ant.taskdefs.optional.javacc.JJDoc jjtree=org.apache.tools.ant.taskdefs.optional.javacc.JJTree stcheckout=org.apache.tools.ant.taskdefs.optional.starteam.StarTeamCheckout stcheckin=org.apache.tools.ant.taskdefs.optional.starteam.StarTeamCheckin diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java new file mode 100644 index 000000000..3260bfd99 --- /dev/null +++ b/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java @@ -0,0 +1,242 @@ +/* + * The Apache Software License, Version 1.1 + * + * Copyright (c) 2003 The Apache Software Foundation. All rights + * reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The end-user documentation included with the redistribution, if + * any, must include the following acknowlegement: + * "This product includes software developed by the + * Apache Software Foundation (http://www.apache.org/)." + * Alternately, this acknowlegement may appear in the software itself, + * if and wherever such third-party acknowlegements normally appear. + * + * 4. The names "Ant" and "Apache Software + * Foundation" must not be used to endorse or promote products derived + * from this software without prior written permission. For written + * permission, please contact apache@apache.org. + * + * 5. Products derived from this software may not be called "Apache" + * nor may "Apache" appear in their names without prior written + * permission of the Apache Group. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * ==================================================================== + * + * This software consists of voluntary contributions made by many + * individuals on behalf of the Apache Software Foundation. For more + * information on the Apache Software Foundation, please see + * . + */ + +package org.apache.tools.ant.taskdefs.optional.javacc; + +import java.io.File; +import java.io.IOException; +import java.util.Enumeration; +import java.util.Hashtable; +import org.apache.tools.ant.BuildException; +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.types.Commandline; +import org.apache.tools.ant.types.CommandlineJava; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.JavaEnvUtils; + +/** + * Runs the JJDoc compiler compiler. + * + * @author Jene Jasper jjasper@abz.nl + * @author thomas.haas@softwired-inc.com + * @author Michael Saunders + * michael@amtec.com + */ +public class JJDoc extends Task { + + // keys to optional attributes + private static final String OUTPUT_FILE = "OUTPUT_FILE"; + private static final String TEXT = "TEXT"; + private static final String ONE_TABLE = "ONE_TABLE"; + + private final Hashtable optionalAttrs = new Hashtable(); + + private String outputFile = null; + private boolean plainText = false; + + private static final String DEFAULT_SUFFIX_HTML = ".html"; + private static final String DEFAULT_SUFFIX_TEXT = ".txt"; + + // required attributes + private File target = null; + private File javaccHome = null; + + private CommandlineJava cmdl = new CommandlineJava(); + + + /** + * Sets the TEXT BNF documentation option. + */ + public void setText(boolean plainText) { + optionalAttrs.put(TEXT, new Boolean(plainText)); + this.plainText = plainText; + } + + /** + * Sets the ONE_TABLE documentation option. + */ + public void setOnetable(boolean oneTable) { + optionalAttrs.put(ONE_TABLE, new Boolean(oneTable)); + } + + /** + * The outputfile to write the generated BNF documentation file to. + * If not set, the file is written with the same name as + * the JavaCC grammar file with a suffix .html or .txt. + */ + public void setOutputfile(String outputFile) { + this.outputFile = outputFile; + } + + /** + * The javacc grammar file to process. + */ + public void setTarget(File target) { + this.target = target; + } + + /** + * The directory containing the JavaCC distribution. + */ + public void setJavacchome(File javaccHome) { + this.javaccHome = javaccHome; + } + + public JJDoc() { + cmdl.setVm(JavaEnvUtils.getJreExecutable("java")); + } + + public void execute() throws BuildException { + + // load command line with optional attributes + Enumeration iter = optionalAttrs.keys(); + while (iter.hasMoreElements()) { + String name = (String) iter.nextElement(); + Object value = optionalAttrs.get(name); + cmdl.createArgument() + .setValue("-" + name + ":" + value.toString()); + } + + if (target == null || !target.isFile()) { + throw new BuildException("Invalid target: " + target); + } + + if (outputFile != null) { + cmdl.createArgument() .setValue("-" + OUTPUT_FILE + ":" + + outputFile.replace('\\', '/')); + } + + // use the directory containing the target as the output directory + File javaFile = new File(createOutputFileName(target, outputFile, + plainText)); + + if (javaFile.exists() + && target.lastModified() < javaFile.lastModified()) { + log("Target is already built - skipping (" + target + ")", + Project.MSG_VERBOSE); + return; + } + + cmdl.createArgument().setValue(target.getAbsolutePath()); + + cmdl.setClassname(JavaCC.getMainClass(javaccHome, + JavaCC.TASKDEF_TYPE_JJDOC)); + + final Path classpath = cmdl.createClasspath(getProject()); + final File javaccJar = JavaCC.getArchiveFile(javaccHome); + classpath.createPathElement().setPath(javaccJar.getAbsolutePath()); + classpath.addJavaRuntime(); + + final Commandline.Argument arg = cmdl.createVmArgument(); + arg.setValue("-mx140M"); + arg.setValue("-Dinstall.root=" + javaccHome.getAbsolutePath()); + + final Execute process = + new Execute(new LogStreamHandler(this, + Project.MSG_INFO, + Project.MSG_INFO), + null); + log(cmdl.describeCommand(), Project.MSG_VERBOSE); + process.setCommandline(cmdl.getCommandline()); + + try { + if (process.execute() != 0) { + throw new BuildException("JJDoc failed."); + } + } catch (IOException e) { + throw new BuildException("Failed to launch JJDoc", e); + } + } + + private String createOutputFileName(File target, String optionalOutputFile, + boolean plainText) { + String suffix = DEFAULT_SUFFIX_HTML; + String javaccFile = target.getAbsolutePath().replace('\\','/'); + + if (plainText) { + suffix = DEFAULT_SUFFIX_TEXT; + } + + if ((optionalOutputFile == null) || optionalOutputFile.equals("")) { + int filePos = javaccFile.lastIndexOf("/"); + + if (filePos >= 0) { + javaccFile = javaccFile.substring(filePos + 1); + } + + int suffixPos = javaccFile.lastIndexOf('.'); + + if (suffixPos == -1) { + optionalOutputFile = javaccFile + suffix; + } else { + String currentSuffix = javaccFile.substring(suffixPos); + + if (currentSuffix.equals(suffix)) { + optionalOutputFile = javaccFile + suffix; + } else { + optionalOutputFile = javaccFile.substring(0, suffixPos) + + suffix; + } + } + } else { + optionalOutputFile = optionalOutputFile.replace('\\','/'); + } + + return (getProject().getBaseDir() + "/" + optionalOutputFile) + .replace('\\', '/'); + } +} 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 e8d863fb8..d2ea187b4 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 @@ -72,11 +72,13 @@ import org.apache.tools.ant.util.JavaEnvUtils; * Runs the JJTree compiler compiler. * * @author thomas.haas@softwired-inc.com - * @author Michael Saunders michael@amtec.com + * @author Michael Saunders + * michael@amtec.com */ public class JJTree extends Task { // keys to optional attributes + private static final String OUTPUT_FILE = "OUTPUT_FILE"; private static final String BUILD_NODE_FILES = "BUILD_NODE_FILES"; private static final String MULTI = "MULTI"; private static final String NODE_DEFAULT_VOID = "NODE_DEFAULT_VOID"; @@ -92,6 +94,10 @@ public class JJTree extends Task { private final Hashtable optionalAttrs = new Hashtable(); + private String outputFile = null; + + private static final String DEFAULT_SUFFIX = ".jj"; + // required attributes private File outputDirectory = null; private File target = null; @@ -178,7 +184,7 @@ public class JJTree extends Task { } /** - * The directory to write the generated file to. + * The directory to write the generated JavaCC grammar and node files to. * If not set, the files are written to the directory * containing the grammar file. */ @@ -186,6 +192,15 @@ public class JJTree extends Task { this.outputDirectory = outputDirectory; } + /** + * The outputfile to write the generated JavaCC grammar file to. + * If not set, the file is written with the same name as + * the JJTree grammar file with a suffix .jj. + */ + public void setOutputfile(String outputFile) { + this.outputFile = outputFile; + } + /** * The jjtree grammar file to process. */ @@ -217,32 +232,44 @@ public class JJTree extends Task { if (target == null || !target.isFile()) { throw new BuildException("Invalid target: " + target); } + + if (outputFile != null) { + cmdl.createArgument().setValue("-" + OUTPUT_FILE + ":" + + outputFile.replace('\\', '/')); + } + + File javaFile = null; // use the directory containing the target as the output directory if (outputDirectory == null) { - outputDirectory = new File(target.getParent()); - } - if (!outputDirectory.isDirectory()) { - throw new BuildException("'outputdirectory' " + outputDirectory - + " is not a directory."); + javaFile = new File(createOutputFileName(target, outputFile, + null)); + } else { + if (!outputDirectory.isDirectory()) { + throw new BuildException("'outputdirectory' " + outputDirectory + + " is not a directory."); + } + + // convert backslashes to slashes, otherwise jjtree will + // put this as comments and this seems to confuse javacc + cmdl.createArgument().setValue("-OUTPUT_DIRECTORY:" + + outputDirectory.getAbsolutePath() + .replace('\\', '/')); + + javaFile = new File(createOutputFileName(target, outputFile, + outputDirectory + .getPath())); } - // convert backslashes to slashes, otherwise jjtree will put this as - // comments and this seems to confuse javacc - cmdl.createArgument().setValue("-OUTPUT_DIRECTORY:" - + outputDirectory.getAbsolutePath().replace('\\', '/')); - - String targetName = target.getName(); - final File javaFile = new File(outputDirectory, - targetName.substring(0, targetName.indexOf(".jjt")) + ".jj"); + if (javaFile.exists() - && target.lastModified() < javaFile.lastModified()) { + && target.lastModified() < javaFile.lastModified()) { log("Target is already built - skipping (" + target + ")", Project.MSG_VERBOSE); return; } cmdl.createArgument().setValue(target.getAbsolutePath()); - cmdl.setClassname(JavaCC.getMainClass(javaccHome, + cmdl.setClassname(JavaCC.getMainClass(javaccHome, JavaCC.TASKDEF_TYPE_JJTREE)); final Path classpath = cmdl.createClasspath(getProject()); @@ -270,4 +297,37 @@ public class JJTree extends Task { throw new BuildException("Failed to launch JJTree", e); } } + + private String createOutputFileName(File target, String optionalOutputFile, + String outputDirectory) { + String jjtreeFile = target.getAbsolutePath().replace('\\','/'); + + if ((optionalOutputFile == null) || optionalOutputFile.equals("")) { + int filePos = jjtreeFile.lastIndexOf("/"); + + if (filePos >= 0) { + jjtreeFile = jjtreeFile.substring(filePos + 1); + } + + int suffixPos = jjtreeFile.lastIndexOf('.'); + + if (suffixPos == -1) { + optionalOutputFile = jjtreeFile + DEFAULT_SUFFIX; + } else { + String currentSuffix = jjtreeFile.substring(suffixPos); + + if (currentSuffix.equals(DEFAULT_SUFFIX)) { + optionalOutputFile = jjtreeFile + DEFAULT_SUFFIX; + } else { + optionalOutputFile = jjtreeFile.substring(0, suffixPos) + + DEFAULT_SUFFIX; + } + } + } + + if ((outputDirectory == null) || outputDirectory.equals("")) { + outputDirectory = getProject().getBaseDir().getAbsolutePath(); + } + return (outputDirectory + "/" + optionalOutputFile).replace('\\', '/'); + } } 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 c91ece0db..266eddf37 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 @@ -98,6 +98,7 @@ public class JavaCC extends Task { private static final String SANITY_CHECK = "SANITY_CHECK"; private static final String FORCE_LA_CHECK = "FORCE_LA_CHECK"; private static final String CACHE_TOKENS = "CACHE_TOKENS"; + private static final String KEEP_LINE_COLUMN = "KEEP_LINE_COLUMN"; private final Hashtable optionalAttrs = new Hashtable(); @@ -113,18 +114,28 @@ public class JavaCC extends Task { protected static final int TASKDEF_TYPE_JJDOC = 3; protected static final String[] ARCHIVE_LOCATIONS = - new String[] {"JavaCC.zip", "bin/lib/JavaCC.zip", - "bin/lib/javacc.jar", - "javacc.jar", // used by jpackage for JavaCC 3.x + new String[] { + "JavaCC.zip", + "bin/lib/JavaCC.zip", + "bin/lib/javacc.jar", + "javacc.jar", // used by jpackage for JavaCC 3.x }; + protected static final int[] ARCHIVE_LOCATIONS_VS_MAJOR_VERSION = + new int[] { + 1, + 2, + 3, + 3, + }; + protected static final String COM_PACKAGE = "COM.sun.labs."; protected static final String COM_JAVACC_CLASS = "javacc.Main"; protected static final String COM_JJTREE_CLASS = "jjtree.Main"; protected static final String COM_JJDOC_CLASS = "jjdoc.JJDocMain"; - protected static final String ORG_PACKAGE = "org.netbeans.javacc."; - protected static final String ORG_JAVACC_PACKAGE = "org.javacc."; + protected static final String ORG_PACKAGE_3_0 = "org.netbeans.javacc."; + protected static final String ORG_PACKAGE_3_1 = "org.javacc."; protected static final String ORG_JAVACC_CLASS = "parser.Main"; protected static final String ORG_JJTREE_CLASS = COM_JJTREE_CLASS; protected static final String ORG_JJDOC_CLASS = COM_JJDOC_CLASS; @@ -269,6 +280,13 @@ public class JavaCC extends Task { optionalAttrs.put(CACHE_TOKENS, new Boolean(cacheTokens)); } + /** + * Sets the KEEP_LINE_COLUMN grammar option. + */ + public void setKeeplinecolumn(boolean keepLineColumn) { + optionalAttrs.put(KEEP_LINE_COLUMN, new Boolean(keepLineColumn)); + } + /** * The directory to write the generated files to. * If not set, the files are written to the directory @@ -354,7 +372,7 @@ public class JavaCC extends Task { */ protected static File getArchiveFile(File home) throws BuildException { return new File(home, - ARCHIVE_LOCATIONS[getMajorVersionNumber(home) - 1]); + ARCHIVE_LOCATIONS[getArchiveLocationIndex(home)]); } /** @@ -397,7 +415,6 @@ public class JavaCC extends Task { break; case 3: - case 4: /* * This is where the fun starts, JavaCC 3.0 uses * org.netbeans.javacc, 3.1 uses org.javacc - I wonder @@ -409,10 +426,10 @@ public class JavaCC extends Task { ZipFile zf = null; try { zf = new ZipFile(getArchiveFile(home)); - if (zf.getEntry(ORG_PACKAGE.replace('.', '/')) != null) { - packagePrefix = ORG_PACKAGE; + if (zf.getEntry(ORG_PACKAGE_3_0.replace('.', '/')) != null) { + packagePrefix = ORG_PACKAGE_3_0; } else { - packagePrefix = ORG_JAVACC_PACKAGE; + packagePrefix = ORG_PACKAGE_3_1; } } catch (IOException e) { throw new BuildException("Error reading javacc.jar", e); @@ -450,23 +467,14 @@ public class JavaCC extends Task { } /** - * Helper method to determine the major version number of JavaCC. - * - *

Don't assume any relation between the number returned by - * this method and the "major version number" of JavaCC - * installed. Both 3 and 4 map to JavaCC 3.x (with no difference - * between 3.0 and 3.1).

- * - *

This method is only useful within this class itself, use - * {@link #getArchiveFile getArchiveFile} and {@link #getMainClass - * getMainClass} for more widely useful results.

+ * Helper method to determine the archive location index. * * @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 attempts to do so. - * @return a number that is useless outside the scope of this class + * @return the archive location index */ - protected static int getMajorVersionNumber(File home) + private static int getArchiveLocationIndex(File home) throws BuildException { if (home == null || !home.isDirectory()) { @@ -477,7 +485,7 @@ public class JavaCC extends Task { File f = new File(home, ARCHIVE_LOCATIONS[i]); if (f.exists()) { - return (i + 1); + return i; } } @@ -485,6 +493,21 @@ public class JavaCC extends Task { + "or javacc.jar from '" + home + "'."); } + /** + * Helper method to determine the major version number of JavaCC. + * + * @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 attempts to do so. + * @return a the major version number + */ + protected static int getMajorVersionNumber(File home) + throws BuildException { + + return + ARCHIVE_LOCATIONS_VS_MAJOR_VERSION[getArchiveLocationIndex(home)]; + } + /** * Determines the output Java file to be generated by the given grammar * file.