Search in sources :

Example 31 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-community by JetBrains.

the class MavenProjectsManagerTest method testForceReimport.

public void testForceReimport() throws Exception {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>junit</groupId>" + "    <artifactId>junit</artifactId>" + "    <version>4.0</version>" + "  </dependency>" + "</dependencies>");
    importProject();
    assertModules("project");
    createProjectSubDir("src/main/java");
    ApplicationManager.getApplication().runWriteAction(() -> {
        ModifiableRootModel model = ModuleRootManager.getInstance(getModule("project")).getModifiableModel();
        for (OrderEntry each : model.getOrderEntries()) {
            if (each instanceof LibraryOrderEntry && MavenRootModelAdapter.isMavenLibrary(((LibraryOrderEntry) each).getLibrary())) {
                model.removeOrderEntry(each);
            }
        }
        model.commit();
    });
    assertSources("project");
    assertModuleLibDeps("project");
    myProjectsManager.forceUpdateAllProjectsOrFindAllAvailablePomFiles();
    waitForReadingCompletion();
    myProjectsManager.waitForResolvingCompletion();
    myProjectsManager.performScheduledImportInTests();
    assertSources("project", "src/main/java");
    assertModuleLibDeps("project", "Maven: junit:junit:4.0");
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry)

Example 32 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-community by JetBrains.

the class JUnitDependencyScopeSuggesterTest method getScope.

private DependencyScope getScope(String name) {
    LibraryOrderEntry entry = OrderEntryUtil.findLibraryOrderEntry(ModuleRootManager.getInstance(myModule), name);
    assertNotNull(entry);
    Library library = entry.getLibrary();
    assertNotNull(library);
    return new JUnitDependencyScopeSuggester().getDefaultDependencyScope(library);
}
Also used : LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library)

Example 33 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-community by JetBrains.

the class ChangeLibraryLevelInClasspathAction method isEnabled.

@Override
protected boolean isEnabled() {
    final OrderEntry entry = myPanel.getSelectedEntry();
    boolean enabled = false;
    if (entry instanceof LibraryOrderEntry) {
        final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
        if (libraryOrderEntry.getLibrary() != null) {
            boolean isFromModuleLibrary = libraryOrderEntry.isModuleLevel();
            boolean isToModuleLibrary = isConvertingToModuleLibrary();
            enabled = isFromModuleLibrary != isToModuleLibrary;
        }
    }
    return enabled;
}
Also used : LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry)

Example 34 with LibraryOrderEntry

use of com.intellij.openapi.roots.LibraryOrderEntry in project intellij-community by JetBrains.

the class FindInProjectUtil method addSourceDirectoriesFromLibraries.

private static void addSourceDirectoriesFromLibraries(@NotNull Project project, @NotNull VirtualFile directory, @NotNull Collection<VirtualFile> outSourceRoots) {
    ProjectFileIndex index = ProjectFileIndex.SERVICE.getInstance(project);
    // if we already are in the sources, search just in this directory only
    if (!index.isInLibraryClasses(directory))
        return;
    VirtualFile classRoot = index.getClassRootForFile(directory);
    if (classRoot == null)
        return;
    String relativePath = VfsUtilCore.getRelativePath(directory, classRoot);
    if (relativePath == null)
        return;
    Collection<VirtualFile> otherSourceRoots = new THashSet<>();
    // otherwise, if we outside sources or in a jar directory, add directories from other source roots
    searchForOtherSourceDirs: for (OrderEntry entry : index.getOrderEntriesForFile(directory)) {
        if (entry instanceof LibraryOrderEntry) {
            Library library = ((LibraryOrderEntry) entry).getLibrary();
            if (library == null)
                continue;
            // note: getUrls() returns jar directories too
            String[] sourceUrls = library.getUrls(OrderRootType.SOURCES);
            for (String sourceUrl : sourceUrls) {
                if (VfsUtilCore.isEqualOrAncestor(sourceUrl, directory.getUrl())) {
                    // already in this library sources, no need to look for another source root
                    otherSourceRoots.clear();
                    break searchForOtherSourceDirs;
                }
            // otherwise we may be inside the jar file in a library which is configured as a jar directory
            // in which case we have no way to know whether this is a source jar or classes jar - so try to locate the source jar
            }
        }
        for (VirtualFile sourceRoot : entry.getFiles(OrderRootType.SOURCES)) {
            VirtualFile sourceFile = sourceRoot.findFileByRelativePath(relativePath);
            if (sourceFile != null) {
                otherSourceRoots.add(sourceFile);
            }
        }
    }
    outSourceRoots.addAll(otherSourceRoots);
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library) THashSet(gnu.trove.THashSet)

Example 35 with LibraryOrderEntry

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

the class BallerinaSdkConfigurable method updateModules.

private static void updateModules(@NotNull Project project, @NotNull Library lib, boolean remove) {
    Module[] modules = ModuleManager.getInstance(project).getModules();
    for (Module module : modules) {
        ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
        if (!remove) {
            if (model.findLibraryOrderEntry(lib) == null) {
                LibraryOrderEntry entry = model.addLibraryEntry(lib);
                entry.setScope(DependencyScope.PROVIDED);
            }
        } else {
            LibraryOrderEntry entry = model.findLibraryOrderEntry(lib);
            if (entry != null) {
                model.removeOrderEntry(entry);
            }
        }
        model.commit();
    }
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Module(com.intellij.openapi.module.Module)

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