New attribute outputfile for <jjtree>. PR: 21526 Submitted by: Jene Jasper <jjasper at abz dot nl> git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274913 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -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> | |||
| @@ -115,6 +115,11 @@ | |||
| <td valign="top">Sets the JAVA_UNICODE_ESCAPE grammar option. This is a boolean option.</td> | |||
| <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> | |||
| @@ -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> | |||
| @@ -0,0 +1,101 @@ | |||
| <!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> | |||
| @@ -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 @@ generated JavaCC file.</p> | |||
| <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 @@ grammar file, Parser.jj, file to build/src. The grammar option NODE_USES_PARSER | |||
| 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> | |||
| @@ -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> | |||
| @@ -318,12 +318,12 @@ documentation.</p> | |||
| <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 @@ documentation.</p> | |||
| <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 @@ documentation.</p> | |||
| <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> | |||
| @@ -870,9 +870,19 @@ documentation.</p> | |||
| <td><p>Generates JNI headers from a Java class.</p></td> | |||
| </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 @@ documentation.</p> | |||
| <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 @@ documentation.</p> | |||
| <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 @@ documentation.</p> | |||
| in the same JVM can have through-the-firewall access to remote web sites.</p></td> | |||
| </tr> | |||
| </table> | |||
| <p></p> | |||
| @@ -1083,8 +1093,8 @@ documentation.</p> | |||
| <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 @@ documentation.</p> | |||
| <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> | |||
| @@ -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 | |||
| @@ -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 | |||
| * <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:jjasper@abz.nl">jjasper@abz.nl</a> | |||
| * @author thomas.haas@softwired-inc.com | |||
| * @author Michael Saunders | |||
| * <a href="mailto:michael@amtec.com">michael@amtec.com</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('\\', '/'); | |||
| } | |||
| } | |||
| @@ -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 <a href="mailto:michael@amtec.com">michael@amtec.com</a> | |||
| * @author Michael Saunders | |||
| * <a href="mailto:michael@amtec.com">michael@amtec.com</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 @@ 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('\\', '/'); | |||
| } | |||
| } | |||
| @@ -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. | |||
| * | |||
| * <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 | |||
| * {@link #getArchiveFile getArchiveFile} and {@link #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,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. | |||