Search in sources :

Example 41 with OrderEntry

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

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

the class ProjectStructureSelectInTarget method selectIn.

@Override
public void selectIn(final SelectInContext context, final boolean requestFocus) {
    final Project project = context.getProject();
    final VirtualFile file = context.getVirtualFile();
    final Module module;
    final Facet facet;
    if (file instanceof WrappingVirtualFile) {
        final Object o = ((WrappingVirtualFile) file).getWrappedObject(project);
        facet = o instanceof Facet ? (Facet) o : null;
        module = facet == null ? null : facet.getModule();
    } else {
        Module moduleByIml = file.getFileType().equals(StdFileTypes.IDEA_MODULE) ? findModuleByModuleFile(project, file) : null;
        final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
        module = moduleByIml != null ? moduleByIml : fileIndex.getModuleForFile(file);
        facet = fileIndex.isInSourceContent(file) ? null : findFacet(project, file);
    }
    if (module != null || facet != null) {
        ApplicationManager.getApplication().invokeLater(() -> {
            if (facet != null) {
                ModulesConfigurator.showFacetSettingsDialog(facet, null);
            } else {
                ProjectSettingsService.getInstance(project).openModuleSettings(module);
            }
        });
        return;
    }
    final OrderEntry orderEntry = LibraryUtil.findLibraryEntry(file, project);
    if (orderEntry != null) {
        ApplicationManager.getApplication().invokeLater(() -> ProjectSettingsService.getInstance(project).openLibraryOrSdkSettings(orderEntry));
    }
}
Also used : WrappingVirtualFile(com.intellij.openapi.vfs.WrappingVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OrderEntry(com.intellij.openapi.roots.OrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) WrappingVirtualFile(com.intellij.openapi.vfs.WrappingVirtualFile) Module(com.intellij.openapi.module.Module)

Example 43 with OrderEntry

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

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

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

the class PyBuiltinCache method findSdkForNonModuleFile.

@Nullable
public static Sdk findSdkForNonModuleFile(PsiFileSystemItem psiFile) {
    Project project = psiFile.getProject();
    Sdk sdk = null;
    final VirtualFile vfile = psiFile instanceof PsiFile ? ((PsiFile) psiFile).getOriginalFile().getVirtualFile() : psiFile.getVirtualFile();
    if (vfile != null) {
        // reality
        final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
        sdk = projectRootManager.getProjectSdk();
        if (sdk == null) {
            final List<OrderEntry> orderEntries = projectRootManager.getFileIndex().getOrderEntriesForFile(vfile);
            for (OrderEntry orderEntry : orderEntries) {
                if (orderEntry instanceof JdkOrderEntry) {
                    sdk = ((JdkOrderEntry) orderEntry).getJdk();
                } else if (orderEntry instanceof ModuleLibraryOrderEntryImpl) {
                    sdk = PythonSdkType.findPythonSdk(orderEntry.getOwnerModule());
                }
            }
        }
    }
    return sdk;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OrderEntry(com.intellij.openapi.roots.OrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) ModuleLibraryOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl) Sdk(com.intellij.openapi.projectRoots.Sdk) ProjectRootManager(com.intellij.openapi.roots.ProjectRootManager) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

OrderEntry (com.intellij.openapi.roots.OrderEntry)54 Module (com.intellij.openapi.module.Module)24 VirtualFile (com.intellij.openapi.vfs.VirtualFile)23 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)18 Project (com.intellij.openapi.project.Project)14 Library (com.intellij.openapi.roots.libraries.Library)12 ArrayList (java.util.ArrayList)11 JdkOrderEntry (com.intellij.openapi.roots.JdkOrderEntry)10 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)10 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)8 ModuleOrderEntry (com.intellij.openapi.roots.ModuleOrderEntry)8 Nullable (org.jetbrains.annotations.Nullable)8 NotNull (org.jetbrains.annotations.NotNull)7 ModuleLibraryOrderEntryImpl (com.intellij.openapi.roots.impl.ModuleLibraryOrderEntryImpl)5 List (java.util.List)5 Sdk (com.intellij.openapi.projectRoots.Sdk)4 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)4 AccessToken (com.intellij.openapi.application.AccessToken)3 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)3 LibraryTable (com.intellij.openapi.roots.libraries.LibraryTable)3