@Nullable public static MavenDomPlugin searchManagingPlugin(@NotNull final MavenDomPlugin plugin) { final String artifactId = plugin.getArtifactId().getStringValue(); final String groupId = plugin.getGroupId().getStringValue(); if (artifactId == null) return null; final MavenDomProjectModel model = plugin.getParentOfType(MavenDomProjectModel.class, false); if (model == null) return null; SearchProcessor<MavenDomPlugin, MavenDomPlugins> processor = new SearchProcessor<MavenDomPlugin, MavenDomPlugins>() { @Override protected MavenDomPlugin find(MavenDomPlugins mavenDomPlugins) { if (!model.equals(mavenDomPlugins.getParentOfType(MavenDomProjectModel.class, true))) { for (MavenDomPlugin domPlugin : mavenDomPlugins.getPlugins()) { if (MavenPluginDomUtil.isPlugin(domPlugin, groupId, artifactId)) { return domPlugin; } } } return null; } }; Function<MavenDomProjectModelBase, MavenDomPlugins> domProfileFunction = mavenDomProfile -> mavenDomProfile.getBuild().getPluginManagement().getPlugins(); process( model, processor, model.getManager().getProject(), domProfileFunction, domProfileFunction); return processor.myResult; }
@NotNull public static Collection<MavenDomPlugin> searchManagedPluginUsages( @NotNull final MavenDomProjectModel model, @Nullable final String groupId, @NotNull final String artifactId) { Project project = model.getManager().getProject(); final Set<MavenDomPlugin> usages = new HashSet<MavenDomPlugin>(); Processor<MavenDomProjectModel> collectProcessor = mavenDomProjectModel -> { for (MavenDomPlugin domPlugin : mavenDomProjectModel.getBuild().getPlugins().getPlugins()) { if (MavenPluginDomUtil.isPlugin(domPlugin, groupId, artifactId)) { usages.add(domPlugin); } } return false; }; processChildrenRecursively( model, collectProcessor, project, new HashSet<MavenDomProjectModel>(), true); return usages; }
@NotNull public static Set<MavenDomDependency> searchDependencyUsages( @NotNull final MavenDomProjectModel model, @NotNull final DependencyConflictId dependencyId, @NotNull final Set<MavenDomDependency> excludes) { Project project = model.getManager().getProject(); final Set<MavenDomDependency> usages = new HashSet<MavenDomDependency>(); Processor<MavenDomProjectModel> collectProcessor = mavenDomProjectModel -> { for (MavenDomDependency domDependency : mavenDomProjectModel.getDependencies().getDependencies()) { if (excludes.contains(domDependency)) continue; if (dependencyId.equals(DependencyConflictId.create(domDependency))) { usages.add(domDependency); } } return false; }; processChildrenRecursively( model, collectProcessor, project, new HashSet<MavenDomProjectModel>(), true); return usages; }
public static boolean processDependencies( @NotNull MavenDomProjectModel projectDom, @NotNull final Processor<MavenDomDependencies> processor) { Function<MavenDomProjectModelBase, MavenDomDependencies> domFunction = mavenDomProfile -> mavenDomProfile.getDependencies(); return process( projectDom, processor, projectDom.getManager().getProject(), domFunction, domFunction); }
public static void processChildrenRecursively( @Nullable MavenDomProjectModel model, @NotNull Processor<MavenDomProjectModel> processor, boolean processCurrentModel) { if (model != null) { processChildrenRecursively( model, processor, model.getManager().getProject(), new HashSet<MavenDomProjectModel>(), processCurrentModel); } }
public static void processParentProjects( @NotNull final MavenDomProjectModel projectDom, @NotNull final Processor<MavenDomProjectModel> processor) { Set<MavenDomProjectModel> processed = new HashSet<MavenDomProjectModel>(); Project project = projectDom.getManager().getProject(); MavenDomProjectModel parent = findParent(projectDom, project); while (parent != null) { if (processed.contains(parent)) break; processed.add(parent); if (processor.process(parent)) break; parent = findParent(parent, project); } }
private static void collectChildrenProjects( @NotNull final MavenDomProjectModel model, @NotNull Set<MavenDomProjectModel> models) { MavenProject mavenProject = MavenDomUtil.findProject(model); if (mavenProject != null) { final Project project = model.getManager().getProject(); for (MavenProject inheritor : MavenProjectsManager.getInstance(project).findInheritors(mavenProject)) { MavenDomProjectModel inheritorProjectModel = MavenDomUtil.getMavenDomProjectModel(project, inheritor.getFile()); if (inheritorProjectModel != null && !models.contains(inheritorProjectModel)) { models.add(inheritorProjectModel); collectChildrenProjects(inheritorProjectModel, models); } } } }