Validate grid width bounds and qualify Archiver window and document states in IntelliJ
This commit is contained in:
@@ -2,6 +2,7 @@ package de.neitzel.fxdesigner.build;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.BasicFileAttributes;
|
||||
import java.util.*;
|
||||
|
||||
/** Detects transient changes and overflow in addition to pre/post hashes and file attributes. */
|
||||
@@ -13,18 +14,32 @@ final class SourceWatch implements AutoCloseable {
|
||||
SourceWatch(Path root) throws IOException {
|
||||
this.root = root;
|
||||
watch = root.getFileSystem().newWatchService();
|
||||
try (var dirs = Files.walk(root)) {
|
||||
for (Path dir :
|
||||
dirs.filter(Files::isDirectory)
|
||||
.filter(p -> InputTree.included(root, root.relativize(p)))
|
||||
.toList())
|
||||
keys.put(
|
||||
dir.register(
|
||||
watch,
|
||||
StandardWatchEventKinds.ENTRY_CREATE,
|
||||
StandardWatchEventKinds.ENTRY_DELETE,
|
||||
StandardWatchEventKinds.ENTRY_MODIFY),
|
||||
dir);
|
||||
try {
|
||||
Files.walkFileTree(
|
||||
root,
|
||||
new SimpleFileVisitor<>() {
|
||||
@Override
|
||||
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
|
||||
throws IOException {
|
||||
if (!InputTree.included(root, root.relativize(dir)))
|
||||
return FileVisitResult.SKIP_SUBTREE;
|
||||
keys.put(
|
||||
dir.register(
|
||||
watch,
|
||||
StandardWatchEventKinds.ENTRY_CREATE,
|
||||
StandardWatchEventKinds.ENTRY_DELETE,
|
||||
StandardWatchEventKinds.ENTRY_MODIFY),
|
||||
dir);
|
||||
return FileVisitResult.CONTINUE;
|
||||
}
|
||||
});
|
||||
} catch (IOException | RuntimeException failure) {
|
||||
try {
|
||||
watch.close();
|
||||
} catch (IOException cleanup) {
|
||||
failure.addSuppressed(cleanup);
|
||||
}
|
||||
throw failure;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package de.neitzel.fxdesigner.build;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
import java.nio.file.*;
|
||||
import java.nio.file.attribute.PosixFilePermissions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
class SourceWatchTest {
|
||||
@Test
|
||||
void registeringBuildInputsNeverTraversesSnapshotContents(@TempDir Path project)
|
||||
throws Exception {
|
||||
assumeTrue(project.getFileSystem().supportedFileAttributeViews().contains("posix"));
|
||||
var snapshot = Files.createDirectories(project.resolve(".neitzel-fx-designer/snapshots"));
|
||||
Files.createFile(snapshot.resolve("state.tmp"));
|
||||
var permissions = Files.getPosixFilePermissions(snapshot);
|
||||
try {
|
||||
Files.setPosixFilePermissions(snapshot, PosixFilePermissions.fromString("---------"));
|
||||
assumeTrue(!Files.isReadable(snapshot));
|
||||
try (var watch = new SourceWatch(project)) {
|
||||
assertFalse(watch.changed());
|
||||
}
|
||||
} finally {
|
||||
Files.setPosixFilePermissions(snapshot, permissions);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user