Runs the JJTree compiler compiler.
| Method from org.apache.tools.ant.taskdefs.optional.javacc.JJTree Detail: |
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 (targetFile == null || !targetFile.isFile()) {
throw new BuildException("Invalid target: " + targetFile);
}
File javaFile = null;
// use the directory containing the target as the output directory
if (outputDirectory == null) {
// convert backslashes to slashes, otherwise jjtree will
// put this as comments and this seems to confuse javacc
cmdl.createArgument().setValue("-OUTPUT_DIRECTORY:"
+ getDefaultOutputDirectory());
javaFile = new File(createOutputFileName(targetFile, 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(targetFile, outputFile,
outputDirectory
.getPath()));
}
if (javaFile.exists()
&& targetFile.lastModified() < javaFile.lastModified()) {
log("Target is already built - skipping (" + targetFile + ")",
Project.MSG_VERBOSE);
return;
}
if (outputFile != null) {
cmdl.createArgument().setValue("-" + OUTPUT_FILE + ":"
+ outputFile.replace('\\", '/"));
}
cmdl.createArgument().setValue(targetFile.getAbsolutePath());
final Path classpath = cmdl.createClasspath(getProject());
final File javaccJar = JavaCC.getArchiveFile(javaccHome);
classpath.createPathElement().setPath(javaccJar.getAbsolutePath());
classpath.addJavaRuntime();
cmdl.setClassname(JavaCC.getMainClass(classpath,
JavaCC.TASKDEF_TYPE_JJTREE));
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("JJTree failed.");
}
} catch (IOException e) {
throw new BuildException("Failed to launch JJTree", e);
}
}
|
public void setBuildnodefiles(boolean buildNodeFiles) {
optionalAttrs.put(BUILD_NODE_FILES, buildNodeFiles ? Boolean.TRUE : Boolean.FALSE);
}
Sets the BUILD_NODE_FILES grammar option. |
public void setJavacchome(File javaccHome) {
this.javaccHome = javaccHome;
}
The directory containing the JavaCC distribution. |
public void setMulti(boolean multi) {
optionalAttrs.put(MULTI, multi ? Boolean.TRUE : Boolean.FALSE);
}
Sets the MULTI grammar option. |
public void setNodedefaultvoid(boolean nodeDefaultVoid) {
optionalAttrs.put(NODE_DEFAULT_VOID, nodeDefaultVoid ? Boolean.TRUE : Boolean.FALSE);
}
Sets the NODE_DEFAULT_VOID grammar option. |
public void setNodefactory(boolean nodeFactory) {
optionalAttrs.put(NODE_FACTORY, nodeFactory ? Boolean.TRUE : Boolean.FALSE);
}
Sets the NODE_FACTORY grammar option. |
public void setNodepackage(String nodePackage) {
optionalAttrs.put(NODE_PACKAGE, nodePackage);
}
Sets the NODE_PACKAGE grammar option. |
public void setNodeprefix(String nodePrefix) {
optionalAttrs.put(NODE_PREFIX, nodePrefix);
}
Sets the NODE_PREFIX grammar option. |
public void setNodescopehook(boolean nodeScopeHook) {
optionalAttrs.put(NODE_SCOPE_HOOK, nodeScopeHook ? Boolean.TRUE : Boolean.FALSE);
}
Sets the NODE_SCOPE_HOOK grammar option. |
public void setNodeusesparser(boolean nodeUsesParser) {
optionalAttrs.put(NODE_USES_PARSER, nodeUsesParser ? Boolean.TRUE : Boolean.FALSE);
}
Sets the NODE_USES_PARSER grammar option. |
public void setOutputdirectory(File outputDirectory) {
this.outputDirectory = outputDirectory;
}
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. |
public void setOutputfile(String outputFile) {
this.outputFile = outputFile;
}
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 setStatic(boolean staticParser) {
optionalAttrs.put(STATIC, staticParser ? Boolean.TRUE : Boolean.FALSE);
}
Sets the STATIC grammar option. |
public void setTarget(File targetFile) {
this.targetFile = targetFile;
}
The jjtree grammar file to process. |
public void setVisitor(boolean visitor) {
optionalAttrs.put(VISITOR, visitor ? Boolean.TRUE : Boolean.FALSE);
}
Sets the VISITOR grammar option. |
public void setVisitorException(String visitorException) {
optionalAttrs.put(VISITOR_EXCEPTION, visitorException);
}
Sets the VISITOR_EXCEPTION grammar option. |