Search in sources :

Example 66 with LibraryTable

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");
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Ref(com.intellij.openapi.util.Ref) Library(com.intellij.openapi.roots.libraries.Library)

Example 67 with LibraryTable

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);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) OrderEntry(com.intellij.openapi.roots.OrderEntry) WriteAction(com.intellij.openapi.application.WriteAction) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Library(com.intellij.openapi.roots.libraries.Library) Result(com.intellij.openapi.application.Result)

Example 68 with LibraryTable

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();
                }
            });
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Library(com.intellij.openapi.roots.libraries.Library)

Example 69 with LibraryTable

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));
    }
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library)

Example 70 with LibraryTable

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);
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) Library(com.intellij.openapi.roots.libraries.Library)

Aggregations

LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)76 Library (com.intellij.openapi.roots.libraries.Library)55 ProjectLibraryTable (com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)19 Module (com.intellij.openapi.module.Module)11 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)7 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)7 NotNull (org.jetbrains.annotations.NotNull)7 Project (com.intellij.openapi.project.Project)6 File (java.io.File)5 Element (org.jdom.Element)4 BlazeLibrary (com.google.idea.blaze.base.model.BlazeLibrary)3 Result (com.intellij.openapi.application.Result)3 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)3 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)3 LibraryTablesRegistrar (com.intellij.openapi.roots.libraries.LibraryTablesRegistrar)3 LocalFileSystem (com.intellij.openapi.vfs.LocalFileSystem)3 FlexLibraryProperties (com.intellij.lang.javascript.flex.library.FlexLibraryProperties)2 Application (com.intellij.openapi.application.Application)2 WriteAction (com.intellij.openapi.application.WriteAction)2