public static boolean processDependenciesInDependencyManagement( @NotNull MavenDomProjectModel projectDom, @NotNull final Processor<MavenDomDependency> processor, @NotNull final Project project) { Processor<MavenDomDependencies> managedDependenciesListProcessor = dependencies -> { SmartList<MavenDomDependency> importDependencies = null; for (MavenDomDependency domDependency : dependencies.getDependencies()) { if ("import".equals(domDependency.getScope().getRawText())) { if (importDependencies == null) { importDependencies = new SmartList<MavenDomDependency>(); } importDependencies.add(domDependency); } else { if (processor.process(domDependency)) return true; } } if (importDependencies != null) { for (MavenDomDependency domDependency : importDependencies) { GenericDomValue<String> version = domDependency.getVersion(); if (version.getXmlElement() != null) { GenericDomValueReference reference = new GenericDomValueReference(version); PsiElement resolve = reference.resolve(); if (resolve instanceof XmlFile) { MavenDomProjectModel dependModel = MavenDomUtil.getMavenDomModel((PsiFile) resolve, MavenDomProjectModel.class); if (dependModel != null) { for (MavenDomDependency dep : dependModel.getDependencyManagement().getDependencies().getDependencies()) { if (processor.process(dep)) return true; } } } } } } return false; }; Function<MavenDomProjectModelBase, MavenDomDependencies> domFunction = mavenDomProfile -> mavenDomProfile.getDependencyManagement().getDependencies(); return process(projectDom, managedDependenciesListProcessor, project, domFunction, domFunction); }
private static <T> boolean processSettingsXml( @Nullable MavenProject mavenProject, @NotNull Processor<T> processor, @NotNull Project project, Function<? super MavenDomProfile, T> domProfileFunction) { MavenGeneralSettings settings = MavenProjectsManager.getInstance(project).getGeneralSettings(); for (VirtualFile each : settings.getEffectiveSettingsFiles()) { MavenDomSettingsModel settingsDom = MavenDomUtil.getMavenDomModel(project, each, MavenDomSettingsModel.class); if (settingsDom == null) continue; if (processProfiles(settingsDom.getProfiles(), mavenProject, processor, domProfileFunction)) return true; } return false; }