From a9dfca3666bdcd74476ca5aa6f3baa1e396ce6ce Mon Sep 17 00:00:00 2001 From: Daniel Halperin Date: Tue, 11 Jul 2017 20:58:24 -0700 Subject: [PATCH] isDependencyChanged: consider equal timestamps as out of date Some systems have low-granularity timestamps, so that file modification dates are rounded to seconds. This causes false negatives when detecting if a grammar needs to be recompiled if it changes a second after producing its tokens. This likely only causes an issue for tests that frequently mutate files; real humans are unlikely to compile within 1s of changing a grammar. Still, this seems a cleaner solution that hacking the failing test to use force a different modification time, as there will almost never be false positives. This fixes the failing test after making the test correct. --- .../src/main/java/org/antlr/mojo/antlr4/Antlr4Mojo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/antlr4-maven-plugin/src/main/java/org/antlr/mojo/antlr4/Antlr4Mojo.java b/antlr4-maven-plugin/src/main/java/org/antlr/mojo/antlr4/Antlr4Mojo.java index dcdc0a29d..0a81f51fb 100644 --- a/antlr4-maven-plugin/src/main/java/org/antlr/mojo/antlr4/Antlr4Mojo.java +++ b/antlr4-maven-plugin/src/main/java/org/antlr/mojo/antlr4/Antlr4Mojo.java @@ -395,7 +395,7 @@ public class Antlr4Mojo extends AbstractMojo { String tokensFileName = grammarFile.getName().split("\\.")[0] + ".tokens"; File outputFile = new File(outputDirectory, tokensFileName); if ( (! outputFile.exists()) || - outputFile.lastModified() < grammarFile.lastModified() || + outputFile.lastModified() <= grammarFile.lastModified() || dependencies.isDependencyChanged(grammarFile)) { grammarFilesToProcess.add(grammarFile); }