Search in sources :

Example 86 with Library

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

the class LibrariesContainerFactory method createLibraryInTable.

@NotNull
private static Library createLibraryInTable(@NotNull final NewLibraryEditor editor, final LibraryTable table) {
    LibraryTable.ModifiableModel modifiableModel = table.getModifiableModel();
    final String name = StringUtil.isEmpty(editor.getName()) ? null : getUniqueLibraryName(editor.getName(), modifiableModel);
    final LibraryType<?> type = editor.getType();
    Library library = modifiableModel.createLibrary(name, type == null ? null : type.getKind());
    final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx) library.getModifiableModel();
    editor.applyTo(model);
    model.commit();
    modifiableModel.commit();
    return library;
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library) NotNull(org.jetbrains.annotations.NotNull)

Example 87 with Library

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

the class LibrariesModifiableModel method getLibraryEditor.

public ExistingLibraryEditor getLibraryEditor(Library library) {
    final Library source = ((LibraryImpl) library).getSource();
    if (source != null) {
        return getLibraryEditor(source);
    }
    ExistingLibraryEditor libraryEditor = myLibrary2EditorMap.get(library);
    if (libraryEditor == null) {
        libraryEditor = createLibraryEditor(library);
    }
    return libraryEditor;
}
Also used : ExistingLibraryEditor(com.intellij.openapi.roots.ui.configuration.libraryEditor.ExistingLibraryEditor) LibraryImpl(com.intellij.openapi.roots.impl.libraries.LibraryImpl) Library(com.intellij.openapi.roots.libraries.Library)

Example 88 with Library

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

the class ExternalLibrariesNode method getChildren.

@NotNull
@Override
public Collection<? extends AbstractTreeNode> getChildren() {
    Project project = Objects.requireNonNull(getProject());
    List<AbstractTreeNode> children = new ArrayList<>();
    ProjectFileIndex fileIndex = ProjectFileIndex.getInstance(project);
    Module[] modules = ModuleManager.getInstance(project).getModules();
    Set<Library> processedLibraries = new THashSet<>();
    Set<Sdk> processedSdk = new THashSet<>();
    for (Module module : modules) {
        final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
        final OrderEntry[] orderEntries = moduleRootManager.getOrderEntries();
        for (final OrderEntry orderEntry : orderEntries) {
            if (orderEntry instanceof LibraryOrderEntry) {
                final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) orderEntry;
                final Library library = libraryOrderEntry.getLibrary();
                if (library == null)
                    continue;
                if (processedLibraries.contains(library))
                    continue;
                processedLibraries.add(library);
                if (!hasExternalEntries(fileIndex, libraryOrderEntry))
                    continue;
                final String libraryName = library.getName();
                if (libraryName == null || libraryName.length() == 0) {
                    addLibraryChildren(libraryOrderEntry, children, project, this);
                } else {
                    children.add(new NamedLibraryElementNode(project, new NamedLibraryElement(null, libraryOrderEntry), getSettings()));
                }
            } else if (orderEntry instanceof JdkOrderEntry) {
                final JdkOrderEntry jdkOrderEntry = (JdkOrderEntry) orderEntry;
                final Sdk jdk = jdkOrderEntry.getJdk();
                if (jdk != null) {
                    if (processedSdk.contains(jdk))
                        continue;
                    processedSdk.add(jdk);
                    children.add(new NamedLibraryElementNode(project, new NamedLibraryElement(null, jdkOrderEntry), getSettings()));
                }
            }
        }
    }
    for (AdditionalLibraryRootsProvider provider : AdditionalLibraryRootsProvider.EP_NAME.getExtensions()) {
        Collection<SyntheticLibrary> libraries = provider.getAdditionalProjectLibraries(project);
        for (SyntheticLibrary library : libraries) {
            //noinspection InstanceofIncompatibleInterface
            if (library instanceof ItemPresentation) {
                children.add(new SyntheticLibraryElementNode(project, library, getSettings()));
            }
        }
    }
    return children;
}
Also used : ItemPresentation(com.intellij.navigation.ItemPresentation) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) Sdk(com.intellij.openapi.projectRoots.Sdk) THashSet(gnu.trove.THashSet) Project(com.intellij.openapi.project.Project) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 89 with Library

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

the class SimpleClasspathElementFactory method createElements.

public static List<SimpleClasspathElement> createElements(@Nullable Project project, @NotNull Element element) {
    final String name = element.getAttributeValue(GlobalLibraryReferenceElement.NAME_ATTRIBUTE);
    final String level = element.getAttributeValue(GlobalLibraryReferenceElement.LEVEL_ATTRIBUTE);
    final String url = element.getChildText(SingleRootClasspathElement.URL_ELEMENT);
    if (!StringUtil.isEmpty(url)) {
        return Collections.<SimpleClasspathElement>singletonList(new SingleRootClasspathElement(url));
    }
    if (name == null || level == null) {
        return Collections.emptyList();
    }
    if (LibraryTablesRegistrar.APPLICATION_LEVEL.equals(level)) {
        return Collections.<SimpleClasspathElement>singletonList(new GlobalLibraryReferenceElement(name));
    }
    //this is needed only for backward compatibility with version before 8
    if (project != null) {
        final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(level, project);
        if (libraryTable != null) {
            final Library library = libraryTable.getLibraryByName(name);
            if (library != null) {
                return createElements(library);
            }
        }
    }
    return Collections.emptyList();
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library)

Example 90 with Library

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

the class AddSupportForSingleFrameworkDialog method askAndRemoveDuplicatedLibraryEntry.

private boolean askAndRemoveDuplicatedLibraryEntry(@NotNull ModifiableRootModel rootModel, @NotNull CustomLibraryDescription description) {
    List<OrderEntry> existingEntries = new ArrayList<>();
    final LibrariesContainer container = myModel.getLibrariesContainer();
    for (OrderEntry entry : rootModel.getOrderEntries()) {
        if (!(entry instanceof LibraryOrderEntry))
            continue;
        final Library library = ((LibraryOrderEntry) entry).getLibrary();
        if (library == null)
            continue;
        if (LibraryPresentationManager.getInstance().isLibraryOfKind(library, container, description.getSuitableLibraryKinds())) {
            existingEntries.add(entry);
        }
    }
    if (!existingEntries.isEmpty()) {
        String message;
        if (existingEntries.size() > 1) {
            message = "There are already " + existingEntries.size() + " " + myFrameworkType.getPresentableName() + " libraries.\n Do you want to replace them?";
        } else {
            final String name = existingEntries.get(0).getPresentableName();
            message = "There is already a " + myFrameworkType.getPresentableName() + " library '" + name + "'.\n Do you want to replace it?";
        }
        final int result = Messages.showYesNoCancelDialog(rootModel.getProject(), message, "Library Already Exists", "&Replace", "&Add", "&Cancel", null);
        if (result == Messages.YES) {
            for (OrderEntry entry : existingEntries) {
                rootModel.removeOrderEntry(entry);
            }
        } else if (result != Messages.NO) {
            return false;
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) LibrariesContainer(com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer) Library(com.intellij.openapi.roots.libraries.Library)

Aggregations

Library (com.intellij.openapi.roots.libraries.Library)240 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)58 VirtualFile (com.intellij.openapi.vfs.VirtualFile)58 Module (com.intellij.openapi.module.Module)41 NotNull (org.jetbrains.annotations.NotNull)31 File (java.io.File)29 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)25 Nullable (org.jetbrains.annotations.Nullable)25 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)23 Project (com.intellij.openapi.project.Project)22 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)20 ArrayList (java.util.ArrayList)15 Sdk (com.intellij.openapi.projectRoots.Sdk)13 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)13 OrderEntry (com.intellij.openapi.roots.OrderEntry)10 THashSet (gnu.trove.THashSet)9 IOException (java.io.IOException)9 Element (org.jdom.Element)9 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)8 LibrariesContainer (com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer)7