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