Search in sources :

Example 1 with ArchiveFileType

use of com.intellij.ide.highlighter.ArchiveFileType in project intellij-community by JetBrains.

the class FacetLibraryConfigurator method fillLibrary.

private static void fillLibrary(Project project, Library lib, List<String> paths) {
    Library.ModifiableModel modifiableModel = lib.getModifiableModel();
    for (String root : lib.getUrls(OrderRootType.CLASSES)) {
        modifiableModel.removeRoot(root, OrderRootType.CLASSES);
    }
    Set<VirtualFile> roots = new HashSet<>();
    ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
    Collections.addAll(roots, rootManager.getContentRoots());
    Collections.addAll(roots, rootManager.getContentSourceRoots());
    if (paths != null) {
        for (String dir : paths) {
            VirtualFile pathEntry = LocalFileSystem.getInstance().findFileByPath(dir);
            if (pathEntry != null && !pathEntry.isDirectory() && pathEntry.getFileType() instanceof ArchiveFileType) {
                pathEntry = JarFileSystem.getInstance().getJarRootForLocalFile(pathEntry);
            }
            // buildout includes source root of project in paths; don't add it as library home
            if (pathEntry != null && roots.contains(pathEntry)) {
                continue;
            }
            if (pathEntry != null) {
                modifiableModel.addRoot(pathEntry, OrderRootType.CLASSES);
            } else {
                modifiableModel.addRoot("file://" + dir, OrderRootType.CLASSES);
            }
        }
    }
    modifiableModel.commit();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArchiveFileType(com.intellij.ide.highlighter.ArchiveFileType) Library(com.intellij.openapi.roots.libraries.Library) HashSet(java.util.HashSet)

Example 2 with ArchiveFileType

use of com.intellij.ide.highlighter.ArchiveFileType in project intellij-community by JetBrains.

the class PyRemoteLibrariesNode method create.

@Nullable
public static PyRemoteLibrariesNode create(@NotNull Project project, @NotNull Sdk sdk, ViewSettings settings) {
    if (sdk.getSdkAdditionalData() instanceof PyRemoteSdkAdditionalDataBase) {
        VirtualFile remoteLibrary = PySdkUtil.findAnyRemoteLibrary(sdk);
        if (remoteLibrary != null && remoteLibrary.getFileType() instanceof ArchiveFileType) {
            remoteLibrary = JarFileSystem.getInstance().getLocalVirtualFileFor(remoteLibrary);
        }
        if (remoteLibrary != null) {
            final VirtualFile remoteLibraries = remoteLibrary.getParent();
            final PsiDirectory remoteLibrariesDirectory = PsiManager.getInstance(project).findDirectory(remoteLibraries);
            return new PyRemoteLibrariesNode(sdk, project, remoteLibrariesDirectory, settings);
        }
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArchiveFileType(com.intellij.ide.highlighter.ArchiveFileType) PyRemoteSdkAdditionalDataBase(com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ArchiveFileType

use of com.intellij.ide.highlighter.ArchiveFileType in project intellij-community by JetBrains.

the class BaseAnalysisAction method getInspectionScopeImpl.

@Nullable
private AnalysisScope getInspectionScopeImpl(@NotNull DataContext dataContext) {
    //Possible scopes: file, directory, package, project, module.
    Project projectContext = PlatformDataKeys.PROJECT_CONTEXT.getData(dataContext);
    if (projectContext != null) {
        return new AnalysisScope(projectContext);
    }
    final AnalysisScope analysisScope = AnalysisScopeUtil.KEY.getData(dataContext);
    if (analysisScope != null) {
        return analysisScope;
    }
    final PsiFile psiFile = CommonDataKeys.PSI_FILE.getData(dataContext);
    if (psiFile != null && psiFile.getManager().isInProject(psiFile)) {
        final VirtualFile file = psiFile.getVirtualFile();
        if (file != null && file.isValid() && file.getFileType() instanceof ArchiveFileType && acceptNonProjectDirectories()) {
            final VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(file);
            if (jarRoot != null) {
                PsiDirectory psiDirectory = psiFile.getManager().findDirectory(jarRoot);
                if (psiDirectory != null) {
                    return new AnalysisScope(psiDirectory);
                }
            }
        }
        return new AnalysisScope(psiFile);
    }
    VirtualFile[] virtualFiles = CommonDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext);
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (virtualFiles != null && project != null) {
        //analyze on selection
        ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
        if (virtualFiles.length == 1) {
            PsiDirectory psiDirectory = PsiManager.getInstance(project).findDirectory(virtualFiles[0]);
            if (psiDirectory != null && (acceptNonProjectDirectories() || psiDirectory.getManager().isInProject(psiDirectory))) {
                return new AnalysisScope(psiDirectory);
            }
        }
        Set<VirtualFile> files = new HashSet<>();
        for (VirtualFile vFile : virtualFiles) {
            if (fileIndex.isInContent(vFile)) {
                files.add(vFile);
            }
        }
        return new AnalysisScope(project, files);
    }
    Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
    if (moduleContext != null) {
        return new AnalysisScope(moduleContext);
    }
    Module[] modulesArray = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
    if (modulesArray != null) {
        return new AnalysisScope(modulesArray);
    }
    return project == null ? null : new AnalysisScope(project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ArchiveFileType(com.intellij.ide.highlighter.ArchiveFileType) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with ArchiveFileType

use of com.intellij.ide.highlighter.ArchiveFileType in project android by JetBrains.

the class AndroidRootUtil method fillExternalLibrariesAndModules.

private static void fillExternalLibrariesAndModules(@NotNull final Module module, @NotNull final Set<VirtualFile> outputDirs, @NotNull final Set<Module> visited, @Nullable final Set<VirtualFile> libraries, final boolean exportedLibrariesOnly, final boolean recursive) {
    if (!visited.add(module)) {
        return;
    }
    ApplicationManager.getApplication().runReadAction(() -> {
        ModuleRootManager manager = ModuleRootManager.getInstance(module);
        for (OrderEntry entry : manager.getOrderEntries()) {
            if (!(entry instanceof ExportableOrderEntry) || ((ExportableOrderEntry) entry).getScope() != DependencyScope.COMPILE) {
                continue;
            }
            if (libraries != null && entry instanceof LibraryOrderEntry) {
                LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
                Library library = libraryOrderEntry.getLibrary();
                if (library != null && (!exportedLibrariesOnly || libraryOrderEntry.isExported())) {
                    for (VirtualFile file : library.getFiles(OrderRootType.CLASSES)) {
                        if (!file.exists()) {
                            continue;
                        }
                        if (file.getFileType() instanceof ArchiveFileType) {
                            if (file.getFileSystem() instanceof JarFileSystem) {
                                VirtualFile localFile = JarFileSystem.getInstance().getVirtualFileForJar(file);
                                if (localFile != null) {
                                    libraries.add(localFile);
                                }
                            } else {
                                libraries.add(file);
                            }
                        } else if (file.isDirectory() && !(file.getFileSystem() instanceof JarFileSystem)) {
                            collectClassFilesAndJars(file, libraries, new HashSet<>());
                        }
                    }
                }
            } else if (entry instanceof ModuleOrderEntry) {
                Module depModule = ((ModuleOrderEntry) entry).getModule();
                if (depModule == null) {
                    continue;
                }
                AndroidFacet facet = AndroidFacet.getInstance(depModule);
                boolean libraryProject = facet != null && facet.isLibraryProject();
                CompilerModuleExtension extension = CompilerModuleExtension.getInstance(depModule);
                if (extension != null) {
                    VirtualFile classDir = extension.getCompilerOutputPath();
                    if (libraryProject) {
                        VirtualFile tmpArtifactsDir = AndroidDexCompiler.getOutputDirectoryForDex(depModule);
                        if (tmpArtifactsDir != null) {
                            VirtualFile packedClassesJar = tmpArtifactsDir.findChild(CLASSES_JAR_FILE_NAME);
                            if (packedClassesJar != null) {
                                outputDirs.add(packedClassesJar);
                            }
                        }
                    } else // do not support android-app->android-app compile dependencies
                    if (facet == null && !outputDirs.contains(classDir) && classDir != null && classDir.exists()) {
                        outputDirs.add(classDir);
                    }
                }
                if (recursive) {
                    fillExternalLibrariesAndModules(depModule, outputDirs, visited, libraries, !libraryProject || exportedLibrariesOnly, true);
                }
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArchiveFileType(com.intellij.ide.highlighter.ArchiveFileType) JarFileSystem(com.intellij.openapi.vfs.JarFileSystem) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) AndroidMavenUtil.isMavenizedModule(org.jetbrains.android.maven.AndroidMavenUtil.isMavenizedModule)

Example 5 with ArchiveFileType

use of com.intellij.ide.highlighter.ArchiveFileType in project intellij-community by JetBrains.

the class LibraryDataService method registerPaths.

static void registerPaths(boolean unresolved, @NotNull Map<OrderRootType, Collection<File>> libraryFiles, @NotNull Library.ModifiableModel model, @NotNull String libraryName) {
    for (Map.Entry<OrderRootType, Collection<File>> entry : libraryFiles.entrySet()) {
        for (File file : entry.getValue()) {
            VirtualFile virtualFile = unresolved ? null : ExternalSystemUtil.refreshAndFindFileByIoFile(file);
            if (virtualFile == null) {
                if (!unresolved && ExternalSystemConstants.VERBOSE_PROCESSING && entry.getKey() == OrderRootType.CLASSES) {
                    LOG.warn(String.format("Can't find %s of the library '%s' at path '%s'", entry.getKey(), libraryName, file.getAbsolutePath()));
                }
                String url = VfsUtil.getUrlForLibraryRoot(file);
                String[] urls = model.getUrls(entry.getKey());
                if (!ArrayUtil.contains(url, urls)) {
                    model.addRoot(url, entry.getKey());
                }
                continue;
            }
            if (virtualFile.isDirectory()) {
                VirtualFile[] files = model.getFiles(entry.getKey());
                if (!ArrayUtil.contains(virtualFile, files)) {
                    model.addRoot(virtualFile, entry.getKey());
                }
            } else {
                VirtualFile root = virtualFile;
                if (virtualFile.getFileType() instanceof ArchiveFileType) {
                    root = JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile);
                    if (root == null) {
                        LOG.warn(String.format("Can't parse contents of the JAR file at path '%s' for the library '%s''", file.getAbsolutePath(), libraryName));
                        continue;
                    }
                }
                VirtualFile[] files = model.getFiles(entry.getKey());
                if (!ArrayUtil.contains(root, files)) {
                    model.addRoot(root, entry.getKey());
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArchiveFileType(com.intellij.ide.highlighter.ArchiveFileType) OrderRootType(com.intellij.openapi.roots.OrderRootType) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

ArchiveFileType (com.intellij.ide.highlighter.ArchiveFileType)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 Nullable (org.jetbrains.annotations.Nullable)4 FileType (com.intellij.openapi.fileTypes.FileType)2 Module (com.intellij.openapi.module.Module)2 Library (com.intellij.openapi.roots.libraries.Library)2 HashSet (java.util.HashSet)2 AndroidSdks (com.android.tools.idea.sdk.AndroidSdks)1 DiffContent (com.intellij.openapi.diff.DiffContent)1 DiffTool (com.intellij.openapi.diff.DiffTool)1 SimpleDiffRequest (com.intellij.openapi.diff.SimpleDiffRequest)1 UIBasedFileType (com.intellij.openapi.fileTypes.UIBasedFileType)1 Project (com.intellij.openapi.project.Project)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 ModuleRootModificationUtil.setModuleSdk (com.intellij.openapi.roots.ModuleRootModificationUtil.setModuleSdk)1 OrderRootType (com.intellij.openapi.roots.OrderRootType)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 DialogWrapper (com.intellij.openapi.ui.DialogWrapper)1 JarFileSystem (com.intellij.openapi.vfs.JarFileSystem)1 PsiDirectory (com.intellij.psi.PsiDirectory)1