use of com.intellij.openapi.vfs.newvfs.ManagingFS in project intellij-community by JetBrains.
the class PersistentFsTest method testModCountNotIncreases.
public void testModCountNotIncreases() throws IOException {
VirtualFile vFile = setupFile();
ManagingFS managingFS = ManagingFS.getInstance();
final int globalModCount = managingFS.getFilesystemModificationCount();
final int parentModCount = managingFS.getModificationCount(vFile.getParent());
int inSessionModCount = managingFS.getModificationCount();
FSRecords.force();
assertFalse(FSRecords.isDirty());
FileAttribute attribute = new FileAttribute("test.attribute", 1, true);
WriteAction.run(() -> {
try (DataOutputStream output = attribute.writeAttribute(vFile)) {
DataInputOutputUtil.writeINT(output, 1);
}
});
assertEquals(globalModCount, managingFS.getModificationCount(vFile));
assertEquals(globalModCount, managingFS.getFilesystemModificationCount());
assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent()));
assertEquals(inSessionModCount + 1, managingFS.getModificationCount());
assertTrue(FSRecords.isDirty());
FSRecords.force();
assertFalse(FSRecords.isDirty());
//
int fileId = ((VirtualFileWithId) vFile).getId();
FSRecords.setTimestamp(fileId, FSRecords.getTimestamp(fileId));
FSRecords.setLength(fileId, FSRecords.getLength(fileId));
assertEquals(globalModCount, managingFS.getModificationCount(vFile));
assertEquals(globalModCount, managingFS.getFilesystemModificationCount());
assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent()));
assertEquals(inSessionModCount + 1, managingFS.getModificationCount());
assertFalse(FSRecords.isDirty());
}
use of com.intellij.openapi.vfs.newvfs.ManagingFS in project intellij-community by JetBrains.
the class ExcludedFromCompileFilesUtil method getExcludedFilesScope.
static GlobalSearchScope getExcludedFilesScope(@NotNull ExcludeEntryDescription[] descriptions, @NotNull Set<FileType> fileTypes, @NotNull Project project, @NotNull ProjectFileIndex fileIndex) {
ManagingFS fs = ManagingFS.getInstance();
final Collection<VirtualFile> excludedFiles = Stream.of(descriptions).flatMap(description -> {
final VirtualFile file = description.getVirtualFile();
if (file == null)
return Stream.empty();
if (description.isFile()) {
return Stream.of(file);
} else if (description.isIncludeSubdirectories()) {
final Stream.Builder<VirtualFile> builder = Stream.builder();
VfsUtilCore.iterateChildrenRecursively(file, f -> !f.isDirectory() || fs.areChildrenLoaded(f), f -> {
builder.accept(f);
return true;
});
return builder.build();
} else {
return fs.areChildrenLoaded(file) ? Stream.of(file.getChildren()) : Stream.empty();
}
}).filter(f -> !f.isDirectory() && fileTypes.contains(f.getFileType()) && fileIndex.isInSourceContent(f)).collect(Collectors.toList());
return GlobalSearchScope.filesWithoutLibrariesScope(project, excludedFiles);
}
use of com.intellij.openapi.vfs.newvfs.ManagingFS in project intellij-community by JetBrains.
the class PersistentFsTest method testModCountIncreases.
public void testModCountIncreases() throws IOException {
VirtualFile vFile = setupFile();
ManagingFS managingFS = ManagingFS.getInstance();
int inSessionModCount = managingFS.getModificationCount();
int globalModCount = managingFS.getFilesystemModificationCount();
final int parentModCount = managingFS.getModificationCount(vFile.getParent());
WriteAction.run(() -> vFile.setWritable(false));
assertEquals(globalModCount + 1, managingFS.getModificationCount(vFile));
assertEquals(globalModCount + 1, managingFS.getFilesystemModificationCount());
assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent()));
assertEquals(inSessionModCount + 1, managingFS.getModificationCount());
FSRecords.force();
assertFalse(FSRecords.isDirty());
++globalModCount;
int finalGlobalModCount = globalModCount;
try (AccessToken ignore = HeavyProcessLatch.INSTANCE.processStarted("This test wants no indices flush")) {
WriteAction.run(() -> {
final long timestamp = vFile.getTimeStamp();
int finalInSessionModCount = managingFS.getModificationCount();
// 1 change
vFile.setWritable(true);
// content change + length change + maybe timestamp change
vFile.setBinaryContent("foo".getBytes(Charset.defaultCharset()));
// we check in write action to avoid observing background thread to index stuff
final int changesCount = timestamp == vFile.getTimeStamp() ? 3 : 4;
assertEquals(finalGlobalModCount + changesCount, managingFS.getModificationCount(vFile));
assertEquals(finalGlobalModCount + changesCount, managingFS.getFilesystemModificationCount());
assertEquals(finalInSessionModCount + changesCount, managingFS.getModificationCount());
assertEquals(parentModCount, managingFS.getModificationCount(vFile.getParent()));
});
}
}
Aggregations