Search in sources :

Example 1 with ArtifactCallback

use of org.eclipse.ceylon.cmr.api.ArtifactCallback in project ceylon by eclipse.

the class RootRepositoryManager method putContent.

private File putContent(ArtifactContext context, Node node, InputStream stream, long length) throws IOException {
    log.debug("  Creating local copy of external node: " + node + " at repo: " + (fileContentStore != null ? fileContentStore.getDisplayString() : null));
    if (fileContentStore == null)
        throw new IOException("No location to place node at: fileContentStore is null");
    ArtifactCallback callback = context.getCallback();
    if (callback == null) {
        callback = ArtifactCallbackStream.getCallback();
    }
    final File finalFile;
    VerifiedDownload dl = new VerifiedDownload(log, context, fileContentStore, node);
    try {
        dl.fetch(callback, stream, length);
        // only check for jars or forced checks
        if (ArtifactContext.JAR.equals(context.getSingleSuffix()) || context.forceDescriptorCheck()) {
            // transfer descriptor as well, if there is one
            final Node descriptor = Configuration.getResolvers(this).descriptor(node);
            if (descriptor != null && descriptor.hasBinaries()) {
                VerifiedDownload descriptorDl = new VerifiedDownload(log, context, fileContentStore, descriptor);
                try {
                    descriptorDl.fetch(callback, descriptor.getInputStream(), 40);
                    descriptorDl.commit();
                } catch (RuntimeException e) {
                    dl.rollback(e);
                    throw e;
                } catch (IOException e) {
                    dl.rollback(e);
                    throw e;
                }
            }
        }
        // ... got descriptor OK, so can now commit
        finalFile = dl.commit();
    } catch (RuntimeException e) {
        dl.rollback(e);
        throw e;
    } catch (IOException e) {
        dl.rollback(e);
        throw e;
    }
    // refresh markers from root to this newly put node
    if (getCache() != null) {
        final List<String> paths = NodeUtils.toLabelPath(node);
        OpenNode current = getCache();
        for (String path : paths) {
            if (current == null) {
                break;
            }
            current.refresh(false);
            final Node tmp = current.peekChild(path);
            current = (tmp instanceof OpenNode) ? OpenNode.class.cast(tmp) : null;
        }
    }
    return finalFile;
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) IOException(java.io.IOException) ArtifactCallback(org.eclipse.ceylon.cmr.api.ArtifactCallback) File(java.io.File) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ArtifactCallback (org.eclipse.ceylon.cmr.api.ArtifactCallback)1 Node (org.eclipse.ceylon.cmr.spi.Node)1 OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)1