Search in sources :

Example 1 with ArchiveFileSystem

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

the class ChangeLibraryLevelActionBase method doCopy.

@Nullable
protected Library doCopy(LibraryEx library) {
    final VirtualFile baseDir = getBaseDir();
    final String libPath = baseDir != null ? baseDir.getPath() + "/lib" : "";
    final VirtualFile[] classesRoots = library.getFiles(OrderRootType.CLASSES);
    boolean allowEmptyName = isConvertingToModuleLibrary() && classesRoots.length == 1;
    final String libraryName = allowEmptyName ? "" : StringUtil.notNullize(library.getName(), LibraryTypeServiceImpl.suggestLibraryName(classesRoots));
    final LibraryTableModifiableModelProvider provider = getModifiableTableModelProvider();
    final ChangeLibraryLevelDialog dialog = new ChangeLibraryLevelDialog(getParentComponent(), myProject, myCopy, libraryName, libPath, allowEmptyName, provider);
    if (!dialog.showAndGet()) {
        return null;
    }
    final Set<File> fileToCopy = new LinkedHashSet<>();
    final Map<String, String> copiedFiles = new HashMap<>();
    final String targetDirectoryPath = dialog.getDirectoryForFilesPath();
    if (targetDirectoryPath != null) {
        for (OrderRootType type : OrderRootType.getAllTypes()) {
            for (VirtualFile root : library.getFiles(type)) {
                if (root.isInLocalFileSystem() || root.getFileSystem() instanceof ArchiveFileSystem) {
                    fileToCopy.add(VfsUtil.virtualToIoFile(PathUtil.getLocalFile(root)));
                }
            }
        }
        if (!copyOrMoveFiles(fileToCopy, targetDirectoryPath, copiedFiles)) {
            return null;
        }
    }
    final Library copied = provider.getModifiableModel().createLibrary(StringUtil.nullize(dialog.getLibraryName()), library.getKind());
    final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx) copied.getModifiableModel();
    LibraryEditingUtil.copyLibrary(library, copiedFiles, model);
    WriteAction.run(() -> model.commit());
    return copied;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) ChangeLibraryLevelDialog(com.intellij.openapi.roots.ui.configuration.libraryEditor.ChangeLibraryLevelDialog) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) ArchiveFileSystem(com.intellij.openapi.vfs.newvfs.ArchiveFileSystem) LibraryTableModifiableModelProvider(com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider) OrderRootType(com.intellij.openapi.roots.OrderRootType) Library(com.intellij.openapi.roots.libraries.Library) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ArchiveFileSystem

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

the class JavaDirectoryIconProvider method getIcon.

@Override
@Nullable
public Icon getIcon(@NotNull PsiElement element, int flags) {
    if (element instanceof PsiDirectory) {
        final PsiDirectory psiDirectory = (PsiDirectory) element;
        final VirtualFile vFile = psiDirectory.getVirtualFile();
        final Project project = psiDirectory.getProject();
        SourceFolder sourceFolder;
        Icon symbolIcon;
        if (vFile.getParent() == null && vFile.getFileSystem() instanceof ArchiveFileSystem) {
            symbolIcon = PlatformIcons.JAR_ICON;
        } else if (ProjectRootsUtil.isModuleContentRoot(vFile, project)) {
            Module module = ProjectRootManager.getInstance(project).getFileIndex().getModuleForFile(vFile);
            symbolIcon = module != null ? ModuleType.get(module).getIcon() : PlatformIcons.CONTENT_ROOT_ICON_CLOSED;
        } else if ((sourceFolder = ProjectRootsUtil.getModuleSourceRoot(vFile, project)) != null) {
            symbolIcon = SourceRootPresentation.getSourceRootIcon(sourceFolder);
        } else if (JrtFileSystem.isModuleRoot(vFile)) {
            symbolIcon = AllIcons.Nodes.JavaModuleRoot;
        } else if (JavaDirectoryService.getInstance().getPackage(psiDirectory) != null) {
            symbolIcon = PlatformIcons.PACKAGE_ICON;
        } else if (!Registry.is("ide.hide.excluded.files") && ProjectRootManager.getInstance(project).getFileIndex().isExcluded(vFile)) {
            symbolIcon = AllIcons.Modules.ExcludeRoot;
        } else {
            symbolIcon = PlatformIcons.DIRECTORY_CLOSED_ICON;
        }
        return ElementBase.createLayeredIcon(element, symbolIcon, 0);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) SourceFolder(com.intellij.openapi.roots.SourceFolder) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) ArchiveFileSystem(com.intellij.openapi.vfs.newvfs.ArchiveFileSystem) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ArchiveFileSystem (com.intellij.openapi.vfs.newvfs.ArchiveFileSystem)2 Nullable (org.jetbrains.annotations.Nullable)2 Module (com.intellij.openapi.module.Module)1 Project (com.intellij.openapi.project.Project)1 OrderRootType (com.intellij.openapi.roots.OrderRootType)1 SourceFolder (com.intellij.openapi.roots.SourceFolder)1 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)1 Library (com.intellij.openapi.roots.libraries.Library)1 LibraryTableModifiableModelProvider (com.intellij.openapi.roots.ui.configuration.LibraryTableModifiableModelProvider)1 ChangeLibraryLevelDialog (com.intellij.openapi.roots.ui.configuration.libraryEditor.ChangeLibraryLevelDialog)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1