Search in sources :

Example 6 with Node

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

the class AbstractNodeRepositoryManager method getLeafNode.

protected Node getLeafNode(ArtifactContext context) {
    final Node node = getFromAllRoots(context, true);
    if (node == null) {
        if (context.isThrowErrorIfMissing())
            throw new IllegalArgumentException("No such artifact: " + context);
        return null;
    }
    // save the context info
    context.toNode(node);
    return node;
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node)

Example 7 with Node

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

the class AbstractNodeRepositoryManager method fromRepositories.

/**
 * Cache is only used for remote repos; see issue #47.
 */
private Node fromRepositories(Iterable<CmrRepository> repositories, ArtifactContext context, boolean addLeaf) {
    log.debug("Looking for " + context);
    for (CmrRepository repository : repositories) {
        log.debug(" Looking in " + repository);
        if (!repository.supportsNamespace(context.getNamespace())) {
            log.debug(" -> does not support namespace " + context.getNamespace());
            continue;
        }
        Node child = fromRepository(repository, context, addLeaf);
        if (child != null) {
            log.debug(" -> Found");
            return child;
        }
        log.debug("  -> Not Found");
    }
    log.debug(" -> Artifact " + context + " not found in any repository");
    return null;
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository)

Example 8 with Node

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

the class AbstractOpenNode method getChildren.

@Override
public Iterable<? extends Node> getChildren() {
    if (!children.containsKey(NODE_MARKER)) {
        // add marker
        children.put(NODE_MARKER, new MarkerNode());
        ConcurrentMap<String, OpenNode> tmp = new ConcurrentHashMap<>();
        for (OpenNode on : findService(StructureBuilder.class).find(this)) put(tmp, on.getLabel(), on);
        children.putAll(tmp);
        return tmp.values();
    } else {
        List<Node> nodes = new ArrayList<>();
        for (Node on : children.values()) {
            if (on instanceof MarkerNode == false)
                nodes.add(on);
        }
        return nodes;
    }
}
Also used : StructureBuilder(org.eclipse.ceylon.cmr.spi.StructureBuilder) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) ArrayList(java.util.ArrayList) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 9 with Node

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

the class AbstractRepository method getBestInfoArtifact.

private Node getBestInfoArtifact(Node versionNode) {
    String moduleName = toModuleName(NodeUtils.firstParent(versionNode));
    String version = versionNode.getLabel();
    String artifactName = getArtifactName(moduleName, version, ArtifactContext.CAR);
    Node artifact = versionNode.getChild(artifactName);
    if (artifact == null) {
        artifactName = getArtifactName(moduleName, version, ArtifactContext.NPM_DESCRIPTOR);
        artifact = versionNode.getChild(artifactName);
        if (artifact == null) {
            artifactName = getArtifactName(moduleName, version, ArtifactContext.JS);
            artifact = versionNode.getChild(artifactName);
            if (artifact == null) {
                artifactName = getArtifactName(moduleName, version, ArtifactContext.JAR);
                artifact = versionNode.getChild(artifactName);
            }
        }
    }
    return artifact;
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node)

Example 10 with Node

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

the class AbstractRepository method matchesSearch.

private boolean matchesSearch(String name, Node artifact, Node versionNode, ModuleQuery query) {
    // match on the module name first
    Node moduleNode = NodeUtils.firstParent(versionNode);
    // can't happen but hey
    if (moduleNode == null)
        return false;
    String moduleName = toModuleName(moduleNode);
    if (moduleName.toLowerCase().contains(query.getName()))
        return true;
    // now search on the metadata
    Node infoArtifact = getBestInfoArtifact(versionNode);
    return matchFromCar(infoArtifact, moduleName, versionNode.getLabel(), query.getName());
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node)

Aggregations

Node (org.eclipse.ceylon.cmr.spi.Node)35 OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)33 IOException (java.io.IOException)11 RepositoryException (org.eclipse.ceylon.model.cmr.RepositoryException)6 File (java.io.File)5 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)4 ArrayList (java.util.ArrayList)3 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)3 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)2 ContentFinderDelegate (org.eclipse.ceylon.cmr.api.ContentFinderDelegate)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 SocketTimeoutException (java.net.SocketTimeoutException)1 LinkedList (java.util.LinkedList)1 TreeSet (java.util.TreeSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ArtifactCallback (org.eclipse.ceylon.cmr.api.ArtifactCallback)1 ContentHandle (org.eclipse.ceylon.cmr.spi.ContentHandle)1 StructureBuilder (org.eclipse.ceylon.cmr.spi.StructureBuilder)1