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.- Version:
- $Id: AbstractJavaCCMojo.java 10774 2009-09-26 11:40:48Z bentmann $
- Author:
- jruiz@exist.com, jesse
-
-
Constructor Summary
Constructors Constructor Description AbstractJavaCCMojo()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description 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.void
execute()
Execute the tool.protected abstract File[]
getCompileSourceRoots()
Gets all the output directories to register with the project for compilation.protected abstract String[]
getExcludes()
Gets a set of Ant-like exclusion patterns used to unselect files from the source directory for processing.protected String
getGrammarEncoding()
Gets the file encoding of the grammar files.protected abstract String[]
getIncludes()
Gets a set of Ant-like inclusion patterns used to select files from the source directory for processing.protected Boolean
getIsStatic()
Gets the flag whether to generate static parser.protected String
getJdkVersion()
Gets the Java version for which to generate source code.protected abstract File
getOutputDirectory()
Gets the absolute path to the directory where the generated Java files for the parser will be stored.protected String
getParserPackage()
Gets the package into which the generated parser files should be stored.protected abstract 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 File
getTempDirectory()
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 org.codehaus.mojo.javacc.JavaCC
newJavaCC()
Creates a new facade to invoke JavaCC.protected abstract void
processGrammar(org.codehaus.mojo.javacc.GrammarInfo grammarInfo)
Passes the specified grammar file through the tool.
-
-
-
Method Detail
-
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 testing 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(org.codehaus.mojo.javacc.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.
-
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 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:
packageName
- The name of the destination package for the output files, must not benull
.sourceRoot
- The (absolute) path to the compile source root into which the output files should eventually be copied, 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.
-
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 benull
.- Returns:
true
if the specified directory is a compile source root of the project,false
otherwise.
-
newJavaCC
protected org.codehaus.mojo.javacc.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
.
-
-