Package org.antlr.mojo.antlr4
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.AbstractMojoParses ANTLR 4 grammar files*.g4and transforms them into Java source files.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classAntlr4Mojo.CustomTool
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<java.lang.String>argumentsA list of additional command line arguments to pass to the ANTLR tool.protected booleanatnIf set to true then the ANTLR tool will generate a description of the ATN for each rule in Dot format.private org.sonatype.plexus.build.incremental.BuildContextbuildContextprotected java.util.Set<java.lang.String>excludesA set of Ant-like exclusion patterns used to prevent certain files from being processed.protected booleanforceATNUse the ATN simulator for all predictions.private booleangenerateTestSourcesSpecifies whether sources are added to thecompileortestscope.protected java.util.Set<java.lang.String>includesProvides an explicit list of all the grammars that should be included in the generate phase of the plugin.protected java.lang.StringinputEncodingspecify grammar file encoding; e.g., euc-jpprivate java.io.FilelibDirectorySpecify location of imported grammars and tokens files.protected booleanlistenerGenerate parse tree listener interface and base class.protected java.util.Map<java.lang.String,java.lang.String>optionsA list of grammar options to explicitly specify to the tool.private java.io.FileoutputDirectorySpecify output directory where the Java files are generated.protected java.lang.StringoutputEncodingspecify output file encoding; defaults to source encodingprotected org.apache.maven.project.MavenProjectprojectThe current Maven project.private java.io.FilesourceDirectoryThe directory where the ANTLR grammar files (*.g4) are located.private java.io.FilestatusDirectoryThe directory where build status information is located.protected TooltoolAn instance of the ANTLR tool buildprotected booleantreatWarningsAsErrorsTreat warnings as errors.protected booleanvisitorGenerate parse tree visitor interface and base class.
-
Constructor Summary
Constructors Constructor Description Antlr4Mojo()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddSourceRoot(java.io.File outputDir)voidexecute()The main entry point for this Mojo, it is responsible for converting ANTLR 4.x grammars into the target language specified by the grammar.private java.util.List<java.lang.String>getCommandArguments()private java.io.FilegetDependenciesStatusFile()private java.util.Set<java.io.File>getGrammarFiles(java.io.File sourceDirectory)private java.util.Set<java.io.File>getImportFiles(java.io.File sourceDirectory)java.util.Set<java.lang.String>getIncludesPatterns()java.io.FilegetLibDirectory()java.io.FilegetOutputDirectory()private static java.lang.StringgetPackageName(java.lang.String relativeFolderPath)java.io.FilegetSourceDirectory()private java.util.List<java.util.List<java.lang.String>>processGrammarFiles(java.util.List<java.lang.String> args, java.util.Set<java.io.File> grammarFiles, GrammarDependencies dependencies, java.io.File sourceDirectory)private java.lang.StringvalidateEncoding(java.lang.String encoding)Validates the given encoding.
-
-
-
Field Detail
-
atn
@Parameter(property="antlr4.atn", defaultValue="false") protected boolean atnIf 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 java.lang.String inputEncoding
specify grammar file encoding; e.g., euc-jp
-
outputEncoding
@Parameter(property="project.build.sourceEncoding") protected java.lang.String outputEncoding
specify output file encoding; defaults to source encoding
-
listener
@Parameter(property="antlr4.listener", defaultValue="true") protected boolean listenerGenerate parse tree listener interface and base class.
-
visitor
@Parameter(property="antlr4.visitor", defaultValue="false") protected boolean visitorGenerate parse tree visitor interface and base class.
-
treatWarningsAsErrors
@Parameter(property="antlr4.treatWarningsAsErrors", defaultValue="false") protected boolean treatWarningsAsErrorsTreat warnings as errors.
-
forceATN
@Parameter(property="antlr4.forceATN", defaultValue="false") protected boolean forceATNUse the ATN simulator for all predictions.
-
options
@Parameter protected java.util.Map<java.lang.String,java.lang.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 java.util.List<java.lang.String> arguments
A list of additional command line arguments to pass to the ANTLR tool.
-
includes
@Parameter protected java.util.Set<java.lang.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
**/*.g4is used to select grammar files.
-
excludes
@Parameter protected java.util.Set<java.lang.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 projectThe current Maven project.
-
generateTestSources
@Parameter(property="antlr4.generateTestSources", defaultValue="false") private boolean generateTestSourcesSpecifies whether sources are added to thecompileortestscope.
-
sourceDirectory
@Parameter(defaultValue="${basedir}/src/main/antlr4") private java.io.File sourceDirectoryThe directory where the ANTLR grammar files (*.g4) are located.
-
outputDirectory
@Parameter(defaultValue="${project.build.directory}/generated-sources/antlr4") private java.io.File outputDirectorySpecify output directory where the Java files are generated.
-
libDirectory
@Parameter(defaultValue="${basedir}/src/main/antlr4/imports") private java.io.File libDirectorySpecify location of imported grammars and tokens files.
-
statusDirectory
@Parameter(defaultValue="${project.build.directory}/maven-status/antlr4", readonly=true) private java.io.File statusDirectoryThe 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
-
-
Method Detail
-
getSourceDirectory
public java.io.File getSourceDirectory()
-
getOutputDirectory
public java.io.File getOutputDirectory()
-
getLibDirectory
public java.io.File getLibDirectory()
-
addSourceRoot
void addSourceRoot(java.io.File outputDir)
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureExceptionThe 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 failorg.apache.maven.plugin.MojoFailureException- if an instance of the ANTLR 4Toolcannot be created
-
getCommandArguments
private java.util.List<java.lang.String> getCommandArguments()
-
processGrammarFiles
private java.util.List<java.util.List<java.lang.String>> processGrammarFiles(java.util.List<java.lang.String> args, java.util.Set<java.io.File> grammarFiles, GrammarDependencies dependencies, java.io.File sourceDirectory) throws org.codehaus.plexus.compiler.util.scan.InclusionScanException, java.io.IOException- Parameters:
sourceDirectory-- Throws:
org.codehaus.plexus.compiler.util.scan.InclusionScanExceptionjava.io.IOException
-
getImportFiles
private java.util.Set<java.io.File> getImportFiles(java.io.File sourceDirectory) throws org.codehaus.plexus.compiler.util.scan.InclusionScanException- Throws:
org.codehaus.plexus.compiler.util.scan.InclusionScanException
-
getGrammarFiles
private java.util.Set<java.io.File> getGrammarFiles(java.io.File sourceDirectory) throws org.codehaus.plexus.compiler.util.scan.InclusionScanException- Throws:
org.codehaus.plexus.compiler.util.scan.InclusionScanException
-
getPackageName
private static java.lang.String getPackageName(java.lang.String relativeFolderPath)
-
getIncludesPatterns
public java.util.Set<java.lang.String> getIncludesPatterns()
-
getDependenciesStatusFile
private java.io.File getDependenciesStatusFile()
-
validateEncoding
private java.lang.String validateEncoding(java.lang.String encoding)
Validates the given encoding.- Returns:
- the validated encoding. If
nullwas provided, returns the platform default encoding.
-
-