Search in sources :

Example 6 with ModuleOrderEntry

use of com.intellij.openapi.roots.ModuleOrderEntry in project kotlin by JetBrains.

the class ExternalSystemImportingTestCase method assertModuleModuleDepScope.

protected void assertModuleModuleDepScope(String moduleName, String depName, DependencyScope... scopes) {
    List<ModuleOrderEntry> deps = getModuleModuleDeps(moduleName, depName);
    Set<DependencyScope> actualScopes = new HashSet<DependencyScope>();
    for (ModuleOrderEntry dep : deps) {
        actualScopes.add(dep.getScope());
    }
    HashSet<DependencyScope> expectedScopes = new HashSet<DependencyScope>(Arrays.asList(scopes));
    assertEquals("Dependency '" + depName + "' for module '" + moduleName + "' has unexpected scope", expectedScopes, actualScopes);
}
Also used : DependencyScope(com.intellij.openapi.roots.DependencyScope) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry)

Example 7 with ModuleOrderEntry

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

the class DependenciesModuleSetupStep method updateDependency.

private static void updateDependency(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull JavaModuleDependency dependency) {
    DependencySetupErrors setupErrors = DependencySetupErrors.getInstance(module.getProject());
    String moduleName = dependency.getModuleName();
    Module found = null;
    for (Module m : modelsProvider.getModules()) {
        if (moduleName.equals(m.getName())) {
            found = m;
        }
    }
    ModifiableRootModel moduleModel = modelsProvider.getModifiableRootModel(module);
    if (found != null) {
        AndroidFacet androidFacet = findFacet(found, modelsProvider, AndroidFacet.ID);
        if (androidFacet == null) {
            ModuleOrderEntry entry = moduleModel.addModuleOrderEntry(found);
            entry.setExported(true);
        } else {
            // If it depends on an android module, we should skip that.
            setupErrors.addInvalidModuleDependency(moduleModel.getModule(), found.getName(), "Java modules cannot depend on Android modules");
        }
        return;
    }
    setupErrors.addMissingModule(moduleName, module.getName(), null);
}
Also used : ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) DependencySetupErrors(com.android.tools.idea.gradle.project.sync.setup.module.common.DependencySetupErrors) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet)

Example 8 with ModuleOrderEntry

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

the class ModuleDependenciesSubject method contains.

@NotNull
public ModuleDependenciesSubject contains(@NotNull ExpectedModuleDependency dependency) {
    String moduleName = dependency.getModule().getName();
    ModuleOrderEntry orderEntry = myModuleDependenciesByName.get(moduleName);
    assertNotNull("dependency on module '" + moduleName + "'", orderEntry);
    assertEquals("scope", orderEntry.getScope(), dependency.getScope());
    assertEquals("exported", orderEntry.isExported(), dependency.isExported());
    return this;
}
Also used : ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) Assert.assertNotNull(org.junit.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with ModuleOrderEntry

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

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

the class UnnecessaryModuleDependencyInspection method checkElement.

@Override
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull final GlobalInspectionContext globalContext) {
    if (refEntity instanceof RefModule) {
        final RefModule refModule = (RefModule) refEntity;
        final Module module = refModule.getModule();
        if (module.isDisposed() || !scope.containsModule(module))
            return CommonProblemDescriptor.EMPTY_ARRAY;
        final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
        final OrderEntry[] declaredDependencies = moduleRootManager.getOrderEntries();
        final Module[] declaredModuleDependencies = moduleRootManager.getDependencies();
        List<CommonProblemDescriptor> descriptors = new ArrayList<>();
        final Set<Module> modules = refModule.getUserData(UnnecessaryModuleDependencyAnnotator.DEPENDENCIES);
        Graph<Module> graph = myGraph.get();
        if (graph == null) {
            graph = ModuleManager.getInstance(globalContext.getProject()).moduleGraph();
            myGraph = new SoftReference<>(graph);
        }
        final RefManager refManager = globalContext.getRefManager();
        for (final OrderEntry entry : declaredDependencies) {
            if (entry instanceof ModuleOrderEntry) {
                final Module dependency = ((ModuleOrderEntry) entry).getModule();
                if (dependency != null) {
                    if (modules == null || !modules.contains(dependency)) {
                        List<String> dependenciesThroughExported = null;
                        if (((ModuleOrderEntry) entry).isExported()) {
                            final Iterator<Module> iterator = graph.getOut(module);
                            while (iterator.hasNext()) {
                                final Module dep = iterator.next();
                                final RefModule depRefModule = refManager.getRefModule(dep);
                                if (depRefModule != null) {
                                    final Set<Module> neededModules = depRefModule.getUserData(UnnecessaryModuleDependencyAnnotator.DEPENDENCIES);
                                    if (neededModules != null && neededModules.contains(dependency)) {
                                        if (dependenciesThroughExported == null) {
                                            dependenciesThroughExported = new ArrayList<>();
                                        }
                                        dependenciesThroughExported.add(dep.getName());
                                    }
                                }
                            }
                        }
                        if (modules != null) {
                            List<String> transitiveDependencies = new ArrayList<>();
                            final OrderEntry[] dependenciesOfDependencies = ModuleRootManager.getInstance(dependency).getOrderEntries();
                            for (OrderEntry secondDependency : dependenciesOfDependencies) {
                                if (secondDependency instanceof ModuleOrderEntry && ((ModuleOrderEntry) secondDependency).isExported()) {
                                    final Module mod = ((ModuleOrderEntry) secondDependency).getModule();
                                    if (mod != null && modules.contains(mod) && ArrayUtil.find(declaredModuleDependencies, mod) < 0) {
                                        transitiveDependencies.add(mod.getName());
                                    }
                                }
                            }
                            if (!transitiveDependencies.isEmpty()) {
                                final String exported = StringUtil.join(transitiveDependencies, ", ");
                                descriptors.add(manager.createProblemDescriptor(InspectionsBundle.message("unnecessary.module.dependency.exported.problem.descriptor1", module.getName(), dependency.getName(), exported)));
                                continue;
                            }
                        }
                        descriptors.add(createDescriptor(scope, manager, module, dependency, dependenciesThroughExported));
                    }
                }
            }
        }
        return descriptors.isEmpty() ? null : descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]);
    }
    return null;
}
Also used : RefManager(com.intellij.codeInspection.reference.RefManager) ArrayList(java.util.ArrayList) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) RefModule(com.intellij.codeInspection.reference.RefModule) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) OrderEntry(com.intellij.openapi.roots.OrderEntry) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) RefModule(com.intellij.codeInspection.reference.RefModule) Module(com.intellij.openapi.module.Module)

Aggregations

ModuleOrderEntry (com.intellij.openapi.roots.ModuleOrderEntry)11 Module (com.intellij.openapi.module.Module)8 OrderEntry (com.intellij.openapi.roots.OrderEntry)6 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 DependencySetupErrors (com.android.tools.idea.gradle.project.sync.setup.module.common.DependencySetupErrors)2 DependencyScope (com.intellij.openapi.roots.DependencyScope)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ArrayList (java.util.ArrayList)2 LibraryDependency (com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency)1 RefManager (com.intellij.codeInspection.reference.RefManager)1 RefModule (com.intellij.codeInspection.reference.RefModule)1 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)1 ModuleDependencyData (com.intellij.openapi.externalSystem.model.project.ModuleDependencyData)1 OrderAware (com.intellij.openapi.externalSystem.model.project.OrderAware)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 ModuleOrderEntryImpl (com.intellij.openapi.roots.impl.ModuleOrderEntryImpl)1 Pair (com.intellij.openapi.util.Pair)1 NotNull (org.jetbrains.annotations.NotNull)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1