private static void waitForFileWatcher(@NotNull ProgressIndicator indicator) { LocalFileSystem fs = LocalFileSystem.getInstance(); if (!(fs instanceof LocalFileSystemImpl)) return; final FileWatcher watcher = ((LocalFileSystemImpl)fs).getFileWatcher(); if (!watcher.isOperational() || !watcher.isSettingRoots()) return; LOG.info("FW/roots waiting started"); indicator.setIndeterminate(true); indicator.setText(ProjectBundle.message("project.load.waiting.watcher")); if (indicator instanceof ProgressWindow) { ((ProgressWindow)indicator).setCancelButtonText(CommonBundle.message("button.skip")); } while (watcher.isSettingRoots() && !indicator.isCanceled()) { TimeoutUtil.sleep(10); } LOG.info("FW/roots waiting finished"); }
private void waitForFileWatcher(@NotNull Project project) { LocalFileSystem fs = LocalFileSystem.getInstance(); if (!(fs instanceof LocalFileSystemImpl)) return; final FileWatcher watcher = ((LocalFileSystemImpl)fs).getFileWatcher(); if (!watcher.isOperational() || !watcher.isSettingRoots()) return; LOG.info("FW/roots waiting started"); Task.Modal task = new Task.Modal(project, ProjectBundle.message("project.load.progress"), true) { @Override public void run(@NotNull ProgressIndicator indicator) { indicator.setIndeterminate(true); indicator.setText(ProjectBundle.message("project.load.waiting.watcher")); if (indicator instanceof ProgressWindow) { ((ProgressWindow)indicator).setCancelButtonText(CommonBundle.message("button.skip")); } while (watcher.isSettingRoots() && !indicator.isCanceled()) { TimeoutUtil.sleep(10); } LOG.info("FW/roots waiting finished"); } }; myProgressManager.run(task); }
private void checkProjectRoots() { LocalFileSystem fs = LocalFileSystem.getInstance(); if (!(fs instanceof LocalFileSystemImpl)) return; FileWatcher watcher = ((LocalFileSystemImpl)fs).getFileWatcher(); if (!watcher.isOperational()) return; List<String> manualWatchRoots = watcher.getManualWatchRoots(); if (manualWatchRoots.isEmpty()) return; VirtualFile[] roots = ProjectRootManager.getInstance(myProject).getContentRoots(); if (roots.length == 0) return; List<String> nonWatched = new SmartList<String>(); for (VirtualFile root : roots) { if (!(root.getFileSystem() instanceof LocalFileSystem)) continue; String rootPath = root.getPath(); for (String manualWatchRoot : manualWatchRoots) { if (FileUtil.isAncestor(manualWatchRoot, rootPath, false)) { nonWatched.add(rootPath); } } } if (!nonWatched.isEmpty()) { String message = ApplicationBundle.message("watcher.non.watchable.project"); watcher.notifyOnFailure(message, null); LOG.info("unwatched roots: " + nonWatched); LOG.info("manual watches: " + manualWatchRoots); } }
@Override protected void setUp() throws Exception { LOG.debug("================== setting up " + getName() + " =================="); super.setUp(); myFileSystem = LocalFileSystem.getInstance(); assertNotNull(myFileSystem); myWatcher = ((LocalFileSystemImpl)myFileSystem).getFileWatcher(); assertNotNull(myWatcher); assertFalse(myWatcher.isOperational()); myWatcher.startup(myNotifier); assertTrue(myWatcher.isOperational()); myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, getProject()); myTimeout = NATIVE_PROCESS_DELAY; myConnection = ApplicationManager.getApplication().getMessageBus().connect(); myConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { synchronized (myEvents) { myEvents.addAll(events); } } }); ((LocalFileSystemImpl)myFileSystem).cleanupForNextTest(); LOG = FileWatcher.getLog(); LOG.debug("================== setting up " + getName() + " =================="); }
@Override @Before public void setUp() throws Exception { System.setProperty(FileWatcher.PROPERTY_WATCHER_DISABLED, "false"); super.setUp(); clManager = (ChangeListManagerImpl) ChangeListManager.getInstance(myProject); myVcsDirtyScopeManager = VcsDirtyScopeManager.getInstance(myProject); enableSilentOperation(VcsConfiguration.StandardConfirmation.ADD); enableSilentOperation(VcsConfiguration.StandardConfirmation.REMOVE); myVcs = SvnVcs.getInstance(myProject); }
private void checkProjectRoots() { VirtualFile[] roots = ProjectRootManager.getInstance(myProject).getContentRoots(); if (roots.length == 0) return; LocalFileSystem fs = LocalFileSystem.getInstance(); if (!(fs instanceof LocalFileSystemImpl)) return; FileWatcher watcher = ((LocalFileSystemImpl)fs).getFileWatcher(); if (!watcher.isOperational()) return; PooledThreadExecutor.INSTANCE.submit(() -> { LOG.debug("FW/roots waiting started"); while (true) { if (myProject.isDisposed()) return; if (!watcher.isSettingRoots()) break; TimeoutUtil.sleep(10); } LOG.debug("FW/roots waiting finished"); Collection<String> manualWatchRoots = watcher.getManualWatchRoots(); if (!manualWatchRoots.isEmpty()) { List<String> nonWatched = new SmartList<>(); for (VirtualFile root : roots) { if (!(root.getFileSystem() instanceof LocalFileSystem)) continue; String rootPath = root.getPath(); for (String manualWatchRoot : manualWatchRoots) { if (FileUtil.isAncestor(manualWatchRoot, rootPath, false)) { nonWatched.add(rootPath); } } } if (!nonWatched.isEmpty()) { String message = ApplicationBundle.message("watcher.non.watchable.project"); watcher.notifyOnFailure(message, null); LOG.info("unwatched roots: " + nonWatched); LOG.info("manual watches: " + manualWatchRoots); } } }); }
public void scan() { List<VirtualFile> workQueue = myWorkQueue; myWorkQueue = new ArrayList<VirtualFile>(); boolean haveEventsToFire = myFinishRunnable != null || !myEvents.isEmpty(); if (!workQueue.isEmpty()) { final LocalFileSystem fileSystem = LocalFileSystem.getInstance(); final FileWatcher watcher; if (fileSystem instanceof LocalFileSystemImpl) { LocalFileSystemImpl fs = (LocalFileSystemImpl)fileSystem; fs.markSuspiciousFilesDirty(workQueue); watcher = fs.getFileWatcher(); } else { watcher = null; } long t = 0; if (LOG.isDebugEnabled()) { LOG.debug("scanning " + workQueue); t = System.currentTimeMillis(); } for (VirtualFile file : workQueue) { if (myCancelled) break; NewVirtualFile nvf = (NewVirtualFile)file; if (!myIsRecursive && (!myIsAsync || (watcher != null && !watcher.isWatched(nvf)))) { // we're unable to definitely refresh synchronously by means of file watcher. nvf.markDirty(); } RefreshWorker worker = myWorker = new RefreshWorker(nvf, myIsRecursive); worker.scan(); List<VFileEvent> events = worker.getEvents(); if (myEvents.addAll(events)) { haveEventsToFire = true; } } if (t != 0) { t = System.currentTimeMillis() - t; LOG.debug((myCancelled ? "cancelled, " : "done, ") + t + " ms, events " + myEvents); } } myWorker = null; iHaveEventsToFire = haveEventsToFire; }
public void scan() { List<VirtualFile> workQueue = myWorkQueue; myWorkQueue = new ArrayList<VirtualFile>(); boolean haveEventsToFire = myFinishRunnable != null || !myEvents.isEmpty(); if (!workQueue.isEmpty()) { LocalFileSystemImpl fs = (LocalFileSystemImpl)LocalFileSystem.getInstance(); fs.markSuspiciousFilesDirty(workQueue); FileWatcher watcher = fs.getFileWatcher(); long t = 0; if (LOG.isDebugEnabled()) { LOG.debug("scanning " + workQueue); t = System.currentTimeMillis(); } for (VirtualFile file : workQueue) { if (myCancelled) break; NewVirtualFile nvf = (NewVirtualFile)file; if (!myIsRecursive && (!myIsAsync || !watcher.isWatched(nvf))) { // we're unable to definitely refresh synchronously by means of file watcher. nvf.markDirty(); } RefreshWorker worker = myWorker = new RefreshWorker(nvf, myIsRecursive); worker.scan(); List<VFileEvent> events = worker.getEvents(); if (myEvents.addAll(events)) { haveEventsToFire = true; } } if (t != 0) { t = System.currentTimeMillis() - t; LOG.debug((myCancelled ? "cancelled, " : "done, ") + t + " ms, events " + myEvents); } } myWorker = null; iHaveEventsToFire = haveEventsToFire; }