Search in sources :

Example 1 with ManagingFS

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());
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) DataOutputStream(java.io.DataOutputStream) ManagingFS(com.intellij.openapi.vfs.newvfs.ManagingFS) FileAttribute(com.intellij.openapi.vfs.newvfs.FileAttribute)

Example 2 with ManagingFS

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VfsUtilCore(com.intellij.openapi.vfs.VfsUtilCore) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Collection(java.util.Collection) ExcludeEntryDescription(com.intellij.openapi.compiler.options.ExcludeEntryDescription) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Set(java.util.Set) FileType(com.intellij.openapi.fileTypes.FileType) Collectors(java.util.stream.Collectors) Stream(java.util.stream.Stream) ManagingFS(com.intellij.openapi.vfs.newvfs.ManagingFS) Project(com.intellij.openapi.project.Project) NotNull(org.jetbrains.annotations.NotNull) ManagingFS(com.intellij.openapi.vfs.newvfs.ManagingFS)

Example 3 with ManagingFS

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()));
        });
    }
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) AccessToken(com.intellij.openapi.application.AccessToken) ManagingFS(com.intellij.openapi.vfs.newvfs.ManagingFS)

Aggregations

ManagingFS (com.intellij.openapi.vfs.newvfs.ManagingFS)3 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)2 AccessToken (com.intellij.openapi.application.AccessToken)1 ExcludeEntryDescription (com.intellij.openapi.compiler.options.ExcludeEntryDescription)1 FileType (com.intellij.openapi.fileTypes.FileType)1 Project (com.intellij.openapi.project.Project)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 VfsUtilCore (com.intellij.openapi.vfs.VfsUtilCore)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 FileAttribute (com.intellij.openapi.vfs.newvfs.FileAttribute)1 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)1 DataOutputStream (java.io.DataOutputStream)1 Collection (java.util.Collection)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 NotNull (org.jetbrains.annotations.NotNull)1