Package org.codehaus.mojo.javacc
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
FieldsModifier and TypeFieldDescriptionprivate 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 totrue
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 totrue
, every call to the token manager's methodgetNextToken()
(see the description of the Java Compiler Compiler API) will cause a call to a user-defined methodCommonTokenAction()
after the token has been scanned in by the token manager.private Boolean
This is a boolean option whose default value isfalse
.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 tofalse
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 totrue
causes the generated token manager to ignore case in the token specifications and the input files.private Boolean
Iftrue
, all methods and class variables are specified as static in the generated parser and token manager.private Boolean
When set totrue
, the generated parser uses an input stream object that processes Java Unicode escapes (\
u
xxxx) 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 Collection
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 generatedToken
class.private String
The name of a custom factory class used to createToken
objects.private Boolean
When set totrue
, the generated token manager will include a field calledparser
that references the instantiating parser instance.private Boolean
When set totrue
, 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 optionsjavaUnicodeEscape
andunicodeInput
or whether the token manager reads from a user-supplied implementation ofCharStream
.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 -
Method Summary
Modifier and TypeMethodDescriptionprivate 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()
Execute the tool.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.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
processGrammar
(GrammarInfo grammarInfo) 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
-
Field Details
-
project
@Parameter(defaultValue="${project}", readonly=true, required=true) private org.apache.maven.project.MavenProject projectThe current Maven project. -
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
The Java version for which to generate source code. Default value is1.5
for plugin version 2.6+ and1.4
in older versions.- Since:
- 2.4
-
lookAhead
The number of tokens to look ahead before making a decision at a choice point during parsing. The default value is1
. -
choiceAmbiguityCheck
This is the number of tokens considered in checking choices of the form "A | B | ..." for ambiguity. Default value is2
. -
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 is1
. -
isStatic
Iftrue
, 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 istrue
. -
debugParser
This option is used to obtain debugging information from the generated parser. Setting this option totrue
causes the parser to generate a trace of its actions. Default value isfalse
. -
debugLookAhead
This is a boolean option whose default value isfalse
. Setting this option totrue
causes the parser to generate all the tracing information it does when the optiondebugParser
istrue
, and in addition, also causes it to generated a trace of actions performed during lookahead operation. -
debugTokenManager
This option is used to obtain debugging information from the generated token manager. Default value isfalse
. -
errorReporting
Setting it tofalse
causes errors due to parse errors to be reported in somewhat less detail. Default value istrue
. -
javaUnicodeEscape
When set totrue
, the generated parser uses an input stream object that processes Java Unicode escapes (\
u
xxxx) before sending characters to the token manager. Default value isfalse
. -
unicodeInput
When set totrue
, the generated parser uses uses an input stream object that reads Unicode files. By default, ASCII files are assumed. Default value isfalse
. -
ignoreCase
Setting this option totrue
causes the generated token manager to ignore case in the token specifications and the input files. Default value isfalse
. -
commonTokenAction
When set totrue
, every call to the token manager's methodgetNextToken()
(see the description of the Java Compiler Compiler API) will cause a call to a user-defined methodCommonTokenAction()
after the token has been scanned in by the token manager. Default value isfalse
. -
userTokenManager
The default action is to generate a token manager that works on the specified grammar tokens. If this option is set totrue
, then the parser is generated to accept tokens from any token manager of typeTokenManager
- this interface is generated into the generated parser directory. Default value isfalse
. -
userCharStream
This flag controls whether the token manager will read characters from a character stream reader as defined by the optionsjavaUnicodeEscape
andunicodeInput
or whether the token manager reads from a user-supplied implementation ofCharStream
. Default value isfalse
. -
buildParser
A flag that controls whether the parser file (*Parser.java
) should be generated or not. If set tofalse
, only the token manager is generated. Default value istrue
. -
buildTokenManager
A flag that controls whether the token manager file (*TokenManager.java
) should be generated or not. Setting this tofalse
can speed up the generation process if only the parser part of the grammar changed. Default value istrue
. -
tokenManagerUsesParser
When set totrue
, the generated token manager will include a field calledparser
that references the instantiating parser instance. Default value isfalse
. -
tokenExtends
The name of the base class for the generatedToken
class. Default value isjava.lang.Object
.- Since:
- 2.5
-
tokenFactory
The name of a custom factory class used to createToken
objects. This class must have a method with the signaturepublic static Token newToken(int ofKind, String image)
. By default, tokens are created by callingToken.newToken()
.- Since:
- 2.5
-
sanityCheck
Enables/disables many syntactic and semantic checks on the grammar file during parser generation. Default value istrue
. -
forceLaCheck
This option setting controls lookahead ambiguity checking performed by JavaCC. Default value isfalse
. -
cacheTokens
Setting this option totrue
causes the generated parser to lookahead for extra tokens ahead of time. Default value isfalse
. -
keepLineColumn
A flag whether to keep line and column information along with a token. Default value istrue
. -
supportClassVisibilityPublic
@Parameter(property="javacc.supportClassVisibilityPublic") private Boolean supportClassVisibilityPublicA flag whether the generated support classes of the parser should have public or package-private visibility. Default value istrue
.- Since:
- 2.6
-
grammarEncoding
@Parameter(property="javacc.grammarEncoding", defaultValue="${project.build.sourceEncoding}") private String grammarEncodingThe file encoding to use for reading the grammar files.- Since:
- 2.6
-
-
Constructor Details
-
AbstractJavaCCMojo
public AbstractJavaCCMojo()
-
-
Method Details
-
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
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
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
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
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
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
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
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
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.MojoFailureExceptionExecute 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 benull
.- 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
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
Gets a temporary directory within the project's build directory.- Returns:
- The path to the temporary directory, never
null
.
-
deleteTempDirectory
Deletes the specified temporary directory.- Parameters:
tempDirectory
- The directory to delete, must not benull
.
-
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 insrc/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 benull
.packageName
- The name of the destination package for the output files, must not benull
.tempDirectory
- The (absolute) path to the directory to scan for generated output files, must not benull
.updatePattern
- A glob pattern that matches the (simple) names of those files which should always be updated in case we are outputting directly intosrc/main/java
, may benull
. 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.MojoExecutionExceptionDetermines 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
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 benull
.- Returns:
- The (absolute) path to the existing source file if any,
null
otherwise.
-
isSourceRoot
Determines whether the specified directory denotes a compile source root of the current project.- Parameters:
directory
- The directory to check, must not benull
.- Returns:
true
if the specified directory is a compile source root of the project,false
otherwise.
-
addSourceRoot
Registers the specified directory as a compile source root for the current project.- Parameters:
directory
- The absolute path to the source root, must not benull
.
-
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
.
-