use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class ImpliedRepositoryDetectorTest method addImpliedPluginRepositoryToNewGroup.
@Test
public void addImpliedPluginRepositoryToNewGroup() throws Exception {
Transfer txfr = writeTransfer("one-plugin-repo.pom");
final FileStorageEvent event = new FileStorageEvent(TransferOperation.DOWNLOAD, txfr, new EventMetadata());
detector.detectRepos(event);
synchronized (detector) {
detector.wait();
}
assertThat(storeManager.query().packageType(MAVEN_PKG_KEY).getRemoteRepository("i-repo-one"), notNullValue());
assertThat(getGroup().getConstituents().contains(new StoreKey(StoreType.remote, "i-repo-one")), equalTo(true));
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class ImpliedRepositoryDetectorTest method addRepositoryFromPomStorageEvent.
// @Test
// public void idWithSpaceInIt_ConvertToDashes()
// {
// String in = "my id";
// String out = detector.formatId( in );
// assertThat( out, equalTo( "i-my-id" ) );
// }
//
// @Test
// public void idWithPlusInIt_ConvertToDashes()
// {
// String in = "my+id";
// String out = detector.formatId( in );
// assertThat( out, equalTo( "i-my-id" ) );
// }
@Test
public void addRepositoryFromPomStorageEvent() throws Exception {
Transfer txfr = writeTransfer("one-repo.pom");
final FileStorageEvent event = new FileStorageEvent(TransferOperation.DOWNLOAD, txfr, new EventMetadata());
detector.detectRepos(event);
synchronized (detector) {
detector.wait();
}
assertThat(storeManager.query().packageType(MAVEN_PKG_KEY).getRemoteRepository("i-repo-one"), notNullValue());
assertThat(getGroup().getConstituents().contains(new StoreKey(StoreType.remote, "i-repo-one")), equalTo(true));
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class ImpliedRepositoryDetectorTest method writeTransfer.
private Transfer writeTransfer(final String resource) throws IndyDataException, IOException {
final String path = "/path/to/1/to-1.pom";
final Transfer txfr = fixture.getCache().getTransfer(new ConcreteResource(new RepositoryLocation(getRemote()), path));
try (OutputStream out = txfr.openOutputStream(TransferOperation.UPLOAD, false);
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource)) {
String pom = IOUtils.toString(in);
pom = StringUtils.replace(pom, "${baseurl}", server.formatUrl());
IOUtils.copy(new StringReader(pom), out);
}
return txfr;
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class KojiBuildAuthority method checksumArtifact.
private String checksumArtifact(ArtifactStore store, String path, EventMetadata eventMetadata) {
final Logger logger = LoggerFactory.getLogger(getClass());
try {
if (directContentAccess.exists(store, path)) {
String md5Path = path + ".md5";
Transfer md5 = directContentAccess.retrieveRaw(store, md5Path, eventMetadata);
if (md5 != null && md5.exists()) {
try (InputStream in = md5.openInputStream(true)) {
return IOUtils.toString(in).trim();
} catch (IOException e) {
logger.warn("Error reading MD5 checksum for transfer of path {} in store {}, error is {}", md5Path, store, e.getMessage());
}
} else {
EventMetadata forcedEventMetadata = new EventMetadata(eventMetadata).set(FORCE_CHECKSUM, TRUE);
final TransferMetadata artifactData = contentDigester.digest(store.getKey(), path, forcedEventMetadata);
if (artifactData != null) {
return artifactData.getDigests().get(ContentDigest.MD5);
}
}
}
} catch (IndyWorkflowException e) {
logger.warn("Error happened when calculate md5 checksum for transfer of path {} in store {}, error is {}", path, store, e.getMessage());
}
return null;
}
use of org.commonjava.maven.galley.model.Transfer in project indy by Commonjava.
the class ProxyResponseWriter method transfer.
private void transfer(final HttpConduitWrapper http, final RemoteRepository repo, final String path, final boolean writeBody, final UserPass proxyUserPass) throws IOException, IndyWorkflowException {
if (transferred) {
return;
}
transferred = true;
if (!http.isOpen()) {
throw new IOException("Sink channel already closed (or null)!");
}
final EventMetadata eventMetadata = createEventMetadata(writeBody, proxyUserPass, path, repo);
Transfer txfr = null;
try {
txfr = contentController.get(repo.getKey(), path, eventMetadata);
} catch (final IndyWorkflowException e) {
// block TransferException to allow handling below.
if (!(e.getCause() instanceof TransferException)) {
throw e;
}
logger.debug("Suppressed exception for further handling inside proxy logic:", e);
}
if (txfr != null && txfr.exists()) {
http.writeExistingTransfer(txfr, writeBody, path, eventMetadata);
} else {
http.writeNotFoundTransfer(repo, path);
}
}
Aggregations