Package org.codehaus.mojo.javacc
Class JTB
- java.lang.Object
-
- org.codehaus.mojo.javacc.ToolFacade
-
- org.codehaus.mojo.javacc.JTB
-
class JTB extends ToolFacade
Provides a facade for the mojos to invoke JTB.- Version:
- $Id: JTB.java 6463 2008-03-15 22:20:09Z bentmann $
- See Also:
- Java Tree Builder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
JTB.MojoLogStreamConsumer
Consume and log command line output from the JJDoc process.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Boolean
descriptiveFieldNames
The option "-f".private java.io.File
inputFile
The input grammar.private java.lang.Boolean
javadocFriendlyComments
The option "-jd".private java.io.File
nodeDirectory
The output directory for the syntax tree files.private java.lang.String
nodePackageName
The option "-np".private java.lang.String
nodeParentClass
The option "-ns".private java.io.File
outputDirectory
The base directory for the option "-o".private java.lang.String
packageName
The option "-p".private java.lang.Boolean
parentPointers
The option "-pp".private java.lang.Boolean
printer
The toolkit option "-printer".private java.lang.Boolean
scheme
The toolkit option "-scheme".private java.lang.Boolean
specialTokens
The option "-tk".private java.lang.Boolean
supressErrorChecking
The option "-e".private static java.lang.String
SYNTAX_TREE
The default package name for syntax tree files.private static java.lang.String
VISITOR
The default package name for visitor files.private java.io.File
visitorDirectory
The output directory for the visitor files.private java.lang.String
visitorPackageName
The option "-vp".
-
Constructor Summary
Constructors Constructor Description JTB()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected int
execute()
Runs the tool using the previously set parameters.private java.lang.String[]
generateArguments()
Assembles the command line arguments for the invocation of JTB according to the configuration.private java.io.File
getEffectiveNodeDirectory()
Gets the absolute path to the output directory for the syntax tree files.private java.lang.String
getEffectiveNodePackageName()
Gets the effective package name for the syntax tree files.private java.io.File
getEffectiveVisitorDirectory()
Gets the absolute path to the output directory for the visitor files.private java.lang.String
getEffectiveVisitorPackageName()
Gets the effective package name for the visitor files.private java.lang.String
getLastPackageName(java.lang.String name)
Gets the last identifier from the specified package name.java.io.File
getOutputFile()
Gets the absolute path to the enhanced grammar file generated by JTB.private void
moveDirectory(java.io.File sourceDir, java.io.File targetDir)
Moves all Java files generated by JTB from the specified source directory to the given target directory.private void
moveJavaFiles()
Moves the previously generated Java files to their proper target directories.void
setDescriptiveFieldNames(java.lang.Boolean value)
Sets the option "-f".void
setInputFile(java.io.File value)
Sets the absolute path to the grammar file to pass into JTB for preprocessing.void
setJavadocFriendlyComments(java.lang.Boolean value)
Sets the option "-jd".void
setNodeDirectory(java.io.File value)
Sets the absolute path to the output directory for the syntax tree files.void
setNodePackageName(java.lang.String value)
Sets the option "-np".void
setNodeParentClass(java.lang.String value)
Sets the option "-ns".void
setOutputDirectory(java.io.File value)
Sets the absolute path to the output directory for the generated grammar file.void
setPackageName(java.lang.String value)
Sets the option "-p".void
setParentPointers(java.lang.Boolean value)
Sets the option "-pp".void
setPrinter(java.lang.Boolean value)
Sets the toolkit option "-printer".void
setScheme(java.lang.Boolean value)
Sets the toolkit option "-scheme".void
setSpecialTokens(java.lang.Boolean value)
Sets the option "-tk".void
setSupressErrorChecking(java.lang.Boolean value)
Sets the option "-e".void
setVisitorDirectory(java.io.File value)
Sets the absolute path to the output directory for the visitor files.void
setVisitorPackageName(java.lang.String value)
Sets the option "-vp".java.lang.String
toString()
Gets a string representation of the command line arguments.-
Methods inherited from class org.codehaus.mojo.javacc.ToolFacade
getLog, getToolName, run, setLog
-
-
-
-
Field Detail
-
SYNTAX_TREE
private static final java.lang.String SYNTAX_TREE
The default package name for syntax tree files.- See Also:
- Constant Field Values
-
VISITOR
private static final java.lang.String VISITOR
The default package name for visitor files.- See Also:
- Constant Field Values
-
inputFile
private java.io.File inputFile
The input grammar.
-
outputDirectory
private java.io.File outputDirectory
The base directory for the option "-o".
-
nodeDirectory
private java.io.File nodeDirectory
The output directory for the syntax tree files.
-
visitorDirectory
private java.io.File visitorDirectory
The output directory for the visitor files.
-
packageName
private java.lang.String packageName
The option "-p".
-
nodePackageName
private java.lang.String nodePackageName
The option "-np".
-
visitorPackageName
private java.lang.String visitorPackageName
The option "-vp".
-
supressErrorChecking
private java.lang.Boolean supressErrorChecking
The option "-e".
-
javadocFriendlyComments
private java.lang.Boolean javadocFriendlyComments
The option "-jd".
-
descriptiveFieldNames
private java.lang.Boolean descriptiveFieldNames
The option "-f".
-
nodeParentClass
private java.lang.String nodeParentClass
The option "-ns".
-
parentPointers
private java.lang.Boolean parentPointers
The option "-pp".
-
specialTokens
private java.lang.Boolean specialTokens
The option "-tk".
-
scheme
private java.lang.Boolean scheme
The toolkit option "-scheme".
-
printer
private java.lang.Boolean printer
The toolkit option "-printer".
-
-
Method Detail
-
setInputFile
public void setInputFile(java.io.File value)
Sets the absolute path to the grammar file to pass into JTB for preprocessing.- Parameters:
value
- The absolute path to the grammar file to pass into JTB for preprocessing.
-
setOutputDirectory
public void setOutputDirectory(java.io.File value)
Sets the absolute path to the output directory for the generated grammar file.- Parameters:
value
- The absolute path to the output directory for the generated grammar file. If this directory does not exist yet, it is created. Note that this path should already include the desired package hierarchy because JTB will not append the required sub directories automatically.
-
getOutputFile
public java.io.File getOutputFile()
Gets the absolute path to the enhanced grammar file generated by JTB.- Returns:
- The absolute path to the enhanced grammar file generated by JTB or
null
if either the input file or the output directory have not been set.
-
setNodeDirectory
public void setNodeDirectory(java.io.File value)
Sets the absolute path to the output directory for the syntax tree files.- Parameters:
value
- The absolute path to the output directory for the generated syntax tree files, may benull
to use a sub directory in the output directory of the grammar file. If this directory does not exist yet, it is created. Note that this path should already include the desired package hierarchy because JTB will not append the required sub directories automatically.
-
getEffectiveNodeDirectory
private java.io.File getEffectiveNodeDirectory()
Gets the absolute path to the output directory for the syntax tree files.- Returns:
- The absolute path to the output directory for the syntax tree files, only
null
if neitheroutputDirectory
nornodeDirectory
have been set.
-
setVisitorDirectory
public void setVisitorDirectory(java.io.File value)
Sets the absolute path to the output directory for the visitor files.- Parameters:
value
- The absolute path to the output directory for the generated visitor files, may benull
to use a sub directory in the output directory of the grammar file. If this directory does not exist yet, it is created. Note that this path should already include the desired package hierarchy because JTB will not append the required sub directories automatically.
-
getEffectiveVisitorDirectory
private java.io.File getEffectiveVisitorDirectory()
Gets the absolute path to the output directory for the visitor files.- Returns:
- The absolute path to the output directory for the visitor, only
null
if neitheroutputDirectory
norvisitorDirectory
have been set.
-
setPackageName
public void setPackageName(java.lang.String value)
Sets the option "-p". Will overwrite the options "-np" and "-vp" if specified.- Parameters:
value
- The option value, may benull
.
-
setNodePackageName
public void setNodePackageName(java.lang.String value)
Sets the option "-np".- Parameters:
value
- The option value, may benull
.
-
getEffectiveNodePackageName
private java.lang.String getEffectiveNodePackageName()
Gets the effective package name for the syntax tree files.- Returns:
- The effective package name for the syntax tree files, never
null
.
-
setVisitorPackageName
public void setVisitorPackageName(java.lang.String value)
Sets the option "-vp".- Parameters:
value
- The option value, may benull
.
-
getEffectiveVisitorPackageName
private java.lang.String getEffectiveVisitorPackageName()
Gets the effective package name for the visitor files.- Returns:
- The effective package name for the visitor files, never
null
.
-
setSupressErrorChecking
public void setSupressErrorChecking(java.lang.Boolean value)
Sets the option "-e".- Parameters:
value
- The option value, may benull
.
-
setJavadocFriendlyComments
public void setJavadocFriendlyComments(java.lang.Boolean value)
Sets the option "-jd".- Parameters:
value
- The option value, may benull
.
-
setDescriptiveFieldNames
public void setDescriptiveFieldNames(java.lang.Boolean value)
Sets the option "-f".- Parameters:
value
- The option value, may benull
.
-
setNodeParentClass
public void setNodeParentClass(java.lang.String value)
Sets the option "-ns".- Parameters:
value
- The option value, may benull
.
-
setParentPointers
public void setParentPointers(java.lang.Boolean value)
Sets the option "-pp".- Parameters:
value
- The option value, may benull
.
-
setSpecialTokens
public void setSpecialTokens(java.lang.Boolean value)
Sets the option "-tk".- Parameters:
value
- The option value, may benull
.
-
setScheme
public void setScheme(java.lang.Boolean value)
Sets the toolkit option "-scheme".- Parameters:
value
- The option value, may benull
.
-
setPrinter
public void setPrinter(java.lang.Boolean value)
Sets the toolkit option "-printer".- Parameters:
value
- The option value, may benull
.
-
execute
protected int execute() throws java.lang.Exception
Runs the tool using the previously set parameters.- Specified by:
execute
in classToolFacade
- Returns:
- The exit code of the tool, non-zero means failure.
- Throws:
java.lang.Exception
- If the tool could not be invoked.
-
generateArguments
private java.lang.String[] generateArguments()
Assembles the command line arguments for the invocation of JTB according to the configuration.- Returns:
- A string array that represents the command line arguments to use for JTB.
-
getLastPackageName
private java.lang.String getLastPackageName(java.lang.String name)
Gets the last identifier from the specified package name. For example, returns "apache" upon input of "org.apache". JTB uses this approach to derive the output directories for the visitor and syntax tree files.- Parameters:
name
- The package name from which to retrieve the last sub package, may benull
.- Returns:
- The name of the last sub package or
null
if the input wasnull
-
moveJavaFiles
private void moveJavaFiles() throws java.io.IOException
Moves the previously generated Java files to their proper target directories. JTB simply assumes that the current working directory represents the parent package of the configured node/visitor packages which does not meet our needs.- Throws:
java.io.IOException
- If the move failed.
-
moveDirectory
private void moveDirectory(java.io.File sourceDir, java.io.File targetDir) throws java.io.IOException
Moves all Java files generated by JTB from the specified source directory to the given target directory. Existing files in the target directory will be overwritten. Note that this move assumes a flat source directory, i.e. copying of sub directories is not supported.
This method must be used instead ofFile.renameTo(java.io.File)
which would fail if the target directory already existed (at least on Windows).- Parameters:
sourceDir
- The absolute path to the source directory, must not benull
.targetDir
- The absolute path to the target directory, must not benull
.- Throws:
java.io.IOException
- If the move failed.
-
toString
public java.lang.String toString()
Gets a string representation of the command line arguments.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string representation of the command line arguments.
-
-