Tolerate non-existent source folders in DevTools
Closes gh-13620
This commit is contained in:
parent
fddc9e9c7e
commit
032d5488cd
|
|
@ -125,8 +125,7 @@ public class FileSystemWatcher {
|
|||
*/
|
||||
public void addSourceFolder(File folder) {
|
||||
Assert.notNull(folder, "Folder must not be null");
|
||||
Assert.isTrue(folder.isDirectory(),
|
||||
"Folder '" + folder + "' must exist and must" + " be a directory");
|
||||
Assert.isTrue(!folder.isFile(), "Folder '" + folder + "' must not be a file");
|
||||
synchronized (this.monitor) {
|
||||
checkNotStarted();
|
||||
this.folders.put(folder, null);
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class FolderSnapshot {
|
|||
*/
|
||||
FolderSnapshot(File folder) {
|
||||
Assert.notNull(folder, "Folder must not be null");
|
||||
Assert.isTrue(folder.isDirectory(), "Folder must not be a file");
|
||||
Assert.isTrue(!folder.isFile(), "Folder '" + folder + "' must not be a file");
|
||||
this.folder = folder;
|
||||
this.time = new Date();
|
||||
Set<FileSnapshot> files = new LinkedHashSet<>();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -106,21 +106,11 @@ public class FileSystemWatcherTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void sourceFolderMustExist() {
|
||||
File folder = new File("does/not/exist");
|
||||
assertThat(folder.exists()).isFalse();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage(
|
||||
"Folder '" + folder + "' must exist and must be a directory");
|
||||
this.watcher.addSourceFolder(folder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sourceFolderMustBeADirectory() {
|
||||
public void sourceFolderMustNotBeAFile() {
|
||||
File folder = new File("pom.xml");
|
||||
assertThat(folder.isFile()).isTrue();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Folder 'pom.xml' must exist and must be a directory");
|
||||
this.thrown.expectMessage("Folder 'pom.xml' must not be a file");
|
||||
this.watcher.addSourceFolder(new File("pom.xml"));
|
||||
}
|
||||
|
||||
|
|
@ -152,6 +142,19 @@ public class FileSystemWatcherTests {
|
|||
assertThat(changedFiles.getFiles()).contains(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSourceFolderAndAddFile() throws IOException {
|
||||
File folder = new File(this.temp.getRoot(), "does/not/exist");
|
||||
assertThat(folder.exists()).isFalse();
|
||||
this.watcher.addSourceFolder(folder);
|
||||
this.watcher.start();
|
||||
folder.mkdirs();
|
||||
touch(new File(folder, "text.txt"));
|
||||
this.watcher.stopAfter(1);
|
||||
ChangedFiles changedFiles = getSingleChangedFiles();
|
||||
System.out.println(changedFiles);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void waitsForPollingInterval() throws Exception {
|
||||
setupWatcher(10, 1);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -62,9 +62,17 @@ public class FolderSnapshotTests {
|
|||
|
||||
@Test
|
||||
public void folderMustNotBeFile() throws Exception {
|
||||
File file = this.temporaryFolder.newFile();
|
||||
this.thrown.expect(IllegalArgumentException.class);
|
||||
this.thrown.expectMessage("Folder must not be a file");
|
||||
new FolderSnapshot(this.temporaryFolder.newFile());
|
||||
this.thrown.expectMessage("Folder '" + file + "' must not be a file");
|
||||
new FolderSnapshot(file);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void folderDoesNotHaveToExist() throws Exception {
|
||||
File file = new File(this.temporaryFolder.getRoot(), "does/not/exist");
|
||||
FolderSnapshot snapshot = new FolderSnapshot(file);
|
||||
assertThat(snapshot).isEqualTo(new FolderSnapshot(file));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue