Package jflex.maven.plugin.jflex
Class JFlexMojo
- java.lang.Object
-
- org.apache.maven.plugin.AbstractMojo
-
- jflex.maven.plugin.jflex.JFlexMojo
-
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
@Mojo(name="generate", defaultPhase=GENERATE_SOURCES, threadSafe=false) public class JFlexMojo extends org.apache.maven.plugin.AbstractMojo
Generates lexical scanners from one or more JFlex grammar files.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
JFlexMojo.ExtensionPredicate
-
Field Summary
Fields Modifier and Type Field Description private boolean
backup
A flag whether to enable the generation of a backup copy if the generated source file already exists.private boolean
dot
Whether to produce graphviz .dot files for the generated automata.private boolean
dump
Whether to dump full debug information.private java.lang.String
encodingName
The name of the character encoding for reading lexer specifications.private java.lang.String
generationMethod
The generation method to use for the scanner.private boolean
jlex
Strict JLex compatibility.private boolean
legacyDot
If true, the dot (.) metachar matches [^\n] instead of [^\n\r ].private java.io.File[]
lexDefinitions
List of grammar definitions to run the JFlex parser generator on.private boolean
minimize
A flag whether to perform the DFA minimization step during scanner generation.private java.io.File
outputDirectory
Name of the directory into which JFlex should generate the parser.private org.apache.maven.project.MavenProject
project
private java.io.File
skeleton
Use external skeleton file.private static java.lang.String
SRC_MAIN_JFLEX
Name of the directory where to look for jflex files by default.private int
staleMillis
The granularity in milliseconds of the last modification date for testing whether a source needs regeneration.private boolean
unusedWarning
Whether a warning will be logged when there are unused macros.private boolean
verbose
Whether source code generation should be verbose.
-
Constructor Summary
Constructors Constructor Description JFlexMojo()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
checkParameters(java.io.File lexFile)
Check parameter lexFile.void
execute()
Generate java parsers from lexer definition files.private SpecInfo
findSpecInfo(java.io.File lexFile)
private java.io.File
getAbsolutePath(java.io.File path)
Converts the specified path argument into an absolute path.private static long
latestModified(java.util.Set<java.io.File> includedFiles)
Determines the highestFile.lastModified()
value among the specifiedincludedFiles
, which are resolved relative to the specifiedparent
directory.private void
parseLexDefinition(java.io.File lexDefinition)
Generates java code of a parser from a lexer file.private void
parseLexFile(java.io.File lexFile)
-
-
-
Field Detail
-
SRC_MAIN_JFLEX
private static final java.lang.String SRC_MAIN_JFLEX
Name of the directory where to look for jflex files by default.- See Also:
- Constant Field Values
-
project
@Parameter(property="project", required=true, readonly=true) private org.apache.maven.project.MavenProject project
-
lexDefinitions
@Parameter private java.io.File[] lexDefinitions
List of grammar definitions to run the JFlex parser generator on. Each path may either specify a single grammar file or a directory. Directories will be recursively scanned for files with one of the following extensions: ".jflex", ".flex", ".jlex" or ".lex". By default, all files insrc/main/jflex
will be processed.- See Also:
SRC_MAIN_JFLEX
-
outputDirectory
@Parameter(defaultValue="${project.build.directory}/generated-sources/jflex") private java.io.File outputDirectory
Name of the directory into which JFlex should generate the parser.
-
staleMillis
@Parameter(property="lastModGranularityMs", defaultValue="0") private int staleMillis
The granularity in milliseconds of the last modification date for testing whether a source needs regeneration.
-
verbose
@Parameter(defaultValue="false") private boolean verbose
Whether source code generation should be verbose.
-
unusedWarning
@Parameter(defaultValue="true") private boolean unusedWarning
Whether a warning will be logged when there are unused macros.
-
dump
@Parameter(defaultValue="false") private boolean dump
Whether to dump full debug information.
-
dot
@Parameter(defaultValue="false") private boolean dot
Whether to produce graphviz .dot files for the generated automata. This feature is EXPERIMENTAL.
-
skeleton
@Parameter private java.io.File skeleton
Use external skeleton file.
-
jlex
@Parameter(defaultValue="false") private boolean jlex
Strict JLex compatibility.
-
generationMethod
@Parameter(defaultValue="pack") private java.lang.String generationMethod
The generation method to use for the scanner. The only valid value ispack
.
-
minimize
@Parameter(defaultValue="true") private boolean minimize
A flag whether to perform the DFA minimization step during scanner generation.
-
backup
@Parameter(defaultValue="true") private boolean backup
A flag whether to enable the generation of a backup copy if the generated source file already exists.
-
legacyDot
@Parameter(defaultValue="false") private boolean legacyDot
If true, the dot (.) metachar matches [^\n] instead of [^\n\r ].
-
encodingName
@Parameter(defaultValue="") private java.lang.String encodingName
The name of the character encoding for reading lexer specifications. Uses JVM default encoding if unset.
-
-
Method Detail
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
Generate java parsers from lexer definition files.This methods is checks parameters, sets options and calls JFlex.Main.generate()
- Throws:
org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoFailureException
-
parseLexDefinition
private void parseLexDefinition(java.io.File lexDefinition) throws org.apache.maven.plugin.MojoFailureException, org.apache.maven.plugin.MojoExecutionException
Generates java code of a parser from a lexer file.If the
lexDefinition
is a directory, process all lexer files contained within.- Parameters:
lexDefinition
- Lexer definiton file or directory to process.- Throws:
org.apache.maven.plugin.MojoFailureException
- if the file is not found.org.apache.maven.plugin.MojoExecutionException
- if file could not be parsed
-
parseLexFile
private void parseLexFile(java.io.File lexFile) throws org.apache.maven.plugin.MojoFailureException, org.apache.maven.plugin.MojoExecutionException
- Throws:
org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoExecutionException
-
findSpecInfo
private SpecInfo findSpecInfo(java.io.File lexFile) throws org.apache.maven.plugin.MojoFailureException
- Throws:
org.apache.maven.plugin.MojoFailureException
-
checkParameters
private void checkParameters(java.io.File lexFile) throws org.apache.maven.plugin.MojoExecutionException
Check parameter lexFile.Must not be
null
and file must exist.- Parameters:
lexFile
- input file to check.- Throws:
org.apache.maven.plugin.MojoExecutionException
- in case of error
-
getAbsolutePath
private java.io.File getAbsolutePath(java.io.File path)
Converts the specified path argument into an absolute path. If the path is relative like "src/main/jflex", it is resolved against the base directory of the project (in constrast, File.getAbsoluteFile() would resolve against the current directory which may be different, especially during a reactor build).- Parameters:
path
- The path argument to convert, may benull
.- Returns:
- The absolute path corresponding to the input argument.
-
latestModified
private static long latestModified(java.util.Set<java.io.File> includedFiles)
Determines the highestFile.lastModified()
value among the specifiedincludedFiles
, which are resolved relative to the specifiedparent
directory.- Returns:
- the latest value -- or 0 if the list is empty, if no files exist, or if I/O exceptions prevent getting any values
-
-