Search in sources :

Example 11 with Dependency

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

the class AetherUtils method parseDependency.

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.sonatype.aether.graph.Exclusion) ArrayList(java.util.ArrayList) Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact)

Example 12 with Dependency

use of org.sonatype.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.sonatype.aether.graph.Exclusion) Dependency(org.sonatype.aether.graph.Dependency) Test(org.junit.Test)

Example 13 with Dependency

use of org.sonatype.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.sonatype.aether.graph.Dependency) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) Test(org.junit.Test)

Example 14 with Dependency

use of org.sonatype.aether.graph.Dependency in project karaf by apache.

the class Dependency30Helper method getDependencyTree.

private DependencyNode getDependencyTree(Artifact artifact) throws MojoExecutionException {
    try {
        CollectRequest collectRequest = new CollectRequest(new Dependency(artifact, "compile"), null, projectRepositories);
        DefaultRepositorySystemSession session = new DefaultRepositorySystemSession(repositorySystemSession);
        session.setDependencySelector(new AndDependencySelector(new OptionalDependencySelector(), new ScopeDependencySelector1(), new ExclusionDependencySelector()));
        DependencyGraphTransformer transformer = new ChainedDependencyGraphTransformer(new ConflictMarker(), new JavaEffectiveScopeCalculator(), new JavaDependencyContextRefiner());
        session.setDependencyGraphTransformer(transformer);
        CollectResult result = repositorySystem.collectDependencies(session, collectRequest);
        return result.getRoot();
    } catch (DependencyCollectionException e) {
        throw new MojoExecutionException("Cannot build project dependency tree", e);
    }
}
Also used : JavaDependencyContextRefiner(org.sonatype.aether.util.graph.transformer.JavaDependencyContextRefiner) DependencyCollectionException(org.sonatype.aether.collection.DependencyCollectionException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) CollectResult(org.sonatype.aether.collection.CollectResult) AndDependencySelector(org.sonatype.aether.util.graph.selector.AndDependencySelector) Dependency(org.sonatype.aether.graph.Dependency) CollectRequest(org.sonatype.aether.collection.CollectRequest) ChainedDependencyGraphTransformer(org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer) OptionalDependencySelector(org.sonatype.aether.util.graph.selector.OptionalDependencySelector) DefaultRepositorySystemSession(org.sonatype.aether.util.DefaultRepositorySystemSession) JavaEffectiveScopeCalculator(org.sonatype.aether.util.graph.transformer.JavaEffectiveScopeCalculator) DependencyGraphTransformer(org.sonatype.aether.collection.DependencyGraphTransformer) ChainedDependencyGraphTransformer(org.sonatype.aether.util.graph.transformer.ChainedDependencyGraphTransformer) ConflictMarker(org.sonatype.aether.util.graph.transformer.ConflictMarker) ExclusionDependencySelector(org.sonatype.aether.util.graph.selector.ExclusionDependencySelector)

Example 15 with Dependency

use of org.sonatype.aether.graph.Dependency in project sonatype-aether by sonatype.

the class PatternInclusionsDependencyFilter method accept.

public boolean accept(final DependencyNode node, List<DependencyNode> parents) {
    final Dependency dependency = node.getDependency();
    if (dependency == null) {
        return true;
    }
    final Artifact artifact = dependency.getArtifact();
    for (final String pattern : patterns) {
        final boolean matched = accept(artifact, pattern);
        if (matched) {
            return true;
        }
    }
    return false;
}
Also used : Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact)

Aggregations

Dependency (org.sonatype.aether.graph.Dependency)45 Artifact (org.sonatype.aether.artifact.Artifact)22 Test (org.junit.Test)14 CollectRequest (org.sonatype.aether.collection.CollectRequest)14 DependencyNode (org.sonatype.aether.graph.DependencyNode)14 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)12 CollectResult (org.sonatype.aether.collection.CollectResult)11 Exclusion (org.sonatype.aether.graph.Exclusion)9 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)9 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)7 ArrayList (java.util.ArrayList)5 RepositorySystem (org.sonatype.aether.RepositorySystem)4 ArtifactDescriptorException (org.sonatype.aether.resolution.ArtifactDescriptorException)4 ArtifactDescriptorRequest (org.sonatype.aether.resolution.ArtifactDescriptorRequest)4 ArtifactDescriptorResult (org.sonatype.aether.resolution.ArtifactDescriptorResult)4 DependencyRequest (org.sonatype.aether.resolution.DependencyRequest)4 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)4 DependencyCollectionException (org.sonatype.aether.collection.DependencyCollectionException)3 ConsoleDependencyGraphDumper (demo.util.ConsoleDependencyGraphDumper)2 HashMap (java.util.HashMap)2