diff --git a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java index bc857548ca2b..2e7c490790d3 100644 --- a/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java +++ b/java/compiler/impl/src/com/intellij/packaging/impl/artifacts/ArtifactManagerImpl.java @@ -285,7 +285,7 @@ public class ArtifactManagerImpl extends ArtifactManager implements ProjectCompo ContainerUtil.addIfNotNull(request, requestsToRemove); } - Set newRequests = LocalFileSystem.getInstance().replaceWatchedRoots(requestsToRemove, toAdd, true); + Set newRequests = LocalFileSystem.getInstance().replaceWatchedRoots(requestsToRemove, toAdd, null); for (LocalFileSystem.WatchRequest request : newRequests) { myWatchedOutputs.put(request.getRootPath(), request); } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java index 475b28f951c2..6246ec1d7e23 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java @@ -61,7 +61,6 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl { private Set myRootsToWatch = new HashSet(); public ProjectRootManagerComponent(Project project, - FileTypeManager fileTypeManager, DirectoryIndex directoryIndex, StartupManager startupManager) { super(project, directoryIndex); @@ -146,16 +145,16 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl { protected void addRootsToWatch() { final Set rootPaths = getAllRoots(false); if (rootPaths == null) return; - myRootsToWatch = LocalFileSystem.getInstance().replaceWatchedRoots(myRootsToWatch, rootPaths, true); + myRootsToWatch = LocalFileSystem.getInstance().replaceWatchedRoots(myRootsToWatch, rootPaths, null); } - private void beforeRootsChange(boolean filetypes) { + private void beforeRootsChange(boolean fileTypes) { if (myProject.isDisposed()) return; - getBatchSession(filetypes).beforeRootsChanged(); + getBatchSession(fileTypes).beforeRootsChanged(); } - private void rootsChanged(boolean filetypes) { - getBatchSession(filetypes).rootsChanged(); + private void rootsChanged(boolean fileTypes) { + getBatchSession(fileTypes).rootsChanged(); } private void doUpdateOnRefresh() { @@ -176,24 +175,24 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl { return false; } - protected void fireBeforeRootsChangeEvent(boolean filetypes) { + protected void fireBeforeRootsChangeEvent(boolean fileTypes) { isFiringEvent = true; try { myProject.getMessageBus() .syncPublisher(ProjectTopics.PROJECT_ROOTS) - .beforeRootsChange(new ModuleRootEventImpl(myProject, filetypes)); + .beforeRootsChange(new ModuleRootEventImpl(myProject, fileTypes)); } finally { isFiringEvent= false; } } - protected void fireRootsChangedEvent(boolean filetypes) { + protected void fireRootsChangedEvent(boolean fileTypes) { isFiringEvent = true; try { myProject.getMessageBus() .syncPublisher(ProjectTopics.PROJECT_ROOTS) - .rootsChanged(new ModuleRootEventImpl(myProject, filetypes)); + .rootsChanged(new ModuleRootEventImpl(myProject, fileTypes)); } finally { isFiringEvent = false; diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/JarDirectoryWatcherImpl.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/JarDirectoryWatcherImpl.java index a0b9b4a42731..638956e670ac 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/JarDirectoryWatcherImpl.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/libraries/JarDirectoryWatcherImpl.java @@ -60,24 +60,7 @@ public class JarDirectoryWatcherImpl implements JarDirectoryWatcher { } } - if (flatRoots.isEmpty()) { - myWatchRequests = fs.replaceWatchedRoots(myWatchRequests, recursiveRoots, true); - } - else if (recursiveRoots.isEmpty()) { - myWatchRequests = fs.replaceWatchedRoots(myWatchRequests, flatRoots, false); - } - else { - fs.removeWatchedRoots(myWatchRequests); - final int rootsTotal = flatRoots.size() + recursiveRoots.size(); - if (rootsTotal > 0) { - myWatchRequests = new ArrayList(rootsTotal); - myWatchRequests.addAll(fs.addRootsToWatch(flatRoots, false)); - myWatchRequests.addAll(fs.addRootsToWatch(recursiveRoots, true)); - } - else { - myWatchRequests = Collections.emptySet(); - } - } + myWatchRequests = fs.replaceWatchedRoots(myWatchRequests, recursiveRoots, flatRoots); if (myBusConnection == null) { myBusConnection = ApplicationManager.getApplication().getMessageBus().connect(); diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/LocalFileSystem.java b/platform/platform-api/src/com/intellij/openapi/vfs/LocalFileSystem.java index b0bd675cb721..34b27fb12735 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/LocalFileSystem.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/LocalFileSystem.java @@ -149,13 +149,14 @@ public abstract class LocalFileSystem extends NewVirtualFileSystem { @NotNull final String rootPath, final boolean watchRecursively) { final Set requests = watchRequest != null ? singleton(watchRequest) : Collections.emptySet(); - final Set result = replaceWatchedRoots(requests, singleton(rootPath), watchRecursively); + final Set result = watchRecursively ? replaceWatchedRoots(requests, singleton(rootPath), null) + : replaceWatchedRoots(requests, null, singleton(rootPath)); return result.size() == 1 ? result.iterator().next() : null; } public abstract Set replaceWatchedRoots(@NotNull final Collection watchRequests, - @NotNull final Collection rootPaths, - final boolean watchRecursively); + @Nullable final Collection recursiveRoots, + @Nullable final Collection flatRoots); public abstract void registerAuxiliaryFileOperationsHandler(@NotNull LocalFileOperationsHandler handler); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java index b2d1cacfe972..7c1eb96e1263 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/impl/local/LocalFileSystemImpl.java @@ -15,7 +15,6 @@ */ package com.intellij.openapi.vfs.impl.local; -import com.intellij.openapi.application.AccessToken; import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.components.ApplicationComponent; @@ -37,6 +36,7 @@ import com.intellij.util.TimeoutUtil; import com.intellij.util.containers.HashSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; import java.io.File; @@ -323,28 +323,26 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap final Application application = ApplicationManager.getApplication(); if (application.isDisposeInProgress() || !myWatcher.isOperational()) return; - final AccessToken token = application.acquireReadActionLock(); - try { - synchronized (myLock) { - final WatchRequestImpl[] watchRequests = normalizeRootsForRefresh(); - final List myRecursiveRoots = new ArrayList(); - final List myFlatRoots = new ArrayList(); + application.runReadAction(new Runnable() { + public void run() { + synchronized (myLock) { + final WatchRequestImpl[] watchRequests = normalizeRootsForRefresh(); + final List myRecursiveRoots = new ArrayList(); + final List myFlatRoots = new ArrayList(); - for (WatchRequestImpl watchRequest : watchRequests) { - if (watchRequest.isToWatchRecursively()) { - myRecursiveRoots.add(watchRequest.myFSRootPath); - } - else { - myFlatRoots.add(watchRequest.myFSRootPath); + for (WatchRequestImpl watchRequest : watchRequests) { + if (watchRequest.isToWatchRecursively()) { + myRecursiveRoots.add(watchRequest.myFSRootPath); + } + else { + myFlatRoots.add(watchRequest.myFSRootPath); + } } + + myWatcher.setWatchRoots(myRecursiveRoots, myFlatRoots); } - - myWatcher.setWatchRoots(myRecursiveRoots, myFlatRoots); } - } - finally { - token.finish(); - } + }); } private class StoreRefreshStatusThread extends Thread { @@ -374,8 +372,11 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap if (rootPaths.isEmpty() || !myWatcher.isOperational()) { return Collections.emptySet(); } + else if (watchRecursively) { + return replaceWatchedRoots(Collections.emptySet(), rootPaths, null); + } else { - return replaceWatchedRoots(Collections.emptySet(), rootPaths, watchRecursively); + return replaceWatchedRoots(Collections.emptySet(), null, rootPaths); } } @@ -383,26 +384,27 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap public void removeWatchedRoots(@NotNull final Collection watchRequests) { if (watchRequests.isEmpty()) return; - final AccessToken token = ApplicationManager.getApplication().acquireReadActionLock(); - try { - synchronized (myLock) { - final boolean update = doRemoveWatchedRoots(watchRequests); - if (update) { - myNormalizedTree = null; - setUpFileWatcher(); + ApplicationManager.getApplication().runReadAction(new Runnable() { + public void run() { + synchronized (myLock) { + final boolean update = doRemoveWatchedRoots(watchRequests); + if (update) { + myNormalizedTree = null; + setUpFileWatcher(); + } } } - } - finally { - token.finish(); - } + }); } @Override public Set replaceWatchedRoots(@NotNull final Collection watchRequests, - @NotNull final Collection rootPaths, - final boolean watchRecursively) { - if (rootPaths.isEmpty() || !myWatcher.isOperational()) { + @Nullable final Collection _recursiveRoots, + @Nullable final Collection _flatRoots) { + final Collection recursiveRoots = _recursiveRoots != null ? _recursiveRoots : Collections.emptyList(); + final Collection flatRoots = _flatRoots != null ? _flatRoots : Collections.emptyList(); + + if (recursiveRoots.isEmpty() && flatRoots.isEmpty() || !myWatcher.isOperational()) { removeWatchedRoots(watchRequests); return Collections.emptySet(); } @@ -410,47 +412,55 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap final Set result = new HashSet(); final Set filesToSync = new HashSet(); - final AccessToken token = ApplicationManager.getApplication().acquireReadActionLock(); - try { - synchronized (myLock) { - final boolean update = doAddRootsToWatch(rootPaths, watchRecursively, result, filesToSync) || - doRemoveWatchedRoots(watchRequests); - if (update) { - myNormalizedTree = null; - setUpFileWatcher(); + ApplicationManager.getApplication().runReadAction(new Runnable() { + public void run() { + synchronized (myLock) { + final boolean update = doAddRootsToWatch(recursiveRoots, flatRoots, result, filesToSync) || + doRemoveWatchedRoots(watchRequests); + if (update) { + myNormalizedTree = null; + setUpFileWatcher(); + } } } - } - finally { - token.finish(); - } + }); - syncFiles(filesToSync, watchRecursively); + syncFiles(filesToSync); return result; } - private boolean doAddRootsToWatch(@NotNull final Collection roots, - final boolean recursively, + private boolean doAddRootsToWatch(@NotNull final Collection recursiveRoots, + @NotNull final Collection flatRoots, @NotNull final Set results, @NotNull final Set filesToSync) { boolean update = false; - for (String root : roots) { - final WatchRequestImpl result = new WatchRequestImpl(root, recursively); - final boolean alreadyWatched = isAlreadyWatched(result); + for (String root : recursiveRoots) { + final WatchRequestImpl request = new WatchRequestImpl(root, true); + final boolean alreadyWatched = isAlreadyWatched(request); + + request.myDominated = alreadyWatched; + myRootsToWatch.add(request); + results.add(request); + + update |= !alreadyWatched; + } + + for (String root : flatRoots) { + final WatchRequestImpl request = new WatchRequestImpl(root, false); + final boolean alreadyWatched = isAlreadyWatched(request); if (!alreadyWatched) { final VirtualFile existingFile = findFileByPathIfCached(root); - if (existingFile != null) { - if (existingFile.isDirectory() && !recursively && existingFile instanceof NewVirtualFile) { - filesToSync.addAll(((NewVirtualFile)existingFile).getCachedChildren()); - } + if (existingFile != null && existingFile.isDirectory() && existingFile instanceof NewVirtualFile) { + filesToSync.addAll(((NewVirtualFile)existingFile).getCachedChildren()); } } - result.myDominated = alreadyWatched; - myRootsToWatch.add(result); - results.add(result); + + request.myDominated = alreadyWatched; + myRootsToWatch.add(request); + results.add(request); update |= !alreadyWatched; } @@ -458,7 +468,7 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap return update; } - private void syncFiles(@NotNull final Set filesToSync, final boolean watchRecursively) { + private void syncFiles(@NotNull final Set filesToSync) { if (filesToSync.isEmpty() || ApplicationManager.getApplication().isUnitTestMode()) return; for (VirtualFile file : filesToSync) { @@ -466,7 +476,8 @@ public final class LocalFileSystemImpl extends LocalFileSystemBase implements Ap ((NewVirtualFile)file).markDirtyRecursively(); } } - refreshFiles(filesToSync, true, watchRecursively, null); + + refreshFiles(filesToSync, true, false, null); } private boolean doRemoveWatchedRoots(@NotNull final Collection watchRequests) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/FileWatchRequestModifier.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/FileWatchRequestModifier.java index b2fb77cc96aa..24e44013b13c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/FileWatchRequestModifier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/impl/projectlevelman/FileWatchRequestModifier.java @@ -64,7 +64,7 @@ public class FileWatchRequestModifier implements Runnable { } } - final Set requests = myLfs.replaceWatchedRoots(toRemove, toAdd.keySet(), true); + final Set requests = myLfs.replaceWatchedRoots(toRemove, toAdd.keySet(), null); for (LocalFileSystem.WatchRequest request : requests) { myDirectoryMappingWatches.put(toAdd.get(request.getRootPath()), request); }