Skip to content

Commit

Permalink
Rename rootProjectDirectoriesForWatching
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfs committed Aug 3, 2020
1 parent f9cc882 commit 2885daf
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
Expand Up @@ -209,7 +209,7 @@ BuildLifecycleAwareVirtualFileSystem createVirtualFileSystem(
))
.orElse(new WatchingNotSupportedVirtualFileSystem(rootReference));
listenerManager.addListener((BuildAddedListener) buildState ->
virtualFileSystem.buildRootDirectoryAdded(buildState.getBuildRootDir())
virtualFileSystem.registerRootDirectoryForWatching(buildState.getBuildRootDir())
);
return virtualFileSystem;
}
Expand Down
Expand Up @@ -31,12 +31,13 @@ public interface BuildLifecycleAwareVirtualFileSystem extends VirtualFileSystem
void afterBuildStarted(boolean watchingEnabled);

/**
* Called when a new build (aka project) root directory has been added.
* Register a root directory for watching.
*
* Adds a directory as a root directory for watching.
* This method is first called for the root directory of the root project.
* It is also called for the root directories of included builds, and all other nested builds.
*/
void buildRootDirectoryAdded(File buildRootDirectory);
void registerRootDirectoryForWatching(File rootDirectoryForWatching);

/**
* Called when the build is finished.
Expand Down
Expand Up @@ -57,7 +57,7 @@ public void afterBuildStarted(boolean watchingEnabled) {
}

@Override
public void buildRootDirectoryAdded(File buildRootDirectory) {
public void registerRootDirectoryForWatching(File rootDirectoryForWatching) {
}

@Override
Expand Down
Expand Up @@ -53,7 +53,7 @@ public class WatchingVirtualFileSystem implements BuildLifecycleAwareVirtualFile
private final Predicate<String> watchFilter;
private final DaemonDocumentationIndex daemonDocumentationIndex;
private final LocationsWrittenByCurrentBuild locationsWrittenByCurrentBuild;
private final Set<File> rootProjectDirectoriesForWatching = new HashSet<>();
private final Set<File> rootDirectoriesForWatching = new HashSet<>();

private FileWatcherRegistry watchRegistry;
private Exception reasonForNotWatchingFiles;
Expand Down Expand Up @@ -110,25 +110,25 @@ public void afterBuildStarted(boolean watchingEnabled) {
}

@Override
public void buildRootDirectoryAdded(File buildRootDirectory) {
synchronized (rootProjectDirectoriesForWatching) {
rootProjectDirectoriesForWatching.add(buildRootDirectory);
public void registerRootDirectoryForWatching(File buildRootDirectory) {
synchronized (rootDirectoriesForWatching) {
rootDirectoriesForWatching.add(buildRootDirectory);
rootReference.update(currentRoot -> {
if (watchRegistry == null) {
return currentRoot;
}
return withWatcherChangeErrorHandling(
currentRoot,
() -> watchRegistry.getFileWatcherUpdater().updateRootProjectDirectories(rootProjectDirectoriesForWatching)
() -> watchRegistry.getFileWatcherUpdater().updateRootProjectDirectories(rootDirectoriesForWatching)
);
});
}
}

@Override
public void beforeBuildFinished(boolean watchingEnabled) {
synchronized (rootProjectDirectoriesForWatching) {
rootProjectDirectoriesForWatching.clear();
synchronized (rootDirectoriesForWatching) {
rootDirectoriesForWatching.clear();
}
if (watchingEnabled) {
if (reasonForNotWatchingFiles != null) {
Expand Down Expand Up @@ -191,7 +191,7 @@ public void handleLostState() {
stopWatchingAndInvalidateHierarchy();
}
});
watchRegistry.getFileWatcherUpdater().updateRootProjectDirectories(rootProjectDirectoriesForWatching);
watchRegistry.getFileWatcherUpdater().updateRootProjectDirectories(rootDirectoriesForWatching);
long endTime = System.currentTimeMillis() - startTime;
LOGGER.warn("Spent {} ms registering watches for file system events", endTime);
// TODO: Move start watching early enough so that the root is always empty
Expand Down
Expand Up @@ -124,7 +124,7 @@ class WatchingVirtualFileSystemTest extends Specification {
def newRootDirectory = new File("newRoot")

when:
watchingHandler.buildRootDirectoryAdded(rootDirectory)
watchingHandler.registerRootDirectoryForWatching(rootDirectory)
then:
0 * _

Expand All @@ -137,7 +137,7 @@ class WatchingVirtualFileSystemTest extends Specification {
0 * _

when:
watchingHandler.buildRootDirectoryAdded(anotherBuildRootDirectory)
watchingHandler.registerRootDirectoryForWatching(anotherBuildRootDirectory)
then:
1 * watcherRegistry.fileWatcherUpdater >> fileWatcherUpdater
1 * fileWatcherUpdater.updateRootProjectDirectories(ImmutableSet.of(rootDirectory, anotherBuildRootDirectory))
Expand All @@ -151,7 +151,7 @@ class WatchingVirtualFileSystemTest extends Specification {
0 * _

when:
watchingHandler.buildRootDirectoryAdded(newRootDirectory)
watchingHandler.registerRootDirectoryForWatching(newRootDirectory)
then:
1 * watcherRegistry.fileWatcherUpdater >> fileWatcherUpdater
1 * fileWatcherUpdater.updateRootProjectDirectories(ImmutableSet.of(newRootDirectory))
Expand Down

0 comments on commit 2885daf

Please sign in to comment.