use of com.intellij.openapi.vfs.newvfs.BulkFileListener in project intellij-community by JetBrains.
the class JarDirectoryWatcherImpl method updateWatchedRoots.
@Override
public void updateWatchedRoots() {
final LocalFileSystem fs = LocalFileSystem.getInstance();
if (!myJarDirectories.isEmpty()) {
final Set<String> recursiveRoots = new HashSet<>();
final Set<String> flatRoots = new HashSet<>();
final VirtualFileManager fm = VirtualFileManager.getInstance();
for (OrderRootType rootType : myJarDirectories.getRootTypes()) {
for (String url : myJarDirectories.getDirectories(rootType)) {
if (fm.getFileSystem(VirtualFileManager.extractProtocol(url)) instanceof LocalFileSystem) {
final boolean watchRecursively = myJarDirectories.isRecursive(rootType, url);
final String path = VirtualFileManager.extractPath(url);
(watchRecursively ? recursiveRoots : flatRoots).add(path);
}
}
}
myWatchRequests = fs.replaceWatchedRoots(myWatchRequests, recursiveRoots, flatRoots);
if (myBusConnection == null) {
myBusConnection = ApplicationManager.getApplication().getMessageBus().connect();
myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@Override
public void after(@NotNull final List<? extends VFileEvent> events) {
boolean changesDetected = false;
for (VFileEvent event : events) {
if (event instanceof VFileCopyEvent) {
final VFileCopyEvent copyEvent = (VFileCopyEvent) event;
final VirtualFile file = copyEvent.getFile();
if (isUnderJarDirectory(copyEvent.getNewParent() + "/" + copyEvent.getNewChildName()) || file != null && isUnderJarDirectory(file.getUrl())) {
changesDetected = true;
break;
}
} else if (event instanceof VFileMoveEvent) {
final VFileMoveEvent moveEvent = (VFileMoveEvent) event;
final VirtualFile file = moveEvent.getFile();
if (file != null && (isUnderJarDirectory(file.getUrl()) || isUnderJarDirectory(moveEvent.getOldParent().getUrl() + "/" + file.getName()))) {
changesDetected = true;
break;
}
} else if (event instanceof VFileDeleteEvent) {
final VFileDeleteEvent deleteEvent = (VFileDeleteEvent) event;
if (isUnderJarDirectory(deleteEvent.getFile().getUrl())) {
changesDetected = true;
break;
}
} else if (event instanceof VFileCreateEvent) {
final VFileCreateEvent createEvent = (VFileCreateEvent) event;
if (isUnderJarDirectory(createEvent.getParent().getUrl() + "/" + createEvent.getChildName())) {
changesDetected = true;
break;
}
}
}
if (changesDetected) {
fireRootSetChanged();
}
}
private boolean isUnderJarDirectory(String url) {
for (String rootUrl : myJarDirectories.getAllDirectories()) {
if (FileUtil.startsWith(url, rootUrl)) {
return true;
}
}
return false;
}
});
}
} else {
cleanup();
}
}
use of com.intellij.openapi.vfs.newvfs.BulkFileListener in project intellij-community by JetBrains.
the class DirectoryIndexImpl method subscribeToFileChanges.
protected void subscribeToFileChanges() {
myConnection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() {
@Override
public void fileTypesChanged(@NotNull FileTypeEvent event) {
myRootIndex = null;
}
});
myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@Override
public void rootsChanged(ModuleRootEvent event) {
myRootIndex = null;
}
});
myConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
RootIndex rootIndex = myRootIndex;
if (rootIndex != null && rootIndex.resetOnEvents(events)) {
myRootIndex = null;
}
}
});
}
use of com.intellij.openapi.vfs.newvfs.BulkFileListener in project intellij-community by JetBrains.
the class FileContentUtilCore method reparseFiles.
/**
* 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(() -> {
// files must be processed under one write action to prevent firing event for invalid files.
final Set<VFilePropertyChangeEvent> events = new THashSet<>();
for (VirtualFile file : files) {
saveOrReload(file, events);
}
BulkFileListener publisher = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
List<VFileEvent> eventList = new ArrayList<>(events);
publisher.before(eventList);
publisher.after(eventList);
});
}
use of com.intellij.openapi.vfs.newvfs.BulkFileListener in project intellij-community by JetBrains.
the class SvnTestCase method imitateEvent.
public static void imitateEvent(VirtualFile dir) {
final VirtualFile child = dir.findChild(".svn");
assertNotNull(child);
final VirtualFile wcdb = child.findChild("wc.db");
assertNotNull(wcdb);
final BulkFileListener listener = ApplicationManager.getApplication().getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
final VFileContentChangeEvent event = new VFileContentChangeEvent(null, wcdb, wcdb.getModificationStamp() - 1, wcdb.getModificationStamp(), true);
final List<VFileContentChangeEvent> events = Collections.singletonList(event);
listener.before(events);
listener.after(events);
}
use of com.intellij.openapi.vfs.newvfs.BulkFileListener in project intellij-community by JetBrains.
the class VirtualFileManagerImpl method notifyPropertyChanged.
@Override
public void notifyPropertyChanged(@NotNull final VirtualFile virtualFile, @NotNull final String property, final Object oldValue, final Object newValue) {
final Application application = ApplicationManager.getApplication();
final Runnable runnable = new Runnable() {
@Override
public void run() {
if (virtualFile.isValid() && !application.isDisposed()) {
application.runWriteAction(new Runnable() {
@Override
public void run() {
List<VFilePropertyChangeEvent> events = Collections.singletonList(new VFilePropertyChangeEvent(this, virtualFile, property, oldValue, newValue, false));
BulkFileListener listener = application.getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES);
listener.before(events);
listener.after(events);
}
});
}
}
};
application.invokeLater(runnable, ModalityState.NON_MODAL);
}
Aggregations