Class AbstractJavaCCMojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.codehaus.mojo.javacc.AbstractJavaCCMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
JavaCCMojo, JJTreeJavaCCMojo, JTBJavaCCMojo

public abstract class AbstractJavaCCMojo extends org.apache.maven.plugin.AbstractMojo
Provides common services for all mojos that compile JavaCC grammar files.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Boolean
    A flag that controls whether the parser file (*Parser.java) should be generated or not.
    private Boolean
    A flag that controls whether the token manager file (*TokenManager.java) should be generated or not.
    private Boolean
    Setting this option to true causes the generated parser to lookahead for extra tokens ahead of time.
    private Integer
    This is the number of tokens considered in checking choices of the form "A | B | ..." for ambiguity.
    private Boolean
    When set to true, every call to the token manager's method getNextToken() (see the description of the Java Compiler Compiler API) will cause a call to a user-defined method CommonTokenAction() after the token has been scanned in by the token manager.
    private Boolean
    This is a boolean option whose default value is false.
    private Boolean
    This option is used to obtain debugging information from the generated parser.
    private Boolean
    This option is used to obtain debugging information from the generated token manager.
    private Boolean
    Setting it to false causes errors due to parse errors to be reported in somewhat less detail.
    private Boolean
    This option setting controls lookahead ambiguity checking performed by JavaCC.
    private String
    The file encoding to use for reading the grammar files.
    private Boolean
    Setting this option to true causes the generated token manager to ignore case in the token specifications and the input files.
    private Boolean
    If true, all methods and class variables are specified as static in the generated parser and token manager.
    private Boolean
    When set to true, the generated parser uses an input stream object that processes Java Unicode escapes (\uxxxx) before sending characters to the token manager.
    private String
    The Java version for which to generate source code.
    private Boolean
    A flag whether to keep line and column information along with a token.
    private Integer
    The number of tokens to look ahead before making a decision at a choice point during parsing.
    private Set<File>
    The set of compile source roots whose contents are not generated as part of the build, i.e.
    private Integer
    This is the number of tokens considered in checking all other kinds of choices (i.e., of the forms "(A)*", "(A)+", and "(A)?") for ambiguity.
    private org.apache.maven.project.MavenProject
    The current Maven project.
    private Boolean
    Enables/disables many syntactic and semantic checks on the grammar file during parser generation.
    private Boolean
    A flag whether the generated support classes of the parser should have public or package-private visibility.
    private String
    The name of the base class for the generated Token class.
    private String
    The name of a custom factory class used to create Token objects.
    private Boolean
    When set to true, the generated token manager will include a field called parser that references the instantiating parser instance.
    private Boolean
    When set to true, the generated parser uses uses an input stream object that reads Unicode files.
    private Boolean
    This flag controls whether the token manager will read characters from a character stream reader as defined by the options javaUnicodeEscape and unicodeInput or whether the token manager reads from a user-supplied implementation of CharStream.
    private Boolean
    The default action is to generate a token manager that works on the specified grammar tokens.

    Fields inherited from interface org.apache.maven.plugin.Mojo

    ROLE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    addSourceRoot(File directory)
    Registers the specified directory as a compile source root for the current project.
    protected void
    copyGrammarOutput(File sourceRoot, String packageName, File tempDirectory, String updatePattern)
    Scans the filesystem for output files and copies them to the specified compile source root.
    protected void
    deleteTempDirectory(File tempDirectory)
    Deletes the specified temporary directory.
    private void
    Determines those compile source roots of the project that do not reside below the project's build directories.
    void
    Execute the tool.
    private File
    Determines whether the specified source file is already present in any of the compile source roots registered with the current Maven project.
    protected abstract File[]
    Gets all the output directories to register with the project for compilation.
    protected abstract String[]
    Gets a set of Ant-like exclusion patterns used to unselect files from the source directory for processing.
    protected String
    Gets the file encoding of the grammar files.
    protected abstract String[]
    Gets a set of Ant-like inclusion patterns used to select files from the source directory for processing.
    protected Boolean
    Gets the flag whether to generate static parser.
    protected String
    Gets the Java version for which to generate source code.
    protected abstract File
    Gets the absolute path to the directory where the generated Java files for the parser will be stored.
    protected String
    Gets the package into which the generated parser files should be stored.
    protected abstract File
    Gets the absolute path to the directory where the grammar files are located.
    protected abstract int
    Gets the granularity in milliseconds of the last modification date for testing whether a source needs recompilation.
    protected File
    Gets a temporary directory within the project's build directory.
    protected boolean
    isSourceRoot(File directory)
    Determines whether the specified directory denotes a compile source root of the current project.
    protected JavaCC
    Creates a new facade to invoke JavaCC.
    protected abstract void
    Passes the specified grammar file through the tool.
    private GrammarInfo[]
    Scans the configured source directory for grammar files which need processing.

    Methods inherited from class org.apache.maven.plugin.AbstractMojo

    getLog, getPluginContext, setLog, setPluginContext

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • project

      @Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject project
      The current Maven project.
    • nonGeneratedSourceRoots

      private Set<File> nonGeneratedSourceRoots
      The set of compile source roots whose contents are not generated as part of the build, i.e. those that usually reside somewhere below "${basedir}/src" in the project structure. Files in these source roots are owned by the user and must not be overwritten with generated files.
    • jdkVersion

      @Parameter(property="javacc.jdkVersion") private String jdkVersion
      The Java version for which to generate source code. Default value is 1.5 for plugin version 2.6+ and 1.4 in older versions.
      Since:
      2.4
    • lookAhead

      @Parameter(property="javacc.lookAhead") private Integer lookAhead
      The number of tokens to look ahead before making a decision at a choice point during parsing. The default value is 1.
    • choiceAmbiguityCheck

      @Parameter(property="javacc.choiceAmbiguityCheck") private Integer choiceAmbiguityCheck
      This is the number of tokens considered in checking choices of the form "A | B | ..." for ambiguity. Default value is 2.
    • otherAmbiguityCheck

      @Parameter(property="javacc.otherAmbiguityCheck") private Integer otherAmbiguityCheck
      This is the number of tokens considered in checking all other kinds of choices (i.e., of the forms "(A)*", "(A)+", and "(A)?") for ambiguity. Default value is 1.
    • isStatic

      @Parameter(property="javacc.isStatic") private Boolean isStatic
      If true, all methods and class variables are specified as static in the generated parser and token manager. This allows only one parser object to be present, but it improves the performance of the parser. Default value is true.
    • debugParser

      @Parameter(property="javacc.debugParser") private Boolean debugParser
      This option is used to obtain debugging information from the generated parser. Setting this option to true causes the parser to generate a trace of its actions. Default value is false.
    • debugLookAhead

      @Parameter(property="javacc.debugLookAhead") private Boolean debugLookAhead
      This is a boolean option whose default value is false. Setting this option to true causes the parser to generate all the tracing information it does when the option debugParser is true, and in addition, also causes it to generated a trace of actions performed during lookahead operation.
    • debugTokenManager

      @Parameter(property="javacc.debugTokenManager") private Boolean debugTokenManager
      This option is used to obtain debugging information from the generated token manager. Default value is false.
    • errorReporting

      @Parameter(property="javacc.errorReporting") private Boolean errorReporting
      Setting it to false causes errors due to parse errors to be reported in somewhat less detail. Default value is true.
    • javaUnicodeEscape

      @Parameter(property="javacc.javaUnicodeEscape") private Boolean javaUnicodeEscape
      When set to true, the generated parser uses an input stream object that processes Java Unicode escapes (\uxxxx) before sending characters to the token manager. Default value is false.
    • unicodeInput

      @Parameter(property="javacc.unicodeInput") private Boolean unicodeInput
      When set to true, the generated parser uses uses an input stream object that reads Unicode files. By default, ASCII files are assumed. Default value is false.
    • ignoreCase

      @Parameter(property="javacc.ignoreCase") private Boolean ignoreCase
      Setting this option to true causes the generated token manager to ignore case in the token specifications and the input files. Default value is false.
    • commonTokenAction

      @Parameter(property="javacc.commonTokenAction") private Boolean commonTokenAction
      When set to true, every call to the token manager's method getNextToken() (see the description of the Java Compiler Compiler API) will cause a call to a user-defined method CommonTokenAction() after the token has been scanned in by the token manager. Default value is false.
    • userTokenManager

      @Parameter(property="javacc.userTokenManager") private Boolean userTokenManager
      The default action is to generate a token manager that works on the specified grammar tokens. If this option is set to true, then the parser is generated to accept tokens from any token manager of type TokenManager - this interface is generated into the generated parser directory. Default value is false.
    • userCharStream

      @Parameter(property="javacc.userCharStream") private Boolean userCharStream
      This flag controls whether the token manager will read characters from a character stream reader as defined by the options javaUnicodeEscape and unicodeInput or whether the token manager reads from a user-supplied implementation of CharStream. Default value is false.
    • buildParser

      @Parameter(property="javacc.buildParser") private Boolean buildParser
      A flag that controls whether the parser file (*Parser.java) should be generated or not. If set to false, only the token manager is generated. Default value is true.
    • buildTokenManager

      @Parameter(property="javacc.buildTokenManager") private Boolean buildTokenManager
      A flag that controls whether the token manager file (*TokenManager.java) should be generated or not. Setting this to false can speed up the generation process if only the parser part of the grammar changed. Default value is true.
    • tokenManagerUsesParser

      @Parameter(property="javacc.tokenManagerUsesParser") private Boolean tokenManagerUsesParser
      When set to true, the generated token manager will include a field called parser that references the instantiating parser instance. Default value is false.
    • tokenExtends

      @Parameter(property="javacc.tokenExtends") private String tokenExtends
      The name of the base class for the generated Token class. Default value is java.lang.Object.
      Since:
      2.5
    • tokenFactory

      @Parameter(property="javacc.tokenFactory") private String tokenFactory
      The name of a custom factory class used to create Token objects. This class must have a method with the signature public static Token newToken(int ofKind, String image). By default, tokens are created by calling Token.newToken().
      Since:
      2.5
    • sanityCheck

      @Parameter(property="javacc.sanityCheck") private Boolean sanityCheck
      Enables/disables many syntactic and semantic checks on the grammar file during parser generation. Default value is true.
    • forceLaCheck

      @Parameter(property="javacc.forceLaCheck") private Boolean forceLaCheck
      This option setting controls lookahead ambiguity checking performed by JavaCC. Default value is false.
    • cacheTokens

      @Parameter(property="javacc.cacheTokens") private Boolean cacheTokens
      Setting this option to true causes the generated parser to lookahead for extra tokens ahead of time. Default value is false.
    • keepLineColumn

      @Parameter(property="javacc.keepLineColumn") private Boolean keepLineColumn
      A flag whether to keep line and column information along with a token. Default value is true.
    • supportClassVisibilityPublic

      @Parameter(property="javacc.supportClassVisibilityPublic") private Boolean supportClassVisibilityPublic
      A flag whether the generated support classes of the parser should have public or package-private visibility. Default value is true.
      Since:
      2.6
    • grammarEncoding

      @Parameter(property="javacc.grammarEncoding", defaultValue="${project.build.sourceEncoding}") private String grammarEncoding
      The file encoding to use for reading the grammar files.
      Since:
      2.6
  • Constructor Details

    • AbstractJavaCCMojo

      public AbstractJavaCCMojo()
  • Method Details

    • getGrammarEncoding

      protected String getGrammarEncoding()
      Gets the file encoding of the grammar files.
      Returns:
      The file encoding of the grammar files or null if the user did not specify this mojo parameter.
    • getJdkVersion

      protected String getJdkVersion()
      Gets the Java version for which to generate source code.
      Returns:
      The Java version for which to generate source code, will be null if the user did not specify this mojo parameter.
    • getIsStatic

      protected Boolean getIsStatic()
      Gets the flag whether to generate static parser.
      Returns:
      The flag whether to generate static parser, will be null if the user did not specify this mojo parameter.
    • getSourceDirectory

      protected abstract File getSourceDirectory()
      Gets the absolute path to the directory where the grammar files are located.
      Returns:
      The absolute path to the directory where the grammar files are located, never null.
    • getIncludes

      protected abstract String[] getIncludes()
      Gets a set of Ant-like inclusion patterns used to select files from the source directory for processing.
      Returns:
      A set of Ant-like inclusion patterns used to select files from the source directory for processing, can be null if all files should be included.
    • getExcludes

      protected abstract String[] getExcludes()
      Gets a set of Ant-like exclusion patterns used to unselect files from the source directory for processing.
      Returns:
      A set of Ant-like inclusion patterns used to unselect files from the source directory for processing, can be null if no files should be excluded.
    • getOutputDirectory

      protected abstract File getOutputDirectory()
      Gets the absolute path to the directory where the generated Java files for the parser will be stored.
      Returns:
      The absolute path to the directory where the generated Java files for the parser will be stored, never null.
    • getStaleMillis

      protected abstract int getStaleMillis()
      Gets the granularity in milliseconds of the last modification date for testing whether a source needs recompilation.
      Returns:
      The granularity in milliseconds of the last modification date for testiintng whether a source needs recompilation.
    • getCompileSourceRoots

      protected abstract File[] getCompileSourceRoots()
      Gets all the output directories to register with the project for compilation.
      Returns:
      The compile source roots to register with the project, never null.
    • getParserPackage

      protected String getParserPackage()
      Gets the package into which the generated parser files should be stored.
      Returns:
      The package into which the generated parser files should be stored, can be null to use the package declaration from the grammar file.
    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      Execute the tool.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - If the invocation of the tool failed.
      org.apache.maven.plugin.MojoFailureException - If the tool reported a non-zero exit code.
    • processGrammar

      protected abstract void processGrammar(GrammarInfo grammarInfo) throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      Passes the specified grammar file through the tool.
      Parameters:
      grammarInfo - The grammar info describing the grammar file to process, must not be null.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - If the invocation of the tool failed.
      org.apache.maven.plugin.MojoFailureException - If the tool reported a non-zero exit code.
    • scanForGrammars

      private GrammarInfo[] scanForGrammars() throws org.apache.maven.plugin.MojoExecutionException
      Scans the configured source directory for grammar files which need processing.
      Returns:
      An array of grammar infos describing the found grammar files or null if the source directory does not exist.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - If the source directory could not be scanned.
    • getTempDirectory

      protected File getTempDirectory()
      Gets a temporary directory within the project's build directory.
      Returns:
      The path to the temporary directory, never null.
    • deleteTempDirectory

      protected void deleteTempDirectory(File tempDirectory)
      Deletes the specified temporary directory.
      Parameters:
      tempDirectory - The directory to delete, must not be null.
    • copyGrammarOutput

      protected void copyGrammarOutput(File sourceRoot, String packageName, File tempDirectory, String updatePattern) throws org.apache.maven.plugin.MojoExecutionException
      Scans the filesystem for output files and copies them to the specified compile source root. An output file is only copied to the compile source root if it doesn't already exist in another compile source root. This prevents duplicate class errors during compilation in case the user provided customized files in src/main/java or similar.
      Parameters:
      sourceRoot - The (absolute) path to the compile source root into which the output files should eventually be copied, must not be null.
      packageName - The name of the destination package for the output files, must not be null.
      tempDirectory - The (absolute) path to the directory to scan for generated output files, must not be null.
      updatePattern - A glob pattern that matches the (simple) names of those files which should always be updated in case we are outputting directly into src/main/java, may be null. A leading "!" may be used to negate the pattern.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - If the output files could not be copied.
    • determineNonGeneratedSourceRoots

      private void determineNonGeneratedSourceRoots() throws org.apache.maven.plugin.MojoExecutionException
      Determines those compile source roots of the project that do not reside below the project's build directories. These compile source roots are assumed to contain hand-crafted sources that must not be overwritten with generated files. In most cases, this is simply "${project.build.sourceDirectory}".
      Throws:
      org.apache.maven.plugin.MojoExecutionException - If the compile source rotos could not be determined.
    • findSourceFile

      private File findSourceFile(String filename)
      Determines whether the specified source file is already present in any of the compile source roots registered with the current Maven project.
      Parameters:
      filename - The source filename to check, relative to a source root, must not be null.
      Returns:
      The (absolute) path to the existing source file if any, null otherwise.
    • isSourceRoot

      protected boolean isSourceRoot(File directory)
      Determines whether the specified directory denotes a compile source root of the current project.
      Parameters:
      directory - The directory to check, must not be null.
      Returns:
      true if the specified directory is a compile source root of the project, false otherwise.
    • addSourceRoot

      private void addSourceRoot(File directory)
      Registers the specified directory as a compile source root for the current project.
      Parameters:
      directory - The absolute path to the source root, must not be null.
    • newJavaCC

      protected JavaCC newJavaCC()
      Creates a new facade to invoke JavaCC. Most options for the invocation are derived from the current values of the corresponding mojo parameters. The caller is responsible to set the input file and output directory on the returned facade.
      Returns:
      The facade for the tool invocation, never null.