Search in sources :

Example 11 with OpenNode

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);
    }
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 12 with OpenNode

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

Example 13 with OpenNode

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);
    }
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) IOException(java.io.IOException) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 14 with OpenNode

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);
    }
}
Also used : RepositoryManagerBuilder(org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder) DefaultRepository(org.eclipse.ceylon.cmr.impl.DefaultRepository) ByteArrayInputStream(java.io.ByteArrayInputStream) InMemoryContentStore(org.eclipse.ceylon.test.smoke.support.InMemoryContentStore) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Test(org.junit.Test)

Example 15 with OpenNode

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();
    }
}
Also used : ArrayList(java.util.ArrayList) WebDAVResource(org.eclipse.ceylon.cmr.repository.webdav.WebDAVResource) IOException(java.io.IOException) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Aggregations

OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)22 IOException (java.io.IOException)7 Node (org.eclipse.ceylon.cmr.spi.Node)7 File (java.io.File)6 ArrayList (java.util.ArrayList)3 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ContentHandle (org.eclipse.ceylon.cmr.spi.ContentHandle)2 ContentStore (org.eclipse.ceylon.cmr.spi.ContentStore)2 StructureBuilder (org.eclipse.ceylon.cmr.spi.StructureBuilder)2 RepositoryException (org.eclipse.ceylon.model.cmr.RepositoryException)2 FileInputStream (java.io.FileInputStream)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ArtifactCallback (org.eclipse.ceylon.cmr.api.ArtifactCallback)1 ArtifactCallbackStream (org.eclipse.ceylon.cmr.api.ArtifactCallbackStream)1 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)1 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)1 ModuleVersionQuery (org.eclipse.ceylon.cmr.api.ModuleVersionQuery)1 ModuleVersionResult (org.eclipse.ceylon.cmr.api.ModuleVersionResult)1 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)1