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