Search in sources :

Example 1 with ModuleOrderEntryImpl

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

the class MavenRootModelAdapter method addModuleDependency.

public void addModuleDependency(@NotNull String moduleName, @NotNull DependencyScope scope, boolean testJar) {
    Module m = findModuleByName(moduleName);
    ModuleOrderEntry e;
    if (m != null) {
        e = myRootModel.addModuleOrderEntry(m);
    } else {
        AccessToken accessToken = ReadAction.start();
        try {
            e = myRootModel.addInvalidModuleEntry(moduleName);
        } finally {
            accessToken.finish();
        }
    }
    e.setScope(scope);
    if (testJar) {
        ((ModuleOrderEntryImpl) e).setProductionOnTestDependency(true);
    }
    if (myOrderEntriesBeforeJdk.contains(moduleName)) {
        moveLastOrderEntryBeforeJdk();
    }
}
Also used : AccessToken(com.intellij.openapi.application.AccessToken) Module(com.intellij.openapi.module.Module) ModuleOrderEntryImpl(com.intellij.openapi.roots.impl.ModuleOrderEntryImpl)

Example 2 with ModuleOrderEntryImpl

use of com.intellij.openapi.roots.impl.ModuleOrderEntryImpl 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)

Aggregations

Module (com.intellij.openapi.module.Module)2 ModuleOrderEntryImpl (com.intellij.openapi.roots.impl.ModuleOrderEntryImpl)2 AccessToken (com.intellij.openapi.application.AccessToken)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 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)1 ModuleOrderEntry (com.intellij.openapi.roots.ModuleOrderEntry)1 OrderEntry (com.intellij.openapi.roots.OrderEntry)1 Pair (com.intellij.openapi.util.Pair)1