@Test public void filterDependencies() throws IOException { final Path root = BASEDIR.resolve("target/test-classes/MavenSourceTree/set-versions"); final MavenSourceTree t = new Builder(root, StandardCharsets.UTF_8).pomXml(root.resolve("pom.xml")).build(); final GavSet gavSet = GavSet.builder().include("org.srcdeps.external").build(); final Set<Ga> actual = t.filterDependencies(gavSet, ActiveProfiles.of()); final Set<Ga> expected = new TreeSet<Ga>(Arrays.asList( Ga.of("org.srcdeps.external:extenal-parent"), Ga.of("org.srcdeps.external:extenal-bom"), Ga.of("org.srcdeps.external:external-extension"), Ga.of("org.srcdeps.external:external-plugin-1"), Ga.of("org.srcdeps.external:external-plugin-2") )); Assert.assertEquals(expected, actual); }
public Set<Ga> filterDependencies(GavSet gavSet, final Predicate<Profile> isProfileActive) { final Set<Ga> result = new TreeSet<>(); for (Module module : getModulesByGa().values()) { final GavExpression parentGav = module.getParentGav(); if (parentGav != null) { final Ga ga = parentGav.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Profile p : module.getProfiles()) { if (isProfileActive.test(p)) { for (Dependency depGa : p.getDependencies()) { final Ga ga = depGa.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Dependency depGa : p.getDependencyManagement()) { final Ga ga = depGa.resolveGa(this, isProfileActive); if ("import".equals(depGa.getScope()) && gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Plugin plugin : p.getPlugins()) { { final Ga ga = plugin.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (GavExpression plugnDep : plugin.getDependencies()) { final Ga plugnDepGa = plugnDep.resolveGa(this, isProfileActive); if (gavSet.contains(plugnDepGa.getGroupId(), plugnDepGa.getArtifactId())) { result.add(plugnDepGa); } } } for (Plugin plugin : p.getPluginManagement()) { { final Ga ga = plugin.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (GavExpression pluginDep : plugin.getDependencies()) { final Ga plugnDepGa = pluginDep.resolveGa(this, isProfileActive); if (gavSet.contains(plugnDepGa.getGroupId(), plugnDepGa.getArtifactId())) { result.add(plugnDepGa); } } } for (GavExpression ext : p.getExtensions()) { final Ga ga = ext.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } } } } return result; }
MavenSourceTree { public Set<Ga> filterDependencies(GavSet gavSet, final Predicate<Profile> isProfileActive) { final Set<Ga> result = new TreeSet<>(); for (Module module : getModulesByGa().values()) { final GavExpression parentGav = module.getParentGav(); if (parentGav != null) { final Ga ga = parentGav.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Profile p : module.getProfiles()) { if (isProfileActive.test(p)) { for (Dependency depGa : p.getDependencies()) { final Ga ga = depGa.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Dependency depGa : p.getDependencyManagement()) { final Ga ga = depGa.resolveGa(this, isProfileActive); if ("import".equals(depGa.getScope()) && gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Plugin plugin : p.getPlugins()) { { final Ga ga = plugin.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (GavExpression plugnDep : plugin.getDependencies()) { final Ga plugnDepGa = plugnDep.resolveGa(this, isProfileActive); if (gavSet.contains(plugnDepGa.getGroupId(), plugnDepGa.getArtifactId())) { result.add(plugnDepGa); } } } for (Plugin plugin : p.getPluginManagement()) { { final Ga ga = plugin.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (GavExpression pluginDep : plugin.getDependencies()) { final Ga plugnDepGa = pluginDep.resolveGa(this, isProfileActive); if (gavSet.contains(plugnDepGa.getGroupId(), plugnDepGa.getArtifactId())) { result.add(plugnDepGa); } } } for (GavExpression ext : p.getExtensions()) { final Ga ga = ext.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } } } } return result; } }
MavenSourceTree { public Set<Ga> filterDependencies(GavSet gavSet, final Predicate<Profile> isProfileActive) { final Set<Ga> result = new TreeSet<>(); for (Module module : getModulesByGa().values()) { final GavExpression parentGav = module.getParentGav(); if (parentGav != null) { final Ga ga = parentGav.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Profile p : module.getProfiles()) { if (isProfileActive.test(p)) { for (Dependency depGa : p.getDependencies()) { final Ga ga = depGa.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Dependency depGa : p.getDependencyManagement()) { final Ga ga = depGa.resolveGa(this, isProfileActive); if ("import".equals(depGa.getScope()) && gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Plugin plugin : p.getPlugins()) { { final Ga ga = plugin.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (GavExpression plugnDep : plugin.getDependencies()) { final Ga plugnDepGa = plugnDep.resolveGa(this, isProfileActive); if (gavSet.contains(plugnDepGa.getGroupId(), plugnDepGa.getArtifactId())) { result.add(plugnDepGa); } } } for (Plugin plugin : p.getPluginManagement()) { { final Ga ga = plugin.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (GavExpression pluginDep : plugin.getDependencies()) { final Ga plugnDepGa = pluginDep.resolveGa(this, isProfileActive); if (gavSet.contains(plugnDepGa.getGroupId(), plugnDepGa.getArtifactId())) { result.add(plugnDepGa); } } } for (GavExpression ext : p.getExtensions()) { final Ga ga = ext.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } } } } return result; } MavenSourceTree(Path rootDirectory, Charset encoding, Map<String, Module> modulesByPath,
            Map<Ga, Module> modulesByGa); }
MavenSourceTree { public Set<Ga> filterDependencies(GavSet gavSet, final Predicate<Profile> isProfileActive) { final Set<Ga> result = new TreeSet<>(); for (Module module : getModulesByGa().values()) { final GavExpression parentGav = module.getParentGav(); if (parentGav != null) { final Ga ga = parentGav.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Profile p : module.getProfiles()) { if (isProfileActive.test(p)) { for (Dependency depGa : p.getDependencies()) { final Ga ga = depGa.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Dependency depGa : p.getDependencyManagement()) { final Ga ga = depGa.resolveGa(this, isProfileActive); if ("import".equals(depGa.getScope()) && gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Plugin plugin : p.getPlugins()) { { final Ga ga = plugin.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (GavExpression plugnDep : plugin.getDependencies()) { final Ga plugnDepGa = plugnDep.resolveGa(this, isProfileActive); if (gavSet.contains(plugnDepGa.getGroupId(), plugnDepGa.getArtifactId())) { result.add(plugnDepGa); } } } for (Plugin plugin : p.getPluginManagement()) { { final Ga ga = plugin.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (GavExpression pluginDep : plugin.getDependencies()) { final Ga plugnDepGa = pluginDep.resolveGa(this, isProfileActive); if (gavSet.contains(plugnDepGa.getGroupId(), plugnDepGa.getArtifactId())) { result.add(plugnDepGa); } } } for (GavExpression ext : p.getExtensions()) { final Ga ga = ext.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } } } } return result; } MavenSourceTree(Path rootDirectory, Charset encoding, Map<String, Module> modulesByPath,
            Map<Ga, Module> modulesByGa); static MavenSourceTree of(Path rootPomXml, Charset encoding); Set<Ga> computeModuleClosure(Collection<Ga> initialModules, Predicate<Profile> isProfileActive); String evaluate(Expression expression, Predicate<Profile> isProfileActive); Set<Ga> filterDependencies(GavSet gavSet, final Predicate<Profile> isProfileActive); Charset getEncoding(); Map<Ga, Module> getModulesByGa(); Map<String, Module> getModulesByPath(); Path getRootDirectory(); Module getRootModule(); void setVersions(final String newVersion, final Predicate<Profile> isProfileActive); void unlinkUneededModules(Set<Ga> includes, Predicate<Profile> isProfileActive); }
MavenSourceTree { public Set<Ga> filterDependencies(GavSet gavSet, final Predicate<Profile> isProfileActive) { final Set<Ga> result = new TreeSet<>(); for (Module module : getModulesByGa().values()) { final GavExpression parentGav = module.getParentGav(); if (parentGav != null) { final Ga ga = parentGav.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Profile p : module.getProfiles()) { if (isProfileActive.test(p)) { for (Dependency depGa : p.getDependencies()) { final Ga ga = depGa.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Dependency depGa : p.getDependencyManagement()) { final Ga ga = depGa.resolveGa(this, isProfileActive); if ("import".equals(depGa.getScope()) && gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (Plugin plugin : p.getPlugins()) { { final Ga ga = plugin.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (GavExpression plugnDep : plugin.getDependencies()) { final Ga plugnDepGa = plugnDep.resolveGa(this, isProfileActive); if (gavSet.contains(plugnDepGa.getGroupId(), plugnDepGa.getArtifactId())) { result.add(plugnDepGa); } } } for (Plugin plugin : p.getPluginManagement()) { { final Ga ga = plugin.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } for (GavExpression pluginDep : plugin.getDependencies()) { final Ga plugnDepGa = pluginDep.resolveGa(this, isProfileActive); if (gavSet.contains(plugnDepGa.getGroupId(), plugnDepGa.getArtifactId())) { result.add(plugnDepGa); } } } for (GavExpression ext : p.getExtensions()) { final Ga ga = ext.resolveGa(this, isProfileActive); if (gavSet.contains(ga.getGroupId(), ga.getArtifactId())) { result.add(ga); } } } } } return result; } MavenSourceTree(Path rootDirectory, Charset encoding, Map<String, Module> modulesByPath,
            Map<Ga, Module> modulesByGa); static MavenSourceTree of(Path rootPomXml, Charset encoding); Set<Ga> computeModuleClosure(Collection<Ga> initialModules, Predicate<Profile> isProfileActive); String evaluate(Expression expression, Predicate<Profile> isProfileActive); Set<Ga> filterDependencies(GavSet gavSet, final Predicate<Profile> isProfileActive); Charset getEncoding(); Map<Ga, Module> getModulesByGa(); Map<String, Module> getModulesByPath(); Path getRootDirectory(); Module getRootModule(); void setVersions(final String newVersion, final Predicate<Profile> isProfileActive); void unlinkUneededModules(Set<Ga> includes, Predicate<Profile> isProfileActive);  }