Class 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 java.lang.Boolean buildParser
      A flag that controls whether the parser file (*Parser.java) should be generated or not.
      private java.lang.Boolean buildTokenManager
      A flag that controls whether the token manager file (*TokenManager.java) should be generated or not.
      private java.lang.Boolean cacheTokens
      Setting this option to true causes the generated parser to lookahead for extra tokens ahead of time.
      private java.lang.Integer choiceAmbiguityCheck
      This is the number of tokens considered in checking choices of the form "A | B | ..." for ambiguity.
      private java.lang.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.
      private java.lang.Boolean debugLookAhead
      This is a boolean option whose default value is false.
      private java.lang.Boolean debugParser
      This option is used to obtain debugging information from the generated parser.
      private java.lang.Boolean debugTokenManager
      This option is used to obtain debugging information from the generated token manager.
      private java.lang.Boolean errorReporting
      Setting it to false causes errors due to parse errors to be reported in somewhat less detail.
      private java.lang.Boolean forceLaCheck
      This option setting controls lookahead ambiguity checking performed by JavaCC.
      private java.lang.String grammarEncoding
      The file encoding to use for reading the grammar files.
      private java.lang.Boolean ignoreCase
      Setting this option to true causes the generated token manager to ignore case in the token specifications and the input files.
      private java.lang.Boolean isStatic
      If true, all methods and class variables are specified as static in the generated parser and token manager.
      private java.lang.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.
      private java.lang.String jdkVersion
      The Java version for which to generate source code.
      private java.lang.Boolean keepLineColumn
      A flag whether to keep line and column information along with a token.
      private java.lang.Integer lookAhead
      The number of tokens to look ahead before making a decision at a choice point during parsing.
      private java.util.Set<java.io.File> nonGeneratedSourceRoots
      The set of compile source roots whose contents are not generated as part of the build, i.e.
      private java.lang.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.
      private org.apache.maven.project.MavenProject project
      The current Maven project.
      private java.lang.Boolean sanityCheck
      Enables/disables many syntactic and semantic checks on the grammar file during parser generation.
      private java.lang.Boolean supportClassVisibilityPublic
      A flag whether the generated support classes of the parser should have public or package-private visibility.
      private java.lang.String tokenExtends
      The name of the base class for the generated Token class.
      private java.lang.String tokenFactory
      The name of a custom factory class used to create Token objects.
      private java.lang.Boolean tokenManagerUsesParser
      When set to true, the generated token manager will include a field called parser that references the instantiating parser instance.
      private java.lang.Boolean unicodeInput
      When set to true, the generated parser uses uses an input stream object that reads Unicode files.
      private java.lang.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.
      private java.lang.Boolean userTokenManager
      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
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      private void addSourceRoot​(java.io.File directory)
      Registers the specified directory as a compile source root for the current project.
      protected void copyGrammarOutput​(java.io.File sourceRoot, java.lang.String packageName, java.io.File tempDirectory, java.lang.String updatePattern)
      Scans the filesystem for output files and copies them to the specified compile source root.
      protected void deleteTempDirectory​(java.io.File tempDirectory)
      Deletes the specified temporary directory.
      private void determineNonGeneratedSourceRoots()
      Determines those compile source roots of the project that do not reside below the project's build directories.
      void execute()
      Execute the tool.
      private java.io.File findSourceFile​(java.lang.String filename)
      Determines whether the specified source file is already present in any of the compile source roots registered with the current Maven project.
      protected abstract java.io.File[] getCompileSourceRoots()
      Gets all the output directories to register with the project for compilation.
      protected abstract java.lang.String[] getExcludes()
      Gets a set of Ant-like exclusion patterns used to unselect files from the source directory for processing.
      protected java.lang.String getGrammarEncoding()
      Gets the file encoding of the grammar files.
      protected abstract java.lang.String[] getIncludes()
      Gets a set of Ant-like inclusion patterns used to select files from the source directory for processing.
      protected java.lang.Boolean getIsStatic()
      Gets the flag whether to generate static parser.
      protected java.lang.String getJdkVersion()
      Gets the Java version for which to generate source code.
      protected abstract java.io.File getOutputDirectory()
      Gets the absolute path to the directory where the generated Java files for the parser will be stored.
      protected java.lang.String getParserPackage()
      Gets the package into which the generated parser files should be stored.
      protected abstract java.io.File getSourceDirectory()
      Gets the absolute path to the directory where the grammar files are located.
      protected abstract int getStaleMillis()
      Gets the granularity in milliseconds of the last modification date for testing whether a source needs recompilation.
      protected java.io.File getTempDirectory()
      Gets a temporary directory within the project's build directory.
      protected boolean isSourceRoot​(java.io.File directory)
      Determines whether the specified directory denotes a compile source root of the current project.
      protected JavaCC newJavaCC()
      Creates a new facade to invoke JavaCC.
      protected abstract void processGrammar​(GrammarInfo grammarInfo)
      Passes the specified grammar file through the tool.
      private GrammarInfo[] scanForGrammars()
      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 java.lang.Object

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

      • project

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

        private java.util.Set<java.io.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.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 java.lang.Boolean forceLaCheck
        This option setting controls lookahead ambiguity checking performed by JavaCC. Default value is false.
      • cacheTokens

        @Parameter(property="javacc.cacheTokens")
        private java.lang.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 java.lang.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 java.lang.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 java.lang.String grammarEncoding
        The file encoding to use for reading the grammar files.
        Since:
        2.6
    • Constructor Detail

      • AbstractJavaCCMojo

        public AbstractJavaCCMojo()
    • Method Detail

      • getGrammarEncoding

        protected java.lang.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 java.lang.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 java.lang.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 java.io.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 java.lang.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 java.lang.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 java.io.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 java.io.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 java.lang.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 java.io.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​(java.io.File tempDirectory)
        Deletes the specified temporary directory.
        Parameters:
        tempDirectory - The directory to delete, must not be null.
      • copyGrammarOutput

        protected void copyGrammarOutput​(java.io.File sourceRoot,
                                         java.lang.String packageName,
                                         java.io.File tempDirectory,
                                         java.lang.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:
        packageName - The name of the destination package for the output files, must not be null.
        sourceRoot - The (absolute) path to the compile source root into which the output files should eventually be copied, 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 java.io.File findSourceFile​(java.lang.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​(java.io.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​(java.io.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.