Search in sources :

Example 1 with ArchiveHandler

use of com.intellij.openapi.vfs.impl.ArchiveHandler in project intellij-community by JetBrains.

the class JrtFileSystemImpl method getHandler.

@NotNull
@Override
protected ArchiveHandler getHandler(@NotNull VirtualFile entryFile) {
    checkSubscription();
    String homePath = extractLocalPath(extractRootPath(entryFile.getPath()));
    ArchiveHandler handler = myHandlers.get(homePath);
    if (handler == null) {
        handler = new JrtHandler(homePath);
        myHandlers.put(homePath, handler);
        ApplicationManager.getApplication().invokeLater(() -> LocalFileSystem.getInstance().refreshAndFindFileByPath(homePath + "/release"), ModalityState.defaultModalityState());
    }
    return handler;
}
Also used : ArchiveHandler(com.intellij.openapi.vfs.impl.ArchiveHandler) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with ArchiveHandler

use of com.intellij.openapi.vfs.impl.ArchiveHandler 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 3 with ArchiveHandler

use of com.intellij.openapi.vfs.impl.ArchiveHandler in project intellij-community by JetBrains.

the class VfsImplUtil method getHandler.

@NotNull
public static <T extends ArchiveHandler> T getHandler(@NotNull ArchiveFileSystem vfs, @NotNull String localPath, @NotNull Function<String, T> producer) {
    checkSubscription();
    ArchiveHandler handler;
    synchronized (ourLock) {
        Pair<ArchiveFileSystem, ArchiveHandler> record = ourHandlers.get(localPath);
        if (record == null) {
            handler = producer.fun(localPath);
            record = Pair.create(vfs, handler);
            ourHandlers.put(localPath, record);
            final String finalRootPath = localPath;
            forEachDirectoryComponent(localPath, containingDirectoryPath -> {
                Set<String> handlers = ourDominatorsMap.get(containingDirectoryPath);
                if (handlers == null) {
                    ourDominatorsMap.put(containingDirectoryPath, handlers = ContainerUtil.newTroveSet());
                }
                handlers.add(finalRootPath);
            });
        }
        handler = record.second;
    }
    @SuppressWarnings("unchecked") T t = (T) handler;
    return t;
}
Also used : ArchiveHandler(com.intellij.openapi.vfs.impl.ArchiveHandler) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ArchiveHandler (com.intellij.openapi.vfs.impl.ArchiveHandler)3 NotNull (org.jetbrains.annotations.NotNull)2 Application (com.intellij.openapi.application.Application)1 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 BulkFileListener (com.intellij.openapi.vfs.newvfs.BulkFileListener)1 NewVirtualFile (com.intellij.openapi.vfs.newvfs.NewVirtualFile)1 VFileContentChangeEvent (com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent)1 VFileEvent (com.intellij.openapi.vfs.newvfs.events.VFileEvent)1 Set (java.util.Set)1