Search in sources :

Example 11 with JarFileSystem

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

the class ModuleHighlightUtil method getModuleDescriptor.

@Nullable
static PsiJavaModule getModuleDescriptor(@NotNull PsiFileSystemItem fsItem) {
    VirtualFile file = fsItem.getVirtualFile();
    if (file == null)
        return null;
    Project project = fsItem.getProject();
    ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project);
    if (index.isInLibraryClasses(file)) {
        VirtualFile classRoot = index.getClassRootForFile(file);
        if (classRoot != null) {
            VirtualFile descriptorFile = classRoot.findChild(PsiJavaModule.MODULE_INFO_CLS_FILE);
            if (descriptorFile == null) {
                descriptorFile = classRoot.findFileByRelativePath("META-INF/versions/9/" + PsiJavaModule.MODULE_INFO_CLS_FILE);
            }
            if (descriptorFile != null) {
                PsiFile psiFile = PsiManager.getInstance(project).findFile(descriptorFile);
                if (psiFile instanceof PsiJavaFile) {
                    return ((PsiJavaFile) psiFile).getModuleDeclaration();
                }
            } else if (classRoot.getFileSystem() instanceof JarFileSystem && "jar".equalsIgnoreCase(classRoot.getExtension())) {
                return LightJavaModule.getModule(PsiManager.getInstance(project), classRoot);
            }
        }
        return null;
    } else {
        return getModuleDescriptor(index.getModuleForFile(file));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Nullable(org.jetbrains.annotations.Nullable)

Example 12 with JarFileSystem

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

the class JavaDocumentationProvider method findUrlForVirtualFile.

@Nullable
public static List<String> findUrlForVirtualFile(@NotNull Project project, @NotNull VirtualFile virtualFile, @NotNull String relPath) {
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    Module module = fileIndex.getModuleForFile(virtualFile);
    if (module == null) {
        final VirtualFileSystem fs = virtualFile.getFileSystem();
        if (fs instanceof JarFileSystem) {
            final VirtualFile jar = ((JarFileSystem) fs).getVirtualFileForJar(virtualFile);
            if (jar != null) {
                module = fileIndex.getModuleForFile(jar);
            }
        }
    }
    if (module != null) {
        String[] javadocPaths = JavaModuleExternalPaths.getInstance(module).getJavadocUrls();
        final List<String> httpRoots = PlatformDocumentationUtil.getHttpRoots(javadocPaths, relPath);
        // if found nothing and the file is from library classes, fall back to order entries
        if (httpRoots != null || !fileIndex.isInLibraryClasses(virtualFile)) {
            return httpRoots;
        }
    }
    for (OrderEntry orderEntry : fileIndex.getOrderEntriesForFile(virtualFile)) {
        for (VirtualFile root : orderEntry.getFiles(JavadocOrderRootType.getInstance())) {
            if (root.getFileSystem() == JarFileSystem.getInstance()) {
                VirtualFile file = root.findFileByRelativePath(relPath);
                List<Url> urls = file == null ? null : BuiltInWebBrowserUrlProviderKt.getBuiltInServerUrls(file, project, null);
                if (!ContainerUtil.isEmpty(urls)) {
                    List<String> result = new SmartList<>();
                    for (Url url : urls) {
                        result.add(url.toExternalForm());
                    }
                    return result;
                }
            }
        }
        List<String> httpRoot = PlatformDocumentationUtil.getHttpRoots(JavadocOrderRootType.getUrls(orderEntry), relPath);
        if (httpRoot != null) {
            return httpRoot;
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VirtualFileSystem(com.intellij.openapi.vfs.VirtualFileSystem) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Module(com.intellij.openapi.module.Module) SmartList(com.intellij.util.SmartList) Url(com.intellij.util.Url) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with JarFileSystem

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

the class GradleBuildClasspathManager method reload.

public void reload() {
    ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(GradleConstants.SYSTEM_ID);
    assert manager != null;
    AbstractExternalSystemLocalSettings localSettings = manager.getLocalSettingsProvider().fun(myProject);
    Map<String, List<VirtualFile>> /*module build classpath*/
    map = ContainerUtil.newHashMap();
    final JarFileSystem jarFileSystem = JarFileSystem.getInstance();
    for (final ExternalProjectBuildClasspathPojo projectBuildClasspathPojo : localSettings.getProjectBuildClasspath().values()) {
        final List<VirtualFile> projectBuildClasspath = ContainerUtil.newArrayList();
        for (String path : projectBuildClasspathPojo.getProjectBuildClasspath()) {
            final VirtualFile virtualFile = ExternalSystemUtil.findLocalFileByPath(path);
            ContainerUtil.addIfNotNull(projectBuildClasspath, virtualFile == null || virtualFile.isDirectory() ? virtualFile : jarFileSystem.getJarRootForLocalFile(virtualFile));
        }
        for (final ExternalModuleBuildClasspathPojo moduleBuildClasspathPojo : projectBuildClasspathPojo.getModulesBuildClasspath().values()) {
            final List<VirtualFile> moduleBuildClasspath = ContainerUtil.newArrayList(projectBuildClasspath);
            for (String path : moduleBuildClasspathPojo.getEntries()) {
                final VirtualFile virtualFile = ExternalSystemUtil.findLocalFileByPath(path);
                ContainerUtil.addIfNotNull(moduleBuildClasspath, virtualFile == null || virtualFile.isDirectory() ? virtualFile : jarFileSystem.getJarRootForLocalFile(virtualFile));
            }
            map.put(moduleBuildClasspathPojo.getPath(), moduleBuildClasspath);
        }
    }
    myClasspathMap.set(map);
    Set<VirtualFile> set = new LinkedHashSet<>();
    for (List<VirtualFile> virtualFiles : myClasspathMap.get().values()) {
        set.addAll(virtualFiles);
    }
    allFilesCache = ContainerUtil.newArrayList(set);
    Extensions.findExtension(PsiElementFinder.EP_NAME, myProject, GradleClassFinder.class).clearCache();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractExternalSystemLocalSettings(com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) GradleClassFinder(org.jetbrains.plugins.gradle.config.GradleClassFinder) ExternalProjectBuildClasspathPojo(com.intellij.openapi.externalSystem.model.project.ExternalProjectBuildClasspathPojo) ExternalModuleBuildClasspathPojo(com.intellij.openapi.externalSystem.model.project.ExternalModuleBuildClasspathPojo)

Example 14 with JarFileSystem

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

the class MvcFramework method addAvailableSystemScripts.

public static void addAvailableSystemScripts(final Collection<String> result, @NotNull Module module) {
    VirtualFile scriptRoot = null;
    GlobalSearchScope searchScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module, false);
    for (PsiClass aClass : JavaPsiFacade.getInstance(module.getProject()).findClasses("CreateApp_", searchScope)) {
        PsiClass superClass = aClass.getSuperClass();
        if (superClass != null && GroovyCommonClassNames.GROOVY_LANG_SCRIPT.equals(superClass.getQualifiedName())) {
            PsiFile psiFile = aClass.getContainingFile();
            if (psiFile != null) {
                VirtualFile file = psiFile.getVirtualFile();
                if (file != null && file.getFileSystem() instanceof JarFileSystem) {
                    VirtualFile parent = file.getParent();
                    if (parent != null && parent.findChild("Console.class") != null) {
                        scriptRoot = parent;
                        break;
                    }
                }
            }
        }
    }
    if (scriptRoot == null)
        return;
    Pattern scriptPattern = Pattern.compile("([A-Za-z0-9]+)_?\\.class");
    for (VirtualFile file : scriptRoot.getChildren()) {
        Matcher matcher = scriptPattern.matcher(file.getName());
        if (matcher.matches()) {
            result.add(GroovyNamesUtil.camelToSnake(matcher.group(1)));
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Pattern(java.util.regex.Pattern) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Matcher(java.util.regex.Matcher)

Example 15 with JarFileSystem

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

the class EPathUtil method collapse2EclipseVariabledPath.

@Nullable
static String collapse2EclipseVariabledPath(final LibraryOrderEntry libraryOrderEntry, OrderRootType type) {
    final VirtualFile[] virtualFiles = libraryOrderEntry.getRootFiles(type);
    if (virtualFiles.length > 0) {
        VirtualFile jarFile = virtualFiles[0];
        if (jarFile.getFileSystem() instanceof JarFileSystem) {
            jarFile = JarFileSystem.getInstance().getVirtualFileForJar(jarFile);
        }
        if (jarFile == null) {
            return null;
        }
        final Project project = libraryOrderEntry.getOwnerModule().getProject();
        final VirtualFile baseDir = project.getBaseDir();
        final String filePath = jarFile.getPath();
        if (baseDir != null && !VfsUtilCore.isAncestor(baseDir, jarFile, false)) {
            final String ideaCollapsed = PathMacroManager.getInstance(project).collapsePath(filePath);
            if (ideaCollapsed.contains(".."))
                return null;
            final int index = ideaCollapsed.indexOf('$');
            if (index < 0)
                return null;
            return ideaCollapsed.substring(index).replace("$", "");
        }
    }
    for (String url : libraryOrderEntry.getRootUrls(type)) {
        //check if existing eclipse variable points inside project or doesn't exist
        String filePath = VirtualFileManager.extractPath(url);
        final int jarSeparatorIdx = filePath.indexOf(JarFileSystem.JAR_SEPARATOR);
        if (jarSeparatorIdx > -1) {
            filePath = filePath.substring(0, jarSeparatorIdx);
        }
        final PathMacros pathMacros = PathMacros.getInstance();
        final Set<String> names = pathMacros.getUserMacroNames();
        for (String name : names) {
            final String path = FileUtil.toSystemIndependentName(pathMacros.getValue(name));
            if (filePath.startsWith(path + "/")) {
                final String substr = filePath.substring(path.length());
                return name + (substr.startsWith("/") || substr.length() == 0 ? substr : "/" + substr);
            }
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PathMacros(com.intellij.openapi.application.PathMacros) Project(com.intellij.openapi.project.Project) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Nullable(org.jetbrains.annotations.Nullable)

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