Fields Summary |
---|
private static final String | LOOKAHEAD |
private static final String | CHOICE_AMBIGUITY_CHECK |
private static final String | OTHER_AMBIGUITY_CHECK |
private static final String | STATIC |
private static final String | DEBUG_PARSER |
private static final String | DEBUG_LOOKAHEAD |
private static final String | DEBUG_TOKEN_MANAGER |
private static final String | OPTIMIZE_TOKEN_MANAGER |
private static final String | ERROR_REPORTING |
private static final String | JAVA_UNICODE_ESCAPE |
private static final String | UNICODE_INPUT |
private static final String | IGNORE_CASE |
private static final String | COMMON_TOKEN_ACTION |
private static final String | USER_TOKEN_MANAGER |
private static final String | USER_CHAR_STREAM |
private static final String | BUILD_PARSER |
private static final String | BUILD_TOKEN_MANAGER |
private static final String | SANITY_CHECK |
private static final String | FORCE_LA_CHECK |
private static final String | CACHE_TOKENS |
private static final String | KEEP_LINE_COLUMN |
private static final String | JDK_VERSION |
private final Hashtable | optionalAttrs |
private File | outputDirectory |
private File | targetFile |
private File | javaccHome |
private org.apache.tools.ant.types.CommandlineJava | cmdl |
protected static final int | TASKDEF_TYPE_JAVACC |
protected static final int | TASKDEF_TYPE_JJTREE |
protected static final int | TASKDEF_TYPE_JJDOC |
protected static final String[] | ARCHIVE_LOCATIONS |
protected static final int[] | ARCHIVE_LOCATIONS_VS_MAJOR_VERSION |
protected static final String | COM_PACKAGE |
protected static final String | COM_JAVACC_CLASS |
protected static final String | COM_JJTREE_CLASS |
protected static final String | COM_JJDOC_CLASS |
protected static final String | ORG_PACKAGE_3_0 |
protected static final String | ORG_PACKAGE_3_1 |
protected static final String | ORG_JAVACC_CLASS |
protected static final String | ORG_JJTREE_CLASS |
protected static final String | ORG_JJDOC_CLASS |
Methods Summary |
---|
public void | execute()Run the task.
// 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());
}
// check the target is a file
if (targetFile == null || !targetFile.isFile()) {
throw new BuildException("Invalid target: " + targetFile);
}
// use the directory containing the target as the output directory
if (outputDirectory == null) {
outputDirectory = new File(targetFile.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, targetFile);
if (javaFile.exists() && targetFile.lastModified() < javaFile.lastModified()) {
log("Target is already built - skipping (" + targetFile + ")", Project.MSG_VERBOSE);
return;
}
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_JAVACC));
final Commandline.Argument arg = cmdl.createVmArgument();
arg.setValue("-mx140M");
arg.setValue("-Dinstall.root=" + javaccHome.getAbsolutePath());
Execute.runCommand(this, cmdl.getCommandline());
|
protected static java.io.File | getArchiveFile(java.io.File home)Helper method to retrieve the path used to store the JavaCC.zip
or javacc.jar which is different from versions.
return new File(home,
ARCHIVE_LOCATIONS[getArchiveLocationIndex(home)]);
|
private static int | getArchiveLocationIndex(java.io.File home)Helper method to determine the archive location index.
if (home == null || !home.isDirectory()) {
throw new BuildException("JavaCC home must be a valid directory.");
}
for (int i = 0; i < ARCHIVE_LOCATIONS.length; i++) {
File f = new File(home, ARCHIVE_LOCATIONS[i]);
if (f.exists()) {
return i;
}
}
throw new BuildException("Could not find a path to JavaCC.zip "
+ "or javacc.jar from '" + home + "'.");
|
protected static java.lang.String | getMainClass(java.io.File home, int type)Helper method to retrieve main class which is different from versions.
Path p = new Path(null);
p.createPathElement().setLocation(getArchiveFile(home));
p.addJavaRuntime();
return getMainClass(p, type);
|
protected static java.lang.String | getMainClass(org.apache.tools.ant.types.Path path, int type)Helper method to retrieve main class which is different from versions.
String packagePrefix = null;
String mainClass = null;
AntClassLoader l = new AntClassLoader();
l.setClassPath(path.concatSystemClasspath("ignore"));
String javaccClass = COM_PACKAGE + COM_JAVACC_CLASS;
InputStream is = l.getResourceAsStream(javaccClass.replace('.", '/")
+ ".class");
if (is != null) {
packagePrefix = COM_PACKAGE;
switch (type) {
case TASKDEF_TYPE_JAVACC:
mainClass = COM_JAVACC_CLASS;
break;
case TASKDEF_TYPE_JJTREE:
mainClass = COM_JJTREE_CLASS;
break;
case TASKDEF_TYPE_JJDOC:
mainClass = COM_JJDOC_CLASS;
break;
default:
// Fall Through
}
} else {
javaccClass = ORG_PACKAGE_3_1 + ORG_JAVACC_CLASS;
is = l.getResourceAsStream(javaccClass.replace('.", '/")
+ ".class");
if (is != null) {
packagePrefix = ORG_PACKAGE_3_1;
} else {
javaccClass = ORG_PACKAGE_3_0 + ORG_JAVACC_CLASS;
is = l.getResourceAsStream(javaccClass.replace('.", '/")
+ ".class");
if (is != null) {
packagePrefix = ORG_PACKAGE_3_0;
}
}
if (is != null) {
switch (type) {
case TASKDEF_TYPE_JAVACC:
mainClass = ORG_JAVACC_CLASS;
break;
case TASKDEF_TYPE_JJTREE:
mainClass = ORG_JJTREE_CLASS;
break;
case TASKDEF_TYPE_JJDOC:
mainClass = ORG_JJDOC_CLASS;
break;
default:
// Fall Through
}
}
}
if (packagePrefix == null) {
throw new BuildException("failed to load JavaCC");
}
if (mainClass == null) {
throw new BuildException("unknown task type " + type);
}
return packagePrefix + mainClass;
|
protected static int | getMajorVersionNumber(java.io.File home)Helper method to determine the major version number of JavaCC.
return
ARCHIVE_LOCATIONS_VS_MAJOR_VERSION[getArchiveLocationIndex(home)];
|
private java.io.File | getOutputJavaFile(java.io.File outputdir, java.io.File srcfile)Determines the output Java file to be generated by the given grammar
file.
String path = srcfile.getPath();
// Extract file's base-name
int startBasename = path.lastIndexOf(File.separator);
if (startBasename != -1) {
path = path.substring(startBasename + 1);
}
// Replace the file's extension with '.java'
int startExtn = path.lastIndexOf('.");
if (startExtn != -1) {
path = path.substring(0, startExtn) + ".java";
} else {
path += ".java";
}
// Change the directory
if (outputdir != null) {
path = outputdir + File.separator + path;
}
return new File(path);
|
public void | setBuildparser(boolean buildParser)Sets the BUILD_PARSER grammar option.
optionalAttrs.put(BUILD_PARSER, buildParser ? Boolean.TRUE : Boolean.FALSE);
|
public void | setBuildtokenmanager(boolean buildTokenManager)Sets the BUILD_TOKEN_MANAGER grammar option.
optionalAttrs.put(BUILD_TOKEN_MANAGER, buildTokenManager ? Boolean.TRUE : Boolean.FALSE);
|
public void | setCachetokens(boolean cacheTokens)Sets the CACHE_TOKENS grammar option.
optionalAttrs.put(CACHE_TOKENS, cacheTokens ? Boolean.TRUE : Boolean.FALSE);
|
public void | setChoiceambiguitycheck(int choiceAmbiguityCheck)Sets the CHOICE_AMBIGUITY_CHECK grammar option.
optionalAttrs.put(CHOICE_AMBIGUITY_CHECK, new Integer(choiceAmbiguityCheck));
|
public void | setCommontokenaction(boolean commonTokenAction)Sets the COMMON_TOKEN_ACTION grammar option.
optionalAttrs.put(COMMON_TOKEN_ACTION, commonTokenAction ? Boolean.TRUE : Boolean.FALSE);
|
public void | setDebuglookahead(boolean debugLookahead)Sets the DEBUG_LOOKAHEAD grammar option.
optionalAttrs.put(DEBUG_LOOKAHEAD, debugLookahead ? Boolean.TRUE : Boolean.FALSE);
|
public void | setDebugparser(boolean debugParser)Sets the DEBUG_PARSER grammar option.
optionalAttrs.put(DEBUG_PARSER, debugParser ? Boolean.TRUE : Boolean.FALSE);
|
public void | setDebugtokenmanager(boolean debugTokenManager)Sets the DEBUG_TOKEN_MANAGER grammar option.
optionalAttrs.put(DEBUG_TOKEN_MANAGER, debugTokenManager ? Boolean.TRUE : Boolean.FALSE);
|
public void | setErrorreporting(boolean errorReporting)Sets the ERROR_REPORTING grammar option.
optionalAttrs.put(ERROR_REPORTING, errorReporting ? Boolean.TRUE : Boolean.FALSE);
|
public void | setForcelacheck(boolean forceLACheck)Sets the FORCE_LA_CHECK grammar option.
optionalAttrs.put(FORCE_LA_CHECK, forceLACheck ? Boolean.TRUE : Boolean.FALSE);
|
public void | setIgnorecase(boolean ignoreCase)Sets the IGNORE_CASE grammar option.
optionalAttrs.put(IGNORE_CASE, ignoreCase ? Boolean.TRUE : Boolean.FALSE);
|
public void | setJDKversion(java.lang.String jdkVersion)Sets the JDK_VERSION option.
optionalAttrs.put(JDK_VERSION, jdkVersion);
|
public void | setJavacchome(java.io.File javaccHome)The directory containing the JavaCC distribution.
this.javaccHome = javaccHome;
|
public void | setJavaunicodeescape(boolean javaUnicodeEscape)Sets the JAVA_UNICODE_ESCAPE grammar option.
optionalAttrs.put(JAVA_UNICODE_ESCAPE, javaUnicodeEscape ? Boolean.TRUE : Boolean.FALSE);
|
public void | setKeeplinecolumn(boolean keepLineColumn)Sets the KEEP_LINE_COLUMN grammar option.
optionalAttrs.put(KEEP_LINE_COLUMN, keepLineColumn ? Boolean.TRUE : Boolean.FALSE);
|
public void | setLookahead(int lookahead)Sets the LOOKAHEAD grammar option.
optionalAttrs.put(LOOKAHEAD, new Integer(lookahead));
|
public void | setOptimizetokenmanager(boolean optimizeTokenManager)Sets the OPTIMIZE_TOKEN_MANAGER grammar option.
optionalAttrs.put(OPTIMIZE_TOKEN_MANAGER,
optimizeTokenManager ? Boolean.TRUE : Boolean.FALSE);
|
public void | setOtherambiguityCheck(int otherAmbiguityCheck)Sets the OTHER_AMBIGUITY_CHECK grammar option.
optionalAttrs.put(OTHER_AMBIGUITY_CHECK, new Integer(otherAmbiguityCheck));
|
public void | setOutputdirectory(java.io.File outputDirectory)The directory to write the generated files to.
If not set, the files are written to the directory
containing the grammar file.
this.outputDirectory = outputDirectory;
|
public void | setSanitycheck(boolean sanityCheck)Sets the SANITY_CHECK grammar option.
optionalAttrs.put(SANITY_CHECK, sanityCheck ? Boolean.TRUE : Boolean.FALSE);
|
public void | setStatic(boolean staticParser)Sets the STATIC grammar option.
optionalAttrs.put(STATIC, staticParser ? Boolean.TRUE : Boolean.FALSE);
|
public void | setTarget(java.io.File targetFile)The grammar file to process.
this.targetFile = targetFile;
|
public void | setUnicodeinput(boolean unicodeInput)Sets the UNICODE_INPUT grammar option.
optionalAttrs.put(UNICODE_INPUT, unicodeInput ? Boolean.TRUE : Boolean.FALSE);
|
public void | setUsercharstream(boolean userCharStream)Sets the USER_CHAR_STREAM grammar option.
optionalAttrs.put(USER_CHAR_STREAM, userCharStream ? Boolean.TRUE : Boolean.FALSE);
|
public void | setUsertokenmanager(boolean userTokenManager)Sets the USER_TOKEN_MANAGER grammar option.
optionalAttrs.put(USER_TOKEN_MANAGER, userTokenManager ? Boolean.TRUE : Boolean.FALSE);
|