Search in sources :

Example 31 with LibraryEx

use of com.intellij.openapi.roots.impl.libraries.LibraryEx in project intellij-community by JetBrains.

the class LibraryGroupNode method getLibraryRoots.

@NotNull
public static VirtualFile[] getLibraryRoots(@NotNull LibraryOrderEntry orderEntry) {
    Library library = orderEntry.getLibrary();
    if (library == null)
        return VirtualFile.EMPTY_ARRAY;
    OrderRootType[] rootTypes = LibraryType.DEFAULT_EXTERNAL_ROOT_TYPES;
    if (library instanceof LibraryEx) {
        if (((LibraryEx) library).isDisposed())
            return VirtualFile.EMPTY_ARRAY;
        PersistentLibraryKind<?> libKind = ((LibraryEx) library).getKind();
        if (libKind != null) {
            rootTypes = LibraryType.findByKind(libKind).getExternalRootTypes();
        }
    }
    final ArrayList<VirtualFile> files = new ArrayList<>();
    for (OrderRootType rootType : rootTypes) {
        files.addAll(Arrays.asList(library.getFiles(rootType)));
    }
    return VfsUtilCore.toVirtualFileArray(files);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library) NotNull(org.jetbrains.annotations.NotNull)

Example 32 with LibraryEx

use of com.intellij.openapi.roots.impl.libraries.LibraryEx in project intellij-community by JetBrains.

the class RepositoryLibrarySupport method isLibraryEqualsToSelected.

private boolean isLibraryEqualsToSelected(Library library) {
    if (!(library instanceof LibraryEx)) {
        return false;
    }
    LibraryEx libraryEx = (LibraryEx) library;
    if (!RepositoryLibraryType.REPOSITORY_LIBRARY_KIND.equals(libraryEx.getKind())) {
        return false;
    }
    LibraryProperties libraryProperties = libraryEx.getProperties();
    if (libraryProperties == null || !(libraryProperties instanceof RepositoryLibraryProperties)) {
        return false;
    }
    RepositoryLibraryProperties repositoryLibraryProperties = (RepositoryLibraryProperties) libraryProperties;
    RepositoryLibraryDescription description = RepositoryLibraryDescription.findDescription(repositoryLibraryProperties);
    if (!description.equals(libraryDescription)) {
        return false;
    }
    return Comparing.equal(repositoryLibraryProperties.getVersion(), model.getVersion());
}
Also used : LibraryProperties(com.intellij.openapi.roots.libraries.LibraryProperties) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx)

Example 33 with LibraryEx

use of com.intellij.openapi.roots.impl.libraries.LibraryEx 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 34 with LibraryEx

use of com.intellij.openapi.roots.impl.libraries.LibraryEx in project intellij-community by JetBrains.

the class LibraryPresentationManagerImpl method getCustomIcon.

@Override
public Icon getCustomIcon(@NotNull Library library, StructureConfigurableContext context) {
    LibraryEx libraryEx = (LibraryEx) library;
    final LibraryKind kind = libraryEx.getKind();
    if (kind != null) {
        return LibraryType.findByKind(kind).getIcon(libraryEx.getProperties());
    }
    final List<Icon> icons = getCustomIcons(library, context);
    if (icons.size() == 1) {
        return icons.get(0);
    }
    return null;
}
Also used : LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx)

Example 35 with LibraryEx

use of com.intellij.openapi.roots.impl.libraries.LibraryEx in project intellij-community by JetBrains.

the class LibraryProjectStructureElement method check.

@Override
public void check(ProjectStructureProblemsHolder problemsHolder) {
    if (((LibraryEx) myLibrary).isDisposed())
        return;
    final LibraryEx library = (LibraryEx) myContext.getLibraryModel(myLibrary);
    if (library == null || library.isDisposed())
        return;
    reportInvalidRoots(problemsHolder, library, OrderRootType.CLASSES, "classes", ProjectStructureProblemType.error("library-invalid-classes-path"));
    final String libraryName = library.getName();
    if (libraryName == null || !libraryName.startsWith("Maven: ")) {
        reportInvalidRoots(problemsHolder, library, OrderRootType.SOURCES, "sources", ProjectStructureProblemType.warning("library-invalid-source-javadoc-path"));
        reportInvalidRoots(problemsHolder, library, JavadocOrderRootType.getInstance(), "javadoc", ProjectStructureProblemType.warning("library-invalid-source-javadoc-path"));
    }
}
Also used : LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx)

Aggregations

LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)38 Library (com.intellij.openapi.roots.libraries.Library)19 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 NotNull (org.jetbrains.annotations.NotNull)8 Nullable (org.jetbrains.annotations.Nullable)8 Module (com.intellij.openapi.module.Module)6 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)6 Project (com.intellij.openapi.project.Project)5 FlexLibraryProperties (com.intellij.lang.javascript.flex.library.FlexLibraryProperties)4 Logger (com.intellij.openapi.diagnostic.Logger)4 ContainerUtil (com.intellij.util.containers.ContainerUtil)4 Disposable (com.intellij.openapi.Disposable)3 OrderRootType (com.intellij.openapi.roots.OrderRootType)3 LibraryProperties (com.intellij.openapi.roots.libraries.LibraryProperties)3 StringUtil (com.intellij.openapi.util.text.StringUtil)3 List (java.util.List)3 FlexCommonUtils (com.intellij.flex.FlexCommonUtils)2 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)2 OutputType (com.intellij.flex.model.bc.OutputType)2