Search in sources :

Example 16 with OpenNode

use of org.eclipse.ceylon.cmr.spi.OpenNode 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 17 with OpenNode

use of org.eclipse.ceylon.cmr.spi.OpenNode 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)

Example 18 with OpenNode

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

the class NodeUtils method keepRepository.

/**
 * Keep the repository info.
 *
 * @param node       the node
 * @param repository the repository
 */
public static void keepRepository(Node node, CmrRepository repository) {
    if (node instanceof OpenNode) {
        final OpenNode on = (OpenNode) node;
        on.addNode(INFO, repository);
    }
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 19 with OpenNode

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

the class AbstractNodeRepositoryManager method putFolder.

@Override
protected void putFolder(ArtifactContext context, File folder) throws RepositoryException {
    Node parent = getOrCreateParent(context);
    log.debug("Adding folder " + context + " to cache " + cache.getDisplayString());
    log.debug(" -> " + NodeUtils.getFullPath(parent));
    // fast-path for Herd
    if (!canHandleFolders()) {
        uploadZipped(parent, context, folder);
        return;
    }
    final String[] names = cache.getArtifactNames(context);
    if (names.length != 1) {
        throw new RepositoryException("ArtifactContext should have a single suffix");
    }
    final String label = names[0];
    if (parent instanceof OpenNode) {
        final OpenNode on = (OpenNode) parent;
        final OpenNode curent = on.createNode(label);
        try {
            for (// ignore folder, it should match new root
            File f : // ignore folder, it should match new root
            folder.listFiles()) putFiles(curent, f, context);
        } catch (RepositoryException e) {
            throw e;
        } catch (Exception e) {
            removeArtifact(context);
            throw new RepositoryException(e);
        }
    } else {
        throw new RepositoryException("Cannot put folder [" + folder + "] to non-open node: " + context);
    }
    log.debug(" -> [done]");
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) File(java.io.File) IOException(java.io.IOException) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 20 with OpenNode

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

the class AbstractNodeRepositoryManager method removeNode.

protected void removeNode(Node parent, String child) throws IOException {
    if (parent instanceof OpenNode) {
        final OpenNode on = (OpenNode) parent;
        on.removeNode(child);
    } else {
        throw new IOException("Parent node is not open: " + parent);
    }
}
Also used : IOException(java.io.IOException) 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