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 android by JetBrains.
the class DependenciesModuleSetupStep method updateDependency.
private static void updateDependency(@NotNull Module module, @NotNull IdeModifiableModelsProvider modelsProvider, @NotNull JavaModuleDependency dependency) {
DependencySetupErrors setupErrors = DependencySetupErrors.getInstance(module.getProject());
String moduleName = dependency.getModuleName();
Module found = null;
for (Module m : modelsProvider.getModules()) {
if (moduleName.equals(m.getName())) {
found = m;
}
}
ModifiableRootModel moduleModel = modelsProvider.getModifiableRootModel(module);
if (found != null) {
AndroidFacet androidFacet = findFacet(found, modelsProvider, AndroidFacet.ID);
if (androidFacet == null) {
ModuleOrderEntry entry = moduleModel.addModuleOrderEntry(found);
entry.setExported(true);
} else {
// If it depends on an android module, we should skip that.
setupErrors.addInvalidModuleDependency(moduleModel.getModule(), found.getName(), "Java modules cannot depend on Android modules");
}
return;
}
setupErrors.addMissingModule(moduleName, module.getName(), null);
}
use of com.intellij.openapi.roots.ModuleOrderEntry in project android by JetBrains.
the class ModuleDependenciesSubject method contains.
@NotNull
public ModuleDependenciesSubject contains(@NotNull ExpectedModuleDependency dependency) {
String moduleName = dependency.getModule().getName();
ModuleOrderEntry orderEntry = myModuleDependenciesByName.get(moduleName);
assertNotNull("dependency on module '" + moduleName + "'", orderEntry);
assertEquals("scope", orderEntry.getScope(), dependency.getScope());
assertEquals("exported", orderEntry.isExported(), dependency.isExported());
return this;
}
use of com.intellij.openapi.roots.ModuleOrderEntry in project android by JetBrains.
the class NonGradleApkProvider method fillRuntimeAndTestDependencies.
private static void fillRuntimeAndTestDependencies(@NotNull Module module, @NotNull Map<AndroidFacet, String> module2PackageName) throws ApkProvisionException {
for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
if (entry instanceof ModuleOrderEntry) {
ModuleOrderEntry moduleOrderEntry = (ModuleOrderEntry) entry;
Module depModule = moduleOrderEntry.getModule();
if (depModule != null) {
AndroidFacet depFacet = AndroidFacet.getInstance(depModule);
if (depFacet != null && !module2PackageName.containsKey(depFacet) && depFacet.isAppProject()) {
String packageName = ApkProviderUtil.computePackageName(depFacet);
module2PackageName.put(depFacet, packageName);
fillRuntimeAndTestDependencies(depModule, module2PackageName);
}
}
}
}
}
use of com.intellij.openapi.roots.ModuleOrderEntry in project intellij-community by JetBrains.
the class UnnecessaryModuleDependencyInspection method checkElement.
@Override
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull final GlobalInspectionContext globalContext) {
if (refEntity instanceof RefModule) {
final RefModule refModule = (RefModule) refEntity;
final Module module = refModule.getModule();
if (module.isDisposed() || !scope.containsModule(module))
return CommonProblemDescriptor.EMPTY_ARRAY;
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
final OrderEntry[] declaredDependencies = moduleRootManager.getOrderEntries();
final Module[] declaredModuleDependencies = moduleRootManager.getDependencies();
List<CommonProblemDescriptor> descriptors = new ArrayList<>();
final Set<Module> modules = refModule.getUserData(UnnecessaryModuleDependencyAnnotator.DEPENDENCIES);
Graph<Module> graph = myGraph.get();
if (graph == null) {
graph = ModuleManager.getInstance(globalContext.getProject()).moduleGraph();
myGraph = new SoftReference<>(graph);
}
final RefManager refManager = globalContext.getRefManager();
for (final OrderEntry entry : declaredDependencies) {
if (entry instanceof ModuleOrderEntry) {
final Module dependency = ((ModuleOrderEntry) entry).getModule();
if (dependency != null) {
if (modules == null || !modules.contains(dependency)) {
List<String> dependenciesThroughExported = null;
if (((ModuleOrderEntry) entry).isExported()) {
final Iterator<Module> iterator = graph.getOut(module);
while (iterator.hasNext()) {
final Module dep = iterator.next();
final RefModule depRefModule = refManager.getRefModule(dep);
if (depRefModule != null) {
final Set<Module> neededModules = depRefModule.getUserData(UnnecessaryModuleDependencyAnnotator.DEPENDENCIES);
if (neededModules != null && neededModules.contains(dependency)) {
if (dependenciesThroughExported == null) {
dependenciesThroughExported = new ArrayList<>();
}
dependenciesThroughExported.add(dep.getName());
}
}
}
}
if (modules != null) {
List<String> transitiveDependencies = new ArrayList<>();
final OrderEntry[] dependenciesOfDependencies = ModuleRootManager.getInstance(dependency).getOrderEntries();
for (OrderEntry secondDependency : dependenciesOfDependencies) {
if (secondDependency instanceof ModuleOrderEntry && ((ModuleOrderEntry) secondDependency).isExported()) {
final Module mod = ((ModuleOrderEntry) secondDependency).getModule();
if (mod != null && modules.contains(mod) && ArrayUtil.find(declaredModuleDependencies, mod) < 0) {
transitiveDependencies.add(mod.getName());
}
}
}
if (!transitiveDependencies.isEmpty()) {
final String exported = StringUtil.join(transitiveDependencies, ", ");
descriptors.add(manager.createProblemDescriptor(InspectionsBundle.message("unnecessary.module.dependency.exported.problem.descriptor1", module.getName(), dependency.getName(), exported)));
continue;
}
}
descriptors.add(createDescriptor(scope, manager, module, dependency, dependenciesThroughExported));
}
}
}
}
return descriptors.isEmpty() ? null : descriptors.toArray(new CommonProblemDescriptor[descriptors.size()]);
}
return null;
}
Aggregations