Only run the maven plugin when needed.

This commit is contained in:
Josh Chase 2016-01-13 16:24:56 -08:00
parent ac3d78554c
commit 7d478b18ae
1 changed files with 16 additions and 0 deletions

View File

@ -372,6 +372,22 @@ public class Antlr4Mojo extends AbstractMojo {
scan.addSourceMapping(mapping);
Set<File> grammarFiles = scan.getIncludedSources(sourceDirectory, null);
// We don't want the plugin to run for every grammar, regardless of whether
// it's changed since the last compilation. Check the mtime of the tokens vs
// the grammar file mtime to determine whether we even need to execute.
Set<File> grammarFilesToProcess = new HashSet<File>();
for (File grammarFile : grammarFiles) {
String tokensFileName = grammarFile.getName().split("\\.")[0] + ".tokens";
File outputFile = new File(outputDirectory, tokensFileName);
if ( (! outputFile.exists()) ||
outputFile.lastModified() < grammarFile.lastModified() ) {
grammarFilesToProcess.add(grammarFile);
}
}
grammarFiles = grammarFilesToProcess;
if (grammarFiles.isEmpty()) {
getLog().info("No grammars to process");
return Collections.emptyList();