Search in sources :

Example 1 with JarFileSystem

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

the class PathEditor method isJarFile.

private static boolean isJarFile(final VirtualFile file) {
    return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {

        @Override
        public Boolean compute() {
            VirtualFile tempFile = file;
            if ((file.getFileSystem() instanceof JarFileSystem) && file.getParent() == null) {
                //[myakovlev] It was bug - directories with *.jar extensions was saved as files of JarFileSystem.
                //    so we can not just return true, we should filter such directories.
                String path = file.getPath().substring(0, file.getPath().length() - JarFileSystem.JAR_SEPARATOR.length());
                tempFile = LocalFileSystem.getInstance().findFileByPath(path);
            }
            if (tempFile != null && !tempFile.isDirectory()) {
                return Boolean.valueOf(tempFile.getFileType().equals(FileTypes.ARCHIVE));
            }
            return Boolean.FALSE;
        }
    }).booleanValue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Computable(com.intellij.openapi.util.Computable)

Example 2 with JarFileSystem

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

the class ShowFilePathAction method show.

private static void show(@NotNull VirtualFile file, @NotNull Consumer<ListPopup> action) {
    if (!isSupported())
        return;
    List<VirtualFile> files = new ArrayList<>();
    List<String> fileUrls = new ArrayList<>();
    VirtualFile eachParent = file;
    while (eachParent != null) {
        int index = files.size();
        files.add(index, eachParent);
        fileUrls.add(index, getPresentableUrl(eachParent));
        if (eachParent.getParent() == null && eachParent.getFileSystem() instanceof JarFileSystem) {
            eachParent = JarFileSystem.getInstance().getVirtualFileForJar(eachParent);
            if (eachParent == null)
                break;
        }
        eachParent = eachParent.getParent();
    }
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        List<Icon> icons = new ArrayList<>();
        for (String url : fileUrls) {
            File ioFile = new File(url);
            icons.add(ioFile.exists() ? FileSystemView.getFileSystemView().getSystemIcon(ioFile) : EmptyIcon.ICON_16);
        }
        ApplicationManager.getApplication().invokeLater(() -> action.consume(createPopup(files, icons)));
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) ArrayList(java.util.ArrayList) EmptyIcon(com.intellij.util.ui.EmptyIcon) VirtualFile(com.intellij.openapi.vfs.VirtualFile) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 3 with JarFileSystem

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

the class FileTreeStructure method getChildElements.

public Object[] getChildElements(Object nodeElement) {
    if (!(nodeElement instanceof FileElement)) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    FileElement element = (FileElement) nodeElement;
    VirtualFile file = element.getFile();
    if (file == null || !file.isValid()) {
        if (element == myRootElement) {
            return myRootElement.getChildren();
        }
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    VirtualFile[] children = null;
    if (element.isArchive() && myChooserDescriptor.isChooseJarContents()) {
        String path = file.getPath();
        if (!(file.getFileSystem() instanceof JarFileSystem)) {
            file = JarFileSystem.getInstance().findFileByPath(path + JarFileSystem.JAR_SEPARATOR);
        }
        if (file != null) {
            children = file.getChildren();
        }
    } else {
        children = file.getChildren();
    }
    if (children == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    Set<FileElement> childrenSet = new HashSet<>();
    for (VirtualFile child : children) {
        if (myChooserDescriptor.isFileVisible(child, myShowHidden)) {
            final FileElement childElement = new FileElement(child, child.getName());
            childElement.setParent(element);
            childrenSet.add(childElement);
        }
    }
    return ArrayUtil.toObjectArray(childrenSet);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) FileElement(com.intellij.openapi.fileChooser.FileElement) RootFileElement(com.intellij.openapi.fileChooser.ex.RootFileElement) HashSet(java.util.HashSet)

Example 4 with JarFileSystem

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

the class IdeaSpecificSettings method appendModuleRelatedRoot.

public static void appendModuleRelatedRoot(Element element, String classesUrl, final String rootName, ModuleRootModel model) {
    VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(classesUrl);
    if (file == null) {
        return;
    }
    final Project project = model.getModule().getProject();
    if (file.getFileSystem() instanceof JarFileSystem) {
        file = JarFileSystem.getInstance().getVirtualFileForJar(file);
        assert file != null;
    }
    final Module module = ModuleUtilCore.findModuleForFile(file, project);
    if (module != null) {
        appendRelatedToModule(element, classesUrl, rootName, file, module);
    } else if (ProjectRootManager.getInstance(project).getFileIndex().isExcluded(file)) {
        for (Module aModule : ModuleManager.getInstance(project).getModules()) {
            if (appendRelatedToModule(element, classesUrl, rootName, file, aModule)) {
                return;
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Module(com.intellij.openapi.module.Module)

Example 5 with JarFileSystem

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

the class IdeaJdk method addSources.

private static void addSources(File file, SdkModificator sdkModificator) {
    final File src = new File(new File(file, LIB_DIR_NAME), SRC_DIR_NAME);
    if (!src.exists())
        return;
    File[] srcs = src.listFiles(pathname -> {
        @NonNls final String path = pathname.getPath();
        if (path.contains("generics"))
            return false;
        return path.endsWith(".jar") || path.endsWith(".zip");
    });
    for (int i = 0; srcs != null && i < srcs.length; i++) {
        File jarFile = srcs[i];
        if (jarFile.exists()) {
            JarFileSystem jarFileSystem = JarFileSystem.getInstance();
            String path = jarFile.getAbsolutePath().replace(File.separatorChar, '/') + JarFileSystem.JAR_SEPARATOR;
            jarFileSystem.setNoCopyJarForPath(path);
            VirtualFile vFile = jarFileSystem.findFileByPath(path);
            sdkModificator.addRoot(vFile, OrderRootType.SOURCES);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) NonNls(org.jetbrains.annotations.NonNls) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Aggregations

JarFileSystem (com.intellij.openapi.vfs.JarFileSystem)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 Nullable (org.jetbrains.annotations.Nullable)7 Module (com.intellij.openapi.module.Module)6 Project (com.intellij.openapi.project.Project)5 File (java.io.File)4 NonNls (org.jetbrains.annotations.NonNls)4 NotNull (org.jetbrains.annotations.NotNull)4 ArrayList (java.util.ArrayList)3 FileElement (com.intellij.openapi.fileChooser.FileElement)2 RootFileElement (com.intellij.openapi.fileChooser.ex.RootFileElement)2 VirtualFileSystem (com.intellij.openapi.vfs.VirtualFileSystem)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 ZipFile (java.util.zip.ZipFile)2 ArchiveFileType (com.intellij.ide.highlighter.ArchiveFileType)1 PsiDirectoryNode (com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 ParamValue (com.intellij.javaee.model.xml.ParamValue)1 Filter (com.intellij.javaee.model.xml.web.Filter)1 WebApp (com.intellij.javaee.model.xml.web.WebApp)1