Skip to content

Commit

Permalink
Fixed unchanged sources check
Browse files Browse the repository at this point in the history
File .maven-processor-source-files.txt must be skipped in lastModified check (being just an extra file added for control purposes), especially because it is rewritten in method areSourceFilesSameAsPreviousRun, so its lastModified date is necessarily the most recent one, which causes method to always return true.
  • Loading branch information
Andrea Baroncelli committed Apr 11, 2024
1 parent 4b4f747 commit cda172b
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,8 @@ private List<String> prepareOptions(JavaCompiler compiler) throws MojoExecutionE
}

private boolean isSourcesUnchanged(List<JavaFileObject> allSources) throws IOException {
if (!areSourceFilesSameAsPreviousRun(allSources))
Path sourceFileList = outputDirectory.toPath().resolve(".maven-processor-source-files.txt");
if (!areSourceFilesSameAsPreviousRun(allSources, sourceFileList))
return false;

long maxSourceDate = allSources.stream()
Expand All @@ -612,7 +613,7 @@ private boolean isSourcesUnchanged(List<JavaFileObject> allSources) throws IOExc
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
if (Files.isRegularFile(file)) {
if (Files.isRegularFile(file) && !file.equals(sourceFileList)) {
maxOutputDate.updateAndGet(t -> Math.max(t, file.toFile().lastModified()));
}
return FileVisitResult.CONTINUE;
Expand All @@ -631,11 +632,11 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
* Checks the list of {@code allSources} against the stored list of source files in a previous run.
*
* @param allSources
* @param sourceFileList
* @return {@code true} when the filenames of the previous run matches exactly with the current run.
* @throws IOException
*/
private boolean areSourceFilesSameAsPreviousRun(List<JavaFileObject> allSources) throws IOException {
Path sourceFileList = outputDirectory.toPath().resolve(".maven-processor-source-files.txt");
private boolean areSourceFilesSameAsPreviousRun(List<JavaFileObject> allSources, Path sourceFileList) throws IOException {
try {
if (!Files.exists(sourceFileList)) {
getLog().debug("File with previous sources " + sourceFileList + " not found, treating as first run");
Expand Down

0 comments on commit cda172b

Please sign in to comment.