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;
}
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);
}
}
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);
}
Aggregations