use of org.eclipse.ceylon.cmr.spi.OpenNode in project ceylon by eclipse.
the class NpmContentStore method find.
public OpenNode find(Node parent, String child) {
DefaultNode node = null;
if (// TODO: this test looks like rubbish to me!
!hasContent(child) || parent.getLabel().startsWith("@") || parent instanceof RootNode) {
// RootNode has an empty label
node = new DefaultNode(child);
node.setContentMarker();
return node;
} else {
if (getSuffixFromFilename(child).equals(ArtifactContext.JS)) {
String artifactName = getTrueArtifactName(parent);
if (artifactName != null) {
child = artifactName;
}
}
for (FileContentStore store : stores) {
OpenNode result = store.find(parent, child);
if (result != null) {
return result;
}
}
installNpmModule(parent);
return outstore.find(parent, child);
}
}
use of org.eclipse.ceylon.cmr.spi.OpenNode 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;
}
use of org.eclipse.ceylon.cmr.spi.OpenNode 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.OpenNode in project ceylon by eclipse.
the class SmokeTestCase method testExternalNodes.
@Test
public void testExternalNodes() throws Exception {
RepositoryManagerBuilder builder = getRepositoryManagerBuilder(false, 60000, java.net.Proxy.NO_PROXY);
InMemoryContentStore imcs = new InMemoryContentStore();
OpenNode root = imcs.createRoot();
CmrRepository repo = new DefaultRepository(root);
RepositoryManager manager = builder.addRepository(repo).buildRepository();
// a few impl details, feel free to remove/ignore this test
String name = "org.eclipse.acme";
String version = "1.0.0.CR1";
ArtifactContext context = new ArtifactContext(null, name, version);
// ignore with in-memory
context.setIgnoreSHA(true);
OpenNode parent = repo.createParent(context);
parent.addContent(name + "-" + version + ArtifactContext.CAR, new ByteArrayInputStream("qwerty".getBytes()), context);
try {
File file = manager.getArtifact(context);
Assert.assertNotNull("Failed to retrieve after put", file);
} finally {
manager.removeArtifact(null, name, version);
}
}
use of org.eclipse.ceylon.cmr.spi.OpenNode in project ceylon by eclipse.
the class WebDAVContentStore method find.
@Override
public Iterable<? extends OpenNode> find(Node parent) {
if (!connectionAllowed()) {
return Collections.emptyList();
}
final String url = getUrlAsString(parent);
try {
final List<OpenNode> nodes = new ArrayList<>();
final List<WebDAVResource> resources = repository.list(url);
for (WebDAVResource dr : resources) {
final String label = dr.getName();
final RemoteNode node = new RemoteNode(label);
if (dr.isDirectory())
node.setContentMarker();
else
node.setHandle(new WebDAVContentHandle(url + label));
nodes.add(node);
}
return nodes;
} catch (IOException e) {
log.debug("Failed to list url: " + url);
return Collections.emptyList();
}
}
Aggregations