use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-plugins by JetBrains.
the class FlexProjectConfigTest method createModuleLibrary.
private String createModuleLibrary() {
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
final LibraryTable.ModifiableModel libraryTable = modifiableModel.getModuleLibraryTable().getModifiableModel();
LibraryEx library = (LibraryEx) libraryTable.createLibrary("test", FlexLibraryType.FLEX_LIBRARY);
String libraryId = UUID.randomUUID().toString();
((FlexLibraryProperties) library.getProperties()).setId(libraryId);
ApplicationManager.getApplication().runWriteAction(() -> {
libraryTable.commit();
modifiableModel.commit();
});
return libraryId;
}
use of com.intellij.openapi.roots.libraries.LibraryTable 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;
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class PsiTestUtil method addProjectLibrary.
private static Library addProjectLibrary(Module module, ModifiableRootModel model, String libName, List<VirtualFile> classesRoots, List<VirtualFile> sourceRoots) {
LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject());
RunResult<Library> result = new WriteAction<Library>() {
@Override
protected void run(@NotNull Result<Library> result) throws Throwable {
Library library = libraryTable.createLibrary(libName);
Library.ModifiableModel libraryModel = library.getModifiableModel();
try {
for (VirtualFile root : classesRoots) {
libraryModel.addRoot(root, OrderRootType.CLASSES);
}
for (VirtualFile root : sourceRoots) {
libraryModel.addRoot(root, OrderRootType.SOURCES);
}
libraryModel.commit();
} catch (Throwable t) {
//noinspection SSBasedInspection
libraryModel.dispose();
throw t;
}
model.addLibraryEntry(library);
OrderEntry[] orderEntries = model.getOrderEntries();
OrderEntry last = orderEntries[orderEntries.length - 1];
System.arraycopy(orderEntries, 0, orderEntries, 1, orderEntries.length - 1);
orderEntries[0] = last;
model.rearrangeOrderEntries(orderEntries);
result.setResult(library);
}
}.execute();
result.throwException();
return result.getResultObject();
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class LibraryOrderEntryImpl method addListeners.
private void addListeners() {
final String libraryLevel = getLibraryLevel();
final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(libraryLevel, getRootModel().getModule().getProject());
if (libraryTable != null) {
myProjectRootManagerImpl.addListenerForTable(myLibraryListener, libraryTable);
}
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij-community by JetBrains.
the class LibraryOrderEntryImpl method searchForLibrary.
private void searchForLibrary(@NotNull String name, @NotNull String level) {
if (myLibrary != null)
return;
final LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(level, getRootModel().getModule().getProject());
final Library library = libraryTable != null ? libraryTable.getLibraryByName(name) : null;
if (library == null) {
myLibraryName = name;
myLibraryLevel = level;
myLibrary = null;
} else {
myLibraryName = null;
myLibraryLevel = null;
myLibrary = library;
}
}
Aggregations