Search in sources :

Example 16 with Artifact

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

the class DefaultUpdateCheckManagerTest method testCheckArtifactNotFoundInRepoCachingDisabled.

@Test
public void testCheckArtifactNotFoundInRepoCachingDisabled() throws Exception {
    artifact.getFile().delete();
    session.setNotFoundCachingEnabled(false);
    UpdateCheck<Artifact, ArtifactTransferException> check = newArtifactCheck();
    check.setException(new ArtifactNotFoundException(artifact, repository));
    manager.touchArtifact(session, check);
    resetSessionData(session);
    // ! file.exists && ! updateRequired -> artifact not found in remote repo
    check = newArtifactCheck().setPolicy(RepositoryPolicy.UPDATE_POLICY_DAILY);
    manager.checkArtifact(session, check);
    assertEquals(true, check.isRequired());
    assertNull(check.getException());
}
Also used : ArtifactTransferException(org.sonatype.aether.transfer.ArtifactTransferException) ArtifactNotFoundException(org.sonatype.aether.transfer.ArtifactNotFoundException) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 17 with Artifact

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

the class ConnectorTestSuite method testTransferZeroBytesFile.

/**
     * See https://issues.sonatype.org/browse/AETHER-8
     */
@Test
public void testTransferZeroBytesFile() throws IOException, NoRepositoryConnectorException {
    File emptyFile = TestFileUtils.createTempFile("");
    Artifact artifact = new StubArtifact("gid:aid:ext:ver");
    ArtifactUpload upA = new ArtifactUpload(artifact, emptyFile);
    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, emptyFile);
    File downMFile = new File(dir, "downM.file");
    downMFile.deleteOnExit();
    MetadataDownload downM = new MetadataDownload(metadata, "", downMFile, RepositoryPolicy.CHECKSUM_POLICY_FAIL);
    RepositoryConnector connector = factory().newInstance(session, repository);
    connector.put(Arrays.asList(upA), Arrays.asList(upM));
    connector.get(Arrays.asList(downA), Arrays.asList(downM));
    assertNull(String.valueOf(upA.getException()), upA.getException());
    assertNull(String.valueOf(upM.getException()), upM.getException());
    assertNull(String.valueOf(downA.getException()), downA.getException());
    assertNull(String.valueOf(downM.getException()), downM.getException());
    assertEquals(0, downAFile.length());
    assertEquals(0, downMFile.length());
    connector.close();
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) Metadata(org.sonatype.aether.metadata.Metadata) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) RepositoryConnector(org.sonatype.aether.spi.connector.RepositoryConnector) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) File(java.io.File) StubArtifact(org.sonatype.aether.test.util.impl.StubArtifact) Artifact(org.sonatype.aether.artifact.Artifact) Test(org.junit.Test)

Example 18 with Artifact

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

the class ConnectorTestUtils method createTransfers.

/**
     * Creates transfer objects according to the given class. If the file parameter is {@code null}, a new temporary
     * file will be created for downloads. Uploads will just use the parameter as it is.
     */
public static <T extends Transfer> List<T> createTransfers(Class<T> cls, int count, File file) {
    ArrayList<T> ret = new ArrayList<T>();
    Object item;
    if (ArtifactTransfer.class.isAssignableFrom(cls)) {
        item = new StubArtifact("testGroup", "testArtifact", "sources", "jar", "will be replaced");
    } else {
        item = new StubMetadata("testGroup", "testArtifact", "will be replaced", "jar", Metadata.Nature.RELEASE_OR_SNAPSHOT, file);
    }
    for (int i = 0; i < count; i++) {
        String context = null;
        String checksumPolicy = RepositoryPolicy.CHECKSUM_POLICY_IGNORE;
        Object obj = null;
        if (cls.isAssignableFrom(ArtifactUpload.class)) {
            Artifact artifact = ((Artifact) item).setVersion((i + 1) + "-test");
            obj = new ArtifactUpload(artifact, file);
        } else if (cls.isAssignableFrom(ArtifactDownload.class)) {
            try {
                Artifact artifact = ((Artifact) item).setVersion((i + 1) + "-test");
                obj = new ArtifactDownload(artifact, context, safeFile(file), checksumPolicy);
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        } else if (cls.isAssignableFrom(MetadataUpload.class)) {
            Metadata metadata = ((StubMetadata) item).setVersion((i + 1) + "-test");
            obj = new MetadataUpload(metadata, file);
        } else if (cls.isAssignableFrom(MetadataDownload.class)) {
            try {
                Metadata metadata = ((StubMetadata) item).setVersion((i + 1) + "-test");
                obj = new MetadataDownload(metadata, context, safeFile(file), checksumPolicy);
            } catch (IOException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
        ret.add(cls.cast(obj));
    }
    return ret;
}
Also used : ArtifactUpload(org.sonatype.aether.spi.connector.ArtifactUpload) ArrayList(java.util.ArrayList) StubMetadata(org.sonatype.aether.test.util.impl.StubMetadata) Metadata(org.sonatype.aether.metadata.Metadata) MetadataUpload(org.sonatype.aether.spi.connector.MetadataUpload) IOException(java.io.IOException) 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) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload)

Example 19 with Artifact

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

the class RecordingRepositoryConnector method get.

public void get(Collection<? extends ArtifactDownload> artifactDownloads, Collection<? extends MetadataDownload> metadataDownloads) {
    try {
        if (artifactDownloads != null) {
            for (ArtifactDownload artifactDownload : artifactDownloads) {
                artifactDownload.setState(State.ACTIVE);
                Artifact artifact = artifactDownload.getArtifact();
                this.actualGet.add(artifact);
                TestFileUtils.write(artifact.toString(), artifactDownload.getFile());
                artifactDownload.setState(State.DONE);
            }
        }
        if (metadataDownloads != null) {
            for (MetadataDownload metadataDownload : metadataDownloads) {
                metadataDownload.setState(State.ACTIVE);
                Metadata metadata = metadataDownload.getMetadata();
                this.actualGetMD.add(metadata);
                TestFileUtils.write(metadata.toString(), metadataDownload.getFile());
                metadataDownload.setState(State.DONE);
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException("Cannot create temporary file", e);
    }
}
Also used : ArtifactDownload(org.sonatype.aether.spi.connector.ArtifactDownload) Metadata(org.sonatype.aether.metadata.Metadata) MetadataDownload(org.sonatype.aether.spi.connector.MetadataDownload) IOException(java.io.IOException) Artifact(org.sonatype.aether.artifact.Artifact)

Example 20 with Artifact

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

the class SimpleLocalRepositoryManagerTest method testGetPathForLocalArtifact.

@Test
public void testGetPathForLocalArtifact() throws Exception {
    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.getPathForLocalArtifact(artifact));
    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-SNAPSHOT.jar", manager.getPathForLocalArtifact(artifact));
    artifact = new DefaultArtifact("g.i.d", "a.i.d", "", "", "1.0-SNAPSHOT");
    assertEquals("g/i/d/a.i.d/1.0-SNAPSHOT/a.i.d-1.0-SNAPSHOT", manager.getPathForLocalArtifact(artifact));
}
Also used : Artifact(org.sonatype.aether.artifact.Artifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) DefaultArtifact(org.sonatype.aether.util.artifact.DefaultArtifact) Test(org.junit.Test)

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