Search in sources :

Example 81 with Artifact

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

the class DependencyGraphParserTest method assertNodeProperties.

private void assertNodeProperties(DependencyNode node, String suffix) {
    assertNotNull(node);
    Dependency dependency = node.getDependency();
    assertNotNull(dependency);
    if (!"".equals(dependency.getScope())) {
        assertEquals("scope" + suffix, dependency.getScope());
    }
    Artifact artifact = dependency.getArtifact();
    assertNotNull(artifact);
    assertEquals("gid" + suffix, artifact.getGroupId());
    assertEquals("aid" + suffix, artifact.getArtifactId());
    assertEquals("ext" + suffix, artifact.getExtension());
    assertEquals("ver" + suffix, artifact.getVersion());
}
Also used : Dependency(org.sonatype.aether.graph.Dependency) Artifact(org.sonatype.aether.artifact.Artifact)

Example 82 with Artifact

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

the class DependencyGraphParserTest method testSubstitutions.

@Test
public void testSubstitutions() throws IOException {
    parser.setSubstitutions(Arrays.asList("subst1", "subst2"));
    String def = "%s:%s:ext:ver";
    DependencyNode root = parser.parseLiteral(def);
    Artifact artifact = root.getDependency().getArtifact();
    assertEquals("subst2", artifact.getArtifactId());
    assertEquals("subst1", artifact.getGroupId());
    def = "%s:aid:ext:ver\n\\- %s:aid:ext:ver";
    root = parser.parseLiteral(def);
    assertEquals("subst1", root.getDependency().getArtifact().getGroupId());
    assertEquals("subst2", root.getChildren().get(0).getDependency().getArtifact().getGroupId());
}
Also used : DependencyNode(org.sonatype.aether.graph.DependencyNode) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 83 with Artifact

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

the class ConnectorTestSuite method testProgressEventsDataBuffer.

@Test
public void testProgressEventsDataBuffer() throws UnsupportedEncodingException, IOException, NoSuchAlgorithmException, NoRepositoryConnectorException {
    byte[] bytes = "These are the test contents.\n".getBytes("UTF-8");
    int count = 120000;
    MessageDigest digest = MessageDigest.getInstance("SHA-1");
    for (int i = 0; i < count; i++) {
        digest.update(bytes);
    }
    byte[] hash = digest.digest();
    File file = TestFileUtils.createTempFile(bytes, count);
    Artifact artifact = new StubArtifact("gid:aid:ext:ver");
    ArtifactUpload upA = new ArtifactUpload(artifact, file);
    File dir = TestFileUtils.createTempDir("con-test");
    File downAFile = new File(dir, "downA.file");
    downAFile.deleteOnExit();
    ArtifactDownload downA = new ArtifactDownload(artifact, "", downAFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    Metadata metadata = new StubMetadata("gid", "aid", "ver", "maven-metadata.xml", Metadata.Nature.RELEASE_OR_SNAPSHOT);
    MetadataUpload upM = new MetadataUpload(metadata, file);
    File downMFile = new File(dir, "downM.file");
    downMFile.deleteOnExit();
    MetadataDownload downM = new MetadataDownload(metadata, "", downMFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    DigestingTransferListener listener = new DigestingTransferListener();
    session.setTransferListener(listener);
    RepositoryConnector connector = factory().newInstance(session, repository);
    connector.put(Arrays.asList(upA), null);
    assertArrayEquals(hash, listener.getHash());
    listener.rewind();
    connector.put(null, Arrays.asList(upM));
    assertArrayEquals(hash, listener.getHash());
    listener.rewind();
    connector.get(Arrays.asList(downA), null);
    assertArrayEquals(hash, listener.getHash());
    listener.rewind();
    connector.get(null, Arrays.asList(downM));
    assertArrayEquals(hash, listener.getHash());
    listener.rewind();
    connector.close();
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) Metadata(org.sonatype.aether.metadata.Metadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) MessageDigest(java.security.MessageDigest) File(java.io.File) Test(org.junit.Test)

Example 84 with Artifact

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

Example 85 with Artifact

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

Aggregations

Artifact (org.sonatype.aether.artifact.Artifact)116 Test (org.junit.Test)62 File (java.io.File)34 RemoteRepository (org.sonatype.aether.repository.RemoteRepository)33 StubArtifact (org.sonatype.aether.test.util.impl.StubArtifact)28 DefaultArtifact (org.sonatype.aether.util.artifact.DefaultArtifact)28 Dependency (org.sonatype.aether.graph.Dependency)21 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)15 RepositorySystemSession (org.sonatype.aether.RepositorySystemSession)13 SubArtifact (org.sonatype.aether.util.artifact.SubArtifact)13 ArtifactTransferException (org.sonatype.aether.transfer.ArtifactTransferException)12 ArrayList (java.util.ArrayList)11 RepositorySystem (org.sonatype.aether.RepositorySystem)10 Metadata (org.sonatype.aether.metadata.Metadata)10 CollectRequest (org.sonatype.aether.collection.CollectRequest)9 IOException (java.io.IOException)8