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);
}
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 + ")";
}
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;
}
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();
}
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();
}
Aggregations