diff --git a/pom.xml b/pom.xml index 230cc9c..0031708 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ org.bsc.maven maven-processor-plugin-parent pom - 4.3 + 4.4-SNAPSHOT MAVEN PROCESSOR PLUGIN PARENT A maven plugin to process annotation for jdk6 at compile time diff --git a/processor/pom.xml b/processor/pom.xml index b798483..0188712 100644 --- a/processor/pom.xml +++ b/processor/pom.xml @@ -13,7 +13,7 @@ This plugin could be considered the 'alter ego' of maven apt plugin http://mojo. org.bsc.maven maven-processor-plugin-parent - 4.3 + 4.4-SNAPSHOT diff --git a/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java b/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java index e74f954..39ebebd 100644 --- a/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java +++ b/processor/src/main/java/org/bsc/maven/plugin/processor/AbstractAnnotationProcessorMojo.java @@ -64,6 +64,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; +import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -573,7 +574,13 @@ private List prepareOptions( JavaCompiler compiler ) { } private boolean isSourcesUnchanged( List allSources ) throws IOException { - long maxSourceDate = allSources.stream().map(JavaFileObject::getLastModified).max(Long::compare).get(); + if (!areSourceFilesSameAsPreviousRun(allSources)) + return false; + + long maxSourceDate = allSources.stream() + .map(JavaFileObject::getLastModified) + .max(Long::compare) + .orElse(Long.MIN_VALUE); // use atomic long for effectively final wrapper around long variable final AtomicLong maxOutputDate = new AtomicLong(Long.MIN_VALUE); @@ -596,7 +603,41 @@ private boolean isSourcesUnchanged( List allSources ) throws IOE } return maxSourceDate <= maxOutputDate.get(); + } + /** + * Checks the list of {@code allSources} against the stored list of source files in a previous run. + * + * @param allSources + * @return {@code true} when the filenames of the previous run matches exactly with the current run. + * @throws IOException + */ + private boolean areSourceFilesSameAsPreviousRun(List allSources) throws IOException { + Path sourceFileList = outputDirectory.toPath().resolve(".maven-processor-source-files.txt"); + try { + if (!Files.exists(sourceFileList)) { + getLog().debug("File with previous sources " + sourceFileList + " not found, treating as first run"); + return false; + } + + Set previousSourceFiles = new HashSet<>(Files.readAllLines(sourceFileList)); + Set currentSourceFiles = allSources.stream().map(JavaFileObject::getName).collect(Collectors.toSet()); + if (getLog().isDebugEnabled()) { + Set removedSourceFiles = previousSourceFiles.stream() + .filter(f -> !currentSourceFiles.contains(f)) + .collect(Collectors.toSet()); + getLog().debug("removed source files: " + removedSourceFiles); + + Set newSourceFiles = currentSourceFiles.stream() + .filter(f -> !previousSourceFiles.contains(f)) + .collect(Collectors.toSet()); + getLog().debug("new source files: " + newSourceFiles); + } + return previousSourceFiles.equals(currentSourceFiles); + } finally { + outputDirectory.mkdirs(); + Files.write(sourceFileList, allSources.stream().map(JavaFileObject::getName).collect(Collectors.toSet())); + } } private void executeWithExceptionsHandled() throws Exception diff --git a/test/pom.xml b/test/pom.xml index 29ffc4b..e459842 100644 --- a/test/pom.xml +++ b/test/pom.xml @@ -11,7 +11,7 @@ org.bsc.maven maven-processor-plugin-parent - 4.3 + 4.4-SNAPSHOT diff --git a/utils/pom.xml b/utils/pom.xml index c9552be..eeb16db 100644 --- a/utils/pom.xml +++ b/utils/pom.xml @@ -31,7 +31,7 @@ org.bsc.maven maven-processor-plugin-parent - 4.3 + 4.4-SNAPSHOT