private void _before( final List<? extends VFileEvent> events ) { if( _project.isDisposed() ) { return; } for( VFileEvent event : events ) { final VirtualFile file = event.getFile(); if( file != null ) { if( isMoveOrRename( event ) ) { processRenameBefore( event ); } } } }
public void after( final List<? extends VFileEvent> events ) { if( _project.isDisposed() ) { return; } DumbService dumb = DumbService.getInstance( _project ); if( dumb.isDumb() ) { dumb.smartInvokeLater( () -> _after( events ) ); } else { ApplicationManager.getApplication().invokeLater( () ->_after( events ) ); } }
public void after(List<? extends VFileEvent> events) { String sources = Utils.getPropertyValue("sources", true); List<String> sourcesList = Utils.getSourcesList(sources); for (VFileEvent e : events) { VirtualFile virtualFile = e.getFile(); if (virtualFile != null && sourcesList.contains(virtualFile.getName()) && SOURCE_FOLDER_DEFAULT.equals(virtualFile.getParent().getName())) { Project[] projects = ProjectManager.getInstance().getOpenProjects(); Project project = null; if (projects.length == 1) { project = projects[0]; } System.out.println("Changed file " + virtualFile.getCanonicalPath()); Crowdin crowdin = new Crowdin(); String branch = Utils.getCurrentBranch(project); crowdin.uploadFile(virtualFile, branch); } } }
/** * Forces a reparse of the specified collection of files. * * @param files the files to reparse. */ public static void reparseFiles(@NotNull final Collection<VirtualFile> files) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { // files must be processed under one write action to prevent firing event for invalid files. final Set<VFilePropertyChangeEvent> events = new THashSet<VFilePropertyChangeEvent>(); for (VirtualFile file : files) { saveOrReload(file, events); } BulkFileListener publisher = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES); List<VFileEvent> eventList = new ArrayList<VFileEvent>(events); publisher.before(eventList); publisher.after(eventList); } }); }
@Override public void after(@NotNull List<? extends VFileEvent> events) { boolean scheduleRefresh = false; for (VFileEvent event : events) { String changedPath = event.getPath(); for (MyEntry entry : myAutoImportAware) { String projectPath = entry.aware.getAffectedExternalProjectPath(changedPath, myProject); if (projectPath == null) { continue; } ExternalProjectSettings projectSettings = entry.systemSettings.getLinkedProjectSettings(projectPath); if (projectSettings != null && projectSettings.isUseAutoImport()) { addPath(entry.externalSystemId, projectPath); scheduleRefresh = true; break; } } } if (scheduleRefresh) { myVfsAlarm.cancelAllRequests(); myVfsAlarm.addRequest(myFilesRequest, ExternalSystemConstants.AUTO_IMPORT_DELAY_MILLIS); } }
public void testManyPointersUpdatePerformance() throws IOException { LoggingListener listener = new LoggingListener(); final List<VFileEvent> events = new ArrayList<VFileEvent>(); final File ioTempDir = createTempDirectory(); final VirtualFile temp = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioTempDir); for (int i=0; i<100000; i++) { myVirtualFilePointerManager.create(VfsUtilCore.pathToUrl("/a/b/c/d/" + i), disposable, listener); events.add(new VFileCreateEvent(this, temp, "xxx" + i, false, true)); } PlatformTestUtil.startPerformanceTest("vfp update", 10000, new ThrowableRunnable() { @Override public void run() throws Throwable { for (int i=0; i<100; i++) { // simulate VFS refresh events since launching the actual refresh is too slow myVirtualFilePointerManager.before(events); myVirtualFilePointerManager.after(events); } } }).assertTiming(); }
@Override public void after(@NotNull List<? extends VFileEvent> events) { CaptureService service = CaptureService.getInstance(myProject); VirtualFile captures = service.getCapturesDirectory(); if (captures == null) { if (!service.getCaptures().isEmpty()) { queueUpdate(); } return; } for (VFileEvent event : events) { if (event.getFile() != null && VfsUtilCore.isAncestor(captures, event.getFile(), false)) { queueUpdate(); return; } } }
public AndroidProjectTreeBuilder(@NotNull Project project, @NotNull JTree tree, @NotNull DefaultTreeModel treeModel, @Nullable Comparator<NodeDescriptor> comparator, @NotNull ProjectAbstractTreeStructureBase treeStructure) { super(project, tree, treeModel, comparator, treeStructure); MessageBusConnection connection = project.getMessageBus().connect(project); connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { for (VFileEvent e : events) { if (e instanceof VFileDeleteEvent) { removeMapping(e.getFile()); } } } }); }
public static void reparseFiles(@NotNull final Collection<VirtualFile> files) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { // files must be processed under one write action to prevent firing event for invalid files. final Set<VFilePropertyChangeEvent> events = new THashSet<VFilePropertyChangeEvent>(); for (VirtualFile file : files) { saveOrReload(file, events); } ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES) .before(new ArrayList<VFileEvent>(events)); ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES) .after(new ArrayList<VFileEvent>(events)); } }); }
public void activate() { if (messageBusConnection != null) { return; } messageBusConnection = project.getMessageBus().connect(); messageBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { for (VFileEvent event : events) { if (event instanceof VFileDeleteEvent) { synchronized (changedFiles) { changedFiles.remove(event.getFile()); } } } } }); EditorFactory.getInstance().getEventMulticaster().addDocumentListener(listener, project); }
public void testManyPointersUpdatePerformance() throws IOException { FilePointerPartNode.pushDebug(false, disposable); LoggingListener listener = new LoggingListener(); final List<VFileEvent> events = new ArrayList<VFileEvent>(); final File ioTempDir = createTempDirectory(); final VirtualFile temp = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioTempDir); for (int i=0; i<100000; i++) { myVirtualFilePointerManager.create(VfsUtilCore.pathToUrl("/a/b/c/d/" + i), disposable, listener); events.add(new VFileCreateEvent(this, temp, "xxx" + i, false, true)); } PlatformTestUtil.startPerformanceTest("vfp update", 10000, new ThrowableRunnable() { @Override public void run() throws Throwable { for (int i=0; i<100; i++) { // simulate VFS refresh events since launching the actual refresh is too slow myVirtualFilePointerManager.before(events); myVirtualFilePointerManager.after(events); } } }).assertTiming(); }
/** * Handler method that is called before IntelliJ executes the file change, stores a lookup of IntelliJ modules for * deleted files because the module can't be determined after the delete is executed * @param vFileEvents List of file events, provided by IntelliJ */ public void before(@NotNull List<? extends VFileEvent> vFileEvents) { // sometimes file events occur before the plugin was initialized, so lets make sure we have a plugin, a project and a configuration if (plugin == null || plugin.getProject() == null || config == null || !config.isOpenCmsPluginEnabled()) { return; } // save all modules for deleted files in a lookup map, because IntelliJ can't find the module after the // deletion of directories (ModuleUtil.findModuleForFile returns null in that case) for (VFileEvent event : vFileEvents) { if (event instanceof VFileDeleteEvent) { VirtualFile ideaVFile = event.getFile(); if (ideaVFile == null) { continue; } Module ideaModule = ModuleUtil.findModuleForFile(ideaVFile, plugin.getProject()); if (ideaModule == null) { continue; } deletedFileModuleLookup.put(ideaVFile, ideaModule); } } }
/** * Handler method that is called after the file change has been executed by IntelliJ, analyzes file deletes, moves * and renames and calls the change handler (in a separate thread) that handles all the changes and is also used * to present a dialog asking the user if the file change should be reflected in the OpenCms VFS as well. * @param vFileEvents List of file events, provided by IntelliJ */ public void after(@NotNull List<? extends VFileEvent> vFileEvents) { try { if (config == null || !config.isOpenCmsPluginEnabled()) { return; } for (VFileEvent event : vFileEvents) { handleFileEvent(event); } if (changeHandler.hasAffectedFiles()) { ApplicationManager.getApplication().invokeLater(changeHandler); } } catch (CmsConnectionException e) { LOG.error("Error syncing file deletion/move/rename to OpenCms:\n" + e.getMessage(), e); } finally { deletedFileModuleLookup.clear(); } }
/** * Internal handler for file delete, move and rename events * @param event IntelliJ's file change event * @throws CmsConnectionException if the connection to OpenCms fails */ private void handleFileEvent(VFileEvent event) throws CmsConnectionException { // File is deleted if (event instanceof VFileDeleteEvent) { handleFileDeleteEvent(event); } // File is moved if (event instanceof VFileMoveEvent) { handleFileMoveEvent(event); } // File is renamed if (event instanceof VFilePropertyChangeEvent) { String propertyName = ((VFilePropertyChangeEvent)event).getPropertyName(); if ("name".equals(propertyName)) { handleFileRenameEvent(event); } } }
/** * Internal handler for file delete events, fills a list of files to be deleted that is handled later in * {@link OpenCmsModuleFileChangeHandler#handleChanges()} * @param event IntelliJ's file change event * @throws CmsConnectionException if the connection to OpenCms fails */ private void handleFileDeleteEvent(VFileEvent event) throws CmsConnectionException { VirtualFile ideaVFile = event.getFile(); if (ideaVFile != null) { String moduleBasePath = PluginTools.getModuleContentRoot(deletedFileModuleLookup.get(ideaVFile)); OpenCmsModule ocmsModule = openCmsModules.getModuleForBasePath(moduleBasePath); // check if the file belongs to an OpenCms module if (ocmsModule != null && ocmsModule.isPathModuleResource(ideaVFile.getPath())) { LOG.info("The following module resource was deleted: " + ideaVFile.getPath()); String vfsPath = ocmsModule.getVfsPathForRealPath(ideaVFile.getPath()); try { if (getVfsAdapter().exists(vfsPath)) { changeHandler.addFileToBeDeleted(ocmsModule, vfsPath, ideaVFile.isDirectory()); } } catch (CmisPermissionDeniedException e) { throw new CmsConnectionException("A local file has been deleted, but it can't be checked if the file exists in the VFS (permission denied).\nPlease check manually: " + vfsPath); } } } }
/** * Internal handler for file rename events fills a list of files to be renamed that is handled later in * {@link OpenCmsModuleFileChangeHandler#handleChanges()} * @param event IntelliJ's file change event * @throws CmsConnectionException if the connection to OpenCms fails */ private void handleFileRenameEvent(VFileEvent event) throws CmsConnectionException { VirtualFile ideaVFile = event.getFile(); if (ideaVFile != null) { String renameFilePath = ideaVFile.getPath(); OpenCmsModule ocmsModule = openCmsModules.getModuleForPath(renameFilePath); if (ocmsModule != null) { LOG.debug("The following file was renamed: " + ideaVFile.getPath()); String oldName = (String)((VFilePropertyChangeEvent)event).getOldValue(); String newName = (String)((VFilePropertyChangeEvent)event).getNewValue(); String newVfsPath = ocmsModule.getVfsPathForRealPath(renameFilePath); String oldVfsPath = newVfsPath.replaceFirst(newName, oldName); if (!oldVfsPath.equals(newVfsPath) && ocmsModule.isPathModuleResource(ocmsModule.getLocalVfsRoot() + oldVfsPath) && getVfsAdapter().exists(oldVfsPath)) { changeHandler.addFileToBeRenamed(ocmsModule, ideaVFile, oldVfsPath, newVfsPath, newName); } } } }
@RequiredDispatchThread public static void reparseFiles(@Nonnull final Collection<VirtualFile> files) { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { // files must be processed under one write action to prevent firing event for invalid files. final Set<VFilePropertyChangeEvent> events = new THashSet<VFilePropertyChangeEvent>(); for (VirtualFile file : files) { saveOrReload(file, events); } BulkFileListener publisher = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES); List<VFileEvent> eventList = new ArrayList<VFileEvent>(events); publisher.before(eventList); publisher.after(eventList); } }); }
@Override public void after(@Nonnull List<? extends VFileEvent> events) { boolean scheduleRefresh = false; for (VFileEvent event : events) { String changedPath = event.getPath(); for (MyEntry entry : myAutoImportAware) { String projectPath = entry.aware.getAffectedExternalProjectPath(changedPath, myProject); if (projectPath == null) { continue; } ExternalProjectSettings projectSettings = entry.systemSettings.getLinkedProjectSettings(projectPath); if (projectSettings != null && projectSettings.isUseAutoImport()) { addPath(entry.externalSystemId, projectPath); scheduleRefresh = true; break; } } } if (scheduleRefresh) { myVfsAlarm.cancelAllRequests(); myVfsAlarm.addRequest(myFilesRequest, ExternalSystemConstants.AUTO_IMPORT_DELAY_MILLIS); } }
public GistManagerImpl() { ApplicationManager.getApplication().getMessageBus().connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@Nonnull List<? extends VFileEvent> events) { if (events.stream().anyMatch(this::shouldDropCache)) { invalidateData(); } } private boolean shouldDropCache(VFileEvent e) { if (!(e instanceof VFilePropertyChangeEvent)) return false; String propertyName = ((VFilePropertyChangeEvent)e).getPropertyName(); return propertyName.equals(VirtualFile.PROP_NAME) || propertyName.equals(VirtualFile.PROP_ENCODING); } }); }
public NonClasspathClassFinder(@NotNull Project project, @NotNull String... fileExtensions) { myProject = project; myPackageManager = PsiPackageManager.getInstance(myProject); myManager = PsiManager.getInstance(myProject); myFileExtensions = ArrayUtil.append(fileExtensions, "class"); final MessageBusConnection connection = project.getMessageBus().connect(project); connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() { @Override public void after(@NotNull List<? extends VFileEvent> events) { clearCache(); } }); LowMemoryWatcher.register(this::clearCache, project); }
public void before( final List<? extends VFileEvent> events ) { if( _project.isDisposed() ) { return; } DumbService dumb = DumbService.getInstance( _project ); if( !dumb.isDumb() ) { _before( events ); } }
private void _after( final List<? extends VFileEvent> events ) { if( _project.isDisposed() ) { return; } for( VFileEvent event : events ) { final VirtualFile file = event.getFile(); if( file != null ) { if( event instanceof VFileCreateEvent ) { fireCreatedEvent( file ); } else if( event instanceof VFileDeleteEvent ) { fireDeletedEvent( file ); } else if( event instanceof VFileCopyEvent ) { processFileCopyEvent( (VFileCopyEvent)event ); } else if( isMoveOrRename( event ) ) { processRenameAfter( event ); } else // modified { ApplicationManager.getApplication().runReadAction( () -> fireModifiedEvent( file ) ); } } } }
private void processRenameBefore( VFileEvent event ) { VirtualFile originalFile = event.getFile(); if( originalFile instanceof LightVirtualFile ) { return; } // Handle the Deletion *before* it is renamed fireDeletedEvent( originalFile ); }
private void processRenameAfter( VFileEvent event ) { VirtualFile renamedFile = event.getFile(); if( renamedFile instanceof LightVirtualFile ) { return; } // Handle the Creation *after* it is renamed fireCreatedEvent( renamedFile ); }
@Override public void before(@NotNull List<? extends VFileEvent> vFileEvents) { // for (VFileEvent fe : vFileEvents) { // if (fe.getFile() != null && fe.getFile().getCanonicalPath() != null && fe.getFile().getCanonicalPath().contains(_project.getName())) { // System.out.println("before(getCanonicalPath)->" + fe.getFile().getCanonicalPath()); // // System.out.println("before(getName)->" + fe.getFile().getName()); // System.out.println("before(getLength)->" + fe.getFile().getLength()); // } // } }
@Override public void before(@NotNull List<? extends VFileEvent> vFileEvents) { for (VFileEvent fe : vFileEvents) { if(fe.getFile()!=null){ System.out.println("before(getCanonicalPath)->" + fe.getFile().getCanonicalPath()); System.out.println("before(getName)->" + fe.getFile().getName()); System.out.println("before(getLength)->" + fe.getFile().getLength()); } } }
@Override public void after(@NotNull List<? extends VFileEvent> vFileEvents) { for (VFileEvent fe : vFileEvents) { System.out.println("after(getName)->" + fe.getFile().getName()); System.out.println("after(getLength)->" + fe.getFile().getLength()); } }
public NonClasspathClassFinder(Project project, String... fileExtensions) { myProject = project; myManager = PsiManager.getInstance(myProject); myFileExtensions = ArrayUtil.append(fileExtensions, "class"); final MessageBusConnection connection = project.getMessageBus().connect(project); connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { clearCache(); } }); }
private void checkSubscription() { if (mySubscribed.getAndSet(true)) return; Application app = ApplicationManager.getApplication(); app.getMessageBus().connect(app).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { Set<VirtualFile> toRefresh = null; for (VFileEvent event : events) { if (event.getFileSystem() instanceof LocalFileSystem && event instanceof VFileContentChangeEvent) { VirtualFile file = event.getFile(); if (file != null && "jimage".equals(file.getExtension())) { String homePath = file.getParent().getParent().getParent().getPath(); if (myHandlers.remove(homePath) != null) { VirtualFile root = findFileByPath(composeRootPath(homePath)); if (root != null) { ((NewVirtualFile)root).markDirtyRecursively(); if (toRefresh == null) toRefresh = ContainerUtil.newHashSet(); toRefresh.add(root); } } } } } if (toRefresh != null) { boolean async = !ApplicationManager.getApplication().isUnitTestMode(); RefreshQueue.getInstance().refresh(async, true, null, toRefresh); } } }); }
boolean resetOnEvents(@NotNull List<? extends VFileEvent> events) { for (VFileEvent event : events) { VirtualFile file = event.getFile(); if (file == null || file.isDirectory()) { return true; } } return false; }
public void testJarRefresh() throws IOException { File jar = IoTestUtil.createTestJar(); assertTrue(jar.setLastModified(jar.lastModified() - 1000)); VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jar); assertNotNull(vFile); VirtualFile jarRoot = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR); assertEquals(1, jarRoot.getChildren().length); final VirtualFile entry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + JarFile.MANIFEST_NAME); assertContent(entry, ""); final Ref<Boolean> updated = Ref.create(false); ApplicationManager.getApplication().getMessageBus().connect(myTestRootDisposable).subscribe( VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void before(@NotNull List<? extends VFileEvent> events) { for (VFileEvent event : events) { if (event instanceof VFileContentChangeEvent && entry.equals(event.getFile())) { updated.set(true); break; } } } } ); IoTestUtil.createTestJar(jar, JarFile.MANIFEST_NAME, "update", "some.txt", "some text"); vFile.refresh(false, false); assertTrue(updated.get()); assertTrue(entry.isValid()); assertContent(entry, "update"); assertEquals(2, jarRoot.getChildren().length); VirtualFile newEntry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + "some.txt"); assertContent(newEntry, "some text"); }
public void testFileContentChangeEvents() throws IOException { File file = IoTestUtil.createTestFile("file.txt"); long stamp = file.lastModified(); VirtualFile vFile = myFS.refreshAndFindFileByIoFile(file); assertNotNull(vFile); int[] updated = {0}; MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(getTestRootDisposable()); connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { for (VFileEvent event : events) { if (event instanceof VFileContentChangeEvent && vFile.equals(event.getFile())) { updated[0]++; break; } } } }); FileUtil.writeToFile(file, "content"); assertTrue(file.setLastModified(stamp)); vFile.refresh(false, false); assertEquals(1, updated[0]); FileUtil.writeToFile(file, "more content"); assertTrue(file.setLastModified(stamp)); vFile.refresh(false, false); assertEquals(2, updated[0]); }
@Override public void after(@NotNull List<? extends VFileEvent> events) { for (VFileEvent event : events) { String filePath = event.getPath(); for (VcsRootChecker checker : myCheckers) { if (checker.isVcsDir(filePath)) { scheduleScan(); break; } } } }
@Override public void after(@NotNull List<? extends VFileEvent> events) { myContentlessIndicesUpdateQueue.ensureUpToDate(); for (VFileEvent event : events) { BulkVirtualFileListenerAdapter.fireAfter(this, event); } myContentlessIndicesUpdateQueue.signalUpdateEnd(); }
@Override public void after(@NotNull List<? extends VFileEvent> events) { final VirtualFile[] roots = mySdk.getRootProvider().getFiles(OrderRootType.CLASSES); for (VFileEvent event : events) { final VirtualFile file = event.getFile(); if (file != null) { for (VirtualFile root : roots) { if (VfsUtilCore.isAncestor(root, file, false)) { clearCaches(); return; } } } } }
public VFSTestFrameworkListener() { myService = PyTestFrameworkService.getInstance(); MessageBus messageBus = ApplicationManager.getApplication().getMessageBus(); messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener.Adapter() { @Override public void after(@NotNull List<? extends VFileEvent> events) { for (VFileEvent event : events) { if (!(event.getFileSystem() instanceof LocalFileSystem) || event instanceof VFileContentChangeEvent) continue; final String path = event.getPath(); boolean containsNose = path.contains(PyNames.NOSE_TEST); boolean containsPy = path.contains("py-1") || path.contains(PyNames.PY_TEST); boolean containsAt = path.contains(PyNames.AT_TEST); if (!containsAt && !containsNose && !containsPy) continue; for (Sdk sdk : PythonSdkType.getAllSdks()) { if (PySdkUtil.isRemote(sdk)) { continue; } for (VirtualFile virtualFile : sdk.getRootProvider().getFiles(OrderRootType.CLASSES)) { String root = virtualFile.getCanonicalPath(); if (root != null && path.contains(root)) { if (containsNose) { updateTestFrameworks(sdk, PyNames.NOSE_TEST); return; } else if (containsPy) { updateTestFrameworks(sdk, PyNames.PY_TEST); return; } else { updateTestFrameworks(sdk, PyNames.AT_TEST); return; } } } } } } }); }
@Override public void after(@NotNull List<? extends VFileEvent> events) { final Set<VirtualFile> filesToProcess = getFilesToProcess(events); if (filesToProcess.size() > 0) { myQueue.queue(new MyUpdate(filesToProcess)); } }
@NotNull private static Set<VirtualFile> getFilesToProcess(@NotNull List<? extends VFileEvent> events) { final Set<VirtualFile> result = new HashSet<VirtualFile>(); for (VFileEvent event : events) { final VirtualFile file = event.getFile(); if (file != null && shouldScheduleUpdate(file)) { result.add(file); } } return result; }