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);
}
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations