Search in sources :

Example 21 with Dependency

use of org.eclipse.aether.graph.Dependency in project revapi by revapi.

the class ArtifactResolver method collectTransitiveDeps.

protected void collectTransitiveDeps(String gav, Set<Artifact> resolvedArtifacts, Set<Exception> failures) throws RepositoryException {
    final Artifact rootArtifact = resolveArtifact(gav);
    CollectRequest collectRequest = new CollectRequest(new Dependency(rootArtifact, null), repositories);
    DependencyRequest request = new DependencyRequest(collectRequest, null);
    DependencyResult result;
    try {
        result = repositorySystem.resolveDependencies(session, request);
    } catch (DependencyResolutionException dre) {
        result = dre.getResult();
    }
    result.getRoot().accept(new TreeDependencyVisitor(new DependencyVisitor() {

        @Override
        public boolean visitEnter(DependencyNode node) {
            return true;
        }

        @Override
        public boolean visitLeave(DependencyNode node) {
            Dependency dep = node.getDependency();
            if (dep == null || dep.getArtifact().equals(rootArtifact)) {
                return true;
            }
            resolvedArtifacts.add(dep.getArtifact());
            return true;
        }
    }));
    failures.addAll(result.getCollectExceptions());
}
Also used : DependencyRequest(org.eclipse.aether.resolution.DependencyRequest) DependencyResult(org.eclipse.aether.resolution.DependencyResult) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) TreeDependencyVisitor(org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor) DependencyNode(org.eclipse.aether.graph.DependencyNode) TreeDependencyVisitor(org.eclipse.aether.util.graph.visitor.TreeDependencyVisitor) DependencyResolutionException(org.eclipse.aether.resolution.DependencyResolutionException) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact)

Example 22 with Dependency

use of org.eclipse.aether.graph.Dependency in project activemq-artemis by apache.

the class ArtemisAbstractPlugin method explodeDependencies.

protected List<Artifact> explodeDependencies(Artifact artifact) throws DependencyCollectionException {
    final List<Artifact> dependencies = new LinkedList<>();
    CollectRequest exploreDependenciesRequest = new CollectRequest(new Dependency(artifact, "compile"), remoteRepos);
    CollectResult result = repositorySystem.collectDependencies(repoSession, exploreDependenciesRequest);
    final AtomicInteger level = new AtomicInteger(0);
    DependencyNode node = result.getRoot();
    StringWriter writer = new StringWriter();
    final PrintWriter strPrint = new PrintWriter(writer);
    strPrint.println("Dependencies explored for " + artifact + ":");
    if (node != null) {
        node.accept(new DependencyVisitor() {

            @Override
            public boolean visitEnter(DependencyNode node) {
                for (int i = 0; i < level.get(); i++) {
                    strPrint.print("!...");
                }
                level.incrementAndGet();
                strPrint.println("Dependency:: " + node.getDependency() + " node = " + node.getArtifact());
                dependencies.add(node.getArtifact());
                return true;
            }

            @Override
            public boolean visitLeave(DependencyNode node) {
                level.decrementAndGet();
                return true;
            }
        });
    }
    getLog().info(writer.toString());
    return dependencies;
}
Also used : StringWriter(java.io.StringWriter) CollectResult(org.eclipse.aether.collection.CollectResult) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DependencyNode(org.eclipse.aether.graph.DependencyNode) DependencyVisitor(org.eclipse.aether.graph.DependencyVisitor) Dependency(org.eclipse.aether.graph.Dependency) CollectRequest(org.eclipse.aether.collection.CollectRequest) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) LinkedList(java.util.LinkedList) PrintWriter(java.io.PrintWriter)

Example 23 with Dependency

use of org.eclipse.aether.graph.Dependency in project storm by apache.

the class DependencyResolverTest method resolveValid.

@Test
public void resolveValid() throws Exception {
    // please pick small artifact which has small transitive dependency
    // and let's mark as Ignore if we want to run test even without internet or maven central is often not stable
    Dependency dependency = new Dependency(new DefaultArtifact("org.apache.storm:flux-core:1.0.0"), JavaScopes.COMPILE);
    List<ArtifactResult> results = sut.resolve(Lists.newArrayList(dependency));
    assertTrue(results.size() > 0);
    // it should be org.apache.storm:flux-core:jar:1.0.0 and commons-cli:commons-cli:jar:1.2
    assertContains(results, "org.apache.storm", "flux-core", "1.0.0");
    assertContains(results, "commons-cli", "commons-cli", "1.2");
}
Also used : Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) ArtifactResult(org.eclipse.aether.resolution.ArtifactResult) Test(org.junit.Test)

Example 24 with Dependency

use of org.eclipse.aether.graph.Dependency in project storm by apache.

the class AetherUtilsTest method parseDependency.

@Test
public void parseDependency() throws Exception {
    String testDependency = "testgroup:testartifact:1.0.0^testgroup:testexcartifact^testgroup:*";
    Dependency dependency = AetherUtils.parseDependency(testDependency);
    assertEquals("testgroup", dependency.getArtifact().getGroupId());
    assertEquals("testartifact", dependency.getArtifact().getArtifactId());
    assertEquals("1.0.0", dependency.getArtifact().getVersion());
    assertEquals(JavaScopes.COMPILE, dependency.getScope());
    assertEquals(2, dependency.getExclusions().size());
    List<Exclusion> exclusions = Lists.newArrayList(dependency.getExclusions());
    Exclusion exclusion = exclusions.get(0);
    assertEquals("testgroup", exclusion.getGroupId());
    assertEquals("testexcartifact", exclusion.getArtifactId());
    assertEquals(JavaScopes.COMPILE, dependency.getScope());
    exclusion = exclusions.get(1);
    assertEquals("testgroup", exclusion.getGroupId());
    assertEquals("*", exclusion.getArtifactId());
    assertEquals(JavaScopes.COMPILE, dependency.getScope());
}
Also used : Exclusion(org.eclipse.aether.graph.Exclusion) Dependency(org.eclipse.aether.graph.Dependency) Test(org.junit.Test)

Example 25 with Dependency

use of org.eclipse.aether.graph.Dependency in project storm by apache.

the class AetherUtils method parseDependency.

/**
 * Parses dependency parameter and build {@link Dependency} object.
 *
 * @param dependency string representation of dependency parameter
 * @return Dependency object
 */
public static Dependency parseDependency(String dependency) {
    List<String> dependencyAndExclusions = Arrays.asList(dependency.split("\\^"));
    Collection<Exclusion> exclusions = new ArrayList<>();
    for (int idx = 1; idx < dependencyAndExclusions.size(); idx++) {
        exclusions.add(AetherUtils.createExclusion(dependencyAndExclusions.get(idx)));
    }
    Artifact artifact = new DefaultArtifact(dependencyAndExclusions.get(0));
    return new Dependency(artifact, JavaScopes.COMPILE, false, exclusions);
}
Also used : Exclusion(org.eclipse.aether.graph.Exclusion) ArrayList(java.util.ArrayList) Dependency(org.eclipse.aether.graph.Dependency) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact) Artifact(org.eclipse.aether.artifact.Artifact) DefaultArtifact(org.eclipse.aether.artifact.DefaultArtifact)

Aggregations

Dependency (org.eclipse.aether.graph.Dependency)57 DefaultArtifact (org.eclipse.aether.artifact.DefaultArtifact)39 Artifact (org.eclipse.aether.artifact.Artifact)36 File (java.io.File)25 CollectRequest (org.eclipse.aether.collection.CollectRequest)22 ArrayList (java.util.ArrayList)19 DependencyNode (org.eclipse.aether.graph.DependencyNode)17 ArtifactResult (org.eclipse.aether.resolution.ArtifactResult)17 DependencyRequest (org.eclipse.aether.resolution.DependencyRequest)17 RemoteRepository (org.eclipse.aether.repository.RemoteRepository)15 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)15 ArtifactDescriptorResult (org.eclipse.aether.resolution.ArtifactDescriptorResult)14 IOException (java.io.IOException)13 DependencyFilter (org.eclipse.aether.graph.DependencyFilter)13 Exclusion (org.eclipse.aether.graph.Exclusion)13 MalformedURLException (java.net.MalformedURLException)12 DependencyResolutionException (org.eclipse.aether.resolution.DependencyResolutionException)11 List (java.util.List)10 URL (java.net.URL)9 ArtifactDescriptorException (org.eclipse.aether.resolution.ArtifactDescriptorException)9