Search in sources :

Example 71 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.

the class MavenMetadataReader method getMetadata.

public MavenMetadataView getMetadata(final ProjectRef ref, final List<? extends Location> locations, final EventMetadata eventMetadata) throws GalleyMavenException {
    final List<DocRef<ProjectRef>> docs = new ArrayList<DocRef<ProjectRef>>(locations.size());
    final Map<Location, DocRef<ProjectRef>> cached = getAllCached(ref, locations);
    final List<? extends Location> toRetrieve = new ArrayList<Location>(locations);
    for (final Location loc : locations) {
        final DocRef<ProjectRef> dr = cached.get(loc);
        if (dr != null) {
            docs.add(dr);
            toRetrieve.remove(loc);
        } else {
            docs.add(null);
        }
    }
    List<Transfer> transfers;
    try {
        transfers = metadataManager.retrieveAll(toRetrieve, ref, eventMetadata);
    } catch (final TransferException e) {
        throw new GalleyMavenException("Failed to resolve metadata for: {} from: {}. Reason: {}", e, ref, locations, e.getMessage());
    }
    logger.debug("Resolved {} transfers:\n  {}", transfers.size(), new JoinString("\n  ", transfers));
    if (transfers != null && !transfers.isEmpty()) {
        for (final Transfer transfer : transfers) {
            final DocRef<ProjectRef> dr = new DocRef<ProjectRef>(ref, transfer.getLocation(), xml.parse(transfer, eventMetadata));
            final int idx = locations.indexOf(transfer.getLocation());
            //
            if (idx > -1) {
                docs.set(idx, dr);
            } else {
                docs.add(dr);
            }
        }
    }
    for (final Iterator<DocRef<ProjectRef>> iterator = docs.iterator(); iterator.hasNext(); ) {
        final DocRef<ProjectRef> docRef = iterator.next();
        if (docRef == null) {
            iterator.remove();
        }
    }
    logger.debug("Got {} metadata documents for: {}", docs.size(), ref);
    return new MavenMetadataView(docs, xpath, xml);
}
Also used : GalleyMavenException(org.commonjava.maven.galley.maven.GalleyMavenException) ArrayList(java.util.ArrayList) DocRef(org.commonjava.maven.galley.maven.model.view.DocRef) MavenMetadataView(org.commonjava.maven.galley.maven.model.view.meta.MavenMetadataView) TransferException(org.commonjava.maven.galley.TransferException) JoinString(org.commonjava.maven.atlas.ident.util.JoinString) Transfer(org.commonjava.maven.galley.model.Transfer) ProjectRef(org.commonjava.maven.atlas.ident.ref.ProjectRef) Location(org.commonjava.maven.galley.model.Location)

Example 72 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.

the class Md5GeneratorFactoryTest method verifyWithMessageDigest.

@Test
public void verifyWithMessageDigest() throws Exception {
    final byte[] data = "this is a test".getBytes();
    final Transfer txfr = fixture.getCache().getTransfer(new ConcreteResource(new SimpleLocation("test:uri"), "my-path.txt"));
    final Md5GeneratorFactory factory = new Md5GeneratorFactory();
    final Md5Generator generator = factory.newGenerator(txfr, true);
    generator.update(data);
    generator.write();
    final MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(data);
    final byte[] digest = md.digest();
    final String digestHex = Hex.encodeHexString(digest);
    final Transfer md5Txfr = txfr.getSiblingMeta(".md5");
    InputStream in = null;
    String resultHex = null;
    try {
        in = md5Txfr.openInputStream();
        resultHex = IOUtils.toString(in);
    } finally {
        IOUtils.closeQuietly(in);
    }
    assertThat(resultHex, equalTo(digestHex));
}
Also used : Md5Generator(org.commonjava.maven.galley.io.checksum.Md5GeneratorFactory.Md5Generator) InputStream(java.io.InputStream) Transfer(org.commonjava.maven.galley.model.Transfer) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) SimpleLocation(org.commonjava.maven.galley.model.SimpleLocation) MessageDigest(java.security.MessageDigest) Test(org.junit.Test)

Example 73 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.

the class ArtifactManagerImplTest method resolveSnapshot_FirstMatch_SingletonLocationList_SingletonSnapshotList_LatestVersionStrategy.

@Test
public void resolveSnapshot_FirstMatch_SingletonLocationList_SingletonSnapshotList_LatestVersionStrategy() throws Exception {
    final String base = "single-snapshot/";
    final String testResource = base + "single-snapshot.xml";
    final String testPomResource = base + "single-snapshot-pom.xml";
    final ProjectVersionRef ref = new SimpleProjectVersionRef("org.group", "artifact", "1.0-SNAPSHOT");
    final ConcreteResource metadataResource = new ConcreteResource(LOCATION, fixture.snapshotMetadataPath(ref));
    final ConcreteResource pomResource = new ConcreteResource(LOCATION, fixture.pomPath(ref.selectVersion("1.0-20140604.101244-1").asPomArtifact()));
    fixture.getTransport().registerDownload(metadataResource, new TestDownload(ROOT + testResource));
    fixture.getTransport().registerDownload(pomResource, new TestDownload(ROOT + testPomResource));
    final Transfer retrieved = fixture.getArtifactManager().retrieve(LOCATION, ref.asPomArtifact(), new EventMetadata());
    final Document document = fixture.getXml().parse(retrieved, new EventMetadata());
    final ProjectVersionRef result = fixture.getXml().getProjectVersionRef(document);
    System.out.println(result);
//        assertThat( result, notNullValue() );
//        assertThat( result.getVersionString(), equalTo( "1.0-20140604.101244-1" ) );
}
Also used : TestDownload(org.commonjava.maven.galley.testing.core.transport.job.TestDownload) ProjectVersionRef(org.commonjava.maven.atlas.ident.ref.ProjectVersionRef) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) ConcreteResource(org.commonjava.maven.galley.model.ConcreteResource) Transfer(org.commonjava.maven.galley.model.Transfer) SimpleProjectVersionRef(org.commonjava.maven.atlas.ident.ref.SimpleProjectVersionRef) Document(org.w3c.dom.Document) EventMetadata(org.commonjava.maven.galley.event.EventMetadata) Test(org.junit.Test)

Example 74 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.

the class TestCacheProvider method writeClasspathResourceToCache.

public Transfer writeClasspathResourceToCache(final ConcreteResource resource, final String cpResource) throws IOException {
    final InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(cpResource);
    if (in == null) {
        throw new IOException("Classpath resource not found: " + cpResource);
    }
    final Transfer tx = getTransfer(resource);
    OutputStream out = null;
    try {
        out = tx.openOutputStream(TransferOperation.UPLOAD, false);
        IOUtils.copy(in, out);
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
    }
    return tx;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException)

Example 75 with Transfer

use of org.commonjava.maven.galley.model.Transfer in project galley by Commonjava.

the class TestCacheProvider method writeToCache.

public Transfer writeToCache(final ConcreteResource resource, final String content) throws IOException {
    if (content == null) {
        throw new IOException("Content is empty!");
    }
    final Transfer tx = getTransfer(resource);
    OutputStream out = null;
    try {
        out = tx.openOutputStream(TransferOperation.UPLOAD, false);
        out.write(content.getBytes());
    } finally {
        IOUtils.closeQuietly(out);
    }
    return tx;
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Transfer(org.commonjava.maven.galley.model.Transfer) IOException(java.io.IOException)

Aggregations

Transfer (org.commonjava.maven.galley.model.Transfer)154 ConcreteResource (org.commonjava.maven.galley.model.ConcreteResource)63 Test (org.junit.Test)62 IOException (java.io.IOException)39 EventMetadata (org.commonjava.maven.galley.event.EventMetadata)38 IndyWorkflowException (org.commonjava.indy.IndyWorkflowException)37 InputStream (java.io.InputStream)27 StoreKey (org.commonjava.indy.model.core.StoreKey)27 Logger (org.slf4j.Logger)26 SimpleLocation (org.commonjava.maven.galley.model.SimpleLocation)22 ByteArrayInputStream (java.io.ByteArrayInputStream)21 ArtifactStore (org.commonjava.indy.model.core.ArtifactStore)21 HostedRepository (org.commonjava.indy.model.core.HostedRepository)21 Group (org.commonjava.indy.model.core.Group)20 ArrayList (java.util.ArrayList)19 IndyDataException (org.commonjava.indy.data.IndyDataException)19 OutputStream (java.io.OutputStream)15 HashSet (java.util.HashSet)15 Location (org.commonjava.maven.galley.model.Location)14 TransferException (org.commonjava.maven.galley.TransferException)12