use of com.intellij.openapi.vfs.newvfs.events.VFileEvent in project intellij-community by JetBrains.
the class HgRepositoryUpdater method after.
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
// which files in .hg were changed
boolean branchHeadsChanged = false;
boolean branchFileChanged = false;
boolean dirstateFileChanged = false;
boolean mergeFileChanged = false;
boolean rebaseFileChanged = false;
boolean bookmarksFileChanged = false;
boolean tagsFileChanged = false;
boolean localTagsFileChanged = false;
boolean currentBookmarkFileChanged = false;
boolean mqChanged = false;
boolean hgIgnoreChanged = false;
boolean configHgrcChanged = false;
for (VFileEvent event : events) {
String filePath = event.getPath();
if (filePath == null) {
continue;
}
if (myRepositoryFiles.isbranchHeadsFile(filePath)) {
branchHeadsChanged = true;
} else if (myRepositoryFiles.isBranchFile(filePath)) {
branchFileChanged = true;
DvcsUtil.ensureAllChildrenInVfs(myBranchHeadsDir);
} else if (myRepositoryFiles.isDirstateFile(filePath)) {
dirstateFileChanged = true;
} else if (myRepositoryFiles.isMergeFile(filePath)) {
mergeFileChanged = true;
} else if (myRepositoryFiles.isRebaseFile(filePath)) {
rebaseFileChanged = true;
} else if (myRepositoryFiles.isBookmarksFile(filePath)) {
bookmarksFileChanged = true;
} else if (myRepositoryFiles.isTagsFile(filePath)) {
tagsFileChanged = true;
} else if (myRepositoryFiles.isLocalTagsFile(filePath)) {
localTagsFileChanged = true;
} else if (myRepositoryFiles.isCurrentBookmarksFile(filePath)) {
currentBookmarkFileChanged = true;
} else if (myRepositoryFiles.isMqFile(filePath)) {
mqChanged = true;
if (myMqDir == null) {
myMqDir = VcsUtil.getVirtualFile(myRepositoryFiles.getMQDirPath());
}
DvcsUtil.ensureAllChildrenInVfs(myMqDir);
} else if (myRepositoryFiles.isConfigHgrcFile(filePath)) {
configHgrcChanged = true;
} else if (myRepositoryFiles.isHgIgnore(filePath)) {
hgIgnoreChanged = true;
}
}
if (branchHeadsChanged || branchFileChanged || dirstateFileChanged || mergeFileChanged || rebaseFileChanged || bookmarksFileChanged || currentBookmarkFileChanged || tagsFileChanged || localTagsFileChanged || mqChanged) {
myUpdateQueue.queue(new MyUpdater("hgrepositoryUpdate"));
}
if (configHgrcChanged) {
myUpdateConfigQueue.queue(new MyUpdater("hgconfigUpdate"));
}
if (dirstateFileChanged || hgIgnoreChanged) {
myRepository.getLocalIgnoredHolder().startRescan();
final VirtualFile root = myRepository.getRoot();
myDirtyScopeManager.dirDirtyRecursively(root);
if (dirstateFileChanged) {
//update async incoming/outgoing model
myProject.getMessageBus().syncPublisher(HgVcs.REMOTE_TOPIC).update(myProject, root);
}
}
}
use of com.intellij.openapi.vfs.newvfs.events.VFileEvent 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.VFileEvent in project intellij-community by JetBrains.
the class LocalFileSystemTest method doTestInterruptedRefresh.
public static void doTestInterruptedRefresh(@NotNull File top) throws Exception {
for (int i = 1; i <= 3; i++) {
File sub = IoTestUtil.createTestDir(top, "sub_" + i);
for (int j = 1; j <= 3; j++) {
IoTestUtil.createTestDir(sub, "sub_" + j);
}
}
Files.walkFileTree(top.toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
for (int k = 1; k <= 3; k++) {
IoTestUtil.createTestFile(dir.toFile(), "file_" + k, ".");
}
return FileVisitResult.CONTINUE;
}
});
VirtualFile topDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(top);
assertNotNull(topDir);
Set<VirtualFile> files = ContainerUtil.newHashSet();
VfsUtilCore.processFilesRecursively(topDir, file -> {
if (!file.isDirectory())
files.add(file);
return true;
});
// 13 dirs of 3 files
assertEquals(39, files.size());
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 {
files.forEach(f -> IoTestUtil.updateFile(new File(f.getPath()), "+++"));
((NewVirtualFile) topDir).markDirtyRecursively();
RefreshWorker.setCancellingCondition(file -> file.getPath().endsWith(top.getName() + "/sub_2/file_2"));
topDir.refresh(false, true);
assertThat(processed.size()).isGreaterThan(0).isLessThan(files.size());
RefreshWorker.setCancellingCondition(null);
topDir.refresh(false, true);
assertThat(processed).isEqualTo(files);
} finally {
connection.disconnect();
RefreshWorker.setCancellingCondition(null);
}
}
use of com.intellij.openapi.vfs.newvfs.events.VFileEvent 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.VFileEvent in project intellij-community by JetBrains.
the class VfsImplUtil method checkSubscription.
private static void checkSubscription() {
if (ourSubscribed.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) {
InvalidationState state = null;
synchronized (ourLock) {
for (VFileEvent event : events) {
if (!(event.getFileSystem() instanceof LocalFileSystem))
continue;
// created file should not invalidate + getFile is costly
if (event instanceof VFileCreateEvent)
continue;
if (event instanceof VFilePropertyChangeEvent && !VirtualFile.PROP_NAME.equals(((VFilePropertyChangeEvent) event).getPropertyName())) {
continue;
}
String path = event.getPath();
if (event instanceof VFilePropertyChangeEvent) {
path = ((VFilePropertyChangeEvent) event).getOldPath();
} else if (event instanceof VFileMoveEvent) {
path = ((VFileMoveEvent) event).getOldPath();
}
VirtualFile file = event.getFile();
if (file == null || !file.isDirectory()) {
state = InvalidationState.invalidate(state, path);
} else {
Collection<String> affectedPaths = ourDominatorsMap.get(path);
if (affectedPaths != null) {
// defensive copying; original may be updated on invalidation
affectedPaths = ContainerUtil.newArrayList(affectedPaths);
for (String affectedPath : affectedPaths) {
state = InvalidationState.invalidate(state, affectedPath);
}
}
}
}
}
if (state != null)
state.scheduleRefresh();
}
});
}
Aggregations