bodewig 2003/07/23 07:12:12 Modified: docs/manual optionaltasklist.html tasksoverview.html docs/manual/OptionalTasks javacc.html jjtree.html src/main/org/apache/tools/ant/taskdefs defaults.properties src/main/org/apache/tools/ant/taskdefs/optional/javacc JJTree.java JavaCC.java Added: docs/manual/OptionalTasks jjdoc.html src/main/org/apache/tools/ant/taskdefs/optional/javacc JJDoc.java Log: New task <jjdoc>. New attribute outputfile for <jjtree>. PR: 21526 Submitted by: Jene Jasper <jjasper at abz dot nl> Revision Changes Path 1.39 +1 -0 ant/docs/manual/optionaltasklist.html Index: optionaltasklist.html =================================================================== RCS file: /home/cvs/ant/docs/manual/optionaltasklist.html,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- optionaltasklist.html 13 May 2003 14:37:00 -0000 1.38 +++ optionaltasklist.html 23 Jul 2003 14:12:11 -0000 1.39 @@ -37,6 +37,7 @@ <a href="OptionalTasks/javah.html">Javah</a><br> <a href="OptionalTasks/jspc.html">JspC</a><br> <a href="OptionalTasks/jdepend.html">JDepend</a><br> +<a href="OptionalTasks/jjdoc.html">JJDoc</a><br> <a href="OptionalTasks/jjtree.html">JJTree</a><br> <a href="OptionalTasks/jlink.html"><i>Jlink</i></a><br> <a href="OptionalTasks/jpcoverage.html">JProbe Coverage</a><br> 1.22 +21 -11 ant/docs/manual/tasksoverview.html Index: tasksoverview.html =================================================================== RCS file: /home/cvs/ant/docs/manual/tasksoverview.html,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- tasksoverview.html 21 Apr 2003 06:36:46 -0000 1.21 +++ tasksoverview.html 23 Jul 2003 14:12:11 -0000 1.22 @@ -318,12 +318,12 @@ <tr valign="top"> <td nowrap><a href="OptionalTasks/stylebook.html">Stylebook</a></td> - <td><p>Executes the Apache Stylebook documentation generator. + <td><p>Executes the Apache Stylebook documentation generator. Unlike the command-line version of this tool, all three arguments are required to run the Stylebook task.</p></td> </tr> </table> - + <p></p> <table width="100%" border="0" cellpadding="4" cellspacing="0"> <th align="left"> @@ -748,7 +748,7 @@ <tr valign="top"> <td nowrap><a href="OptionalTasks/script.html">Script</a></td> - <td><p>Executes a script in a + <td><p>Executes a script in a <a href="http://jakarta.apache.org/bsf/" target="_top">Apache BSF</a>-supported language.</p></td> </tr> @@ -861,7 +861,7 @@ <tr valign="top"> <td nowrap><a href="OptionalTasks/javacc.html">JavaCC</a></td> <td><p>Invokes the - <a HREF="http://www.webgain.com/products/java_cc/" target="_top"> + <a HREF="http://javacc.dev.java.net/" target="_top"> JavaCC</a> compiler-compiler on a grammar file.</p></td> </tr> @@ -871,8 +871,18 @@ </tr> <tr valign="top"> + <td nowrap><a href="OptionalTasks/jjdoc.html">JJDoc</a></td> + <td><p>Invokes the <a href="http://javacc.dev.java.net/"> + JJDoc</a> 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.</p></td> + </tr> + + <tr valign="top"> <td nowrap><a href="OptionalTasks/jjtree.html">JJTree</a></td> - <td><p>Invokes the <a href="http://www.webgain.com/products/java_cc/"> + <td><p>Invokes the <a href="http://javacc.dev.java.net/"> JJTree</a> 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 @@ <tr valign="top"> <td nowrap><a href="CoreTasks/dirname.html">Dirname</a></td> <td><p>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. </tr> <tr valign="top"> @@ -1032,7 +1042,7 @@ <tr valign="top"> <td nowrap><a href="OptionalTasks/telnet.html">Telnet</a></td> - <td><p>Task to automate a remote <i>telnet</i> session. This task uses + <td><p>Task to automate a remote <i>telnet</i> session. This task uses nested <code><read></code> and <code><write></code> tags to indicate strings to wait for and specify text to send.</p></td> </tr> @@ -1042,7 +1052,7 @@ in the same JVM can have through-the-firewall access to remote web sites.</p></td> </tr> - + </table> <p></p> @@ -1083,8 +1093,8 @@ <tr valign="top"> <td nowrap><a href="CoreTasks/cvstagdiff.html">CvsTagDiff</a></td> - <td><p>Generates an XML-formatted report file of the changes between - two tags or dates recorded in a <a href="http://www.cvshome.org/" + <td><p>Generates an XML-formatted report file of the changes between + two tags or dates recorded in a <a href="http://www.cvshome.org/" target="_top">CVS</a> repository.</p></td> </tr> @@ -1135,7 +1145,7 @@ <td><p>Tasks to perform the StarTeam <i>stcheckout</i>, <i>stcheckin</i>, <i>stlabel</i>, and <i>stlist</i> commands. The <a href="OptionalTasks/starteam.html#starteam">Starteam</a> task - is deprecated; use + is deprecated; use <a href="OptionalTasks/starteam.html#stcheckout">STCheckout</a> instead.</p></td> </tr> 1.6 +17 -12 ant/docs/manual/OptionalTasks/javacc.html Index: javacc.html =================================================================== RCS file: /home/cvs/ant/docs/manual/OptionalTasks/javacc.html,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- javacc.html 1 Jun 2002 12:26:35 -0000 1.5 +++ javacc.html 23 Jul 2003 14:12:11 -0000 1.6 @@ -8,25 +8,25 @@ <body> <h2><a name="javacc">JavaCC</a></h2> -<h3>Description</h3> +<h3>Description</h3> <p> - Invokes the <a HREF="http://www.webgain.com/products/java_cc/" target="_top">JavaCC</a> compiler + Invokes the <a HREF="http://javacc.dev.java.net/" target="_top">JavaCC</a> compiler compiler on a grammar file. </p> <p> - To use the javacc task, set the <i>target</i> attribute to the name of the - grammar file to process. You also need to specify the directory containing - the JavaCC installation using the <i>javacchome</i> attribute, so that ant - can find the JavaCC classes. Optionally, you can also set the + To use the javacc task, set the <i>target</i> attribute to the name of the + grammar file to process. You also need to specify the directory containing + the JavaCC installation using the <i>javacchome</i> attribute, so that ant + can find the JavaCC classes. Optionally, you can also set the <i>outputdirectory</i> to write the generated file to a specific directory. Otherwise javacc writes the generated files to the directory containing the grammar file. </p> <p> - 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. </p> @@ -116,6 +116,11 @@ <td valign="top" align="center">No</td> </tr> <tr> + <td valign="top">keeplinecolumn</td> + <td valign="top">Sets the KEEP_LINE_COLUMN grammar option. This is a boolean option.</td> + <td valign="top" align="center">No</td> + </tr> + <tr> <td valign="top">lookahead</td> <td valign="top">Sets the LOOKAHEAD grammar option. This is an integer option.</td> <td valign="top" align="center">No</td> @@ -158,10 +163,10 @@ </table> <h3>Example</h3> <blockquote><pre> -<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" /> </pre></blockquote> @@ -172,7 +177,7 @@ </p> <hr> -<p align="center">Copyright © 2000-2001 Apache Software Foundation. +<p align="center">Copyright © 2000-2001,2003 Apache Software Foundation. All rights Reserved.</p> 1.7 +23 -8 ant/docs/manual/OptionalTasks/jjtree.html Index: jjtree.html =================================================================== RCS file: /home/cvs/ant/docs/manual/OptionalTasks/jjtree.html,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- jjtree.html 3 Sep 2002 15:24:08 -0000 1.6 +++ jjtree.html 23 Jul 2003 14:12:11 -0000 1.7 @@ -12,18 +12,21 @@ <h3> Description</h3> -Invokes the <a href="http://www.webgain.com/products/java_cc/">JJTree</a> preprocessor +<p>Invokes the <a href="http://javacc.dev.java.net/">JJTree</a> 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. <p>To use the jjtree task, set the <i>target</i> 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 <i>javacchome</i> attribute, so that ant can find the JavaCC classes. Optionally, you can also set the <i>outputdirectory</i> -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.</p> +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 +<i>outputfile</i> 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.</p> <p>This task only invokes JJTree if the grammar file is newer than the generated JavaCC file.</p> @@ -57,8 +60,20 @@ <tr> <td VALIGN=TOP>outputdirectory</td> -<td VALIGN=TOP>The directory to write the generated file to. If not set, -the files are written to the directory containing the grammar file. </td> +<td VALIGN=TOP>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. </td> + +<td ALIGN=CENTER VALIGN=TOP>No</td> +</tr> + +<tr> +<td VALIGN=TOP>outputfile</td> + +<td VALIGN=TOP>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 <code>.jj</code>. This is a +filename relative to <em>outputdirectory</em> if specified, the +project's basedir.</td> <td ALIGN=CENTER VALIGN=TOP>No</td> </tr> @@ -173,7 +188,7 @@ is set to true when invoking JJTree. <br> <hr> -<p align="center">Copyright © 2001-2002 Apache Software Foundation. All rights +<p align="center">Copyright © 2001-2003 Apache Software Foundation. All rights Reserved.</p> </body> </html> 1.1 ant/docs/manual/OptionalTasks/jjdoc.html Index: jjdoc.html =================================================================== <!doctype html public "-//w3c//dtd html 4.0 transitional//en"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta http-equiv="Content-Language" content="en-us"> <title>JJDoc Task</title> </head> <body> <h2> <a NAME="jjtree"></a>JJDoc</h2> <p><em>Since Ant 1.6</em></p> <h3>Description</h3> <p>Invokes the <a href="http://javacc.dev.java.net/">JJDoc</a> 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. <p>To use the jjdoc task, set the <i>target</i> attribute to the name of the JavaCC grammar file to process. You also need to specify the directory containing the JavaCC installation using the <i>javacchome</i> attribute, so that ant can find the JavaCC classes. Optionally, you can also set the <i>outputfile</i> 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.</p> <p>This task only invokes JJDoc if the grammar file is newer than the generated BNF documentation file.</p> <h3>Parameters</h3> <table BORDER CELLSPACING=0 CELLPADDING=2 > <tr> <td VALIGN=TOP><b>Attribute</b></td> <td VALIGN=TOP><b>Description</b></td> <td ALIGN=CENTER VALIGN=TOP><b>Required</b></td> </tr> <tr> <td VALIGN=TOP>target</td> <td VALIGN=TOP>The javacc grammar file to process.</td> <td ALIGN=CENTER VALIGN=TOP>Yes</td> </tr> <tr> <td VALIGN=TOP>javacchome</td> <td VALIGN=TOP>The directory containing the JavaCC distribution.</td> <td ALIGN=CENTER VALIGN=TOP>Yes</td> </tr> <tr> <td VALIGN=TOP>outputfile</td> <td VALIGN=TOP>The 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. </td> <td ALIGN=CENTER VALIGN=TOP>No</td> </tr> <tr> <td VALIGN=TOP>text</td> <td VALIGN=TOP>Sets the TEXT BNF documentation option. This is a boolean option.</td> <td ALIGN=CENTER VALIGN=TOP>No</td> </tr> <tr> <td VALIGN=TOP>onetable</td> <td VALIGN=TOP>Sets the ONE_TABLE BNF documentation option. This is a boolean option.</td> <td ALIGN=CENTER VALIGN=TOP>No</td> </tr> </table> <h3> Example</h3> <blockquote> <pre><jjdoc target="src/Parser.jj" outputfile="doc/ParserBNF.html" javacchome="c:/program files/JavaCC" /></pre> </blockquote> This invokes JJDoc on grammar file src/Parser.jj, writing the generated BNF documentation file, ParserBNF.html, file to doc. <br> <hr> <p align="center">Copyright © 2003 Apache Software Foundation. All rights Reserved.</p> </body> </html> 1.151 +1 -0 ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties Index: defaults.properties =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/defaults.properties,v retrieving revision 1.150 retrieving revision 1.151 diff -u -r1.150 -r1.151 --- defaults.properties 10 Jun 2003 20:57:59 -0000 1.150 +++ defaults.properties 23 Jul 2003 14:12:12 -0000 1.151 @@ -103,6 +103,7 @@ 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 1.22 +77 -17 ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java Index: JJTree.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJTree.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- JJTree.java 19 Jul 2003 08:11:04 -0000 1.21 +++ JJTree.java 23 Jul 2003 14:12:12 -0000 1.22 @@ -72,11 +72,13 @@ * Runs the JJTree compiler compiler. * * @author [EMAIL PROTECTED] - * @author Michael Saunders <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> + * @author Michael Saunders + * <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> */ 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 @@ 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 @@ } /** - * 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. */ @@ -187,6 +193,15 @@ } /** + * 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. */ public void setTarget(File target) { @@ -217,32 +232,44 @@ 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()); + 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())); } - 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('\\', '/')); - - 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()); @@ -269,5 +296,38 @@ } catch (IOException e) { 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('\\', '/'); } } 1.26 +46 -23 ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java Index: JavaCC.java =================================================================== RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- JavaCC.java 17 Jul 2003 14:55:43 -0000 1.25 +++ JavaCC.java 23 Jul 2003 14:12:12 -0000 1.26 @@ -98,6 +98,7 @@ 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 @@ 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; @@ -270,6 +281,13 @@ } /** + * 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 * containing the grammar file. @@ -354,7 +372,7 @@ */ 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 @@ 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 @@ 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 @@ } /** - * Helper method to determine the major version number of JavaCC. - * - * <p>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).</p> - * - * <p>This method is only useful within this class itself, use - * [EMAIL PROTECTED] #getArchiveFile getArchiveFile} and [EMAIL PROTECTED] #getMainClass - * getMainClass} for more widely useful results.</p> + * 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,12 +485,27 @@ File f = new File(home, ARCHIVE_LOCATIONS[i]); if (f.exists()) { - return (i + 1); + return i; } } throw new BuildException("Could not find a path to JavaCC.zip " + "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)]; } /** 1.1 ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JJDoc.java Index: JJDoc.java =================================================================== /* * 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 [EMAIL PROTECTED] * * 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 * <http://www.apache.org/>. */ 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 <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> * @author [EMAIL PROTECTED] * @author Michael Saunders * <a href="mailto:[EMAIL PROTECTED]">[EMAIL PROTECTED]</a> */ 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('\\', '/'); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]