public LocalFileSystemImpl(@NotNull ManagingFS managingFS) { myManagingFS = managingFS; myWatcher = new FileWatcher(myManagingFS); if (myWatcher.isOperational()) { final int PERIOD = 1000; Runnable runnable = new Runnable() { public void run() { final Application application = ApplicationManager.getApplication(); if (application == null || application.isDisposed()) return; storeRefreshStatusToFiles(); JobScheduler.getScheduler().schedule(this, PERIOD, TimeUnit.MILLISECONDS); } }; JobScheduler.getScheduler().schedule(runnable, PERIOD, TimeUnit.MILLISECONDS); } }
public void testFindRootPerformance() throws IOException { File tempJar = IoTestUtil.createTestJar(); final VirtualFile jar = refreshAndFindFile(tempJar); assertNotNull(jar); final JarFileSystem fs = JarFileSystem.getInstance(); final String path = jar.getPath() + "!/"; final NewVirtualFile root = ManagingFS.getInstance().findRoot(path, fs); PlatformTestUtil.startPerformanceTest("find root is slow", 5000, new ThrowableRunnable() { @Override public void run() throws Throwable { JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(500, null), null, false, false, new Processor<Object>() { @Override public boolean process(Object o) { for (int i = 0; i < 20000; i++) { NewVirtualFile rootJar = ManagingFS.getInstance().findRoot(path, fs); assertNotNull(rootJar); assertSame(root, rootJar); } return true; } }); } }).assertTiming(); }
@Override public <Key, Psi extends PsiElement> boolean processElements(@NotNull final StubIndexKey<Key, Psi> indexKey, @NotNull final Key key, @NotNull final Project project, @Nullable final GlobalSearchScope scope, @Nullable IdFilter idFilter, @NotNull final Class<Psi> requiredClass, @NotNull final Processor<? super Psi> processor) { return doProcessStubs(indexKey, key, project, scope, new StubIdListContainerAction(idFilter, project) { final PersistentFS fs = (PersistentFS)ManagingFS.getInstance(); @Override protected boolean process(int id, StubIdList value) { final VirtualFile file = IndexInfrastructure.findFileByIdIfCached(fs, id); if (file == null || scope != null && !scope.contains(file)) { return true; } return myStubProcessingHelper.processStubsInFile(project, file, value, processor, requiredClass); } }); }
private static boolean processVirtualFiles(@NotNull TIntHashSet ids, @NotNull final GlobalSearchScope filter, @NotNull final Processor<VirtualFile> processor) { final PersistentFS fs = (PersistentFS)ManagingFS.getInstance(); return ids.forEach(new TIntProcedure() { @Override public boolean execute(int id) { ProgressManager.checkCanceled(); VirtualFile file = IndexInfrastructure.findFileByIdIfCached(fs, id); if (file != null && filter.accept(file)) { return processor.process(file); } return true; } }); }
public void testFindRootWithDenormalizedPath() { File tempDir = new WriteAction<File>() { @Override protected void run(Result<File> result) throws Throwable { File res = createTempDirectory(); new File(res, "x.jar").createNewFile(); result.setResult(res); } }.execute().getResultObject(); VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir); VirtualFile jar = vDir.findChild("x.jar"); assertNotNull(jar); NewVirtualFile root1 = ManagingFS.getInstance().findRoot(jar.getPath()+"!/", JarFileSystem.getInstance()); NewVirtualFile root2 = ManagingFS.getInstance().findRoot(jar.getParent().getPath() + "//"+ jar.getName()+"!/", JarFileSystem.getInstance()); assertNotNull(root1); assertSame(root1, root2); }
public DirectoryIndexImpl(@NotNull ManagingFS managingFS, @NotNull Project project, @NotNull StartupManager startupManager) { myPersistence = managingFS; myProject = project; myConnection = project.getMessageBus().connect(project); myExcludePolicies = Extensions.getExtensions(DirectoryIndexExcludePolicy.EP_NAME, myProject); startupManager.registerPreStartupActivity(new Runnable() { @Override public void run() { initialize(); } }); Disposer.register(project, new Disposable() { @Override public void dispose() { myDisposed = true; myState.multiDirPackages.clear(); myState.myDirToInfoMap.clear(); myState.myDirToPackageName.clear(); myState.myExcludeRootsMap.clear(); myState.myPackageNameToDirsMap.clear(); myState.myProjectExcludeRoots.clear(); } }); }
public void testFindRootWithDenormalizedPath() { File tempDir = new WriteAction<File>() { @Override protected void run(Result<File> result) throws Throwable { File res = createTempDirectory(); new File(res, "x.jar").createNewFile(); result.setResult(res); } }.execute().getResultObject(); VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir); VirtualFile jar = vDir.findChild("x.jar"); assertNotNull(jar); NewVirtualFile root1 = ManagingFS.getInstance().findRoot(jar.getPath()+"!/", (NewVirtualFileSystem)StandardFileSystems.jar()); NewVirtualFile root2 = ManagingFS.getInstance().findRoot(jar.getParent().getPath() + "//"+ jar.getName()+"!/", (NewVirtualFileSystem)StandardFileSystems.jar()); assertNotNull(root1); assertSame(root1, root2); }
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()); } }
@Override public <Key, Psi extends PsiElement> boolean processElements(@Nonnull final StubIndexKey<Key, Psi> indexKey, @Nonnull final Key key, @Nonnull final Project project, @Nullable final GlobalSearchScope scope, @Nullable IdFilter idFilter, @Nonnull final Class<Psi> requiredClass, @Nonnull final Processor<? super Psi> processor) { return doProcessStubs(indexKey, key, project, scope, new StubIdListContainerAction(idFilter, project) { final PersistentFS fs = (PersistentFS)ManagingFS.getInstance(); @Override protected boolean process(int id, StubIdList value) { final VirtualFile file = IndexInfrastructure.findFileByIdIfCached(fs, id); if (file == null || scope != null && !scope.contains(file)) { return true; } return myStubProcessingHelper.processStubsInFile(project, file, value, processor, requiredClass); } }); }
@Nullable public VirtualFile getScratchVirtualFile() { final int id = SCRATCH_FILE_ID; if (id <= 0) { return null; } return ManagingFS.getInstance().findFileById(id); }
@Override public void initialize(@NotNull ManagingFS managingFS, @NotNull FileWatcherNotificationSink notificationSink) { myManagingFS = managingFS; myNotificationSink = notificationSink; boolean disabled = Boolean.parseBoolean(System.getProperty(PROPERTY_WATCHER_DISABLED)); myExecutable = getExecutable(); if (disabled) { LOG.info("Native file watcher is disabled"); } else if (myExecutable == null) { LOG.info("Native file watcher is not supported on this platform"); } else if (!myExecutable.exists()) { notifyOnFailure(ApplicationBundle.message("watcher.exe.not.found"), null); } else if (!myExecutable.canExecute()) { notifyOnFailure(ApplicationBundle.message("watcher.exe.not.exe", myExecutable), new NotificationListener() { @Override public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { ShowFilePathAction.openFile(myExecutable); } }); } else { try { startupProcess(false); LOG.info("Native file watcher is operational."); } catch (IOException e) { LOG.warn(e.getMessage()); notifyOnFailure(ApplicationBundle.message("watcher.failed.to.start"), null); } } }
FileWatcher(@NotNull ManagingFS managingFS) { MyFileWatcherNotificationSink notificationSink = new MyFileWatcherNotificationSink(); myWatchers = PluggableFileWatcher.EP_NAME.getExtensions(); for (PluggableFileWatcher watcher : myWatchers) { watcher.initialize(managingFS, notificationSink); } }
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 testFindRootWithDenormalizedPath() throws IOException { File tempJar = IoTestUtil.createTestJar(); VirtualFile jar = refreshAndFindFile(tempJar); assertNotNull(jar); JarFileSystem fs = JarFileSystem.getInstance(); NewVirtualFile root1 = ManagingFS.getInstance().findRoot(jar.getPath() + "!/", fs); NewVirtualFile root2 = ManagingFS.getInstance().findRoot(jar.getParent().getPath() + "//" + jar.getName() + "!/", fs); assertNotNull(root1); assertSame(root1, root2); }
@Override public void actionPerformed(AnActionEvent e) { final ApplicationEx application = ApplicationManagerEx.getApplicationEx(); String m = "Started loading content"; LOG.info(m); System.out.println(m); long start = System.currentTimeMillis(); count.set(0); totalSize.set(0); ApplicationManagerEx.getApplicationEx().runProcessWithProgressSynchronously(new Runnable() { @Override public void run() { PersistentFS vfs = (PersistentFS)application.getComponent(ManagingFS.class); VirtualFile[] roots = vfs.getRoots(); for (VirtualFile root : roots) { iterateCached(root); } } }, "Loading", false, null); long end = System.currentTimeMillis(); String message = "Finished loading content of " + count + " files. " + "Total size=" + StringUtil.formatFileSize(totalSize.get()) + ". " + "Elapsed=" + ((end - start) / 1000) + "sec."; LOG.info(message); System.out.println(message); }
@NotNull @Override public Collection<PsiFileSystemItem> computeDefaultContexts() { PsiFile file = getContainingFile(); if (file == null) return ContainerUtil.emptyList(); if (isAbsolutePathReference() && !ApplicationManager.getApplication().isUnitTestMode()) { return toFileSystemItems(ManagingFS.getInstance().getLocalRoots()); } return super.computeDefaultContexts(); }
@NotNull public RootEntry createTransientRootEntry() { ApplicationManager.getApplication().assertReadAccessAllowed(); RootEntry root = new RootEntry(); doCreateChildren(root, Arrays.asList(ManagingFS.getInstance().getLocalRoots()), false); return root; }
@NotNull public RootEntry createTransientRootEntryForPathOnly(@NotNull String path) { ApplicationManager.getApplication().assertReadAccessAllowed(); RootEntry root = new RootEntry(); doCreateChildrenForPathOnly(root, path, Arrays.asList(ManagingFS.getInstance().getLocalRoots())); return root; }
public LocalFileSystemImpl(@NotNull ManagingFS managingFS) { myManagingFS = managingFS; myWatcher = new FileWatcher(myManagingFS); if (myWatcher.isOperational()) { new StoreRefreshStatusThread().start(); } }
FileWatcher(@NotNull ManagingFS managingFS) { myManagingFS = managingFS; boolean disabled = Boolean.parseBoolean(System.getProperty(PROPERTY_WATCHER_DISABLED)); myExecutable = getExecutable(); if (disabled) { LOG.info("Native file watcher is disabled"); } else if (myExecutable == null) { LOG.info("Native file watcher is not supported on this platform"); } else if (!myExecutable.exists()) { notifyOnFailure(ApplicationBundle.message("watcher.exe.not.found"), null); } else if (!myExecutable.canExecute()) { notifyOnFailure(ApplicationBundle.message("watcher.exe.not.exe", myExecutable), new NotificationListener() { @Override public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) { ShowFilePathAction.openFile(myExecutable); } }); } else if (!isUpToDate(myExecutable)) { notifyOnFailure(ApplicationBundle.message("watcher.exe.outdated"), null); } else { try { startupProcess(false); LOG.info("Native file watcher is operational."); } catch (IOException e) { LOG.warn(e.getMessage()); notifyOnFailure(ApplicationBundle.message("watcher.failed.to.start"), null); } } }
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"); } }
public void testFindRootPerformance() { File tempDir = new WriteAction<File>() { @Override protected void run(Result<File> result) throws Throwable { File res = createTempDirectory(); new File(res, "x.jar").createNewFile(); result.setResult(res); } }.execute().getResultObject(); final VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir); final VirtualFile jar = vDir.findChild("x.jar"); assertNotNull(jar); final NewVirtualFile root = ManagingFS.getInstance().findRoot(jar.getPath()+"!/", JarFileSystem.getInstance()); PlatformTestUtil.startPerformanceTest("find root is slow", 500, new ThrowableRunnable() { @Override public void run() throws Throwable { final String path = jar.getPath() + "!/"; final JarFileSystem fileSystem = JarFileSystem.getInstance(); JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(500, null), null, false, new Processor<Object>() { @Override public boolean process(Object o) { for (int i = 0; i < 1000; i++) { NewVirtualFile rootJar = ManagingFS.getInstance().findRoot(path, fileSystem); assertNotNull(rootJar); assertSame(root, rootJar); } return true; } }); } }).assertTiming(); }
public void testFindRootPerformance() { File tempDir = new WriteAction<File>() { @Override protected void run(Result<File> result) throws Throwable { File res = createTempDirectory(); new File(res, "x.jar").createNewFile(); result.setResult(res); } }.execute().getResultObject(); final VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir); final VirtualFile jar = vDir.findChild("x.jar"); assertNotNull(jar); final NewVirtualFile root = ManagingFS.getInstance().findRoot(jar.getPath()+"!/", (NewVirtualFileSystem)StandardFileSystems.jar()); PlatformTestUtil.startPerformanceTest("find root is slow", 500, new ThrowableRunnable() { @Override public void run() throws Throwable { final String path = jar.getPath() + "!/"; final NewVirtualFileSystem fileSystem = (NewVirtualFileSystem)StandardFileSystems.jar(); JobLauncher.getInstance().invokeConcurrentlyUnderProgress(Collections.nCopies(500, null), null, false, new Processor<Object>() { @Override public boolean process(Object o) { for (int i = 0; i < 1000; i++) { NewVirtualFile rootJar = ManagingFS.getInstance().findRoot(path, fileSystem); assertNotNull(rootJar); assertSame(root, rootJar); } return true; } }); } }).assertTiming(); }
public LocalFileSystemImpl(@Nonnull Application app, @Nonnull ManagingFS managingFS) { myManagingFS = managingFS; myWatcher = new FileWatcher(myManagingFS); if (myWatcher.isOperational()) { JobScheduler.getScheduler().scheduleWithFixedDelay( () -> { if (!app.isDisposed()) storeRefreshStatusToFiles(); }, STATUS_UPDATE_PERIOD, STATUS_UPDATE_PERIOD, TimeUnit.MILLISECONDS); } }
FileWatcher(@Nonnull ManagingFS managingFS) { myManagingFS = managingFS; myNotificationSink = new MyFileWatcherNotificationSink(); myWatchers = new PluggableFileWatcher[] {new NativeFileWatcherImpl()}; //FIXME [VISTALL] this is dirty hack, due we don't allow change file watcher for (PluggableFileWatcher watcher : myWatchers) { watcher.initialize(myManagingFS, myNotificationSink); } }
@Override public void actionPerformed(AnActionEvent e) { count.set(0); totalSize.set(0); final ApplicationEx application = ApplicationManagerEx.getApplicationEx(); String m = "Started loading content"; LOG.info(m); System.out.println(m); long start = System.currentTimeMillis(); ApplicationManagerEx.getApplicationEx().runProcessWithProgressSynchronously(new Runnable() { @Override public void run() { PersistentFS vfs = (PersistentFS)application.getComponent(ManagingFS.class); VirtualFile[] roots = vfs.getRoots(); for (VirtualFile root : roots) { iterateCached(root); } } }, "Loading", false, null); long end = System.currentTimeMillis(); String message = "Finished loading content of " + count + " files. Total size=" + StringUtil.formatFileSize(totalSize.get()) + ". Elapsed=" + ((end - start) / 1000) + "sec."; LOG.info(message); System.out.println(message); }
private <K, V> boolean processValuesInScope(@Nonnull ID<K, V> indexId, @Nonnull K dataKey, boolean ensureValueProcessedOnce, @Nonnull GlobalSearchScope scope, @Nullable IdFilter idFilter, @Nonnull ValueProcessor<V> processor) { PersistentFS fs = (PersistentFS)ManagingFS.getInstance(); IdFilter filter = idFilter != null ? idFilter : projectIndexableFiles(scope.getProject()); return processValueIterator(indexId, dataKey, null, scope, valueIt -> { while (valueIt.hasNext()) { final V value = valueIt.next(); for (final ValueContainer.IntIterator inputIdsIterator = valueIt.getInputIdsIterator(); inputIdsIterator.hasNext(); ) { final int id = inputIdsIterator.next(); if (filter != null && !filter.containsFileId(id)) continue; VirtualFile file = IndexInfrastructure.findFileByIdIfCached(fs, id); if (file != null && scope.accept(file)) { if (!processor.process(file, value)) { return false; } if (ensureValueProcessedOnce) { break; // continue with the next value } } } } return true; }); }
private static boolean processVirtualFiles(@Nonnull TIntHashSet ids, @Nonnull final GlobalSearchScope filter, @Nonnull final Processor<VirtualFile> processor) { final PersistentFS fs = (PersistentFS)ManagingFS.getInstance(); return ids.forEach(id -> { ProgressManager.checkCanceled(); VirtualFile file = IndexInfrastructure.findFileByIdIfCached(fs, id); if (file != null && filter.accept(file)) { return processor.process(file); } return true; }); }
private static void appendFileSystemRoot(final Collection<VirtualFile> dirs, final Project project) { final VirtualFile fileSystemRoot; if(SystemInfo.isWindows) { fileSystemRoot = ManagingFS.getInstance().findRoot("", LocalFileSystem.getInstance()); } else { fileSystemRoot = LocalFileSystem.getInstance().findFileByPath("/"); } dirs.add(fileSystemRoot); }
private static List<VirtualFile> getLocalRoots() { return Arrays.asList(ManagingFS.getInstance().getLocalRoots()); }
private static long getVFSTimestamp() { return ManagingFS.getInstance().getCreationTimestamp(); }
@Override public void refresh(final boolean asynchronous) { RefreshQueue.getInstance().refresh(asynchronous, true, null, ManagingFS.getInstance().getRoots(this)); }
public PlatformVirtualFileManager(@NotNull VirtualFileSystem[] fileSystems, @NotNull MessageBus bus, @NotNull ManagingFS managingFS) { super(fileSystems, bus); myManagingFS = managingFS; }
@SuppressWarnings("MethodOverridesStaticMethodOfSuperclass") public static PersistentFS getInstance() { return (PersistentFS)ManagingFS.getInstance(); }
public void actionPerformed(final AnActionEvent e) { RefreshQueue.getInstance().refresh(true, true, null, ModalityState.current(), ManagingFS.getInstance().getLocalRoots()); }
private static PersistentFS getFS() { return (PersistentFS)ManagingFS.getInstance(); }
@Override public VirtualFile findFileById(Project project, int id) { return IndexInfrastructure.findFileById((PersistentFS)ManagingFS.getInstance(), id); }