Java Code Examples for org.eclipse.aether.graph.DependencyNode#accept()
The following examples show how to use
org.eclipse.aether.graph.DependencyNode#accept() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AetherGraphTraverserTest.java From migration-tooling with Apache License 2.0 | 6 votes |
@Test public void testBasicGraphConstruction() { DependencyNode root = dependencyNode("root:root:1"); DependencyNode depA = dependencyNode("a:a:1"); DependencyNode depB = dependencyNode("b:b:1"); root.setChildren(ImmutableList.of(depA, depB)); MavenJarRule rootRule = new MavenJarRule(root); MavenJarRule aRule = new MavenJarRule(depA); MavenJarRule bRule = new MavenJarRule(depB); MutableGraph<MavenJarRule> expected = newGraph(); addEdge(expected, rootRule, aRule); addEdge(expected, rootRule, bRule); // Construct the graph MutableGraph<MavenJarRule> actual = newGraph(); AetherGraphTraverser visitor = new AetherGraphTraverser(actual); root.accept(visitor); assertThatGraphsEqual(actual, expected); }
Example 2
Source File: MavenDependencyResolver.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
public List<com.baidu.formula.launcher.model.Dependency> getArtifactsDependencies( MavenProject project, String scope) throws DependencyCollectionException, DependencyResolutionException { DefaultArtifact pomArtifact = new DefaultArtifact(project.getId()); List<RemoteRepository> remoteRepos = project.getRemoteProjectRepositories(); List<Dependency> ret = new ArrayList<Dependency>(); Dependency dependency = new Dependency(pomArtifact, scope); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot(dependency); collectRequest.setRepositories(remoteRepos); DependencyNode node = repositorySystem.collectDependencies(session, collectRequest).getRoot(); DependencyRequest projectDependencyRequest = new DependencyRequest(node, null); repositorySystem.resolveDependencies(session, projectDependencyRequest); PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); node.accept(nlg); ret.addAll(nlg.getDependencies(true)); return ret.stream().map(d -> { com.baidu.formula.launcher.model.Dependency dep = new com.baidu.formula.launcher.model.Dependency(); dep.setArtifactId(d.getArtifact().getArtifactId()); dep.setGroupId(d.getArtifact().getGroupId()); dep.setVersion(d.getArtifact().getVersion()); return dep; }).collect(Collectors.toList()); }
Example 3
Source File: DependencyGraph.java From cloud-opensource-java with Apache License 2.0 | 5 votes |
private static ImmutableList<List<DependencyNode>> findArtifactPaths( DependencyNode root, Artifact artifact) { String coordinates = Artifacts.toCoordinates(artifact); DependencyFilter filter = (node, parents) -> node.getArtifact() != null // artifact is null at a root dummy node. && Artifacts.toCoordinates(node.getArtifact()).equals(coordinates); UniquePathRecordingDependencyVisitor visitor = new UniquePathRecordingDependencyVisitor(filter); root.accept(visitor); return ImmutableList.copyOf(visitor.getPaths()); }
Example 4
Source File: AetherGraphTraverserTest.java From migration-tooling with Apache License 2.0 | 5 votes |
/** * Asserts that when the dependency visitor is accepted by multiple * nodes, the constructed graph contains nodes and edges from all visits. */ @Test public void testAccumulation() { DependencyNode rootNodeA = dependencyNode("a:a1:1"); DependencyNode childNodeA = dependencyNode("a:a2:1"); DependencyNode rootNodeB = dependencyNode("b:b1:1"); DependencyNode childNodeB = dependencyNode("b:b2:1"); rootNodeA.setChildren(ImmutableList.of(childNodeA)); rootNodeB.setChildren(ImmutableList.of(childNodeB)); MavenJarRule rootRuleA = new MavenJarRule(rootNodeA); MavenJarRule childRuleA = new MavenJarRule(childNodeA); MavenJarRule rootRuleB = new MavenJarRule(rootNodeB); MavenJarRule childRuleB = new MavenJarRule(childNodeB); MutableGraph<MavenJarRule> expected = newGraph(); addEdge(expected, rootRuleA, childRuleA); addEdge(expected, rootRuleB, childRuleB); // Construct the graph MutableGraph<MavenJarRule> actual = newGraph(); AetherGraphTraverser visitor = new AetherGraphTraverser(actual); rootNodeA.accept(visitor); rootNodeB.accept(visitor); assertThatGraphsEqual(actual, expected); }
Example 5
Source File: AetherGraphTraverserTest.java From migration-tooling with Apache License 2.0 | 5 votes |
/** * Tests behavior when there is a duplicate dependency node within the graph, meaning * two nodes with the same maven coordinate. The generated graph should not contain * multiple instances of that node. */ @Test public void testDuplicateChildren() { DependencyNode rootNodeA = dependencyNode("a:a:1"); DependencyNode rootNodeB = dependencyNode("b:b:1"); DependencyNode childNode = dependencyNode("c:c:1"); DependencyNode childNodeDuplicate = dependencyNode("c:c:1"); rootNodeA.setChildren(ImmutableList.of(childNode)); rootNodeB.setChildren(ImmutableList.of(childNode)); rootNodeA.setChildren(ImmutableList.of(childNodeDuplicate)); rootNodeB.setChildren(ImmutableList.of(childNodeDuplicate)); MavenJarRule rootRuleA = new MavenJarRule(rootNodeA); MavenJarRule childRule = new MavenJarRule(childNode); MavenJarRule rootRuleB = new MavenJarRule(rootNodeB); MutableGraph<MavenJarRule> expected = newGraph(); addEdge(expected, rootRuleA, childRule); addEdge(expected, rootRuleB, childRule); // Construct the graph MutableGraph<MavenJarRule> actual = newGraph(); AetherGraphTraverser visitor = new AetherGraphTraverser(actual); rootNodeA.accept(visitor); rootNodeB.accept(visitor); assertThatGraphsEqual(actual, expected); }
Example 6
Source File: RepackageExtensionMojo.java From syndesis with Apache License 2.0 | 5 votes |
private List<Dependency> obtainBomDependencies(final String urlLocation) { final Artifact artifact = downloadAndInstallArtifact(urlLocation).getArtifact(); final Dependency dependency = new Dependency(artifact, JavaScopes.RUNTIME); final List<RemoteRepository> remoteRepositories = project.getRepositories().stream() .map(r -> new RemoteRepository.Builder(r.getId(), r.getLayout(), r.getUrl()).build()) .collect(Collectors.toList()); CollectResult result; try { final ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest(artifact, remoteRepositories, null); final ArtifactDescriptorResult descriptor = repository.readArtifactDescriptor(session, descriptorRequest); final List<Dependency> dependencies = Stream.concat( descriptor.getDependencies().stream(), descriptor.getManagedDependencies().stream()) .collect(Collectors.toList()); final DefaultRepositorySystemSession sessionToUse = new DefaultRepositorySystemSession(session); sessionToUse.setDependencyGraphTransformer(new NoopDependencyGraphTransformer()); final CollectRequest request = new CollectRequest(dependency, dependencies, remoteRepositories); result = repository.collectDependencies(sessionToUse, request); } catch (final DependencyCollectionException | ArtifactDescriptorException e) { throw new IllegalStateException("Unabele to obtain BOM dependencies for: " + urlLocation, e); } final DependencyNode root = result.getRoot(); final PostorderNodeListGenerator visitor = new PostorderNodeListGenerator(); root.accept(visitor); return visitor.getDependencies(true); }
Example 7
Source File: PluginBundleManager.java From BIMserver with GNU Affero General Public License v3.0 | 4 votes |
private void loadDependencies(String pluginBundleVersion, boolean strictDependencyChecking, Model model, DelegatingClassLoader delegatingClassLoader) throws DependencyCollectionException, InvalidVersionSpecificationException, Exception { if (model.getRepositories() != null) { for (Repository repository : model.getRepositories()) { mavenPluginRepository.addRepository(repository.getId(), "default", repository.getUrl()); } } List<Dependency> dependenciesToResolve = new ArrayList<>(); for (org.apache.maven.model.Dependency dependency2 : model.getDependencies()) { String scope = dependency2.getScope(); if (scope != null && (scope.contentEquals("test"))) { // Skip continue; } Dependency d = new Dependency(new DefaultArtifact(dependency2.getGroupId(), dependency2.getArtifactId(), dependency2.getType(), dependency2.getVersion()), dependency2.getScope()); Set<Exclusion> exclusions = new HashSet<>(); d.setExclusions(exclusions); exclusions.add(new Exclusion("org.opensourcebim", "pluginbase", null, "jar")); exclusions.add(new Exclusion("org.opensourcebim", "shared", null, "jar")); exclusions.add(new Exclusion("org.opensourcebim", "ifcplugins", null, "jar")); dependenciesToResolve.add(d); } CollectRequest collectRequest = new CollectRequest(dependenciesToResolve, null, null); collectRequest.setRepositories(mavenPluginRepository.getRepositoriesAsList()); CollectResult collectDependencies = mavenPluginRepository.getSystem().collectDependencies(mavenPluginRepository.getSession(), collectRequest); PreorderNodeListGenerator nlg = new PreorderNodeListGenerator(); DependencyNode rootDep = collectDependencies.getRoot(); rootDep.accept(nlg); for (Dependency dependency : nlg.getDependencies(true)) { if (dependency.getScope().contentEquals("test")) { continue; } // LOGGER.info(dependency.getArtifact().getGroupId() + "." + dependency.getArtifact().getArtifactId()); Artifact dependencyArtifact = dependency.getArtifact(); PluginBundleIdentifier pluginBundleIdentifier = new PluginBundleIdentifier(dependencyArtifact.getGroupId(), dependencyArtifact.getArtifactId()); if (pluginBundleIdentifierToPluginBundle.containsKey(pluginBundleIdentifier)) { if (strictDependencyChecking) { String version = dependencyArtifact.getVersion(); if (!version.contains("[") && !version.contains("(")) { version = "[" + version + "]"; } VersionRange versionRange = VersionRange.createFromVersionSpec(version); // String version = // pluginBundleIdentifierToPluginBundle.get(pluginBundleIdentifier).getPluginBundleVersion().getVersion(); ArtifactVersion artifactVersion = new DefaultArtifactVersion(pluginBundleVersion); if (versionRange.containsVersion(artifactVersion)) { // OK } else { throw new Exception( "Required dependency " + pluginBundleIdentifier + " is installed, but it's version (" + pluginBundleVersion + ") does not comply to the required version (" + dependencyArtifact.getVersion() + ")"); } } else { LOGGER.info("Skipping strict dependency checking for dependency " + dependencyArtifact.getArtifactId()); } } else { try { if (dependencyArtifact.getGroupId().contentEquals("com.sun.xml.ws")) { continue; } MavenPluginLocation mavenPluginLocation = mavenPluginRepository.getPluginLocation(dependencyArtifact.getGroupId(), dependencyArtifact.getArtifactId()); if (dependencyArtifact.getExtension().contentEquals("jar")) { Path depJarFile = mavenPluginLocation.getVersionJar(dependencyArtifact.getVersion()); FileJarClassLoader jarClassLoader = new FileJarClassLoader(pluginManager, delegatingClassLoader, depJarFile); jarClassLoaders.add(jarClassLoader); delegatingClassLoader.add(jarClassLoader); } } catch (Exception e) { e.printStackTrace(); throw new Exception("Required dependency " + pluginBundleIdentifier + " is not installed"); } } } }