Search in sources :

Example 36 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry 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 37 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry 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 38 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry in project sonarlint-intellij by SonarSource.

the class JavaAnalysisConfigurator method getProjectClasspath.

private static VirtualFile[] getProjectClasspath(@Nullable final Module module) {
    if (module == null) {
        return new VirtualFile[0];
    }
    final List<VirtualFile> found = new LinkedList<>();
    final ModuleRootManager mrm = ModuleRootManager.getInstance(module);
    final OrderEntry[] orderEntries = mrm.getOrderEntries();
    for (final OrderEntry entry : orderEntries) {
        if (entry instanceof ModuleOrderEntry) {
            // Add dependent module output dir as library
            Module dependentModule = ((ModuleOrderEntry) entry).getModule();
            found.addAll(getModuleEntries(dependentModule));
        } else if (entry instanceof LibraryOrderEntry) {
            Library lib = ((LibraryOrderEntry) entry).getLibrary();
            found.addAll(getLibraryEntries(lib));
        }
    }
    return found.toArray(new VirtualFile[found.size()]);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library) Module(com.intellij.openapi.module.Module) LinkedList(java.util.LinkedList)

Example 39 with LibraryOrderEntry

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

the class ModuleObserver method addMOEDependencies.

private void addMOEDependencies(@NotNull final Module module) {
    final String home = MOESdkPlugin.getSdkRootPath(module);
    if (home == null || home.isEmpty()) {
        LOG.debug("Unable to find MOE home");
        return;
    }
    ApplicationManager.getApplication().runWriteAction(new DumbAwareRunnable() {

        @Override
        public void run() {
            for (String jar : MOE_JARS) {
                String jarPath = home + File.separator + MOE_JARS_PATH + File.separator + jar;
                VirtualFile file = LocalFileSystem.getInstance().findFileByPath(jarPath);
                if (file == null) {
                    return;
                }
                final ModuleRootManager manager = ModuleRootManager.getInstance(module);
                final ModifiableRootModel rootModel = manager.getModifiableModel();
                final Library jarLibrary = rootModel.getModuleLibraryTable().createLibrary();
                final Library.ModifiableModel libraryModel = jarLibrary.getModifiableModel();
                libraryModel.setName("Maven: " + jar);
                String url = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, jarPath) + JarFileSystem.JAR_SEPARATOR;
                libraryModel.addRoot(url, OrderRootType.CLASSES);
                libraryModel.commit();
                final LibraryOrderEntry orderEntry = rootModel.findLibraryOrderEntry(jarLibrary);
                orderEntry.setScope(DependencyScope.COMPILE);
                rootModel.commit();
            }
            checkRunConfiguration(module.getProject(), module);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) Library(com.intellij.openapi.roots.libraries.Library) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable)

Example 40 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij by bazelbuild.

the class AddLibraryTargetDirectoryToProjectViewAttachSourcesProvider method getActions.

@NotNull
@Override
public Collection<AttachSourcesAction> getActions(List<LibraryOrderEntry> orderEntries, final PsiFile psiFile) {
    Project project = psiFile.getProject();
    BlazeProjectData blazeProjectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
    if (blazeProjectData == null) {
        return ImmutableList.of();
    }
    List<Library> librariesToAttachSourceTo = Lists.newArrayList();
    for (LibraryOrderEntry orderEntry : orderEntries) {
        Library library = orderEntry.getLibrary();
        WorkspacePath workspacePath = AddLibraryTargetDirectoryToProjectViewAction.getDirectoryToAddForLibrary(project, library);
        if (workspacePath == null) {
            continue;
        }
        librariesToAttachSourceTo.add(library);
    }
    if (librariesToAttachSourceTo.isEmpty()) {
        return ImmutableList.of();
    }
    return ImmutableList.of(new AttachSourcesAction() {

        @Override
        public String getName() {
            return "Add Source Directories To Project View";
        }

        @Override
        public String getBusyText() {
            return "Adding directories...";
        }

        @Override
        public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) {
            AddLibraryTargetDirectoryToProjectViewAction.addDirectoriesToProjectView(project, librariesToAttachSourceTo);
            return ActionCallback.DONE;
        }
    });
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) Project(com.intellij.openapi.project.Project) ActionCallback(com.intellij.openapi.util.ActionCallback) BlazeProjectData(com.google.idea.blaze.base.model.BlazeProjectData) Library(com.intellij.openapi.roots.libraries.Library) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)40 Library (com.intellij.openapi.roots.libraries.Library)27 OrderEntry (com.intellij.openapi.roots.OrderEntry)17 Module (com.intellij.openapi.module.Module)8 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)7 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)6 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)5 Nullable (org.jetbrains.annotations.Nullable)5 Project (com.intellij.openapi.project.Project)4 File (java.io.File)4 NotNull (org.jetbrains.annotations.NotNull)4 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)3 ActionCallback (com.intellij.openapi.util.ActionCallback)3 THashSet (gnu.trove.THashSet)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Notification (com.intellij.notification.Notification)2 IdeModifiableModelsProvider (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider)2 IdeModifiableModelsProviderImpl (com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProviderImpl)2