Search in sources :

Example 91 with Library

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

the class InferNullityAnnotationsAction method addAnnotationsDependency.

public static boolean addAnnotationsDependency(@NotNull final Project project, @NotNull final Set<Module> modulesWithoutAnnotations, @NotNull String annoFQN, final String title) {
    final Library annotationsLib = LibraryUtil.findLibraryByClass(annoFQN, project);
    if (annotationsLib != null) {
        String message = "Module" + (modulesWithoutAnnotations.size() == 1 ? " " : "s ");
        message += StringUtil.join(modulesWithoutAnnotations, Module::getName, ", ");
        message += (modulesWithoutAnnotations.size() == 1 ? " doesn't" : " don't");
        message += " refer to the existing '" + annotationsLib.getName() + "' library with IntelliJ IDEA nullity annotations. Would you like to add the dependenc";
        message += (modulesWithoutAnnotations.size() == 1 ? "y" : "ies") + " now?";
        if (Messages.showOkCancelDialog(project, message, title, Messages.getErrorIcon()) == Messages.OK) {
            ApplicationManager.getApplication().runWriteAction(() -> {
                for (Module module : modulesWithoutAnnotations) {
                    ModuleRootModificationUtil.addDependency(module, annotationsLib);
                }
            });
            return true;
        }
        return false;
    }
    if (Messages.showOkCancelDialog(project, "It is required that JetBrains annotations" + " be available in all your project sources.\n\nYou will need to add annotations.jar as a library. " + "It is possible to configure custom JAR\nin e.g. Constant Conditions & Exceptions inspection or use JetBrains annotations available in installation. " + "\nIntelliJ IDEA nullity annotations are freely usable and redistributable under the Apache 2.0 license.\nWould you like to do it now?", title, Messages.getErrorIcon()) == Messages.OK) {
        Module firstModule = modulesWithoutAnnotations.iterator().next();
        JavaProjectModelModificationService.getInstance(project).addDependency(modulesWithoutAnnotations, JetBrainsAnnotationsExternalLibraryResolver.getAnnotationsLibraryDescriptor(firstModule), DependencyScope.COMPILE);
        return true;
    }
    return false;
}
Also used : Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module)

Example 92 with Library

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

the class CreateModuleLibraryFromFilesTest method testJarAndSources.

public void testJarAndSources() {
    Library library = assertOneElement(createLibraries(new OrderRoot(getJDomJar(), OrderRootType.CLASSES), new OrderRoot(getJDomSources(), OrderRootType.SOURCES)));
    assertNull(library.getName());
    assertSameElements(library.getFiles(OrderRootType.CLASSES), getJDomJar());
    assertSameElements(library.getFiles(OrderRootType.SOURCES), getJDomSources());
}
Also used : OrderRoot(com.intellij.openapi.roots.libraries.ui.OrderRoot) Library(com.intellij.openapi.roots.libraries.Library)

Example 93 with Library

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

the class LibraryTest method testNativePathSerialization.

public void testNativePathSerialization() {
    LibraryTable table = getLibraryTable();
    Library library = new WriteAction<Library>() {

        @Override
        protected void run(@NotNull Result<Library> result) throws Throwable {
            Library res = table.createLibrary("native");
            result.setResult(res);
        }
    }.execute().throwException().getResultObject();
    Library.ModifiableModel model = library.getModifiableModel();
    model.addRoot("file://native-lib-root", NativeLibraryOrderRootType.getInstance());
    commit(model);
    Element element = serialize(library);
    PlatformTestUtil.assertElementEquals("<root><library name=\"native\"><CLASSES /><JAVADOC />" + "<NATIVE><root url=\"file://native-lib-root\" /></NATIVE>" + "<SOURCES /></library></root>", element);
}
Also used : ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Element(org.jdom.Element) Library(com.intellij.openapi.roots.libraries.Library)

Example 94 with Library

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

the class LibraryTest method testFindLibraryByNameAfterChainedRename.

public void testFindLibraryByNameAfterChainedRename() {
    Library a = createLibrary("a", null, null);
    Library b = createLibrary("b", null, null);
    assertSame(a, getLibraryTable().getLibraryByName("a"));
    assertSame(b, getLibraryTable().getLibraryByName("b"));
    Library.ModifiableModel bModel = b.getModifiableModel();
    bModel.setName("c");
    commit(bModel);
    Library.ModifiableModel aModel = a.getModifiableModel();
    aModel.setName("b");
    commit(aModel);
    assertNull(getLibraryTable().getLibraryByName("a"));
    assertSame(a, getLibraryTable().getLibraryByName("b"));
    assertSame(b, getLibraryTable().getLibraryByName("c"));
}
Also used : Library(com.intellij.openapi.roots.libraries.Library)

Example 95 with Library

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

the class LibraryTest method testFindLibraryByNameAfterRename.

public void testFindLibraryByNameAfterRename() {
    final long moduleModificationCount = ((ModuleRootManagerComponent) ModuleRootManager.getInstance(myModule)).getStateModificationCount();
    ProjectLibraryTable table = (ProjectLibraryTable) getLibraryTable();
    final long projectLibraryModificationCount = table.getStateModificationCount();
    Library a = createLibrary("a", null, null);
    LibraryTable.ModifiableModel model = table.getModifiableModel();
    assertSame(a, table.getLibraryByName("a"));
    assertSame(a, model.getLibraryByName("a"));
    Library.ModifiableModel libraryModel = a.getModifiableModel();
    libraryModel.setName("b");
    commit(libraryModel);
    // module not marked as to save if project library modified, but module is not affected
    assertThat(((ModuleRootManagerComponent) ModuleRootManager.getInstance(myModule)).getStateModificationCount()).isEqualTo(moduleModificationCount);
    assertThat(table.getStateModificationCount()).isGreaterThan(projectLibraryModificationCount);
    assertNull(table.getLibraryByName("a"));
    assertNull(model.getLibraryByName("a"));
    assertSame(a, table.getLibraryByName("b"));
    assertSame(a, model.getLibraryByName("b"));
    commit(model);
    assertSame(a, table.getLibraryByName("b"));
}
Also used : ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) ModuleRootManagerComponent(com.intellij.openapi.roots.impl.ModuleRootManagerComponent) Library(com.intellij.openapi.roots.libraries.Library)

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