Search in sources :

Example 76 with Library

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());
}
Also used : OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Library(com.intellij.openapi.roots.libraries.Library)

Example 77 with Library

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ModuleRootManagerImpl(com.intellij.openapi.roots.impl.ModuleRootManagerImpl) Element(org.jdom.Element) Iterator(java.util.Iterator) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 78 with Library

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);
    }
}
Also used : LibraryCompositionSettings(com.intellij.facet.impl.ui.libraries.LibraryCompositionSettings) FrameworkSupportProvider(com.intellij.ide.util.frameworkSupport.FrameworkSupportProvider) FacetBasedFrameworkSupportProvider(com.intellij.facet.ui.FacetBasedFrameworkSupportProvider) FrameworkSupportInModuleProvider(com.intellij.framework.addSupport.FrameworkSupportInModuleProvider) FrameworkSupportConfigurable(com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurable) IdeaModifiableModelsProvider(com.intellij.openapi.roots.IdeaModifiableModelsProvider) Library(com.intellij.openapi.roots.libraries.Library) FrameworkSupportInModuleConfigurable(com.intellij.framework.addSupport.FrameworkSupportInModuleConfigurable) FacetBasedFrameworkSupportProvider(com.intellij.facet.ui.FacetBasedFrameworkSupportProvider) FrameworkSupportCommunicator(com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportCommunicator)

Example 79 with Library

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>"));
}
Also used : LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library)

Example 80 with Library

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;
}
Also used : GroupDescriptor(com.intellij.internal.statistic.beans.GroupDescriptor) ModuleManager(com.intellij.openapi.module.ModuleManager) UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) AbstractApplicationUsagesCollector(com.intellij.internal.statistic.AbstractApplicationUsagesCollector) NonNls(org.jetbrains.annotations.NonNls) Set(java.util.Set) LibraryKind(com.intellij.openapi.roots.libraries.LibraryKind) HashSet(java.util.HashSet) Library(com.intellij.openapi.roots.libraries.Library) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Processor(com.intellij.util.Processor) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull) LibraryKind(com.intellij.openapi.roots.libraries.LibraryKind) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

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