Search in sources :

Example 6 with Exclusion

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

the class IniArtifactDataReader method dependencies.

private List<Dependency> dependencies(List<String> list) {
    List<Dependency> ret = new ArrayList<Dependency>();
    if (list == null) {
        return ret;
    }
    Collection<Exclusion> exclusions = new ArrayList<Exclusion>();
    boolean optional = false;
    Artifact artifact = null;
    String scope = null;
    for (String coords : list) {
        if (coords.startsWith("-")) {
            coords = coords.substring(1);
            String[] split = coords.split(":");
            exclusions.add(new Exclusion(split[0], split[1], "", ""));
        } else {
            if (artifact != null) {
                // commit dependency
                Dependency dep = new Dependency(artifact, scope, optional, exclusions);
                ret.add(dep);
                exclusions = new ArrayList<Exclusion>();
            }
            ArtifactDefinition def = new ArtifactDefinition(coords);
            optional = def.isOptional();
            scope = "".equals(def.getScope()) ? "compile" : def.getScope();
            artifact = new StubArtifact(def.getGroupId(), def.getArtifactId(), "", def.getExtension(), def.getVersion());
        }
    }
    if (artifact != null) {
        // commit dependency
        Dependency dep = new Dependency(artifact, scope, optional, exclusions);
        ret.add(dep);
        exclusions = new ArrayList<Exclusion>();
    }
    return ret;
}
Also used : Exclusion(org.sonatype.aether.graph.Exclusion) ArrayList(java.util.ArrayList) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Dependency(org.sonatype.aether.graph.Dependency) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact)

Example 7 with Exclusion

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

the class IniArtifactDataReaderTest method testDependencies.

@Test
public void testDependencies() throws IOException {
    String def = "[dependencies]\ngid:aid:ext:ver\n-exclusion:aid\ngid2:aid2:ext2:ver2";
    ArtifactDescription description = parser.parseLiteral(def);
    List<Dependency> dependencies = description.getDependencies();
    assertNotNull(dependencies);
    assertEquals(2, dependencies.size());
    Dependency dependency = dependencies.get(0);
    assertNotNull(dependency.getArtifact());
    Artifact artifact = dependency.getArtifact();
    assertEquals("aid", artifact.getArtifactId());
    assertEquals("gid", artifact.getGroupId());
    assertEquals("ver", artifact.getVersion());
    assertEquals("ext", artifact.getExtension());
    Collection<Exclusion> exclusions = dependency.getExclusions();
    assertNotNull(exclusions);
    assertEquals(1, exclusions.size());
    Exclusion exclusion = exclusions.iterator().next();
    assertEquals("exclusion", exclusion.getGroupId());
    assertEquals("aid", exclusion.getArtifactId());
    dependency = dependencies.get(1);
    assertNotNull(dependency.getArtifact());
    artifact = dependency.getArtifact();
    assertEquals("aid2", artifact.getArtifactId());
    assertEquals("gid2", artifact.getGroupId());
    assertEquals("ver2", artifact.getVersion());
    assertEquals("ext2", artifact.getExtension());
}
Also used : Exclusion(org.sonatype.aether.graph.Exclusion) Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 8 with Exclusion

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

the class IniArtifactDataReaderTest 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) Artifact(org.sonatype.aether.artifact.Artifact)

Example 9 with Exclusion

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

the class ClassicDependencyManager method manageDependency.

public DependencyManagement manageDependency(Dependency dependency) {
    DependencyManagement management = null;
    Object key = getKey(dependency.getArtifact());
    if (depth >= 2) {
        String version = managedVersions.get(key);
        if (version != null) {
            if (management == null) {
                management = new DependencyManagement();
            }
            management.setVersion(version);
        }
        String scope = managedScopes.get(key);
        if (scope != null) {
            if (management == null) {
                management = new DependencyManagement();
            }
            management.setScope(scope);
            if (!JavaScopes.SYSTEM.equals(scope) && dependency.getArtifact().getProperty(ArtifactProperties.LOCAL_PATH, null) != null) {
                Map<String, String> properties = new HashMap<String, String>(dependency.getArtifact().getProperties());
                properties.remove(ArtifactProperties.LOCAL_PATH);
                management.setProperties(properties);
            }
        }
        if ((scope != null && JavaScopes.SYSTEM.equals(scope)) || (scope == null && JavaScopes.SYSTEM.equals(dependency.getScope()))) {
            String localPath = managedLocalPaths.get(key);
            if (localPath != null) {
                if (management == null) {
                    management = new DependencyManagement();
                }
                Map<String, String> properties = new HashMap<String, String>(dependency.getArtifact().getProperties());
                properties.put(ArtifactProperties.LOCAL_PATH, localPath);
                management.setProperties(properties);
            }
        }
    }
    Collection<Exclusion> exclusions = managedExclusions.get(key);
    if (exclusions != null) {
        if (management == null) {
            management = new DependencyManagement();
        }
        Collection<Exclusion> result = new LinkedHashSet<Exclusion>(dependency.getExclusions());
        result.addAll(exclusions);
        management.setExclusions(result);
    }
    return management;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) Exclusion(org.sonatype.aether.graph.Exclusion) DependencyManagement(org.sonatype.aether.collection.DependencyManagement)

Example 10 with Exclusion

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

the class ClassicDependencyManager method deriveChildManager.

public DependencyManager deriveChildManager(DependencyCollectionContext context) {
    if (depth >= 2) {
        return this;
    } else if (depth == 1) {
        return new ClassicDependencyManager(depth + 1, managedVersions, managedScopes, managedLocalPaths, managedExclusions);
    }
    Map<Object, String> managedVersions = this.managedVersions;
    Map<Object, String> managedScopes = this.managedScopes;
    Map<Object, String> managedLocalPaths = this.managedLocalPaths;
    Map<Object, Collection<Exclusion>> managedExclusions = this.managedExclusions;
    for (Dependency managedDependency : context.getManagedDependencies()) {
        Artifact artifact = managedDependency.getArtifact();
        Object key = getKey(artifact);
        String version = artifact.getVersion();
        if (version.length() > 0 && !managedVersions.containsKey(key)) {
            if (managedVersions == this.managedVersions) {
                managedVersions = new HashMap<Object, String>(this.managedVersions);
            }
            managedVersions.put(key, version);
        }
        String scope = managedDependency.getScope();
        if (scope.length() > 0 && !managedScopes.containsKey(key)) {
            if (managedScopes == this.managedScopes) {
                managedScopes = new HashMap<Object, String>(this.managedScopes);
            }
            managedScopes.put(key, scope);
        }
        String localPath = managedDependency.getArtifact().getProperty(ArtifactProperties.LOCAL_PATH, null);
        if (localPath != null && !managedLocalPaths.containsKey(key)) {
            if (managedLocalPaths == this.managedLocalPaths) {
                managedLocalPaths = new HashMap<Object, String>(this.managedLocalPaths);
            }
            managedLocalPaths.put(key, localPath);
        }
        Collection<Exclusion> exclusions = managedDependency.getExclusions();
        if (!exclusions.isEmpty()) {
            if (managedExclusions == this.managedExclusions) {
                managedExclusions = new HashMap<Object, Collection<Exclusion>>(this.managedExclusions);
            }
            Collection<Exclusion> managed = managedExclusions.get(key);
            if (managed == null) {
                managed = new LinkedHashSet<Exclusion>();
                managedExclusions.put(key, managed);
            }
            managed.addAll(exclusions);
        }
    }
    return new ClassicDependencyManager(depth + 1, managedVersions, managedScopes, managedLocalPaths, managedExclusions);
}
Also used : Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact) Exclusion(org.sonatype.aether.graph.Exclusion) Collection(java.util.Collection)

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