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$
- See Also:
- Java Tree Builder
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classJTB.MojoLogStreamConsumerConsume and log command line output from the JJDoc process.
-
Field Summary
Fields Modifier and Type Field Description private java.lang.BooleandescriptiveFieldNamesThe option "-f".private java.io.FileinputFileThe input grammar.private java.lang.BooleanjavadocFriendlyCommentsThe option "-jd".private java.io.FilenodeDirectoryThe output directory for the syntax tree files.private java.lang.StringnodePackageNameThe option "-np".private java.lang.StringnodeParentClassThe option "-ns".private java.io.FileoutputDirectoryThe base directory for the option "-o".private java.lang.StringpackageNameThe option "-p".private java.lang.BooleanparentPointersThe option "-pp".private java.lang.BooleanprinterThe toolkit option "-printer".private java.lang.BooleanschemeThe toolkit option "-scheme".private java.lang.BooleanspecialTokensThe option "-tk".private java.lang.BooleansupressErrorCheckingThe option "-e".private static java.lang.StringSYNTAX_TREEThe default package name for syntax tree files.private static java.lang.StringVISITORThe default package name for visitor files.private java.io.FilevisitorDirectoryThe output directory for the visitor files.private java.lang.StringvisitorPackageNameThe option "-vp".
-
Constructor Summary
Constructors Constructor Description JTB()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected intexecute()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.FilegetEffectiveNodeDirectory()Gets the absolute path to the output directory for the syntax tree files.private java.lang.StringgetEffectiveNodePackageName()Gets the effective package name for the syntax tree files.private java.io.FilegetEffectiveVisitorDirectory()Gets the absolute path to the output directory for the visitor files.private java.lang.StringgetEffectiveVisitorPackageName()Gets the effective package name for the visitor files.private java.lang.StringgetLastPackageName(java.lang.String name)Gets the last identifier from the specified package name.java.io.FilegetOutputFile()Gets the absolute path to the enhanced grammar file generated by JTB.private voidmoveDirectory(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 voidmoveJavaFiles()Moves the previously generated Java files to their proper target directories.voidsetDescriptiveFieldNames(java.lang.Boolean value)Sets the option "-f".voidsetInputFile(java.io.File value)Sets the absolute path to the grammar file to pass into JTB for preprocessing.voidsetJavadocFriendlyComments(java.lang.Boolean value)Sets the option "-jd".voidsetNodeDirectory(java.io.File value)Sets the absolute path to the output directory for the syntax tree files.voidsetNodePackageName(java.lang.String value)Sets the option "-np".voidsetNodeParentClass(java.lang.String value)Sets the option "-ns".voidsetOutputDirectory(java.io.File value)Sets the absolute path to the output directory for the generated grammar file.voidsetPackageName(java.lang.String value)Sets the option "-p".voidsetParentPointers(java.lang.Boolean value)Sets the option "-pp".voidsetPrinter(java.lang.Boolean value)Sets the toolkit option "-printer".voidsetScheme(java.lang.Boolean value)Sets the toolkit option "-scheme".voidsetSpecialTokens(java.lang.Boolean value)Sets the option "-tk".voidsetSupressErrorChecking(java.lang.Boolean value)Sets the option "-e".voidsetVisitorDirectory(java.io.File value)Sets the absolute path to the output directory for the visitor files.voidsetVisitorPackageName(java.lang.String value)Sets the option "-vp".java.lang.StringtoString()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
nullif 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 benullto 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
nullif neitheroutputDirectorynornodeDirectoryhave 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 benullto 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
nullif neitheroutputDirectorynorvisitorDirectoryhave 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.ExceptionRuns the tool using the previously set parameters.- Specified by:
executein 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
nullif the input wasnull
-
moveJavaFiles
private void moveJavaFiles() throws java.io.IOExceptionMoves 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.IOExceptionMoves 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:
toStringin classjava.lang.Object- Returns:
- A string representation of the command line arguments.
-
-