use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class CreateModuleLibraryFromFilesTest method testTwoJarAndSources.
public void testTwoJarAndSources() {
List<Library> libraries = createLibraries(new OrderRoot(getJDomJar(), OrderRootType.CLASSES), new OrderRoot(getAsmJar(), OrderRootType.CLASSES), new OrderRoot(getJDomSources(), OrderRootType.SOURCES));
Library library = assertOneElement(libraries);
assertNull(library.getName());
assertSameElements(library.getFiles(OrderRootType.CLASSES), getJDomJar(), getAsmJar());
assertSameElements(library.getFiles(OrderRootType.SOURCES), getJDomSources());
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class ModuleRootsExternalizationTest method testModuleLibraries.
public void testModuleLibraries() throws Exception {
File moduleFile = new File(getTestRoot(), "test.iml");
Module module = createModule(moduleFile);
final ModuleRootManagerImpl moduleRootManager = (ModuleRootManagerImpl) ModuleRootManager.getInstance(module);
final ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
final LibraryTable moduleLibraryTable = rootModel.getModuleLibraryTable();
final Library unnamedLibrary = moduleLibraryTable.createLibrary();
final File unnamedLibClasses = new File(getTestRoot(), "unnamedLibClasses");
final VirtualFile unnamedLibClassesRoot = LocalFileSystem.getInstance().findFileByIoFile(unnamedLibClasses);
final Library.ModifiableModel libraryModifyableModel = unnamedLibrary.getModifiableModel();
libraryModifyableModel.addRoot(unnamedLibClassesRoot.getUrl(), OrderRootType.CLASSES);
final Library namedLibrary = moduleLibraryTable.createLibrary("namedLibrary");
final File namedLibClasses = new File(getTestRoot(), "namedLibClasses");
final VirtualFile namedLibClassesRoot = LocalFileSystem.getInstance().findFileByIoFile(namedLibClasses);
final Library.ModifiableModel namedLibraryModel = namedLibrary.getModifiableModel();
namedLibraryModel.addRoot(namedLibClassesRoot.getUrl(), OrderRootType.CLASSES);
ApplicationManager.getApplication().runWriteAction(() -> {
libraryModifyableModel.commit();
namedLibraryModel.commit();
});
final Iterator libraryIterator = moduleLibraryTable.getLibraryIterator();
assertEquals(libraryIterator.next(), unnamedLibrary);
assertEquals(libraryIterator.next(), namedLibrary);
ApplicationManager.getApplication().runWriteAction(rootModel::commit);
final Element element = new Element("root");
moduleRootManager.getState().writeExternal(element);
assertElementEquals(element, "<root inherit-compiler-output=\"true\">" + "<exclude-output />" + "<orderEntry type=\"sourceFolder\" forTests=\"false\" />" + "<orderEntry type=\"module-library\">" + "<library>" + "<CLASSES><root url=\"file://$MODULE_DIR$/unnamedLibClasses\" /></CLASSES>" + "<JAVADOC />" + "<SOURCES />" + "</library>" + "</orderEntry>" + "<orderEntry type=\"module-library\">" + "<library name=\"namedLibrary\">" + "<CLASSES><root url=\"file://$MODULE_DIR$/namedLibClasses\" /></CLASSES>" + "<JAVADOC />" + "<SOURCES />" + "</library>" + "</orderEntry>" + "</root>", module);
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class AddSupportForFrameworksPanel method addSupport.
public void addSupport(@NotNull final Module module, @NotNull final ModifiableRootModel rootModel) {
List<Library> addedLibraries = new ArrayList<>();
List<FrameworkSupportNode> selectedFrameworks = getSelectedNodes();
sortFrameworks(selectedFrameworks);
List<FrameworkSupportConfigurable> selectedConfigurables = new ArrayList<>();
final IdeaModifiableModelsProvider modifiableModelsProvider = new IdeaModifiableModelsProvider();
for (FrameworkSupportNode node : selectedFrameworks) {
FrameworkSupportInModuleConfigurable configurable = node.getConfigurable();
if (configurable instanceof OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) {
selectedConfigurables.add(((OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) configurable).getConfigurable());
}
final LibraryCompositionSettings settings = getLibraryCompositionSettings(node);
Library library = settings != null ? settings.addLibraries(rootModel, addedLibraries, myLibrariesContainer) : null;
if (configurable instanceof OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) {
((OldFrameworkSupportProviderWrapper.FrameworkSupportConfigurableWrapper) configurable).getConfigurable().addSupport(module, rootModel, library);
} else {
configurable.addSupport(module, rootModel, modifiableModelsProvider);
}
}
for (FrameworkSupportNode node : selectedFrameworks) {
FrameworkSupportInModuleProvider provider = node.getUserObject();
if (provider instanceof OldFrameworkSupportProviderWrapper) {
final FrameworkSupportProvider oldProvider = ((OldFrameworkSupportProviderWrapper) provider).getProvider();
if (oldProvider instanceof FacetBasedFrameworkSupportProvider && !addedLibraries.isEmpty()) {
((FacetBasedFrameworkSupportProvider) oldProvider).processAddedLibraries(module, addedLibraries);
}
}
}
for (FrameworkSupportCommunicator communicator : FrameworkSupportCommunicator.EP_NAME.getExtensions()) {
communicator.onFrameworkSupportAdded(module, rootModel, selectedConfigurables, myModel);
}
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class LibraryItem method getTooltipText.
@Override
public String getTooltipText() {
if (myEntry == null)
return null;
final Library library = myEntry.getLibrary();
if (library == null)
return null;
final String name = library.getName();
if (name != null) {
final List<String> invalidUrls = ((LibraryEx) library).getInvalidRootUrls(OrderRootType.CLASSES);
if (!invalidUrls.isEmpty()) {
return ProjectBundle.message("project.roots.tooltip.library.has.broken.paths", name, invalidUrls.size());
}
}
final List<String> descriptions = LibraryPresentationManager.getInstance().getDescriptions(library, myContext);
if (descriptions.isEmpty())
return null;
return XmlStringUtil.wrapInHtml(StringUtil.join(descriptions, "<br>"));
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class LibraryUsageCollector method getProjectUsages.
@NotNull
@Override
public Set<UsageDescriptor> getProjectUsages(@NotNull Project project) {
final Set<LibraryKind> usedKinds = new HashSet<>();
final Processor<Library> processor = library -> {
usedKinds.addAll(LibraryPresentationManagerImpl.getLibraryKinds(library, null));
return true;
};
for (Module module : ModuleManager.getInstance(project).getModules()) {
ModuleRootManager.getInstance(module).orderEntries().librariesOnly().forEachLibrary(processor);
}
final HashSet<UsageDescriptor> usageDescriptors = new HashSet<>();
for (LibraryKind kind : usedKinds) {
usageDescriptors.add(new UsageDescriptor(kind.getKindId(), 1));
}
return usageDescriptors;
}
Aggregations