Search in sources :

Example 26 with OrderEntry

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

the class ModuleDependenciesSetup method addLibraryAsDependency.

protected void addLibraryAsDependency(@NotNull Library library, @NotNull String libraryName, @NotNull DependencyScope scope, @NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider) {
    for (OrderEntry orderEntry : modelsProvider.getModifiableRootModel(module).getOrderEntries()) {
        if (orderEntry instanceof LibraryOrderEntry) {
            Library entryLibrary = ((LibraryOrderEntry) orderEntry).getLibrary();
            if (entryLibrary != null && libraryName.equals(entryLibrary.getName())) {
                // Dependency already set up.
                return;
            }
        }
    }
    LibraryOrderEntry orderEntry = modelsProvider.getModifiableRootModel(module).addLibraryEntry(library);
    orderEntry.setScope(scope);
    orderEntry.setExported(true);
}
Also used : LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Library(com.intellij.openapi.roots.libraries.Library)

Example 27 with OrderEntry

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

the class NonGradleApkProvider method fillRuntimeAndTestDependencies.

private static void fillRuntimeAndTestDependencies(@NotNull Module module, @NotNull Map<AndroidFacet, String> module2PackageName) throws ApkProvisionException {
    for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
        if (entry instanceof ModuleOrderEntry) {
            ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry) entry;
            Module depModule = moduleOrderEntry.getModule();
            if (depModule != null) {
                AndroidFacet depFacet = AndroidFacet.getInstance(depModule);
                if (depFacet != null && !module2PackageName.containsKey(depFacet) && depFacet.isAppProject()) {
                    String packageName = ApkProviderUtil.computePackageName(depFacet);
                    module2PackageName.put(depFacet, packageName);
                    fillRuntimeAndTestDependencies(depModule, module2PackageName);
                }
            }
        }
    }
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 28 with OrderEntry

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

the class DartUrlResolverImpl method initPackagesMapFromLib.

private void initPackagesMapFromLib(@NotNull final VirtualFile contextFile) {
    final Module module = ModuleUtilCore.findModuleForFile(contextFile, myProject);
    final List<OrderEntry> orderEntries = module != null ? Arrays.asList(ModuleRootManager.getInstance(module).getOrderEntries()) : ProjectRootManager.getInstance(myProject).getFileIndex().getOrderEntriesForFile(contextFile);
    for (OrderEntry orderEntry : orderEntries) {
        if (orderEntry instanceof LibraryOrderEntry && LibraryTablesRegistrar.PROJECT_LEVEL.equals(((LibraryOrderEntry) orderEntry).getLibraryLevel()) && DartPackagesLibraryType.DART_PACKAGES_LIBRARY_NAME.equals(((LibraryOrderEntry) orderEntry).getLibraryName())) {
            final LibraryEx library = (LibraryEx) ((LibraryOrderEntry) orderEntry).getLibrary();
            final LibraryProperties properties = library == null ? null : library.getProperties();
            if (properties instanceof DartPackagesLibraryProperties) {
                for (Map.Entry<String, List<String>> entry : ((DartPackagesLibraryProperties) properties).getPackageNameToDirsMap().entrySet()) {
                    if (entry != null && entry.getKey() != null && entry.getValue() != null) {
                        myPackagesMapFromLib.put(entry.getKey(), entry.getValue());
                    }
                }
                return;
            }
        }
    }
}
Also used : DartPackagesLibraryProperties(com.jetbrains.lang.dart.sdk.DartPackagesLibraryProperties) OrderEntry(com.intellij.openapi.roots.OrderEntry) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) DartPackagesLibraryProperties(com.jetbrains.lang.dart.sdk.DartPackagesLibraryProperties) LibraryProperties(com.intellij.openapi.roots.libraries.LibraryProperties) LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) List(java.util.List) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Module(com.intellij.openapi.module.Module) THashMap(gnu.trove.THashMap) Map(java.util.Map)

Example 29 with OrderEntry

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

the class GeneratePluginClassAction method getModule.

@Nullable
protected static Module getModule(PsiDirectory dir) {
    Project project = dir.getProject();
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final VirtualFile vFile = dir.getVirtualFile();
    if (fileIndex.isInLibrarySource(vFile) || fileIndex.isInLibraryClasses(vFile)) {
        final List<OrderEntry> orderEntries = fileIndex.getOrderEntriesForFile(vFile);
        if (orderEntries.isEmpty()) {
            return null;
        }
        Set<Module> modules = new HashSet<>();
        for (OrderEntry orderEntry : orderEntries) {
            modules.add(orderEntry.getOwnerModule());
        }
        final Module[] candidates = modules.toArray(new Module[modules.size()]);
        Arrays.sort(candidates, ModuleManager.getInstance(project).moduleDependencyComparator());
        return candidates[0];
    }
    return fileIndex.getModuleForFile(vFile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) OrderEntry(com.intellij.openapi.roots.OrderEntry) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) Module(com.intellij.openapi.module.Module) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with OrderEntry

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

the class ProjectUtilCore method displayUrlRelativeToProject.

public static String displayUrlRelativeToProject(@NotNull VirtualFile file, @NotNull String url, @NotNull Project project, boolean includeFilePath, boolean keepModuleAlwaysOnTheLeft) {
    final VirtualFile baseDir = project.getBaseDir();
    if (baseDir != null && includeFilePath) {
        //noinspection ConstantConditions
        final String projectHomeUrl = baseDir.getPresentableUrl();
        if (url.startsWith(projectHomeUrl)) {
            url = "..." + url.substring(projectHomeUrl.length());
        }
    }
    if (SystemInfo.isMac && file.getFileSystem() instanceof LocalFileProvider) {
        final VirtualFile fileForJar = ((LocalFileProvider) file.getFileSystem()).getLocalVirtualFileFor(file);
        if (fileForJar != null) {
            final OrderEntry libraryEntry = LibraryUtil.findLibraryEntry(file, project);
            if (libraryEntry != null) {
                if (libraryEntry instanceof JdkOrderEntry) {
                    url = url + " - [" + ((JdkOrderEntry) libraryEntry).getJdkName() + "]";
                } else {
                    url = url + " - [" + libraryEntry.getPresentableName() + "]";
                }
            } else {
                url = url + " - [" + fileForJar.getName() + "]";
            }
        }
    }
    final Module module = ModuleUtilCore.findModuleForFile(file, project);
    if (module == null)
        return url;
    return !keepModuleAlwaysOnTheLeft && SystemInfo.isMac ? url + " - [" + module.getName() + "]" : "[" + module.getName() + "] - " + url;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) OrderEntry(com.intellij.openapi.roots.OrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) JdkOrderEntry(com.intellij.openapi.roots.JdkOrderEntry) LocalFileProvider(com.intellij.openapi.vfs.LocalFileProvider) Module(com.intellij.openapi.module.Module)

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