private void updateDependency(@NotNull ModifiableRootModel model,
@Nullable String project,
@NotNull List<Message> errorsFound) {
if (project == null || project.isEmpty()) return;
ModuleDependency dependency = new ModuleDependency(project, DependencyScope.TEST);
ModuleManager moduleManager = ModuleManager.getInstance(model.getProject());
Module moduleDependency = null;
for (Module module : moduleManager.getModules()) {
AndroidGradleFacet androidGradleFacet = AndroidGradleFacet.getInstance(module);
if (androidGradleFacet != null) {
String gradlePath = androidGradleFacet.getConfiguration().GRADLE_PROJECT_PATH;
if (Objects.equal(gradlePath, dependency.getGradlePath())) {
moduleDependency = module;
break;
}
}
}
if (moduleDependency != null) {
ModuleOrderEntry orderEntry = model.addModuleOrderEntry(moduleDependency);
orderEntry.setExported(true);
return;
}
LibraryDependency backup = dependency.getBackupDependency();
boolean hasLibraryBackup = backup != null;
String msg = String.format("Unable to find module with Gradle path '%1$s'.", dependency.getGradlePath());
Message.Type type = Message.Type.ERROR;
if (hasLibraryBackup) {
msg += String.format(" Linking to library '%1$s' instead.", backup.getName());
type = Message.Type.WARNING;