use of org.eclipse.ceylon.cmr.spi.SizedInputStream in project ceylon by eclipse.
the class RootRepositoryManager method getArtifactResult.
@Override
protected ArtifactResult getArtifactResult(ArtifactContext context, Node node) throws RepositoryException {
if (node.isRemote()) {
final boolean forceOp = context.isForceOperation();
try {
// just force the ops
context.setForceOperation(true);
log.debug("Looking up artifact " + context + " from " + node + " to cache it");
SizedInputStream sizedInputStream = node.getSizedInputStream();
// in theory we should not have nodes with null streams, but at least provide a helpful exception
if (sizedInputStream == null) {
throw new RepositoryException("Node " + node + " for repository " + this + " returned a null stream");
}
try {
log.debug(" -> Found it, now caching it");
final File file = putContent(context, node, sizedInputStream.getInputStream(), sizedInputStream.getSize());
log.debug(" Caching done: " + file);
String repositoryDisplayString = NodeUtils.getRepositoryDisplayString(node);
File originalRepoFile = new File(file.getParentFile(), file.getName().concat(ORIGIN));
FileWriter writer = new FileWriter(originalRepoFile, false);
try {
writer.write(repositoryDisplayString);
writer.close();
} catch (IOException e) {
log.error(e.toString());
}
// we expect the remote nodes to support Ceylon module info
return new FileArtifactResult(NodeUtils.getRepository(node), this, context.getName(), context.getVersion(), file, repositoryDisplayString);
} finally {
IOUtils.safeClose(sizedInputStream.getInputStream());
}
} catch (IOException e) {
throw new RepositoryException(e);
} finally {
context.setForceOperation(forceOp);
}
} else {
return toArtifactResult(node);
}
}
Aggregations