use of com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable in project android by JetBrains.
the class SyncLibraryRegistryTest method simulateProjectLibraryTableHas.
private void simulateProjectLibraryTableHas(@NotNull Library[] libraries1) {
Project project = getProject();
myOriginalProjectLibraryTable = (ProjectLibraryTable) ProjectLibraryTable.getInstance(project);
ProjectLibraryTable projectLibraryTable = IdeComponents.replaceServiceWithMock(project, ProjectLibraryTable.class);
when(projectLibraryTable.getLibraries()).thenReturn(libraries1);
}
use of com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable 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"));
}
use of com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable in project intellij-plugins by JetBrains.
the class DartFileListener method updatePackagesLibraryRoots.
@NotNull
public static Library updatePackagesLibraryRoots(@NotNull final Project project, @NotNull final DartLibInfo libInfo) {
final LibraryTable projectLibraryTable = ProjectLibraryTable.getInstance(project);
final Library existingLibrary = projectLibraryTable.getLibraryByName(DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME);
final Library library = existingLibrary != null ? existingLibrary : WriteAction.compute(() -> {
final LibraryTableBase.ModifiableModel libTableModel = ProjectLibraryTable.getInstance(project).getModifiableModel();
final Library lib = libTableModel.createLibrary(DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME, DartPackagesLibraryType.LIBRARY_KIND);
libTableModel.commit();
return lib;
});
final String[] existingUrls = library.getUrls(OrderRootType.CLASSES);
final Collection<String> libRootUrls = libInfo.getLibRootUrls();
if ((!libInfo.isProjectWithoutPubspec() && isBrokenPackageMap(((LibraryEx) library).getProperties())) || existingUrls.length != libRootUrls.size() || !libRootUrls.containsAll(Arrays.asList(existingUrls))) {
ApplicationManager.getApplication().runWriteAction(() -> {
final LibraryEx.ModifiableModelEx model = (LibraryEx.ModifiableModelEx) library.getModifiableModel();
for (String url : existingUrls) {
model.removeRoot(url, OrderRootType.CLASSES);
}
for (String url : libRootUrls) {
model.addRoot(url, OrderRootType.CLASSES);
}
final DartPackagesLibraryProperties libraryProperties = new DartPackagesLibraryProperties();
libraryProperties.setPackageNameToDirsMap(libInfo.getPackagesMap());
model.setProperties(libraryProperties);
model.commit();
});
}
return library;
}
Aggregations