Class Antlr4Mojo

java.lang.Object
org.apache.maven.plugin.AbstractMojo
org.antlr.mojo.antlr4.Antlr4Mojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo

@Mojo(name="antlr4", defaultPhase=GENERATE_SOURCES, requiresDependencyResolution=COMPILE, requiresProject=true, threadSafe=true) public class Antlr4Mojo extends org.apache.maven.plugin.AbstractMojo
Parses ANTLR 4 grammar files *.g4 and transforms them into Java source files.
  • Field Details

    • atn

      @Parameter(property="antlr4.atn", defaultValue="false") protected boolean atn
      If set to true then the ANTLR tool will generate a description of the ATN for each rule in Dot format.
    • inputEncoding

      @Parameter(property="project.build.sourceEncoding") protected String inputEncoding
      specify grammar file encoding; e.g., euc-jp
    • outputEncoding

      @Parameter(property="project.build.sourceEncoding") protected String outputEncoding
      specify output file encoding; defaults to source encoding
    • listener

      @Parameter(property="antlr4.listener", defaultValue="true") protected boolean listener
      Generate parse tree listener interface and base class.
    • visitor

      @Parameter(property="antlr4.visitor", defaultValue="false") protected boolean visitor
      Generate parse tree visitor interface and base class.
    • treatWarningsAsErrors

      @Parameter(property="antlr4.treatWarningsAsErrors", defaultValue="false") protected boolean treatWarningsAsErrors
      Treat warnings as errors.
    • forceATN

      @Parameter(property="antlr4.forceATN", defaultValue="false") protected boolean forceATN
      Use the ATN simulator for all predictions.
    • options

      @Parameter protected Map<String,String> options
      A list of grammar options to explicitly specify to the tool. These options are passed to the tool using the -D<option>=<value> syntax.
    • arguments

      @Parameter protected List<String> arguments
      A list of additional command line arguments to pass to the ANTLR tool.
    • includes

      @Parameter protected Set<String> includes
      Provides an explicit list of all the grammars that should be included in the generate phase of the plugin. Note that the plugin is smart enough to realize that imported grammars should be included but not acted upon directly by the ANTLR Tool.

      A set of Ant-like inclusion patterns used to select files from the source directory for processing. By default, the pattern **/*.g4 is used to select grammar files.

    • excludes

      @Parameter protected Set<String> excludes
      A set of Ant-like exclusion patterns used to prevent certain files from being processed. By default, this set is empty such that no files are excluded.
    • project

      @Parameter(property="project", required=true, readonly=true) protected org.apache.maven.project.MavenProject project
      The current Maven project.
    • generateTestSources

      @Parameter(property="antlr4.generateTestSources", defaultValue="false") private boolean generateTestSources
      Specifies whether sources are added to the compile or test scope.
    • sourceDirectory

      @Parameter(defaultValue="${basedir}/src/main/antlr4") private File sourceDirectory
      The directory where the ANTLR grammar files (*.g4) are located.
    • outputDirectory

      @Parameter(defaultValue="${project.build.directory}/generated-sources/antlr4") private File outputDirectory
      Specify output directory where the Java files are generated.
    • libDirectory

      @Parameter(defaultValue="${basedir}/src/main/antlr4/imports") private File libDirectory
      Specify location of imported grammars and tokens files.
    • statusDirectory

      @Parameter(defaultValue="${project.build.directory}/maven-status/antlr4", readonly=true) private File statusDirectory
      The directory where build status information is located.
    • buildContext

      @Component private org.sonatype.plexus.build.incremental.BuildContext buildContext
    • tool

      protected Tool tool
      An instance of the ANTLR tool build
  • Constructor Details

    • Antlr4Mojo

      public Antlr4Mojo()
  • Method Details

    • getSourceDirectory

      public File getSourceDirectory()
    • getOutputDirectory

      public File getOutputDirectory()
    • getLibDirectory

      public File getLibDirectory()
    • addSourceRoot

      void addSourceRoot(File outputDir)
    • execute

      public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
      The main entry point for this Mojo, it is responsible for converting ANTLR 4.x grammars into the target language specified by the grammar.
      Throws:
      org.apache.maven.plugin.MojoExecutionException - if a configuration or grammar error causes the code generation process to fail
      org.apache.maven.plugin.MojoFailureException - if an instance of the ANTLR 4 Tool cannot be created
    • getCommandArguments

      private List<String> getCommandArguments()
    • processGrammarFiles

      private List<List<String>> processGrammarFiles(List<String> args, Set<File> grammarFiles, GrammarDependencies dependencies, File sourceDirectory) throws org.codehaus.plexus.compiler.util.scan.InclusionScanException, IOException
      Parameters:
      sourceDirectory -
      Throws:
      org.codehaus.plexus.compiler.util.scan.InclusionScanException
      IOException
    • getImportFiles

      private Set<File> getImportFiles(File sourceDirectory) throws org.codehaus.plexus.compiler.util.scan.InclusionScanException
      Throws:
      org.codehaus.plexus.compiler.util.scan.InclusionScanException
    • getGrammarFiles

      private Set<File> getGrammarFiles(File sourceDirectory) throws org.codehaus.plexus.compiler.util.scan.InclusionScanException
      Throws:
      org.codehaus.plexus.compiler.util.scan.InclusionScanException
    • getPackageName

      private static String getPackageName(String relativeFolderPath)
    • getIncludesPatterns

      public Set<String> getIncludesPatterns()
    • getDependenciesStatusFile

      private File getDependenciesStatusFile()
    • validateEncoding

      private String validateEncoding(String encoding)
      Validates the given encoding.
      Returns:
      the validated encoding. If null was provided, returns the platform default encoding.