Search in sources :

Example 6 with OpenNode

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;
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 7 with OpenNode

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;
}
Also used : ContentHandle(org.eclipse.ceylon.cmr.spi.ContentHandle) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) ContentStore(org.eclipse.ceylon.cmr.spi.ContentStore)

Example 8 with OpenNode

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();
    }
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 9 with OpenNode

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);
    }
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 10 with OpenNode

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);
    }
}
Also used : ArtifactCallbackStream(org.eclipse.ceylon.cmr.api.ArtifactCallbackStream) File(java.io.File) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Aggregations

OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)22 IOException (java.io.IOException)7 Node (org.eclipse.ceylon.cmr.spi.Node)7 File (java.io.File)6 ArrayList (java.util.ArrayList)3 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ContentHandle (org.eclipse.ceylon.cmr.spi.ContentHandle)2 ContentStore (org.eclipse.ceylon.cmr.spi.ContentStore)2 StructureBuilder (org.eclipse.ceylon.cmr.spi.StructureBuilder)2 RepositoryException (org.eclipse.ceylon.model.cmr.RepositoryException)2 FileInputStream (java.io.FileInputStream)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ArtifactCallback (org.eclipse.ceylon.cmr.api.ArtifactCallback)1 ArtifactCallbackStream (org.eclipse.ceylon.cmr.api.ArtifactCallbackStream)1 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)1 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)1 ModuleVersionQuery (org.eclipse.ceylon.cmr.api.ModuleVersionQuery)1 ModuleVersionResult (org.eclipse.ceylon.cmr.api.ModuleVersionResult)1 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)1