Search in sources :

Example 1 with SizedInputStream

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

the class RootRepositoryManager method getArtifactResult.

@Override
protected ArtifactResult getArtifactResult(ArtifactContext context, Node node) throws RepositoryException {
    if (node.isRemote()) {
        final boolean forceOp = context.isForceOperation();
        try {
            // just force the ops
            context.setForceOperation(true);
            log.debug("Looking up artifact " + context + " from " + node + " to cache it");
            SizedInputStream sizedInputStream = node.getSizedInputStream();
            // in theory we should not have nodes with null streams, but at least provide a helpful exception
            if (sizedInputStream == null) {
                throw new RepositoryException("Node " + node + " for repository " + this + " returned a null stream");
            }
            try {
                log.debug(" -> Found it, now caching it");
                final File file = putContent(context, node, sizedInputStream.getInputStream(), sizedInputStream.getSize());
                log.debug("    Caching done: " + file);
                String repositoryDisplayString = NodeUtils.getRepositoryDisplayString(node);
                File originalRepoFile = new File(file.getParentFile(), file.getName().concat(ORIGIN));
                FileWriter writer = new FileWriter(originalRepoFile, false);
                try {
                    writer.write(repositoryDisplayString);
                    writer.close();
                } catch (IOException e) {
                    log.error(e.toString());
                }
                // we expect the remote nodes to support Ceylon module info
                return new FileArtifactResult(NodeUtils.getRepository(node), this, context.getName(), context.getVersion(), file, repositoryDisplayString);
            } finally {
                IOUtils.safeClose(sizedInputStream.getInputStream());
            }
        } catch (IOException e) {
            throw new RepositoryException(e);
        } finally {
            context.setForceOperation(forceOp);
        }
    } else {
        return toArtifactResult(node);
    }
}
Also used : FileWriter(java.io.FileWriter) SizedInputStream(org.eclipse.ceylon.cmr.spi.SizedInputStream) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 SizedInputStream (org.eclipse.ceylon.cmr.spi.SizedInputStream)1 RepositoryException (org.eclipse.ceylon.model.cmr.RepositoryException)1