Commit 032d5488 authored by Andy Wilkinson's avatar Andy Wilkinson

Tolerate non-existent source folders in DevTools

Closes gh-13620
parent fddc9e9c
...@@ -125,8 +125,7 @@ public class FileSystemWatcher { ...@@ -125,8 +125,7 @@ public class FileSystemWatcher {
*/ */
public void addSourceFolder(File folder) { public void addSourceFolder(File folder) {
Assert.notNull(folder, "Folder must not be null"); Assert.notNull(folder, "Folder must not be null");
Assert.isTrue(folder.isDirectory(), Assert.isTrue(!folder.isFile(), "Folder '" + folder + "' must not be a file");
"Folder '" + folder + "' must exist and must" + " be a directory");
synchronized (this.monitor) { synchronized (this.monitor) {
checkNotStarted(); checkNotStarted();
this.folders.put(folder, null); this.folders.put(folder, null);
......
...@@ -52,7 +52,7 @@ class FolderSnapshot { ...@@ -52,7 +52,7 @@ class FolderSnapshot {
*/ */
FolderSnapshot(File folder) { FolderSnapshot(File folder) {
Assert.notNull(folder, "Folder must not be null"); 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.folder = folder;
this.time = new Date(); this.time = new Date();
Set<FileSnapshot> files = new LinkedHashSet<>(); Set<FileSnapshot> files = new LinkedHashSet<>();
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -106,21 +106,11 @@ public class FileSystemWatcherTests { ...@@ -106,21 +106,11 @@ public class FileSystemWatcherTests {
} }
@Test @Test
public void sourceFolderMustExist() { public void sourceFolderMustNotBeAFile() {
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() {
File folder = new File("pom.xml"); File folder = new File("pom.xml");
assertThat(folder.isFile()).isTrue(); assertThat(folder.isFile()).isTrue();
this.thrown.expect(IllegalArgumentException.class); 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")); this.watcher.addSourceFolder(new File("pom.xml"));
} }
...@@ -152,6 +142,19 @@ public class FileSystemWatcherTests { ...@@ -152,6 +142,19 @@ public class FileSystemWatcherTests {
assertThat(changedFiles.getFiles()).contains(expected); 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 @Test
public void waitsForPollingInterval() throws Exception { public void waitsForPollingInterval() throws Exception {
setupWatcher(10, 1); setupWatcher(10, 1);
......
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -62,9 +62,17 @@ public class FolderSnapshotTests { ...@@ -62,9 +62,17 @@ public class FolderSnapshotTests {
@Test @Test
public void folderMustNotBeFile() throws Exception { public void folderMustNotBeFile() throws Exception {
File file = this.temporaryFolder.newFile();
this.thrown.expect(IllegalArgumentException.class); this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Folder must not be a file"); this.thrown.expectMessage("Folder '" + file + "' must not be a file");
new FolderSnapshot(this.temporaryFolder.newFile()); 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 @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment