Fix NoSuchFileException when using the compile phase, fixes #564

This commit is contained in:
Guillaume Nodet
2022-01-07 11:46:54 +01:00
committed by GitHub
parent a9cf000666
commit b3a55333a8
7 changed files with 160 additions and 3 deletions

View File

@@ -17,6 +17,7 @@ package org.mvndaemon.mvnd.cache.impl;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.nio.file.attribute.FileTime;
@@ -57,13 +58,17 @@ public class TimestampCacheFactory implements CacheFactory {
FileState(Path path) {
this.path = path;
BasicFileAttributes attrs;
try {
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
this.lastModifiedTime = attrs.lastModifiedTime();
this.fileKey = attrs.fileKey();
attrs = Files.readAttributes(path, BasicFileAttributes.class);
} catch (NoSuchFileException e) {
// we allow this exception in case of a missing reactor artifact
attrs = null;
} catch (IOException e) {
throw new RuntimeException(e);
}
this.lastModifiedTime = attrs != null ? attrs.lastModifiedTime() : FileTime.fromMillis(0);
this.fileKey = attrs != null ? attrs.fileKey() : null;
}
@Override

View File

@@ -17,6 +17,7 @@ package org.mvndaemon.mvnd.cache.impl;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchEvent;
@@ -102,6 +103,9 @@ public class WatchServiceCacheFactory implements CacheFactory {
new WatchEvent.Kind[] { StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY },
mods);
return new Registration(watchKey);
} catch (NoSuchFileException e) {
// we allow this exception in case of a missing reactor artifact
return null;
} catch (IOException e) {
throw new RuntimeException(e);
}