use of com.intellij.openapi.roots.libraries.LibraryTable in project kotlin by JetBrains.
the class KotlinWithLibraryConfigurator method addJarsToNewLibrary.
private void addJarsToNewLibrary(@NotNull Project project, @NotNull final File runtimeJar, @Nullable final File reflectJar, @NotNull NotificationMessageCollector collector) {
final LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTable(project);
final Ref<Library> library = new Ref<Library>();
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
library.set(table.createLibrary(getLibraryName()));
Library.ModifiableModel model = library.get().getModifiableModel();
model.addRoot(VfsUtil.getUrlForLibraryRoot(runtimeJar), OrderRootType.CLASSES);
if (reflectJar != null) {
model.addRoot(VfsUtil.getUrlForLibraryRoot(reflectJar), OrderRootType.CLASSES);
}
model.commit();
}
});
collector.addMessage(library.get().getName() + " library was created");
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project google-cloud-intellij by GoogleCloudPlatform.
the class AppEngineStandardSupportProvider method removeMavenLibraries.
static void removeMavenLibraries(final Set<AppEngineStandardMavenLibrary> librariesToRemove, final Module module) {
final ModuleRootManager manager = ModuleRootManager.getInstance(module);
final ModifiableRootModel model = manager.getModifiableModel();
final LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject());
ApplicationManager.getApplication().invokeLater(() -> {
new WriteAction() {
@Override
protected void run(@NotNull Result result) throws Throwable {
for (AppEngineStandardMavenLibrary libraryToRemove : librariesToRemove) {
final String displayName = libraryToRemove.toMavenDisplayVersion();
final Library library = libraryTable.getLibraryByName(displayName);
if (library != null) {
libraryTable.removeLibrary(library);
for (OrderEntry orderEntry : model.getOrderEntries()) {
if (orderEntry.getPresentableName().equals(library.getName())) {
model.removeOrderEntry(orderEntry);
}
}
}
}
model.commit();
}
}.execute();
}, ModalityState.NON_MODAL);
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project google-cloud-intellij by GoogleCloudPlatform.
the class EndpointTestBase method addEndpointSdkToProject.
/**
* Adds the App Engine - Endpoint SDK to the test project's library
*/
private void addEndpointSdkToProject() {
LocalFileSystem fs = LocalFileSystem.getInstance();
final VirtualFile libDir = fs.findFileByPath(getTestDataPath());
if (libDir != null) {
final VirtualFile pluginsDir = libDir.findChild("lib");
if (pluginsDir != null) {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
final LibraryTable table = LibraryTablesRegistrar.getInstance().getLibraryTableByLevel(LibraryTablesRegistrar.APPLICATION_LEVEL, myModule.getProject());
assert table != null;
final LibraryTable.ModifiableModel tableModel = table.getModifiableModel();
final Library library = tableModel.createLibrary("endpoints-lib");
final Library.ModifiableModel libraryModel = library.getModifiableModel();
libraryModel.addJarDirectory(pluginsDir, true);
libraryModel.commit();
tableModel.commit();
ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
Library jar = table.getLibraries()[0];
// Endpoint is the only jar added
rootModel.addLibraryEntry(jar);
rootModel.commit();
}
});
}
}
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project go-lang-idea-plugin by go-lang-plugin-org.
the class GoModuleLibrariesInitializer method removeLibraryIfNeeded.
private void removeLibraryIfNeeded() {
ApplicationManager.getApplication().assertIsDispatchThread();
ModifiableModelsProvider modelsProvider = ModifiableModelsProvider.SERVICE.getInstance();
ModifiableRootModel model = modelsProvider.getModuleModifiableModel(myModule);
LibraryOrderEntry goLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName());
if (goLibraryEntry != null) {
ApplicationManager.getApplication().runWriteAction(() -> {
Library library = goLibraryEntry.getLibrary();
if (library != null) {
LibraryTable table = library.getTable();
if (table != null) {
table.removeLibrary(library);
model.removeOrderEntry(goLibraryEntry);
modelsProvider.commitModuleModifiableModel(model);
}
} else {
modelsProvider.disposeModuleModifiableModel(model);
}
});
} else {
ApplicationManager.getApplication().runWriteAction(() -> modelsProvider.disposeModuleModifiableModel(model));
}
}
use of com.intellij.openapi.roots.libraries.LibraryTable in project Intellij-Plugin by getgauge.
the class GaugeLibHelper method updateGaugeJavaLibIfNeeded.
private void updateGaugeJavaLibIfNeeded(ModifiableRootModel model) {
LibraryTable libraryTable = model.getModuleLibraryTable();
Library library = libraryTable.getLibraryByName(GAUGE_LIB);
ProjectLib latestGaugeLib = gaugeLib(model.getModule());
updateLibrary(library, latestGaugeLib);
}
Aggregations