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);
}
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));
}
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" ) );
}
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;
}
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;
}
Aggregations