bodewig 00/09/28 06:46:35
Modified: docs index.html
src/main/org/apache/tools/ant/taskdefs/optional/javacc
JavaCC.java
Added: docs javacc.html
Log:
Documentation for the JavaCC task, changed the location where the
generated file will be placed if no directory has been specified.
Submitted by: Adam Murdoch <[EMAIL PROTECTED]>
Revision Changes Path
1.119 +1 -0 jakarta-ant/docs/index.html
Index: index.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/index.html,v
retrieving revision 1.118
retrieving revision 1.119
diff -u -r1.118 -r1.119
--- index.html 2000/09/27 15:58:34 1.118
+++ index.html 2000/09/28 13:46:29 1.119
@@ -4209,6 +4209,7 @@
<ul>
<li><a href="#cab">Cab</a></li>
<li><a href="#ftp">FTP</a></li>
+ <li><a href="javacc.html">JavaCC</a></li>
<li><a href="jlink.html">Jlink</a></li>
<li><a href="junit.html">JUnit</a></li>
<li><a href="native2ascii.html">Native2Ascii</a></li>
1.1 jakarta-ant/docs/javacc.html
Index: javacc.html
===================================================================
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<title>JavaCC Task</title>
</head>
<body>
<h2><a name="javacc">JavaCC</a></h2>
<h3>Description</h3>
<p>
Invokes the <a HREF="http://www.metamata.com/javacc/">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
<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
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
generate the output files.
</p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
<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 grammar file to process.</td>
<td valign="top" align="center">Yes</td>
</tr>
<tr>
<td valign="top">javacchome</td>
<td valign="top">The directory containing the JavaCC distribution.</td>
<td valign="top" align="center">Yes</td>
</tr>
<tr>
<td valign="top">outputdirectory</td>
<td valign="top">
The directory to write the generated files to. If not set, the files
are written to the directory containing the grammar file.
</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">buildparser</td>
<td valign="top">Sets the BUILD_PARSER grammar option. This is a boolean
option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">buildtokenmanager</td>
<td valign="top">Sets the BUILD_TOKEN_MANAGER grammar option. This is a
boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">cachetokens</td>
<td valign="top">Sets the CACHE_TOKENS grammar option. This is a boolean
option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">choiceambiguitycheck</td>
<td valign="top">Sets the CHOICE_AMBIGUITY_CHECK grammar option. This is
an integer option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">commontokenaction</td>
<td valign="top">Sets the COMMON_TOKEN_ACTION grammar option. This is a
boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">debuglookahead</td>
<td valign="top">Sets the DEBUG_LOOKAHEAD grammar option. This is a
boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">debugparser</td>
<td valign="top">Sets the DEBUG_PARSER grammar option. This is a boolean
option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">debugtokenmanager</td>
<td valign="top">Sets the DEBUG_TOKEN_MANAGER grammar option. This is a
boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">errorreporting</td>
<td valign="top">Sets the ERROR_REPORTING grammar option. This is a
boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">forcelacheck</td>
<td valign="top">Sets the FORCE_LA_CHECK grammar option. This is a
boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">ignorecase</td>
<td valign="top">Sets the IGNORE_CASE grammar option. This is a boolean
option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">javaunicodeescape</td>
<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">lookahead</td>
<td valign="top">Sets the LOOKAHEAD grammar option. This is an integer
option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">optimizetokenmanager</td>
<td valign="top">Sets the OPTIMIZE_TOKEN_MANAGER grammar option. This is
a boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">otherambiguitycheck</td>
<td valign="top">Sets the OTHER_AMBIGUITY_CHECK grammar option. This is
an integer option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">sanitycheck</td>
<td valign="top">Sets the SANITY_CHECK grammar option. This is a boolean
option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">static</td>
<td valign="top">Sets the STATIC grammar option. This is a boolean
option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">unicodeinput</td>
<td valign="top">Sets the UNICODE_INPUT grammar option. This is a
boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">usercharstream</td>
<td valign="top">Sets the USER_CHAR_STREAM grammar option. This is a
boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
<tr>
<td valign="top">usertokenmanager</td>
<td valign="top">Sets the USER_TOKEN_MANAGER grammar option. This is a
boolean option.</td>
<td valign="top" align="center">No</td>
</tr>
</table>
<h3>Example</h3>
<blockquote><pre>
<javacc
target="src/Parser.jj"
outputdirectory"build/src"
javacchome="c:/program files/JavaCC"
static="true"
/>
</pre></blockquote>
<p>
This invokes JavaCC on grammar file src/Parser.jj, writing the generated
files to build/src. The grammar option STATIC is set to true when
invoking JavaCC.
</p>
<hr>
1.7 +13 -26
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java
Index: JavaCC.java
===================================================================
RCS file:
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/optional/javacc/JavaCC.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- JavaCC.java 2000/09/25 14:39:29 1.6
+++ JavaCC.java 2000/09/28 13:46:34 1.7
@@ -216,23 +216,25 @@
cmdl.createArgument().setValue("-"+name+":"+value.toString());
}
- // load command line with required attributes
- if (outputDirectory != null) {
- if (!outputDirectory.isDirectory()) {
- throw new BuildException("Outputdir not a directory.");
- }
- cmdl.createArgument().setValue(
- "-OUTPUT_DIRECTORY:"+outputDirectory.getAbsolutePath());
- }
-
+ // check the target is a file
if (target == null || !target.isFile()) {
throw new BuildException("Invalid target: " + target);
}
+ // use the directory containing the target as the output directory
+ if (outputDirectory == null) {
+ outputDirectory = new File(target.getParent());
+ }
+ else if (!outputDirectory.isDirectory()) {
+ throw new BuildException("Outputdir not a directory.");
+ }
+ cmdl.createArgument().setValue(
+ "-OUTPUT_DIRECTORY:"+outputDirectory.getAbsolutePath());
+
// determine if the generated java file is up-to-date
final File javaFile = getOutputJavaFile(outputDirectory, target);
if (javaFile.exists() && target.lastModified() <
javaFile.lastModified()) {
- project.log("Target is already built - skipping (" + target +
")");
+ log("Target is already built - skipping (" + target + ")",
Project.MSG_VERBOSE);
return;
}
cmdl.createArgument().setValue(target.getAbsolutePath());
@@ -247,23 +249,8 @@
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.toString(), Project.MSG_VERBOSE);
- process.setCommandline(cmdl.getCommandline());
- try {
- if (process.execute() != 0) {
- throw new BuildException("JavaCC failed.");
- }
- }
- catch (IOException e) {
- throw new BuildException("Failed to launch JavaCC: " + e);
- }
+ Execute.runCommand(this, cmdl.getCommandline());
}
/**