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 -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
A flag whether to enable the generation of a backup copy if the generated source file already exists.private boolean
Whether to produce graphviz .dot files for the generated automata.private boolean
Whether to dump full debug information.private String
The name of the character encoding for reading lexer specifications.private String
The generation method to use for the scanner.private boolean
Strict JLex compatibility.private boolean
If true, the dot (.) metachar matches [^\n] instead of [^\n\r ].private File[]
List of grammar definitions to run the JFlex parser generator on.private boolean
A flag whether to perform the DFA minimization step during scanner generation.private File
Name of the directory into which JFlex should generate the parser.private org.apache.maven.project.MavenProject
private File
Use external skeleton file.private static final String
Name of the directory where to look for jflex files by default.private int
The granularity in milliseconds of the last modification date for testing whether a source needs regeneration.private boolean
Whether a warning will be logged when there are unused macros.private boolean
Whether source code generation should be verbose.Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
checkParameters
(File lexFile) Check parameter lexFile.void
execute()
Generate java parsers from lexer definition files.private SpecInfo
findSpecInfo
(File lexFile) private File
getAbsolutePath
(File path) Converts the specified path argument into an absolute path.private static long
latestModified
(Set<File> includedFiles) Determines the highestFile.lastModified()
value among the specifiedincludedFiles
, which are resolved relative to the specifiedparent
directory.private void
parseLexDefinition
(File lexDefinition) Generates java code of a parser from a lexer file.private void
parseLexFile
(File lexFile) Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
SRC_MAIN_JFLEX
Name of the directory where to look for jflex files by default.- See Also:
-
project
@Parameter(property="project", required=true, readonly=true) private org.apache.maven.project.MavenProject project -
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:
-
outputDirectory
@Parameter(defaultValue="${project.build.directory}/generated-sources/jflex") private File outputDirectoryName of the directory into which JFlex should generate the parser. -
staleMillis
@Parameter(property="lastModGranularityMs", defaultValue="0") private int staleMillisThe granularity in milliseconds of the last modification date for testing whether a source needs regeneration. -
verbose
@Parameter(defaultValue="false") private boolean verboseWhether source code generation should be verbose. -
unusedWarning
@Parameter(defaultValue="true") private boolean unusedWarningWhether a warning will be logged when there are unused macros. -
dump
@Parameter(defaultValue="false") private boolean dumpWhether to dump full debug information. -
dot
@Parameter(defaultValue="false") private boolean dotWhether to produce graphviz .dot files for the generated automata. This feature is EXPERIMENTAL. -
skeleton
Use external skeleton file. -
jlex
@Parameter(defaultValue="false") private boolean jlexStrict JLex compatibility. -
generationMethod
The generation method to use for the scanner. The only valid value ispack
. -
minimize
@Parameter(defaultValue="true") private boolean minimizeA flag whether to perform the DFA minimization step during scanner generation. -
backup
@Parameter(defaultValue="true") private boolean backupA flag whether to enable the generation of a backup copy if the generated source file already exists. -
legacyDot
@Parameter(defaultValue="false") private boolean legacyDotIf true, the dot (.) metachar matches [^\n] instead of [^\n\r ]. -
encodingName
The name of the character encoding for reading lexer specifications. Uses JVM default encoding if unset.
-
-
Constructor Details
-
JFlexMojo
public JFlexMojo()
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionGenerate 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(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(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
- Throws:
org.apache.maven.plugin.MojoFailureException
-
checkParameters
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
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
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
-