Search in sources :

Example 71 with LibraryTable

use of com.intellij.openapi.roots.libraries.LibraryTable in project ballerina by ballerina-lang.

the class BallerinaModuleLibrariesInitializer method attachLibraries.

private void attachLibraries(@NotNull Collection<VirtualFile> libraryRoots, Set<VirtualFile> exclusions) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (!libraryRoots.isEmpty()) {
        ApplicationManager.getApplication().runWriteAction(() -> {
            ModuleRootManager model = ModuleRootManager.getInstance(myModule);
            LibraryOrderEntry ballerinaLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName());
            if (ballerinaLibraryEntry != null && ballerinaLibraryEntry.isValid()) {
                Library library = ballerinaLibraryEntry.getLibrary();
                if (library != null && !((LibraryEx) library).isDisposed()) {
                    fillLibrary(library, libraryRoots, exclusions);
                }
            } else {
                LibraryTable libraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(myModule.getProject());
                Library library = libraryTable.createLibrary(getLibraryName());
                fillLibrary(library, libraryRoots, exclusions);
                ModuleRootModificationUtil.addDependency(myModule, library);
            }
        });
        showNotification(myModule.getProject());
    } else {
        removeLibraryIfNeeded();
    }
}
Also used : LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library)

Example 72 with LibraryTable

use of com.intellij.openapi.roots.libraries.LibraryTable in project ballerina by ballerina-lang.

the class BallerinaModuleLibrariesInitializer method removeLibraryIfNeeded.

private void removeLibraryIfNeeded() {
    ApplicationManager.getApplication().assertIsDispatchThread();
    ModifiableModelsProvider modelsProvider = ModifiableModelsProvider.SERVICE.getInstance();
    ModifiableRootModel model = modelsProvider.getModuleModifiableModel(myModule);
    LibraryOrderEntry ballerinaLibraryEntry = OrderEntryUtil.findLibraryOrderEntry(model, getLibraryName());
    if (ballerinaLibraryEntry != null) {
        ApplicationManager.getApplication().runWriteAction(() -> {
            Library library = ballerinaLibraryEntry.getLibrary();
            if (library != null) {
                LibraryTable table = library.getTable();
                if (table != null) {
                    table.removeLibrary(library);
                    model.removeOrderEntry(ballerinaLibraryEntry);
                    modelsProvider.commitModuleModifiableModel(model);
                }
            } else {
                modelsProvider.disposeModuleModifiableModel(model);
            }
        });
    } else {
        ApplicationManager.getApplication().runWriteAction(() -> modelsProvider.disposeModuleModifiableModel(model));
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ModifiableModelsProvider(com.intellij.openapi.roots.ModifiableModelsProvider) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library)

Example 73 with LibraryTable

use of com.intellij.openapi.roots.libraries.LibraryTable in project Perl5-IDEA by Camelcade.

the class PerlModuleBuilder method setupRootModel.

@Override
public void setupRootModel(ModifiableRootModel rootModel) {
    final CompilerModuleExtension compilerModuleExtension = rootModel.getModuleExtension(CompilerModuleExtension.class);
    compilerModuleExtension.setExcludeOutput(true);
    if (myJdk != null) {
        rootModel.setSdk(myJdk);
    } else {
        rootModel.inheritSdk();
    }
    ContentEntry contentEntry = doAddContentEntry(rootModel);
    if (contentEntry != null) {
        final List<Pair<String, String>> sourcePaths = getSourcePaths();
        if (sourcePaths != null) {
            for (final Pair<String, String> sourcePath : sourcePaths) {
                String first = sourcePath.first;
                new File(first).mkdirs();
                final VirtualFile sourceRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(FileUtil.toSystemIndependentName(first));
                if (sourceRoot != null) {
                    contentEntry.addSourceFolder(sourceRoot, false, sourcePath.second);
                }
            }
        }
    }
    LibraryTable libraryTable = rootModel.getModuleLibraryTable();
    for (Pair<String, String> libInfo : myModuleLibraries) {
        final String moduleLibraryPath = libInfo.first;
        final String sourceLibraryPath = libInfo.second;
        Library library = libraryTable.createLibrary();
        Library.ModifiableModel modifiableModel = library.getModifiableModel();
        modifiableModel.addRoot(getUrlByPath(moduleLibraryPath), OrderRootType.CLASSES);
        if (sourceLibraryPath != null) {
            modifiableModel.addRoot(getUrlByPath(sourceLibraryPath), OrderRootType.SOURCES);
        }
        modifiableModel.commit();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ContentEntry(com.intellij.openapi.roots.ContentEntry) Library(com.intellij.openapi.roots.libraries.Library) CompilerModuleExtension(com.intellij.openapi.roots.CompilerModuleExtension) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Pair(com.intellij.openapi.util.Pair)

Example 74 with LibraryTable

use of com.intellij.openapi.roots.libraries.LibraryTable in project moe-ide-integration by multi-os-engine.

the class ModuleObserver method checkMOEDependencies.

private void checkMOEDependencies(@NotNull final Module module) {
    final String home = MOESdkPlugin.getSdkRootPath(module);
    if (home == null || home.isEmpty()) {
        LOG.debug("Unable to find MOE home");
        return;
    }
    ModuleRootManager manager = ModuleRootManager.getInstance(module);
    final ModifiableRootModel rootModel = manager.getModifiableModel();
    final LibraryTable libraryTable = rootModel.getModuleLibraryTable();
    ApplicationManager.getApplication().runWriteAction(new DumbAwareRunnable() {

        @Override
        public void run() {
            for (String jar : MOE_JARS) {
                Library library = libraryTable.getLibraryByName("Maven: " + jar);
                if (library != null) {
                    String jarPath = home + File.separator + MOE_JARS_PATH + File.separator + jar;
                    String[] urls = library.getUrls(OrderRootType.CLASSES);
                    if (urls.length > 0) {
                        String url = urls[0];
                        String newUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, jarPath) + JarFileSystem.JAR_SEPARATOR;
                        if (!url.equals(newUrl)) {
                            final Library.ModifiableModel libraryModel = library.getModifiableModel();
                            libraryModel.removeRoot(url, OrderRootType.CLASSES);
                            libraryModel.addRoot(newUrl, OrderRootType.CLASSES);
                            libraryModel.commit();
                        }
                    }
                }
            }
            rootModel.commit();
        }
    });
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Library(com.intellij.openapi.roots.libraries.Library) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable)

Example 75 with LibraryTable

use of com.intellij.openapi.roots.libraries.LibraryTable in project intellij by bazelbuild.

the class BlazeKotlinSyncPlugin method updateProjectStructure.

/**
 * Attaches sources to Kotlin external artifacts, add missing mandatory std libraries and perform
 * last bit of Kotlin configuration.
 */
@Override
public void updateProjectStructure(Project project, BlazeContext context, WorkspaceRoot workspaceRoot, ProjectViewSet projectViewSet, BlazeProjectData blazeProjectData, @Nullable BlazeProjectData oldBlazeProjectData, ModuleEditor moduleEditor, Module workspaceModule, ModifiableRootModel workspaceModifiableModel) {
    if (!blazeProjectData.workspaceLanguageSettings.isLanguageActive(LanguageClass.KOTLIN)) {
        return;
    }
    LibraryTable.ModifiableModel libraryTable = ProjectLibraryTable.getInstance(project).getModifiableModel();
    externalKotlinLibraries(blazeProjectData).forEach(lib -> {
        Library library = libraryTable.getLibraryByName(lib.key.getIntelliJLibraryName());
        if (library == null) {
            library = libraryTable.createLibrary(lib.key.getIntelliJLibraryName());
        }
        Library.ModifiableModel modifiableIjLibrary = library.getModifiableModel();
        maybeAttachSourceJars(blazeProjectData.artifactLocationDecoder, lib, modifiableIjLibrary);
        modifiableIjLibrary.commit();
    });
    libraryTable.commit();
    KotlinJavaModuleConfigurator.Companion.getInstance().configureSilently(project);
}
Also used : ProjectLibraryTable(com.intellij.openapi.roots.impl.libraries.ProjectLibraryTable) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) BlazeLibrary(com.google.idea.blaze.base.model.BlazeLibrary) Library(com.intellij.openapi.roots.libraries.Library) BlazeJarLibrary(com.google.idea.blaze.java.sync.model.BlazeJarLibrary)

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