Search in sources :

Example 6 with LibraryTable

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

the class LibraryElementPresentation method getLibraryTableDisplayName.

public static String getLibraryTableDisplayName(final Library library) {
    LibraryTable table = library.getTable();
    LibraryTablePresentation presentation = table != null ? table.getPresentation() : ModuleLibraryTable.MODULE_LIBRARY_TABLE_PRESENTATION;
    return presentation.getDisplayName(false);
}
Also used : LibraryTablePresentation(com.intellij.openapi.roots.libraries.LibraryTablePresentation) ModuleLibraryTable(com.intellij.openapi.roots.impl.ModuleLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable)

Example 7 with LibraryTable

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

the class LibraryElementPresentation method getLibraryTableComment.

public static String getLibraryTableComment(final Library library) {
    LibraryTable libraryTable = library.getTable();
    String displayName;
    if (libraryTable != null) {
        displayName = libraryTable.getPresentation().getDisplayName(false);
    } else {
        Module module = ((LibraryImpl) library).getModule();
        String tableName = getLibraryTableDisplayName(library);
        displayName = module != null ? "'" + module.getName() + "' " + tableName : tableName;
    }
    return " (" + displayName + ")";
}
Also used : ModuleLibraryTable(com.intellij.openapi.roots.impl.ModuleLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) LibraryImpl(com.intellij.openapi.roots.impl.libraries.LibraryImpl) Module(com.intellij.openapi.module.Module)

Example 8 with LibraryTable

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

the class LibraryDependencyDataService method importData.

@Override
protected Map<OrderEntry, OrderAware> importData(@NotNull final Collection<DataNode<LibraryDependencyData>> nodesToImport, @NotNull final Module module, @NotNull final IdeModifiableModelsProvider modelsProvider) {
    // The general idea is to import all external project library dependencies and module libraries which don't present at the
    // ide side yet and remove all project library dependencies and module libraries which present at the ide but not at
    // the given collection.
    // The trick is that we should perform module settings modification inside try/finally block against target root model.
    // That means that we need to prepare all necessary data, obtain a model and modify it as necessary.
    final Map<Set<String>, LibraryDependencyData> /* library paths */
    moduleLibrariesToImport = ContainerUtilRt.newHashMap();
    final Map<String, LibraryDependencyData> /* library name + scope */
    projectLibrariesToImport = ContainerUtilRt.newHashMap();
    final Set<LibraryDependencyData> toImport = ContainerUtilRt.newLinkedHashSet();
    final Map<OrderEntry, OrderAware> orderEntryDataMap = ContainerUtil.newLinkedHashMap();
    boolean hasUnresolved = false;
    for (DataNode<LibraryDependencyData> dependencyNode : nodesToImport) {
        LibraryDependencyData dependencyData = dependencyNode.getData();
        LibraryData libraryData = dependencyData.getTarget();
        hasUnresolved |= libraryData.isUnresolved();
        switch(dependencyData.getLevel()) {
            case MODULE:
                Set<String> paths = ContainerUtilRt.newHashSet();
                for (String path : libraryData.getPaths(LibraryPathType.BINARY)) {
                    paths.add(ExternalSystemApiUtil.toCanonicalPath(path) + dependencyData.getScope().name());
                }
                moduleLibrariesToImport.put(paths, dependencyData);
                toImport.add(dependencyData);
                break;
            case PROJECT:
                projectLibrariesToImport.put(libraryData.getInternalName() + dependencyData.getScope().name(), dependencyData);
                toImport.add(dependencyData);
        }
    }
    final boolean finalHasUnresolved = hasUnresolved;
    final ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
    LibraryTable moduleLibraryTable = modifiableRootModel.getModuleLibraryTable();
    syncExistingAndRemoveObsolete(modelsProvider, moduleLibrariesToImport, projectLibrariesToImport, toImport, orderEntryDataMap, modifiableRootModel, finalHasUnresolved);
    // Import missing library dependencies.
    if (!toImport.isEmpty()) {
        importMissing(modelsProvider, toImport, orderEntryDataMap, modifiableRootModel, moduleLibraryTable, module);
    }
    return orderEntryDataMap;
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable)

Example 9 with LibraryTable

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

the class ModuleRootManagerComponent method getStateModificationCount.

@Override
public long getStateModificationCount() {
    Module module = getModule();
    if (!module.isLoaded() || !(module instanceof ModuleEx)) {
        return myModificationCount;
    }
    final long[] result = { myModificationCount };
    result[0] += ((ModuleEx) module).getOptionsModificationCount();
    final List<String> handledLibraryTables = new SmartList<>();
    getRootModel().orderEntries().forEachLibrary(library -> {
        LibraryTable table = library.getTable();
        if (table instanceof LibraryTableBase && !handledLibraryTables.contains(table.getTableLevel())) {
            handledLibraryTables.add(table.getTableLevel());
            long count = ((LibraryTableBase) table).getStateModificationCount();
            if (count > 0) {
                if (Registry.is("store.track.module.root.manager.changes", false)) {
                    LOG.error("modification count changed due to library  " + library.getName() + " change (" + count + "), module " + getModule().getName());
                }
            }
            result[0] += count;
        }
        return true;
    });
    return result[0] + myRootModel.getStateModificationCount();
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ModuleEx(com.intellij.openapi.module.impl.ModuleEx) LibraryTableBase(com.intellij.openapi.roots.impl.libraries.LibraryTableBase) Module(com.intellij.openapi.module.Module) SmartList(com.intellij.util.SmartList)

Example 10 with LibraryTable

use of com.intellij.openapi.roots.libraries.LibraryTable 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)

Aggregations

LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)64 Library (com.intellij.openapi.roots.libraries.Library)43 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)16 Module (com.intellij.openapi.module.Module)10 NotNull (org.jetbrains.annotations.NotNull)7 Project (com.intellij.openapi.project.Project)5 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)5 LibraryTablesRegistrar (com.intellij.openapi.roots.libraries.LibraryTablesRegistrar)4 File (java.io.File)4 Element (org.jdom.Element)4 LibraryImpl (com.intellij.openapi.roots.impl.libraries.LibraryImpl)3 ArrayList (java.util.ArrayList)3 FlexLibraryProperties (com.intellij.lang.javascript.flex.library.FlexLibraryProperties)2 Application (com.intellij.openapi.application.Application)2 Result (com.intellij.openapi.application.Result)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)2 OrderEntry (com.intellij.openapi.roots.OrderEntry)2 ModuleLibraryTable (com.intellij.openapi.roots.impl.ModuleLibraryTable)2