Search in sources :

Example 21 with Artifact

use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.

the class SimpleLocalRepositoryManagerTest method testGetPathForRemoteArtifact.

@Test
public void testGetPathForRemoteArtifact() throws Exception {
    RemoteRepository remoteRepo = new RemoteRepository("repo", "default", "ram:/void");
    Artifact artifact = new DefaultArtifact("g.i.d:a.i.d:1.0-SNAPSHOT");
    assertEquals("1.0-SNAPSHOT", artifact.getBaseVersion());
    assertEquals("g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT.jar", manager.getPathForRemoteArtifact(artifact, remoteRepo, ""));
    artifact = new DefaultArtifact("g.i.d:a.i.d:1.0-20110329.221805-4");
    assertEquals("1.0-SNAPSHOT", artifact.getBaseVersion());
    assertEquals("g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-20110329.221805-4.jar", manager.getPathForRemoteArtifact(artifact, remoteRepo, ""));
}
Also used : RemoteRepository(org.sonatype.aether.repository.RemoteRepository) Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) Test(org.junit.Test)

Example 22 with Artifact

use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.

the class DependencyGraphParser method addNode.

private void addNode(DependencyNode root, int level, List<NodeEntry> entries) {
    NodeEntry entry = new NodeEntry();
    Dependency dependency = root.getDependency();
    StringBuilder defBuilder = new StringBuilder();
    if (dependency == null) {
        defBuilder.append("(null)");
    } else {
        Artifact artifact = dependency.getArtifact();
        defBuilder.append(artifact.getGroupId()).append(":").append(artifact.getArtifactId()).append(":").append(artifact.getExtension()).append(":").append(artifact.getVersion());
        if (dependency.getScope() != null && (!"".equals(dependency.getScope()))) {
            defBuilder.append(":").append(dependency.getScope());
        }
        Map<String, String> properties = artifact.getProperties();
        if (!(properties == null || properties.isEmpty())) {
            for (Map.Entry<String, String> prop : properties.entrySet()) {
                defBuilder.append(";").append(prop.getKey()).append("=").append(prop.getValue());
            }
        }
    }
    entry.setDefinition(defBuilder.toString());
    entry.setLevel(level++);
    entries.add(entry);
    for (DependencyNode node : root.getChildren()) {
        addNode(node, level, entries);
    }
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency) HashMap(java.util.HashMap) Map(java.util.Map) Artifact(org.sonatype.aether.artifact.Artifact)

Example 23 with Artifact

use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.

the class DependencyGraphParserTest method testOnlyRoot.

@Test
public void testOnlyRoot() throws IOException {
    String def = "gid:aid:jar:1:scope";
    DependencyNode node = parser.parseLiteral(def);
    assertNotNull(node);
    assertEquals(0, node.getChildren().size());
    Dependency dependency = node.getDependency();
    assertNotNull(dependency);
    assertEquals("scope", dependency.getScope());
    Artifact artifact = dependency.getArtifact();
    assertNotNull(artifact);
    assertEquals("gid", artifact.getGroupId());
    assertEquals("aid", artifact.getArtifactId());
    assertEquals("jar", artifact.getExtension());
    assertEquals("1", artifact.getVersion());
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 24 with Artifact

use of org.sonatype.aether.artifact.Artifact in project sonatype-aether by sonatype.

the class IniArtifactDataReaderTest method testRelocations.

@Test
public void testRelocations() throws IOException {
    String def = "[relocations]\ngid:aid:ext:ver\ngid2:aid2:ext2:ver2";
    ArtifactDescription description = parser.parseLiteral(def);
    List<Artifact> relocations = description.getRelocations();
    assertNotNull(relocations);
    assertEquals(2, relocations.size());
    Artifact artifact = relocations.get(0);
    assertEquals("aid", artifact.getArtifactId());
    assertEquals("gid", artifact.getGroupId());
    assertEquals("ver", artifact.getVersion());
    assertEquals("ext", artifact.getExtension());
    artifact = relocations.get(1);
    assertEquals("aid2", artifact.getArtifactId());
    assertEquals("gid2", artifact.getGroupId());
    assertEquals("ver2", artifact.getVersion());
    assertEquals("ext2", artifact.getExtension());
}
Also used : Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 25 with Artifact

use of org.sonatype.aether.artifact.Artifact 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)

Aggregations

Artifact (org.sonatype.aether.artifact.Artifact)116 Test (org.junit.Test)63 File (java.io.File)33 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)30 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)28 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)27 Dependency (org.sonatype.aether.graph.Dependency)22 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)17 ArtifactDownload (org.sonatype.aether.spi.connector.ArtifactDownload)16 LocalArtifactRequest (org.sonatype.aether.repository.LocalArtifactRequest)15 LocalArtifactResult (org.sonatype.aether.repository.LocalArtifactResult)15 ArtifactRequest (org.sonatype.aether.resolution.ArtifactRequest)14 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)13 SubArtifact (org.sonatype.aether.util.artifact.SubArtifact)13 ArrayList (java.util.ArrayList)12 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)12 Metadata (org.sonatype.aether.metadata.Metadata)10 RepositorySystem (org.sonatype.aether.RepositorySystem)9 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8