Search in sources :

Example 1 with Exclusion

use of org.sonatype.aether.graph.Exclusion 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 2 with Exclusion

use of org.sonatype.aether.graph.Exclusion 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 3 with Exclusion

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

the class DependencyTest method testSetExclusions.

@Test
public void testSetExclusions() {
    Dependency d1 = new Dependency(new StubArtifact("gid:aid:ver"), "compile", false, Collections.singleton(new Exclusion("g", "a", "c", "e")));
    Dependency d2 = d1.setExclusions(null);
    assertNotSame(d2, d1);
    assertEquals(0, d2.getExclusions().size());
    assertSame(d2, d2.setExclusions(null));
    assertSame(d2, d2.setExclusions(Collections.<Exclusion>emptyList()));
    assertSame(d2, d2.setExclusions(Collections.<Exclusion>emptySet()));
    assertSame(d1, d1.setExclusions(Arrays.asList(new Exclusion("g", "a", "c", "e"))));
    Dependency d3 = d1.setExclusions(Arrays.asList(new Exclusion("g", "a", "c", "e"), new Exclusion("g", "a", "c", "f")));
    assertNotSame(d3, d1);
    assertEquals(2, d3.getExclusions().size());
}
Also used : Exclusion(org.sonatype.aether.graph.Exclusion) Dependency(org.sonatype.aether.graph.Dependency) Test(org.junit.Test)

Example 4 with Exclusion

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

the class IniArtifactDescriptorReaderTest method assertDependencies.

private void assertDependencies(List<Dependency> deps) {
    assertEquals(4, deps.size());
    Dependency dep = deps.get(0);
    assertEquals("scope", dep.getScope());
    assertEquals(false, dep.isOptional());
    assertEquals(2, dep.getExclusions().size());
    Iterator<Exclusion> it = dep.getExclusions().iterator();
    Exclusion excl = it.next();
    assertEquals("gid3", excl.getGroupId());
    assertEquals("aid", excl.getArtifactId());
    excl = it.next();
    assertEquals("gid2", excl.getGroupId());
    assertEquals("aid2", excl.getArtifactId());
    Artifact art = dep.getArtifact();
    assertEquals("gid", art.getGroupId());
    assertEquals("aid", art.getArtifactId());
    assertEquals("ver", art.getVersion());
    assertEquals("ext", art.getExtension());
    dep = deps.get(1);
    assertEquals("scope", dep.getScope());
    assertEquals(true, dep.isOptional());
    assertEquals(0, dep.getExclusions().size());
    art = dep.getArtifact();
    assertEquals("gid", art.getGroupId());
    assertEquals("aid2", art.getArtifactId());
    assertEquals("ver", art.getVersion());
    assertEquals("ext", art.getExtension());
    dep = deps.get(2);
    assertEquals("scope", dep.getScope());
    assertEquals(true, dep.isOptional());
    assertEquals(0, dep.getExclusions().size());
    art = dep.getArtifact();
    assertEquals("gid", art.getGroupId());
    assertEquals("aid", art.getArtifactId());
    assertEquals("ver3", art.getVersion());
    assertEquals("ext", art.getExtension());
    dep = deps.get(3);
    assertEquals("scope5", dep.getScope());
    assertEquals(true, dep.isOptional());
    assertEquals(0, dep.getExclusions().size());
    art = dep.getArtifact();
    assertEquals("gid1", art.getGroupId());
    assertEquals("aid", art.getArtifactId());
    assertEquals("ver", art.getVersion());
    assertEquals("ext", art.getExtension());
}
Also used : Exclusion(org.sonatype.aether.graph.Exclusion) Dependency(org.sonatype.aether.graph.Dependency) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact)

Example 5 with Exclusion

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

the class AetherUtilsTest method createExclusion.

@Test
public void createExclusion() throws Exception {
    String testExclusion = "group";
    Exclusion exclusion = AetherUtils.createExclusion(testExclusion);
    assertEquals("group", exclusion.getGroupId());
    assertEquals("*", exclusion.getArtifactId());
    assertEquals("*", exclusion.getClassifier());
    assertEquals("*", exclusion.getExtension());
    testExclusion = "group:artifact";
    exclusion = AetherUtils.createExclusion(testExclusion);
    assertEquals("group", exclusion.getGroupId());
    assertEquals("artifact", exclusion.getArtifactId());
    assertEquals("*", exclusion.getClassifier());
    assertEquals("*", exclusion.getExtension());
    testExclusion = "group:artifact:site";
    exclusion = AetherUtils.createExclusion(testExclusion);
    assertEquals("group", exclusion.getGroupId());
    assertEquals("artifact", exclusion.getArtifactId());
    assertEquals("site", exclusion.getClassifier());
    assertEquals("*", exclusion.getExtension());
    testExclusion = "group:artifact:site:jar";
    exclusion = AetherUtils.createExclusion(testExclusion);
    assertEquals("group", exclusion.getGroupId());
    assertEquals("artifact", exclusion.getArtifactId());
    assertEquals("site", exclusion.getClassifier());
    assertEquals("jar", exclusion.getExtension());
}
Also used : Exclusion(org.sonatype.aether.graph.Exclusion) Test(org.junit.Test)

Aggregations

Exclusion (org.sonatype.aether.graph.Exclusion)11 Dependency (org.sonatype.aether.graph.Dependency)9 Artifact (org.sonatype.aether.artifact.Artifact)6 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 LinkedHashSet (java.util.LinkedHashSet)2 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 DependencyManagement (org.sonatype.aether.collection.DependencyManagement)1 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)1