use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class RenameLibraryHandler method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull PsiElement[] elements, @NotNull DataContext dataContext) {
final Library library = LangDataKeys.LIBRARY.getData(dataContext);
LOG.assertTrue(library != null);
Messages.showInputDialog(project, IdeBundle.message("prompt.enter.new.library.name"), IdeBundle.message("title.rename.library"), Messages.getQuestionIcon(), library.getName(), new MyInputValidator(project, library));
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class OrderEntryUtil method addLibraryToRoots.
public static void addLibraryToRoots(@NotNull Module module, @NotNull Library library) {
final ModuleRootManager manager = ModuleRootManager.getInstance(module);
final ModifiableRootModel rootModel = manager.getModifiableModel();
if (library.getTable() == null) {
final Library jarLibrary = rootModel.getModuleLibraryTable().createLibrary();
final Library.ModifiableModel libraryModel = jarLibrary.getModifiableModel();
for (OrderRootType orderRootType : OrderRootType.getAllTypes()) {
VirtualFile[] files = library.getFiles(orderRootType);
for (VirtualFile jarFile : files) {
libraryModel.addRoot(jarFile, orderRootType);
}
}
libraryModel.commit();
} else {
rootModel.addLibraryEntry(library);
}
rootModel.commit();
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class OrderEntryUtil method addLibraryToRoots.
public static void addLibraryToRoots(final LibraryOrderEntry libraryOrderEntry, final Module module) {
Library library = libraryOrderEntry.getLibrary();
if (library == null)
return;
addLibraryToRoots(module, library);
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class RootsChangedTest method verifyLibraryTableEditing.
private void verifyLibraryTableEditing(final LibraryTable libraryTable) {
final Module moduleA = createModule("a.iml");
final Module moduleB = createModule("b.iml");
assertEventsCount(2);
ApplicationManager.getApplication().runWriteAction(() -> {
final Library libraryA = libraryTable.createLibrary("A");
final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel();
libraryModifiableModel.addRoot("file:///a", OrderRootType.CLASSES);
libraryModifiableModel.commit();
assertEventsCount(0);
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
rootModelA.addLibraryEntry(libraryA);
rootModelB.addLibraryEntry(libraryA);
rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
ModifiableRootModel[] rootModels = new ModifiableRootModel[] { rootModelA, rootModelB };
if (rootModels.length > 0) {
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
}
assertEventsCount(1);
final Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel();
final File tmpDir;
try {
tmpDir = FileUtil.createTempDirectory(getTestName(true), "");
} catch (IOException e) {
throw new RuntimeException(e);
}
try {
final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tmpDir);
assertNotNull(file);
libraryModifiableModel2.addRoot(file.getUrl(), OrderRootType.CLASSES);
libraryModifiableModel2.commit();
assertEventsCount(1);
} finally {
FileUtil.delete(tmpDir);
}
libraryTable.removeLibrary(libraryA);
assertEventsCount(1);
final Library libraryQ = libraryTable.createLibrary("Q");
assertEventsCount(1);
libraryTable.removeLibrary(libraryQ);
assertEventsCount(1);
});
}
use of com.intellij.openapi.roots.libraries.Library in project intellij-community by JetBrains.
the class RootsChangedTest method verifyLibraryTableEditingInUncommittedModel.
private void verifyLibraryTableEditingInUncommittedModel(final LibraryTable libraryTable) {
ApplicationManager.getApplication().runWriteAction(() -> {
final Module moduleA = createModule("a.iml");
final Module moduleB = createModule("b.iml");
assertEventsCount(2);
final Library libraryA = libraryTable.createLibrary("A");
final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel();
libraryModifiableModel.addRoot("file:///a", OrderRootType.CLASSES);
libraryModifiableModel.commit();
assertEventsCount(0);
final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
rootModelA.addLibraryEntry(libraryA);
rootModelB.addLibraryEntry(libraryA);
final Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel();
libraryModifiableModel2.addRoot("file:///b", OrderRootType.CLASSES);
libraryModifiableModel2.commit();
assertEventsCount(0);
libraryTable.removeLibrary(libraryA);
assertEventsCount(0);
rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel());
rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel());
assertEventsCount(0);
final Library libraryQ = libraryTable.createLibrary("Q");
assertEventsCount(0);
ModifiableRootModel[] rootModels = new ModifiableRootModel[] { rootModelA, rootModelB };
if (rootModels.length > 0) {
ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel());
}
assertEventsCount(1);
libraryTable.removeLibrary(libraryQ);
assertEventsCount(1);
});
}
Aggregations