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