Search in sources :

Example 1 with ModuleOrderEntry

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

the class ReimportingTest method testChangingDependencyTypeToTestJar.

public void testChangingDependencyTypeToTestJar() throws Exception {
    configConfirmationForYesAnswer();
    VirtualFile m1 = createModulePom("m1", createPomXmlWithModuleDependency("jar"));
    VirtualFile m2 = createModulePom("m2", "<groupId>test</groupId>" + "<artifactId>m2</artifactId>" + "<version>1</version>");
    importProjects(m1, m2);
    assertModules("m1", "m2");
    ModuleOrderEntry dep = OrderEntryUtil.findModuleOrderEntry(ModuleRootManager.getInstance(getModule("m1")), getModule("m2"));
    assertNotNull(dep);
    assertFalse(((ModuleOrderEntryImpl) dep).isProductionOnTestDependency());
    createModulePom("m1", createPomXmlWithModuleDependency("test-jar"));
    importProjects(m1, m2);
    ModuleOrderEntry dep2 = OrderEntryUtil.findModuleOrderEntry(ModuleRootManager.getInstance(getModule("m1")), getModule("m2"));
    assertNotNull(dep2);
    assertTrue(((ModuleOrderEntryImpl) dep2).isProductionOnTestDependency());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry)

Example 2 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 3 with ModuleOrderEntry

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

the class ModuleDependencyDataService method importData.

@Override
protected Map<OrderEntry, OrderAware> importData(@NotNull final Collection<DataNode<ModuleDependencyData>> toImport, @NotNull final Module module, @NotNull final IdeModifiableModelsProvider modelsProvider) {
    final Map<Pair<String, DependencyScope>, ModuleOrderEntry> /* dependency module scope */
    toRemove = ContainerUtilRt.newHashMap();
    final Map<OrderEntry, OrderAware> orderEntryDataMap = ContainerUtil.newLinkedHashMap();
    for (OrderEntry entry : modelsProvider.getOrderEntries(module)) {
        if (entry instanceof ModuleOrderEntry) {
            ModuleOrderEntry e = (ModuleOrderEntry) entry;
            toRemove.put(Pair.create(e.getModuleName(), e.getScope()), e);
        }
    }
    final Set<ModuleDependencyData> processed = ContainerUtil.newHashSet();
    final ModifiableRootModel modifiableRootModel = modelsProvider.getModifiableRootModel(module);
    for (DataNode<ModuleDependencyData> dependencyNode : toImport) {
        final ModuleDependencyData dependencyData = dependencyNode.getData();
        if (processed.contains(dependencyData))
            continue;
        processed.add(dependencyData);
        toRemove.remove(Pair.create(dependencyData.getInternalName(), dependencyData.getScope()));
        final ModuleData moduleData = dependencyData.getTarget();
        Module ideDependencyModule = modelsProvider.findIdeModule(moduleData);
        ModuleOrderEntry orderEntry;
        if (module.equals(ideDependencyModule)) {
            // skip recursive module dependency check
            continue;
        } else {
            if (ideDependencyModule == null) {
                LOG.warn(String.format("Can't import module dependency for '%s' module. Reason: target module (%s) is not found at the ide", module.getName(), dependencyData));
            }
            orderEntry = modelsProvider.findIdeModuleDependency(dependencyData, module);
            if (orderEntry == null) {
                orderEntry = ReadAction.compute(() -> ideDependencyModule == null ? modifiableRootModel.addInvalidModuleEntry(moduleData.getInternalName()) : modifiableRootModel.addModuleOrderEntry(ideDependencyModule));
            }
        }
        orderEntry.setScope(dependencyData.getScope());
        orderEntry.setExported(dependencyData.isExported());
        final boolean productionOnTestDependency = dependencyData.isProductionOnTestDependency();
        if (orderEntry instanceof ModuleOrderEntryImpl) {
            ((ModuleOrderEntryImpl) orderEntry).setProductionOnTestDependency(productionOnTestDependency);
        } else if (productionOnTestDependency) {
            LOG.warn("Unable to set productionOnTestDependency for entry: " + orderEntry);
        }
        orderEntryDataMap.put(orderEntry, dependencyData);
    }
    if (!toRemove.isEmpty()) {
        removeData(toRemove.values(), module, modelsProvider);
    }
    return orderEntryDataMap;
}
Also used : ModuleOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleOrderEntryImpl) ModifiableRootModel(com.intellij.openapi.roots.ModifiableRootModel) OrderEntry(com.intellij.openapi.roots.OrderEntry) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) OrderAware(com.intellij.openapi.externalSystem.model.project.OrderAware) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) ModuleData(com.intellij.openapi.externalSystem.model.project.ModuleData) Module(com.intellij.openapi.module.Module) ModuleDependencyData(com.intellij.openapi.externalSystem.model.project.ModuleDependencyData) Pair(com.intellij.openapi.util.Pair)

Example 4 with ModuleOrderEntry

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

the class ModuleSourceItemGroup method collectDependentModules.

private static void collectDependentModules(final Module module, Set<Module> modules, ArtifactEditorContext context) {
    if (!modules.add(module))
        return;
    for (OrderEntry entry : context.getModulesProvider().getRootModel(module).getOrderEntries()) {
        if (entry instanceof ModuleOrderEntry) {
            final ModuleOrderEntry moduleEntry = (ModuleOrderEntry) entry;
            final Module dependency = moduleEntry.getModule();
            final DependencyScope scope = moduleEntry.getScope();
            if (dependency != null && scope.isForProductionRuntime()) {
                collectDependentModules(dependency, modules, context);
            }
        }
    }
}
Also used : OrderEntry(com.intellij.openapi.roots.OrderEntry) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) DependencyScope(com.intellij.openapi.roots.DependencyScope) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) Module(com.intellij.openapi.module.Module)

Example 5 with ModuleOrderEntry

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

the class DependenciesModuleSetupStep method updateModuleDependency.

private void updateModuleDependency(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull ModuleDependency dependency, @NotNull AndroidProject androidProject) {
    Module moduleDependency = dependency.getModule(modelsProvider);
    LibraryDependency compiledArtifact = dependency.getBackupDependency();
    if (moduleDependency != null) {
        ModuleOrderEntry orderEntry = modelsProvider.getModifiableRootModel(module).addModuleOrderEntry(moduleDependency);
        orderEntry.setScope(dependency.getScope());
        orderEntry.setExported(true);
        if (compiledArtifact != null) {
            setModuleCompiledArtifact(moduleDependency, compiledArtifact);
        }
        return;
    }
    DependencySetupErrors dependencySetupErrors = DependencySetupErrors.getInstance(module.getProject());
    String backupName = compiledArtifact != null ? compiledArtifact.getName() : null;
    dependencySetupErrors.addMissingModule(dependency.getGradlePath(), module.getName(), backupName);
    // fall back to library dependency, if available.
    if (compiledArtifact != null) {
        updateLibraryDependency(module, modelsProvider, compiledArtifact, androidProject);
    }
}
Also used : DependencySetupErrors(com.android.tools.idea.gradle.project.sync.setup.module.common.DependencySetupErrors) LibraryDependency(com.android.tools.idea.gradle.project.sync.setup.module.dependency.LibraryDependency) ModuleOrderEntry(com.intellij.openapi.roots.ModuleOrderEntry) 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