use of com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent in project intellij-community by JetBrains.
the class JarFileSystemTest method testJarRefresh.
@Test
public void testJarRefresh() throws IOException {
File jar = IoTestUtil.createTestJar(tempDir.newFile("test.jar"));
assertTrue(jar.setLastModified(jar.lastModified() - 1000));
VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(jar);
assertNotNull(vFile);
VirtualFile jarRoot = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR);
assertThat(Stream.of(jarRoot.getChildren()).map(VirtualFile::getName)).containsExactly("META-INF");
VirtualFile entry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + JarFile.MANIFEST_NAME);
assertEquals("", VfsUtilCore.loadText(entry));
Ref<Boolean> updated = Ref.create(false);
ApplicationManager.getApplication().getMessageBus().connect(getTestRootDisposable()).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@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());
assertEquals("update", VfsUtilCore.loadText(entry));
assertThat(Stream.of(jarRoot.getChildren()).map(VirtualFile::getName)).containsExactlyInAnyOrder("META-INF", "some.txt");
VirtualFile newEntry = findByPath(jar.getPath() + JarFileSystem.JAR_SEPARATOR + "some.txt");
assertEquals("some text", VfsUtilCore.loadText(newEntry));
}
use of com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent in project intellij-community by JetBrains.
the class LocalFileSystemTest method testFileContentChangeEvents.
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() {
@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]);
}
use of com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent in project intellij-community by JetBrains.
the class JrtFileSystemImpl method checkSubscription.
private void checkSubscription() {
if (mySubscribed.getAndSet(true))
return;
Application app = ApplicationManager.getApplication();
app.getMessageBus().connect(app).subscribe(VirtualFileManager.VFS_CHANGES, new BulkFileListener() {
@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 && "release".equals(file.getName())) {
String homePath = file.getParent().getPath();
ArchiveHandler handler = myHandlers.remove(homePath);
if (handler != null) {
handler.dispose();
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);
}
}
});
}
use of com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent 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.events.VFileContentChangeEvent in project intellij by bazelbuild.
the class BulkSymbolTableBuildingChangeListener method after.
@Override
public void after(List<? extends VFileEvent> events) {
if (!enabled) {
return;
}
for (VFileEvent event : events) {
VirtualFile modifiedFile = null;
// Skip delete events.
if (event instanceof VFileContentChangeEvent || event instanceof VFileCreateEvent) {
modifiedFile = event.getFile();
} else if (event instanceof VFileCopyEvent) {
VFileCopyEvent copyEvent = (VFileCopyEvent) event;
modifiedFile = copyEvent.getNewParent();
} else if (event instanceof VFileMoveEvent) {
VFileMoveEvent moveEvent = (VFileMoveEvent) event;
modifiedFile = moveEvent.getNewParent();
} else if (event instanceof VFilePropertyChangeEvent) {
VFilePropertyChangeEvent propEvent = (VFilePropertyChangeEvent) event;
// actually changing though)
if (propEvent.getPropertyName().equals(VirtualFile.PROP_NAME) && !propEvent.getOldValue().equals(propEvent.getNewValue())) {
modifiedFile = propEvent.getFile();
}
}
if (SymbolTableProvider.isSourceFile(modifiedFile)) {
queueChange(modifiedFile);
}
}
}
Aggregations