Search in sources :

Example 1 with OrderAware

use of com.intellij.openapi.externalSystem.model.project.OrderAware 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 2 with OrderAware

use of com.intellij.openapi.externalSystem.model.project.OrderAware in project intellij-community by JetBrains.

the class AbstractModuleDataService method postProcess.

@Override
public void postProcess(@NotNull Collection<DataNode<E>> toImport, @Nullable ProjectData projectData, @NotNull Project project, @NotNull IdeModifiableModelsProvider modelsProvider) {
    for (DataNode<E> moduleDataNode : toImport) {
        final Module module = moduleDataNode.getUserData(MODULE_KEY);
        if (module == null)
            continue;
        final Map<OrderEntry, OrderAware> orderAwareMap = moduleDataNode.getUserData(ORDERED_DATA_MAP_KEY);
        if (orderAwareMap != null) {
            rearrangeOrderEntries(orderAwareMap, modelsProvider.getModifiableRootModel(module));
        }
        setBytecodeTargetLevel(project, module, moduleDataNode.getData());
    }
    for (Module module : modelsProvider.getModules()) {
        module.putUserData(MODULE_DATA_KEY, null);
    }
}
Also used : OrderAware(com.intellij.openapi.externalSystem.model.project.OrderAware) Module(com.intellij.openapi.module.Module)

Example 3 with OrderAware

use of com.intellij.openapi.externalSystem.model.project.OrderAware in project intellij-community by JetBrains.

the class AbstractModuleDataService method rearrangeOrderEntries.

protected void rearrangeOrderEntries(@NotNull Map<OrderEntry, OrderAware> orderEntryDataMap, @NotNull ModifiableRootModel modifiableRootModel) {
    final OrderEntry[] orderEntries = modifiableRootModel.getOrderEntries();
    final int length = orderEntries.length;
    final OrderEntry[] newOrder = new OrderEntry[length];
    final PriorityQueue<Pair<OrderEntry, OrderAware>> priorityQueue = new PriorityQueue<>(11, (o1, o2) -> {
        int order1 = o1.second.getOrder();
        int order2 = o2.second.getOrder();
        return order1 != order2 ? order1 < order2 ? -1 : 1 : 0;
    });
    int shift = 0;
    for (int i = 0; i < length; i++) {
        OrderEntry orderEntry = orderEntries[i];
        final OrderAware orderAware = orderEntryDataMap.get(orderEntry);
        if (orderAware == null) {
            newOrder[i] = orderEntry;
            shift++;
        } else {
            priorityQueue.add(Pair.create(orderEntry, orderAware));
        }
    }
    Pair<OrderEntry, OrderAware> pair;
    while ((pair = priorityQueue.poll()) != null) {
        final OrderEntry orderEntry = pair.first;
        final OrderAware orderAware = pair.second;
        final int order = orderAware.getOrder() != -1 ? orderAware.getOrder() : length - 1;
        final int newPlace = findNewPlace(newOrder, order - shift);
        assert newPlace != -1;
        newOrder[newPlace] = orderEntry;
    }
    if (LOG.isDebugEnabled()) {
        final boolean changed = !ArrayUtil.equals(orderEntries, newOrder, new Comparator<OrderEntry>() {

            @Override
            public int compare(OrderEntry o1, OrderEntry o2) {
                return o1.compareTo(o2);
            }
        });
        LOG.debug(String.format("rearrange status (%s): %s", modifiableRootModel.getModule(), changed ? "modified" : "not modified"));
    }
    modifiableRootModel.rearrangeOrderEntries(newOrder);
}
Also used : OrderAware(com.intellij.openapi.externalSystem.model.project.OrderAware) Pair(com.intellij.openapi.util.Pair)

Aggregations

OrderAware (com.intellij.openapi.externalSystem.model.project.OrderAware)3 Module (com.intellij.openapi.module.Module)2 Pair (com.intellij.openapi.util.Pair)2 ModuleData (com.intellij.openapi.externalSystem.model.project.ModuleData)1 ModuleDependencyData (com.intellij.openapi.externalSystem.model.project.ModuleDependencyData)1 ModifiableRootModel (com.intellij.openapi.roots.ModifiableRootModel)1 ModuleOrderEntry (com.intellij.openapi.roots.ModuleOrderEntry)1 OrderEntry (com.intellij.openapi.roots.OrderEntry)1 ModuleOrderEntryImpl (com.intellij.openapi.roots.impl.ModuleOrderEntryImpl)1