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 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    Check parameter lexFile.
    void
    Generate java parsers from lexer definition files.
    private SpecInfo
    findSpecInfo(File lexFile)
     
    private File
    Converts the specified path argument into an absolute path.
    private static long
    latestModified(Set<File> includedFiles)
    Determines the highest File.lastModified() value among the specified includedFiles, which are resolved relative to the specified parent 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

    Methods inherited from class java.lang.Object

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

    • SRC_MAIN_JFLEX

      private static final String 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

      @Parameter private 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 in src/main/jflex will be processed.
      See Also:
    • outputDirectory

      @Parameter(defaultValue="${project.build.directory}/generated-sources/jflex") private 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 File skeleton
      Use external skeleton file.
    • jlex

      @Parameter(defaultValue="false") private boolean jlex
      Strict JLex compatibility.
    • generationMethod

      @Parameter(defaultValue="pack") private String generationMethod
      The generation method to use for the scanner. The only valid value is pack.
    • 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 String 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.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(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

      private SpecInfo findSpecInfo(File lexFile) throws org.apache.maven.plugin.MojoFailureException
      Throws:
      org.apache.maven.plugin.MojoFailureException
    • checkParameters

      private void checkParameters(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 File getAbsolutePath(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 be null.
      Returns:
      The absolute path corresponding to the input argument.
    • latestModified

      private static long latestModified(Set<File> includedFiles)
      Determines the highest File.lastModified() value among the specified includedFiles, which are resolved relative to the specified parent 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