use of org.eclipse.ceylon.cmr.api.ArtifactCallback in project ceylon by eclipse.
the class RootRepositoryManager method putContent.
private File putContent(ArtifactContext context, Node node, InputStream stream, long length) throws IOException {
log.debug(" Creating local copy of external node: " + node + " at repo: " + (fileContentStore != null ? fileContentStore.getDisplayString() : null));
if (fileContentStore == null)
throw new IOException("No location to place node at: fileContentStore is null");
ArtifactCallback callback = context.getCallback();
if (callback == null) {
callback = ArtifactCallbackStream.getCallback();
}
final File finalFile;
VerifiedDownload dl = new VerifiedDownload(log, context, fileContentStore, node);
try {
dl.fetch(callback, stream, length);
// only check for jars or forced checks
if (ArtifactContext.JAR.equals(context.getSingleSuffix()) || context.forceDescriptorCheck()) {
// transfer descriptor as well, if there is one
final Node descriptor = Configuration.getResolvers(this).descriptor(node);
if (descriptor != null && descriptor.hasBinaries()) {
VerifiedDownload descriptorDl = new VerifiedDownload(log, context, fileContentStore, descriptor);
try {
descriptorDl.fetch(callback, descriptor.getInputStream(), 40);
descriptorDl.commit();
} catch (RuntimeException e) {
dl.rollback(e);
throw e;
} catch (IOException e) {
dl.rollback(e);
throw e;
}
}
}
// ... got descriptor OK, so can now commit
finalFile = dl.commit();
} catch (RuntimeException e) {
dl.rollback(e);
throw e;
} catch (IOException e) {
dl.rollback(e);
throw e;
}
// refresh markers from root to this newly put node
if (getCache() != null) {
final List<String> paths = NodeUtils.toLabelPath(node);
OpenNode current = getCache();
for (String path : paths) {
if (current == null) {
break;
}
current.refresh(false);
final Node tmp = current.peekChild(path);
current = (tmp instanceof OpenNode) ? OpenNode.class.cast(tmp) : null;
}
}
return finalFile;
}
Aggregations