use of com.intellij.openapi.vfs.newvfs.events.VFileEvent in project intellij-leiningen-plugin by derkork.
the class LeiningenProjectsManagerWatcher method start.
public synchronized void start() {
final MessageBusConnection myBusConnection = project.getMessageBus().connect(myQueue);
myBusConnection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
public void before(List<? extends VFileEvent> vFileEvents) {
}
public void after(List<? extends VFileEvent> vFileEvents) {
for (VFileEvent vFileEvent : vFileEvents) {
// }
if (vFileEvent instanceof VFileCreateEvent) {
if (isRelevant(vFileEvent.getPath())) {
manager.importLeiningenProject(vFileEvent.getFileSystem().findFileByPath(vFileEvent.getPath()), project);
}
}
}
}
private boolean isRelevant(String path) {
return path != null && path.endsWith(LeiningenConstants.PROJECT_CLJ);
}
});
myBusConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
public void beforeRootsChange(ModuleRootEvent moduleRootEvent) {
}
public void rootsChanged(ModuleRootEvent moduleRootEvent) {
}
});
myQueue.activate();
}
use of com.intellij.openapi.vfs.newvfs.events.VFileEvent in project intellij-community by JetBrains.
the class JrtFileSystemTest method refresh.
@Test
public void refresh() throws IOException {
assertThat(childNames(myRoot)).containsExactlyInAnyOrder("java.base", "test.a");
Path modules = myTempPath.resolve("lib/modules");
Files.move(modules, myTempPath.resolve("lib/modules.bak"), StandardCopyOption.ATOMIC_MOVE);
Files.copy(myTestData.resolve("image2"), modules);
Files.write(myTempPath.resolve("release"), "JAVA_VERSION=9.0.1\n".getBytes(CharsetToolkit.UTF8_CHARSET));
VirtualFile local = LocalFileSystem.getInstance().findFileByIoFile(myTempDir.getRoot());
assertThat(local).isNotNull();
List<VFileEvent> events = VfsTestUtil.getEvents(() -> local.refresh(false, true));
assertThat(childNames(myRoot)).describedAs("events=" + events).containsExactlyInAnyOrder("java.base", "test.a", "test.b");
}
use of com.intellij.openapi.vfs.newvfs.events.VFileEvent 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.events.VFileEvent in project intellij-community by JetBrains.
the class LocalFileSystemTest method doTestPartialRefresh.
public static void doTestPartialRefresh(@NotNull File top) throws IOException {
File sub = IoTestUtil.createTestDir(top, "sub");
File file1 = IoTestUtil.createTestFile(top, "file1.txt", ".");
File file2 = IoTestUtil.createTestFile(sub, "file2.txt", ".");
LocalFileSystem lfs = LocalFileSystem.getInstance();
VirtualFile topDir = lfs.refreshAndFindFileByIoFile(top);
assertNotNull(topDir);
VirtualFile subDir = lfs.refreshAndFindFileByIoFile(sub);
assertNotNull(subDir);
VirtualFile vFile1 = lfs.refreshAndFindFileByIoFile(file1);
assertNotNull(vFile1);
VirtualFile vFile2 = lfs.refreshAndFindFileByIoFile(file2);
assertNotNull(vFile2);
topDir.refresh(false, true);
Set<VirtualFile> processed = ContainerUtil.newHashSet();
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect();
connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
events.forEach(e -> processed.add(e.getFile()));
}
});
try {
IoTestUtil.updateFile(file1, "++");
IoTestUtil.updateFile(file2, "++");
((NewVirtualFile) topDir).markDirtyRecursively();
topDir.refresh(false, false);
// vFile2 should stay unvisited after non-recursive refresh
assertThat(processed).containsExactly(vFile1);
processed.clear();
topDir.refresh(false, true);
// vFile2 changes should be picked up by a next recursive refresh
assertThat(processed).containsExactly(vFile2);
} finally {
connection.disconnect();
}
}
use of com.intellij.openapi.vfs.newvfs.events.VFileEvent in project intellij-community by JetBrains.
the class LocalFileSystemTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(getTestRootDisposable());
connection.subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@Override
public void before(@NotNull List<? extends VFileEvent> events) {
checkFiles(events, true);
}
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
checkFiles(events, false);
}
private void checkFiles(List<? extends VFileEvent> events, boolean before) {
for (VFileEvent event : events) {
VirtualFile file = event.getFile();
if (file != null) {
boolean shouldBeInvalid = event instanceof VFileCreateEvent && before && !((VFileCreateEvent) event).isReCreation() || event instanceof VFileDeleteEvent && !before;
assertEquals(event.toString(), !shouldBeInvalid, file.isValid());
}
}
}
});
myFS = LocalFileSystem.getInstance();
}
Aggregations