Search in sources :

Example 21 with Node

use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.

the class RootRepositoryManager method addContent.

@Override
protected void addContent(ArtifactContext context, Node parent, String label, InputStream content) throws IOException {
    Node child;
    if (parent instanceof OpenNode) {
        OpenNode on = (OpenNode) parent;
        child = on.peekChild(label);
        if (child == null) {
            child = on.addNode(label);
        }
    } else {
        child = parent.getChild(label);
    }
    if (child != null) {
        putContent(context, child, content, -1);
    } else {
        throw new IOException("Cannot add child [" + label + "] content [" + content + "] on parent node: " + parent);
    }
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) IOException(java.io.IOException) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 22 with Node

use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.

the class WebDAVContentStore method putContent.

@Override
public ContentHandle putContent(Node node, InputStream stream, ContentOptions options) throws IOException {
    if (!connectionAllowed()) {
        return null;
    }
    try {
        /*
             * Most disgusting trick ever. Stef failed to set up Sardine to do preemptive auth on all hosts
             * and ports (may only work on port 80, reading the code), so when not using Herd we generate a ton
             * of requests that will trigger auth, but not for Herd. So we start with a PUT and that replies with
             * an UNAUTHORIZED response, which Sardine can't handle because the InputStream is not "restartable".
             * By making an extra HEAD request (restartable because no entity body) we force the auth to happen.
             * Yuk.
             */
        if (isHerd() && !forcedAuthenticationForPutOnHerd) {
            repository.exists(getUrlAsString(node));
            forcedAuthenticationForPutOnHerd = true;
        }
        final Node parent = NodeUtils.firstParent(node);
        if (!isHerd())
            mkdirs(parent);
        final String pUrl = getUrlAsString(parent);
        String token = null;
        if (!isHerd())
            // local parent
            token = repository.lock(pUrl);
        final String url = getUrlAsString(node);
        try {
            repository.put(url, stream);
            return new WebDAVContentHandle(url);
        } catch (SocketTimeoutException x) {
            SocketTimeoutException ret = new SocketTimeoutException("Timed out writing to " + url);
            ret.initCause(x);
            throw ret;
        } finally {
            if (!isHerd())
                repository.unlock(pUrl, token);
        }
    } catch (IOException x) {
        throw convertIOException(x);
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) IOException(java.io.IOException)

Example 23 with Node

use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.

the class VerifiedDownload method verify.

/**
 * Verify the download by comparing the remote sha1 with a
 * locally computed sha1
 * @throws IOException
 */
protected void verify(final OpenNode on) throws IOException {
    log.debug("  VERIFY: " + tempFile);
    // Now validate the temporary file has a sha1 which matches the remote sha1
    final String computedSha1 = IOUtils.sha1(new FileInputStream(tempFile));
    if (computedSha1 != null) {
        log.debug("    Computed sha1(" + tempFile + "): " + computedSha1);
        ByteArrayInputStream shaStream = new ByteArrayInputStream(computedSha1.getBytes("ASCII"));
        Node shaNode = parent.getChild(on.getLabel() + AbstractNodeRepositoryManager.SHA1);
        if (shaNode == null) {
            log.debug("    Remote sha1 for (" + on + ") does not exist ");
            // put it to ext node as well, if supported
            on.addContent(AbstractNodeRepositoryManager.SHA1, shaStream, context);
            // reset, for next read
            shaStream.reset();
        } else if (shaNode.hasBinaries()) {
            final String retrievedSha1 = IOUtils.readSha1(shaNode.getInputStream());
            if (retrievedSha1.length() != 40 || !retrievedSha1.matches("[a-z0-9]+")) {
                throw new IOException("Remote SHA1 for " + on + " was corrupt: " + retrievedSha1);
            }
            log.debug("    Retrieved " + shaNode + ": " + retrievedSha1);
            if (computedSha1.equals(retrievedSha1)) {
                log.debug("    Yay, sha1's of " + tempFile + " match");
            } else {
                throw new IOException("Remote SHA1 for " + on + " differs from computed SHA1: " + retrievedSha1 + " != " + computedSha1);
            }
        } else {
            log.warning("    Remote sha1 for (" + on + ") exists, but lacks content!");
        }
        // create empty marker node
        OpenNode sl = ((OpenNode) parent).addNode(on.getLabel() + AbstractNodeRepositoryManager.SHA1 + AbstractNodeRepositoryManager.LOCAL);
        // put sha to local store as well
        fileContentStore.putContent(sl, shaStream, context);
    } else {
        log.debug("  Could not calculate sha1 of : " + tempFile);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 24 with Node

use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.

the class AetherRepository method toModuleName.

@Override
protected String toModuleName(Node node) {
    ArtifactContext context = ArtifactContext.fromNode(node);
    if (context != null) {
        return context.getName();
    }
    String moduleName = node.getLabel();
    Node parent = NodeUtils.firstParent(node);
    String groupId = NodeUtils.getFullPath(parent, ".");
    // That's sort of an invariant, but let's be safe
    if (groupId.startsWith("."))
        groupId = groupId.substring(1);
    moduleName = groupId != null ? groupId + ":" + moduleName : moduleName;
    return moduleName;
}
Also used : Node(org.eclipse.ceylon.cmr.spi.Node) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext)

Example 25 with Node

use of org.eclipse.ceylon.cmr.spi.Node in project ceylon by eclipse.

the class NodeUtils method getRepository.

/**
 * Get repository info.
 *
 * @param node the node
 * @return repository info
 */
public static CmrRepository getRepository(Node node) {
    if (node instanceof OpenNode) {
        final OpenNode on = (OpenNode) node;
        final Node info = on.peekChild(INFO);
        return (info != null) ? info.getValue(CmrRepository.class) : null;
    }
    return null;
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Aggregations

Node (org.eclipse.ceylon.cmr.spi.Node)35 OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)33 IOException (java.io.IOException)11 RepositoryException (org.eclipse.ceylon.model.cmr.RepositoryException)6 File (java.io.File)5 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)4 ArrayList (java.util.ArrayList)3 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)3 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)2 ContentFinderDelegate (org.eclipse.ceylon.cmr.api.ContentFinderDelegate)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 SocketTimeoutException (java.net.SocketTimeoutException)1 LinkedList (java.util.LinkedList)1 TreeSet (java.util.TreeSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ArtifactCallback (org.eclipse.ceylon.cmr.api.ArtifactCallback)1 ContentHandle (org.eclipse.ceylon.cmr.spi.ContentHandle)1 StructureBuilder (org.eclipse.ceylon.cmr.spi.StructureBuilder)1