@Nullable private VirtualFileSystemEntry findChild(@NotNull String name, boolean doRefresh, boolean ensureCanonicalName, @NotNull NewVirtualFileSystem delegate) { boolean ignoreCase = !delegate.isCaseSensitive(); VirtualFileSystemEntry result = doFindChild(name, ensureCanonicalName, delegate, ignoreCase); //noinspection UseVirtualFileEquals if (result == NULL_VIRTUAL_FILE) { result = doRefresh ? createAndFindChildWithEventFire(name, delegate) : null; } else if (result != null && doRefresh && delegate.isDirectory(result) != result.isDirectory()) { RefreshQueue.getInstance().refresh(false, false, null, result); result = findChild(name, false, ensureCanonicalName, delegate); } return result; }
@Override public void refreshWithoutFileWatcher(final boolean asynchronous) { Runnable heavyRefresh = new Runnable() { @Override public void run() { for (VirtualFile root : myManagingFS.getRoots(LocalFileSystemImpl.this)) { ((NewVirtualFile)root).markDirtyRecursively(); } refresh(asynchronous); } }; if (asynchronous && myWatcher.isOperational()) { RefreshQueue.getInstance().refresh(true, true, heavyRefresh, myManagingFS.getRoots(this)); } else { heavyRefresh.run(); } }
@Override public void refreshIoFiles(@NotNull Iterable<File> files, boolean async, boolean recursive, @Nullable Runnable onFinish) { final VirtualFileManagerEx manager = (VirtualFileManagerEx)VirtualFileManager.getInstance(); Application app = ApplicationManager.getApplication(); boolean fireCommonRefreshSession = app.isDispatchThread() || app.isWriteAccessAllowed(); if (fireCommonRefreshSession) manager.fireBeforeRefreshStart(false); try { List<VirtualFile> filesToRefresh = new ArrayList<VirtualFile>(); for (File file : files) { final VirtualFile virtualFile = refreshAndFindFileByIoFile(file); if (virtualFile != null) { filesToRefresh.add(virtualFile); } } RefreshQueue.getInstance().refresh(async, recursive, onFinish, filesToRefresh); } finally { if (fireCommonRefreshSession) manager.fireAfterRefreshFinish(false); } }
public void scheduleInitialVfsRefresh() { UIUtil.invokeLaterIfNeeded(new Runnable() { @Override public void run() { if (myProject.isDisposed()) return; markContentRootsForRefresh(); Application app = ApplicationManager.getApplication(); if (!app.isHeadlessEnvironment()) { final long sessionId = VirtualFileManager.getInstance().asyncRefresh(null); final MessageBusConnection connection = app.getMessageBus().connect(); connection.subscribe(ProjectLifecycleListener.TOPIC, new ProjectLifecycleListener.Adapter() { @Override public void afterProjectClosed(@NotNull Project project) { RefreshQueue.getInstance().cancelSession(sessionId); connection.disconnect(); } }); } else { VirtualFileManager.getInstance().syncRefresh(); } } }); }
@Override public void refreshOpenFiles() { List<VirtualFile> files = ContainerUtil.newArrayList(); for (Project project : ProjectManager.getInstance().getOpenProjects()) { for (VirtualFile file : FileEditorManager.getInstance(project).getSelectedFiles()) { if (file instanceof NewVirtualFile) { files.add(file); } } } if (!files.isEmpty()) { // refresh open files synchronously so it doesn't wait for potentially longish refresh request in the queue to finish RefreshQueue.getInstance().refresh(false, false, null, files); } }
@Override public void actionPerformed(AnActionEvent e) { final Project project = getEventProject(e); final VirtualFile[] files = getFiles(e); if (project == null || files == null || files.length == 0) return; ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { for (VirtualFile file : files) { if (file instanceof NewVirtualFile) { ((NewVirtualFile)file).markDirtyRecursively(); } } } }); RefreshQueue.getInstance().refresh(true, true, new Runnable() { @Override public void run() { postRefresh(project, files); } }, files); }
private void refreshFiles(final Project project) { final List<VirtualFile> toRefreshFiles = new ArrayList<VirtualFile>(); final List<VirtualFile> toRefreshDirs = new ArrayList<VirtualFile>(); for (VirtualFile file : myFilesToRefresh) { if (file == null) continue; if (file.isDirectory()) { toRefreshDirs.add(file); } else { toRefreshFiles.add(file); } } // if refresh asynchronously, local changes would also be notified that they are dirty asynchronously, // and commit could be executed while not all changes are visible filterOutInvalid(myFilesToRefresh); RefreshQueue.getInstance().refresh(true, true, new Runnable() { public void run() { if (project.isDisposed()) return; filterOutInvalid(toRefreshFiles); filterOutInvalid(toRefreshDirs); final VcsDirtyScopeManager vcsDirtyScopeManager = VcsDirtyScopeManager.getInstance(project); vcsDirtyScopeManager.filesDirty(toRefreshFiles, toRefreshDirs); } }, myFilesToRefresh); myFilesToRefresh.clear(); }
/** * Refereshs path after adding files * @param files */ public static void refreshAfterAdd(@NotNull Collection<File> files) { LocalFileSystem lfs = LocalFileSystem.getInstance(); ArrayList filesToRefresh = new ArrayList(); Iterator iterator = files.iterator(); while (iterator.hasNext()) { File file = (File) iterator.next(); VirtualFile virtualFile = lfs.refreshAndFindFileByIoFile(file); if (virtualFile != null) { filesToRefresh.add(virtualFile); } } if (!filesToRefresh.isEmpty()) { RefreshQueue.getInstance().refresh(false, true, null, filesToRefresh); } }
@Nullable private VirtualFileSystemEntry findChild(@NotNull String name, final boolean doRefresh, boolean ensureCanonicalName, @NotNull NewVirtualFileSystem delegate) { boolean ignoreCase = !delegate.isCaseSensitive(); Comparator comparator = getComparator(name, ignoreCase); VirtualFileSystemEntry result = doFindChild(name, ensureCanonicalName, delegate, comparator); if (result == NULL_VIRTUAL_FILE) { result = doRefresh ? createAndFindChildWithEventFire(name, delegate) : null; } else if (result != null) { if (doRefresh && delegate.isDirectory(result) != result.isDirectory()) { RefreshQueue.getInstance().refresh(false, false, null, result); result = findChild(name, false, ensureCanonicalName, delegate); } } if (result == null) { addToAdoptedChildren(name, !delegate.isCaseSensitive(), comparator); } return result; }
public static void refreshOpenFiles() { List<VirtualFile> files = ContainerUtil.newArrayList(); for (Project project : ProjectManager.getInstance().getOpenProjects()) { VirtualFile[] projectFiles = FileEditorManager.getInstance(project).getSelectedFiles(); for (VirtualFile file : projectFiles) { if (file instanceof NewVirtualFile) { files.add(file); } } } if (!files.isEmpty()) { // refresh open files synchronously so it doesn't wait for potentially longish refresh request in the queue to finish RefreshQueue.getInstance().refresh(false, false, null, files); } }
@Nullable private VirtualFileSystemEntry findChild(@Nonnull String name, boolean doRefresh, boolean ensureCanonicalName, @Nonnull NewVirtualFileSystem delegate) { boolean ignoreCase = !delegate.isCaseSensitive(); VirtualFileSystemEntry result = doFindChild(name, ensureCanonicalName, delegate, ignoreCase); //noinspection UseVirtualFileEquals if (result == NULL_VIRTUAL_FILE) { result = doRefresh ? createAndFindChildWithEventFire(name, delegate) : null; } else if (result != null && doRefresh && delegate.isDirectory(result) != result.isDirectory()) { RefreshQueue.getInstance().refresh(false, false, null, result); result = findChild(name, false, ensureCanonicalName, delegate); } return result; }
@Override public void refreshWithoutFileWatcher(final boolean asynchronous) { Runnable heavyRefresh = () -> { for (VirtualFile root : myManagingFS.getRoots(this)) { ((NewVirtualFile)root).markDirtyRecursively(); } refresh(asynchronous); }; if (asynchronous && myWatcher.isOperational()) { RefreshQueue.getInstance().refresh(true, true, heavyRefresh, myManagingFS.getRoots(this)); } else { heavyRefresh.run(); } }
@Override public void refreshIoFiles(@Nonnull Iterable<File> files, boolean async, boolean recursive, @Nullable Runnable onFinish) { final VirtualFileManagerEx manager = (VirtualFileManagerEx)VirtualFileManager.getInstance(); Application app = ApplicationManager.getApplication(); boolean fireCommonRefreshSession = app.isDispatchThread() || app.isWriteAccessAllowed(); if (fireCommonRefreshSession) manager.fireBeforeRefreshStart(false); try { List<VirtualFile> filesToRefresh = new ArrayList<VirtualFile>(); for (File file : files) { final VirtualFile virtualFile = refreshAndFindFileByIoFile(file); if (virtualFile != null) { filesToRefresh.add(virtualFile); } } RefreshQueue.getInstance().refresh(async, recursive, onFinish, filesToRefresh); } finally { if (fireCommonRefreshSession) manager.fireAfterRefreshFinish(false); } }
public void scheduleInitialVfsRefresh() { GuiUtils.invokeLaterIfNeeded(() -> { if (myProject.isDisposed() || myInitialRefreshScheduled) return; myInitialRefreshScheduled = true; ((ProjectRootManagerImpl)ProjectRootManager.getInstance(myProject)).markRootsForRefresh(); Application app = ApplicationManager.getApplication(); if (!app.isCommandLine()) { final long sessionId = VirtualFileManager.getInstance().asyncRefresh(null); final MessageBusConnection connection = app.getMessageBus().connect(); connection.subscribe(ProjectLifecycleListener.TOPIC, new ProjectLifecycleListener() { @Override public void afterProjectClosed(@Nonnull Project project) { if (project != myProject) return; RefreshQueue.getInstance().cancelSession(sessionId); connection.disconnect(); } }); } else { VirtualFileManager.getInstance().syncRefresh(); } }, ModalityState.defaultModalityState()); }
public void maybeRefresh(@Nonnull ModalityState modalityState) { if (myBlockSyncOnFrameActivationCount.get() == 0 && mySettings.isSyncOnFrameActivation()) { RefreshQueue queue = RefreshQueue.getInstance(); queue.cancelSession(myRefreshSessionId); RefreshSession session = queue.createSession(true, true, null, modalityState); session.addAllFiles(ManagingFS.getInstance().getLocalRoots()); myRefreshSessionId = session.getId(); session.launch(); LOG.debug("vfs refreshed"); } else if (LOG.isDebugEnabled()) { LOG.debug("vfs refresh rejected, blocked: " + (myBlockSyncOnFrameActivationCount.get() != 0) + ", isSyncOnFrameActivation: " + mySettings.isSyncOnFrameActivation()); } }
public static void refreshOutputDirectories(Collection<File> outputs, boolean async) { LocalFileSystem fileSystem = LocalFileSystem.getInstance(); List<VirtualFile> toRefresh = new ArrayList<VirtualFile>(); int newDirectories = 0; for (File ioOutput : outputs) { VirtualFile output = fileSystem.findFileByIoFile(ioOutput); if (output != null) { toRefresh.add(output); } else if (ioOutput.exists()) { VirtualFile parent = fileSystem.refreshAndFindFileByIoFile(ioOutput.getParentFile()); if (parent != null) { parent.getChildren(); toRefresh.add(parent); newDirectories++; } } } if (newDirectories > 10) { LOG.info(newDirectories + " new output directories were created, refreshing their parents together to avoid too many rootsChange events"); RefreshQueue.getInstance().refresh(async, false, null, toRefresh); } else { LOG.debug("Refreshing " + outputs.size() + " outputs"); fileSystem.refreshIoFiles(outputs, async, false, null); } }
@Override protected long doRefresh(boolean asynchronous, @Nullable Runnable postAction) { if (!asynchronous) { ApplicationManager.getApplication().assertIsDispatchThread(); } // todo: get an idea how to deliver changes from local FS to jar fs before they go refresh RefreshSession session = RefreshQueue.getInstance().createSession(asynchronous, true, postAction); session.addAllFiles(myManagingFS.getRoots()); session.launch(); super.doRefresh(asynchronous, postAction); return session.getId(); }
@Nullable private VirtualFileSystemEntry createAndFindChildWithEventFire(@NotNull String name, @NotNull NewVirtualFileSystem delegate) { final VirtualFile fake = new FakeVirtualFile(this, name); final FileAttributes attributes = delegate.getAttributes(fake); if (attributes == null) return null; final String realName = delegate.getCanonicallyCasedName(fake); final VFileCreateEvent event = new VFileCreateEvent(null, this, realName, attributes.isDirectory(), true); RefreshQueue.getInstance().processSingleEvent(event); return findChild(realName); }
public void treeExpanded(final TreeExpansionEvent event) { if (myTreeBuilder == null || !myTreeBuilder.isNodeBeingBuilt(event.getPath())) return; TreePath path = event.getPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); if (node.getUserObject() instanceof FileNodeDescriptor) { FileNodeDescriptor nodeDescriptor = (FileNodeDescriptor)node.getUserObject(); final FileElement fileDescriptor = nodeDescriptor.getElement(); final VirtualFile virtualFile = fileDescriptor.getFile(); if (virtualFile != null) { if (!myEverExpanded.contains(virtualFile)) { if (virtualFile instanceof NewVirtualFile) { ((NewVirtualFile)virtualFile).markDirty(); } myEverExpanded.add(virtualFile); } AbstractTreeStructure treeStructure = myTreeBuilder.getTreeStructure(); final boolean async = treeStructure != null && treeStructure.isToBuildChildrenInBackground(virtualFile); DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_MODAL, new Runnable() { @Override public void run() { if (virtualFile instanceof NewVirtualFile) { RefreshQueue.getInstance().refresh(async, false, null, ModalityState.stateForComponent(myTree), virtualFile); } else { virtualFile.refresh(async, false); } } }); } } }
public void maybeRefresh(@NotNull ModalityState modalityState) { if (myBlockSyncOnFrameActivationCount.get() == 0 && mySettings.isSyncOnFrameActivation()) { RefreshQueue queue = RefreshQueue.getInstance(); queue.cancelSession(myRefreshSessionId); RefreshSession session = queue.createSession(true, true, null, modalityState); session.addAllFiles(ManagingFS.getInstance().getLocalRoots()); myRefreshSessionId = session.getId(); session.launch(); } }
public void run() { final LocalFileSystem lfs = LocalFileSystem.getInstance(); final FileGroup conflictedGroup = myUpdatedFiles.getGroupById(FileGroup.MERGED_WITH_TREE_CONFLICT); final Collection<String> conflictedFiles = conflictedGroup.getFiles(); final Collection<VirtualFile> parents = new ArrayList<VirtualFile>(); if ((conflictedFiles != null) && (! conflictedFiles.isEmpty())) { for (final String conflictedFile : conflictedFiles) { final File file = new File(conflictedFile); final VirtualFile vfFile = lfs.refreshAndFindFileByIoFile(file); if (vfFile != null) { parents.add(vfFile); continue; } final File parent = file.getParentFile(); VirtualFile vf = lfs.findFileByIoFile(parent); if (vf == null) { vf = lfs.refreshAndFindFileByIoFile(parent); } if (vf != null) { parents.add(vf); } } } if (! parents.isEmpty()) { RefreshQueue.getInstance().refresh(true, true, new Runnable() { public void run() { myDirtyScopeManager.filesDirty(null, parents); } }, parents); } }
protected void fillAndRefreshFiles() { final FileGroup conflictedGroup = myUpdatedFiles.getGroupById(groupId); final Collection<String> conflictedFiles = conflictedGroup.getFiles(); final Collection<VirtualFile> parents = new ArrayList<VirtualFile>(); if ((conflictedFiles != null) && (! conflictedFiles.isEmpty())) { for (final String conflictedFile : conflictedFiles) { final File file = new File(conflictedFile); VirtualFile vf = myLfs.findFileByIoFile(file); if (vf == null) { vf = myLfs.refreshAndFindFileByIoFile(file); } if (vf != null) { myFiles.add(vf); final VirtualFile parent = vf.getParent(); if (parent != null) { parents.add(parent); } } } } if (! myFiles.isEmpty()) { RefreshQueue.getInstance().refresh(true, true, null, parents); myDirtyScopeManager.filesDirty(myFiles, null); } }
@Override public void run(final ContinuationContext context) { List<VirtualFile> changedFiles = shelveChanges(context); context.suspend(); RefreshQueue.getInstance().refresh(true, false, new Runnable() { @Override public void run() { context.ping(); } }, changedFiles); }
@Override public void refresh(boolean asynchronous, boolean recursive, Runnable postRunnable) { List<VirtualFile> files = ContainerUtil.mapNotNull(myResourceBundle.getPropertiesFiles(), new Function<PropertiesFile, VirtualFile>() { @Override public VirtualFile fun(PropertiesFile file) { return file.getVirtualFile(); } }); if (!files.isEmpty()) { RefreshQueue.getInstance().refresh(false, false, postRunnable, files); } }
public static void refreshIODirectories(@NotNull final Collection<File> files) { final LocalFileSystem lfs = LocalFileSystem.getInstance(); final List<VirtualFile> filesToRefresh = new ArrayList<VirtualFile>(); for (File file : files) { final VirtualFile virtualFile = lfs.refreshAndFindFileByIoFile(file); if (virtualFile != null) { filesToRefresh.add(virtualFile); } } if (!filesToRefresh.isEmpty()) { RefreshQueue.getInstance().refresh(false, true, null, filesToRefresh); } }
public void treeExpanded(final TreeExpansionEvent event) { if (myTreeBuilder == null || !myTreeBuilder.isNodeBeingBuilt(event.getPath())) return; TreePath path = event.getPath(); DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); if (node.getUserObject() instanceof FileNodeDescriptor) { FileNodeDescriptor nodeDescriptor = (FileNodeDescriptor)node.getUserObject(); final FileElement fileDescriptor = nodeDescriptor.getElement(); final VirtualFile virtualFile = fileDescriptor.getFile(); if (virtualFile != null) { if (!myEverExpanded.containsKey(virtualFile)) { if (virtualFile instanceof NewVirtualFile) { ((NewVirtualFile)virtualFile).markDirty(); } myEverExpanded.put(virtualFile, virtualFile); } AbstractTreeStructure treeStructure = myTreeBuilder.getTreeStructure(); boolean async = treeStructure != null && treeStructure.isToBuildChildrenInBackground(virtualFile); if (virtualFile instanceof NewVirtualFile) { RefreshQueue.getInstance().refresh(async, false, null, ModalityState.stateForComponent(myTree), virtualFile); } else { virtualFile.refresh(async, false); } } } }
public synchronized void runPostStartupActivities() { final Application app = ApplicationManager.getApplication(); if (myPostStartupActivitiesPassed) return; runActivities(myDumbAwarePostStartupActivities); DumbService.getInstance(myProject).runWhenSmart(new Runnable() { public void run() { synchronized (StartupManagerImpl.this) { app.assertIsDispatchThread(); if (myProject.isDisposed()) return; runActivities(myDumbAwarePostStartupActivities); // they can register activities while in the dumb mode runActivities(myNotDumbAwarePostStartupActivities); myPostStartupActivitiesPassed = true; } } }); if (!app.isUnitTestMode() && !myProject.isDisposed()) { if (!app.isHeadlessEnvironment()) { checkProjectRoots(); final long sessionId = VirtualFileManager.getInstance().asyncRefresh(null); final MessageBusConnection connection = app.getMessageBus().connect(); connection.subscribe(ProjectLifecycleListener.TOPIC, new ProjectLifecycleListener.Adapter() { @Override public void afterProjectClosed(@NotNull Project project) { RefreshQueue.getInstance().cancelSession(sessionId); connection.disconnect(); } }); } else { VirtualFileManager.getInstance().syncRefresh(); } } Registry.get("ide.firstStartup").setValue(false); }
public void maybeRefresh(@NotNull ModalityState modalityState) { if (myBlockSyncOnFrameActivationCount.get() == 0) { LOG.debug("VFS refresh started"); RefreshQueue queue = RefreshQueue.getInstance(); queue.cancelSession(myRefreshSessionId); RefreshSession session = queue.createSession(true, true, null, modalityState); session.addAllFiles(ManagingFS.getInstance().getLocalRoots()); myRefreshSessionId = session.getId(); session.launch(); LOG.debug("VFS refresh finished"); } }
private EditorNotificationPanel createPanel(@NotNull final VirtualFile file) { EditorNotificationPanel panel = new EditorNotificationPanel(); panel.setText(IdeBundle.message("file.changed.externally.message")); panel.createActionLabel(IdeBundle.message("file.changed.externally.reload"), new Runnable() { @Override public void run() { if (!myProject.isDisposed()) { RefreshQueue.getInstance().refresh(false, false, null, file); EditorNotifications.getInstance(myProject).updateNotifications(file); } } }); return panel; }
public static void refreshIODirectories(@Nonnull final Collection<File> files) { final LocalFileSystem lfs = LocalFileSystem.getInstance(); final List<VirtualFile> filesToRefresh = new ArrayList<VirtualFile>(); for (File file : files) { final VirtualFile virtualFile = lfs.refreshAndFindFileByIoFile(file); if (virtualFile != null) { filesToRefresh.add(virtualFile); } } if (!filesToRefresh.isEmpty()) { RefreshQueue.getInstance().refresh(false, true, null, filesToRefresh); } }
@Nullable private VirtualFileSystemEntry createAndFindChildWithEventFire(@Nonnull String name, @Nonnull NewVirtualFileSystem delegate) { final VirtualFile fake = new FakeVirtualFile(this, name); final FileAttributes attributes = delegate.getAttributes(fake); if (attributes == null) return null; final String realName = delegate.getCanonicallyCasedName(fake); final VFileCreateEvent event = new VFileCreateEvent(null, this, realName, attributes.isDirectory(), true); RefreshQueue.getInstance().processSingleEvent(event); return findChild(realName); }