Search in sources :

Example 6 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile 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);
            }
        }
    });
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArchiveHandler(com.intellij.openapi.vfs.impl.ArchiveHandler) Set(java.util.Set) VFileEvent(com.intellij.openapi.vfs.newvfs.events.VFileEvent) VFileContentChangeEvent(com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) BulkFileListener(com.intellij.openapi.vfs.newvfs.BulkFileListener) Application(com.intellij.openapi.application.Application)

Example 7 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.

the class RefreshWorker method checkCancelled.

private void checkCancelled(@NotNull NewVirtualFile stopAt) {
    if (myCancelled || ourCancellingCondition != null && ourCancellingCondition.fun(stopAt)) {
        if (LOG.isTraceEnabled())
            LOG.trace("cancelled at: " + stopAt);
        forceMarkDirty(stopAt);
        while (!myRefreshQueue.isEmpty()) {
            NewVirtualFile next = myRefreshQueue.pullFirst().first;
            forceMarkDirty(next);
        }
        throw new RefreshCancelledException();
    }
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile)

Example 8 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.

the class PersistentFsTest method checkMustCreateRootWithCanonicalPath.

private void checkMustCreateRootWithCanonicalPath(String jarName) throws IOException {
    File tmp = createTempDirectory();
    File x = new File(tmp, jarName);
    assertTrue(x.createNewFile());
    JarFileSystem jfs = JarFileSystem.getInstance();
    String path = x.getPath() + "/../" + x.getName() + JarFileSystem.JAR_SEPARATOR;
    NewVirtualFile root = myFs.findRoot(path, jfs);
    assertFalse(root.getPath(), root.getPath().contains("../"));
    assertFalse(root.getPath(), root.getPath().contains("/.."));
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 9 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.

the class RemoveBomAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    VirtualFile[] files = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(e.getDataContext());
    if (files == null) {
        return;
    }
    List<VirtualFile> filesToProcess = getFilesWithBom(files, true);
    for (VirtualFile virtualFile : filesToProcess) {
        byte[] bom = virtualFile.getBOM();
        assert bom != null;
        if (virtualFile instanceof NewVirtualFile) {
            virtualFile.setBOM(null);
            NewVirtualFile file = (NewVirtualFile) virtualFile;
            try {
                byte[] bytes = file.contentsToByteArray();
                byte[] contentWithStrippedBom = new byte[bytes.length - bom.length];
                System.arraycopy(bytes, bom.length, contentWithStrippedBom, 0, contentWithStrippedBom.length);
                WriteAction.run(() -> file.setBinaryContent(contentWithStrippedBom));
            } catch (IOException ex) {
                LOG.warn("Unexpected exception occurred on attempt to remove BOM from file " + file, ex);
            }
        }
    }
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) IOException(java.io.IOException)

Example 10 with NewVirtualFile

use of com.intellij.openapi.vfs.newvfs.NewVirtualFile in project intellij-community by JetBrains.

the class FileListeningTest method buildDBFileStructure.

private static StringBuilder buildDBFileStructure(@NotNull VirtualFile from, int level, @NotNull StringBuilder builder) {
    List<VirtualFile> children = ContainerUtil.newArrayList(((NewVirtualFile) from).getCachedChildren());
    Collections.sort(children, (o1, o2) -> o1.getName().compareTo(o2.getName()));
    for (VirtualFile eachChild : children) {
        builder.append(StringUtil.repeat(" ", level)).append(eachChild.getName()).append("\n");
        buildDBFileStructure(eachChild, level + 1, builder);
    }
    return builder;
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile)

Aggregations

NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 File (java.io.File)4 VirtualDirectoryImpl (com.intellij.openapi.vfs.newvfs.impl.VirtualDirectoryImpl)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 JobLauncher (com.intellij.concurrency.JobLauncher)1 JobSchedulerImpl (com.intellij.concurrency.JobSchedulerImpl)1 Language (com.intellij.lang.Language)1 ParserDefinition (com.intellij.lang.ParserDefinition)1 Application (com.intellij.openapi.application.Application)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Document (com.intellij.openapi.editor.Document)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 FileType (com.intellij.openapi.fileTypes.FileType)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 ProgressManager (com.intellij.openapi.progress.ProgressManager)1 Project (com.intellij.openapi.project.Project)1 Disposer (com.intellij.openapi.util.Disposer)1 Ref (com.intellij.openapi.util.Ref)1