Class 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:
  • Field Details

    • SYNTAX_TREE

      private static final String SYNTAX_TREE
      The default package name for syntax tree files.
      See Also:
    • VISITOR

      private static final String VISITOR
      The default package name for visitor files.
      See Also:
    • inputFile

      private File inputFile
      The input grammar.
    • outputDirectory

      private File outputDirectory
      The base directory for the option "-o".
    • nodeDirectory

      private File nodeDirectory
      The output directory for the syntax tree files.
    • visitorDirectory

      private File visitorDirectory
      The output directory for the visitor files.
    • packageName

      private String packageName
      The option "-p".
    • nodePackageName

      private String nodePackageName
      The option "-np".
    • visitorPackageName

      private String visitorPackageName
      The option "-vp".
    • supressErrorChecking

      private Boolean supressErrorChecking
      The option "-e".
    • javadocFriendlyComments

      private Boolean javadocFriendlyComments
      The option "-jd".
    • descriptiveFieldNames

      private Boolean descriptiveFieldNames
      The option "-f".
    • nodeParentClass

      private String nodeParentClass
      The option "-ns".
    • parentPointers

      private Boolean parentPointers
      The option "-pp".
    • specialTokens

      private Boolean specialTokens
      The option "-tk".
    • scheme

      private Boolean scheme
      The toolkit option "-scheme".
    • printer

      private Boolean printer
      The toolkit option "-printer".
  • Constructor Details

    • JTB

      JTB()
  • Method Details

    • setInputFile

      public void setInputFile(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(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 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(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 be null 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 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 neither outputDirectory nor nodeDirectory have been set.
    • setVisitorDirectory

      public void setVisitorDirectory(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 be null 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 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 neither outputDirectory nor visitorDirectory have been set.
    • setPackageName

      public void setPackageName(String value)
      Sets the option "-p". Will overwrite the options "-np" and "-vp" if specified.
      Parameters:
      value - The option value, may be null.
    • setNodePackageName

      public void setNodePackageName(String value)
      Sets the option "-np".
      Parameters:
      value - The option value, may be null.
    • getEffectiveNodePackageName

      private 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(String value)
      Sets the option "-vp".
      Parameters:
      value - The option value, may be null.
    • getEffectiveVisitorPackageName

      private 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(Boolean value)
      Sets the option "-e".
      Parameters:
      value - The option value, may be null.
    • setJavadocFriendlyComments

      public void setJavadocFriendlyComments(Boolean value)
      Sets the option "-jd".
      Parameters:
      value - The option value, may be null.
    • setDescriptiveFieldNames

      public void setDescriptiveFieldNames(Boolean value)
      Sets the option "-f".
      Parameters:
      value - The option value, may be null.
    • setNodeParentClass

      public void setNodeParentClass(String value)
      Sets the option "-ns".
      Parameters:
      value - The option value, may be null.
    • setParentPointers

      public void setParentPointers(Boolean value)
      Sets the option "-pp".
      Parameters:
      value - The option value, may be null.
    • setSpecialTokens

      public void setSpecialTokens(Boolean value)
      Sets the option "-tk".
      Parameters:
      value - The option value, may be null.
    • setScheme

      public void setScheme(Boolean value)
      Sets the toolkit option "-scheme".
      Parameters:
      value - The option value, may be null.
    • setPrinter

      public void setPrinter(Boolean value)
      Sets the toolkit option "-printer".
      Parameters:
      value - The option value, may be null.
    • execute

      protected int execute() throws Exception
      Runs the tool using the previously set parameters.
      Specified by:
      execute in class ToolFacade
      Returns:
      The exit code of the tool, non-zero means failure.
      Throws:
      Exception - If the tool could not be invoked.
    • generateArguments

      private 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 String getLastPackageName(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 be null.
      Returns:
      The name of the last sub package or null if the input was null
    • moveJavaFiles

      private void moveJavaFiles() throws 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:
      IOException - If the move failed.
    • moveDirectory

      private void moveDirectory(File sourceDir, File targetDir) throws 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 of File.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 be null.
      targetDir - The absolute path to the target directory, must not be null.
      Throws:
      IOException - If the move failed.
    • toString

      public String toString()
      Gets a string representation of the command line arguments.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the command line arguments.