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