use of org.eclipse.ceylon.cmr.spi.OpenNode in project ceylon by eclipse.
the class AbstractRepository method createParent.
public OpenNode createParent(ArtifactContext context) {
final List<String> tokens = getDefaultParentPath(context);
OpenNode current = root;
for (String token : tokens) {
current = current.addNode(token);
}
return current;
}
use of org.eclipse.ceylon.cmr.spi.OpenNode in project ceylon by eclipse.
the class DefaultNode method addNode.
protected OpenNode addNode(final String label, final Object value, InputStream content, ContentOptions options, boolean allowNoContent) throws IOException {
if (label == null)
throw new IllegalArgumentException("Null label");
if (content == null && allowNoContent == false)
throw new IllegalArgumentException("Null content not allowed: " + label);
final DefaultNode node = new DefaultNode(label, value);
OpenNode previous = putChildIfAbsent(label, node);
if (previous == null) {
previous = node;
node.putParentIfAbsent(getLabel(), this);
if (content != null) {
final ContentStore contentStore = findService(ContentStore.class);
node.handle = contentStore.putContent(node, content, options);
}
} else if (content != null) {
if (options.forceOperation()) {
final ContentStore contentStore = findService(ContentStore.class);
ContentHandle ch = contentStore.putContent(previous, content, options);
if (previous instanceof DefaultNode) {
DefaultNode dn = (DefaultNode) previous;
dn.handle = ch;
}
} else {
throw new IllegalArgumentException("Content node already exists: " + label);
}
}
return previous;
}
use of org.eclipse.ceylon.cmr.spi.OpenNode in project ceylon by eclipse.
the class FileContentStore method find.
public Iterable<? extends OpenNode> find(Node parent) {
final File pf = getFile(parent);
if (pf.exists()) {
List<OpenNode> nodes = new ArrayList<>();
for (File file : pf.listFiles()) {
DefaultNode node = new DefaultNode(file.getName());
node.setHandle(createContentHandle(node, file));
nodes.add(node);
}
return nodes;
} else {
return Collections.emptyList();
}
}
use of org.eclipse.ceylon.cmr.spi.OpenNode in project ceylon by eclipse.
the class ArtifactContext method toNode.
public void toNode(Node node) {
if (node instanceof OpenNode) {
final OpenNode on = (OpenNode) node;
on.addNode(INFO, this);
}
}
use of org.eclipse.ceylon.cmr.spi.OpenNode in project ceylon by eclipse.
the class VerifiedDownload method fetch.
/**
* Perform the download to a temporary file and verify it
* @throws IOException
*/
public void fetch(ArtifactCallback callback, InputStream stream, long length) throws IOException {
log.debug(" FETCH: saving " + node + " to " + tempFile);
final File file;
try {
if (callback != null) {
callback.start(NodeUtils.getFullPath(node), length != -1 ? length : node.getSize(), node.getStoreDisplayString());
stream = new ArtifactCallbackStream(callback, stream);
}
log.debug(" Saving content of " + node + " to " + fileContentStore.getFile(tempNode));
// stream should be closed closer to API call
fileContentStore.putContent(tempNode, stream, context);
// re-get
file = fileContentStore.getFile(tempNode);
assert (file.getPath().equals(tempFile.getPath()));
if (callback != null) {
callback.done(file);
}
} catch (Throwable t) {
if (callback != null) {
callback.error(fileContentStore.getFile(node), t);
}
if (t instanceof RuntimeException) {
throw (RuntimeException) t;
} else {
throw IOUtils.toIOException(t);
}
}
if (context.isIgnoreSHA() == false && node instanceof OpenNode) {
verify((OpenNode) node);
} else {
log.debug(" Not validating checksum: " + tempNode);
}
}
Aggregations