Search in sources :

Example 31 with Node

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

the class AbstractOpenNode method findService.

protected <T> T findService(Class<T> serviceType) {
    T service = getService(serviceType);
    if (service != null)
        return service;
    for (Node parent : getParents()) {
        if (parent instanceof AbstractOpenNode) {
            AbstractOpenNode dn = (AbstractOpenNode) parent;
            T ps = dn.findService(serviceType);
            if (ps != null) {
                addService(serviceType, ps);
                return ps;
            }
        }
    }
    throw new IllegalArgumentException("No such service [" + serviceType + "] found in node chain!");
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node)

Example 32 with Node

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

the class AbstractRepository method collectArtifacts.

private void collectArtifacts(Node node, ModuleQuery lookup, ModuleSearchResult result) {
    // Winner of the less aptly-named method
    boolean isFolder = !node.hasBinaries();
    if (isFolder) {
        if (ArtifactContext.isDirectoryName(node.getLabel()))
            return;
        Ret ret = new Ret();
        if (hasChildrenContainingArtifact(node, lookup, ret)) {
            // we have artifact children, are they of the right type?
            if (ret.foundRightType) {
                // collect them
                String moduleName = toModuleName(node);
                ModuleVersionDetails mvd = getSearchResult(moduleName, node, lookup);
                if (mvd != null) {
                    result.addResult(moduleName, mvd);
                }
            }
        } else {
            // collect in the children
            List<Node> sortedChildren = new ArrayList<Node>();
            for (Node child : node.getChildren()) sortedChildren.add(child);
            Collections.sort(sortedChildren, AlphabeticalNodeComparator);
            for (Node child : sortedChildren) {
                collectArtifacts(child, lookup, result);
            }
        }
    }
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) ArrayList(java.util.ArrayList)

Example 33 with Node

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

the class AbstractRepository method completeModules.

@Override
public void completeModules(ModuleQuery query, ModuleSearchResult result) {
    // check for delegate
    ContentFinderDelegate delegate = root.getService(ContentFinderDelegate.class);
    if (delegate != null) {
        delegate.completeModules(query, result, getOverrides());
        return;
    }
    // this is only for non-Maven modules
    if (ModuleUtil.isMavenModule(query.getName()))
        return;
    // we NEED the -1 limit here to get empty tokens
    String[] paths = query.getName().split("\\.", -1);
    // find the right parent
    Node parent = root;
    for (int i = 0; i < paths.length - 1; i++) {
        parent = parent.getChild(paths[i]);
        // no completion from here
        if (parent == null)
            return;
    }
    String lastPart = paths[paths.length - 1];
    // now find a matching child
    for (Node child : parent.getChildren()) {
        if (child.getLabel().startsWith(lastPart)) {
            collectArtifacts(child, query, result);
        }
    }
}
Also used : ContentFinderDelegate(org.eclipse.ceylon.cmr.api.ContentFinderDelegate) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node)

Example 34 with Node

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

the class AbstractRepository method completeVersions.

@Override
public void completeVersions(ModuleVersionQuery lookup, ModuleVersionResult result) {
    // check for delegate
    ContentFinderDelegate delegate = root.getService(ContentFinderDelegate.class);
    if (delegate != null) {
        delegate.completeVersions(lookup, result, getOverrides());
        return;
    }
    // this is only for non-Maven modules
    if (ModuleUtil.isMavenModule(lookup.getName()))
        return;
    // FIXME: handle default module
    // FIXME: we should really get this splitting done somewhere in common
    String name = lookup.getName();
    Node namePart = NodeUtils.getNode(root, Arrays.asList(name.split("\\.")));
    if (namePart == null)
        return;
    String memberName = lookup.getMemberName();
    // now each child is supposed to be a version part, let's verify that
    for (Node child : namePart.getChildren()) {
        // Winner of the less aptly-named method
        boolean isFolder = !child.hasBinaries();
        // ignore non-folders
        if (!isFolder)
            continue;
        // now make sure we can find the artifact we're looking for in there
        String version = child.getLabel();
        // optional filter on version
        if (lookup.getVersion() != null) {
            if (lookup.isExactVersionMatch()) {
                if (!version.equals(lookup.getVersion()))
                    continue;
            } else {
                if (!version.startsWith(lookup.getVersion()))
                    continue;
            }
        }
        // avoid duplicates
        if (result.hasVersion(version))
            continue;
        // try every known suffix
        boolean found = false;
        boolean foundInfo = false;
        boolean binaryShouldMatch = false;
        boolean binaryMatch = false;
        // null here and read the info later
        ModuleVersionDetails mvd = new ModuleVersionDetails(getNamespace(), name, version, null, null);
        String[] suffixes = lookup.getType().getSuffixes();
        // When we need to find ALL requested suffixes we maintain a set of those not found yet
        HashSet<String> suffixesToFind = null;
        if (lookup.getRetrieval() == Retrieval.ALL) {
            suffixesToFind = new HashSet<String>(Arrays.asList(suffixes));
        }
        // Now try to retrieve information for each of the suffixes
        for (String suffix : suffixes) {
            String artifactName = getArtifactName(name, version, suffix);
            Node artifact = child.getChild(artifactName);
            if (artifact == null) {
                if (lookup.getRetrieval() == Retrieval.ALL) {
                    break;
                } else {
                    continue;
                }
            }
            if (shouldCheckBinaryVersion(suffix)) {
                binaryShouldMatch = true;
                if (!checkBinaryVersion(name, version, artifact, lookup, suffix)) {
                    if (lookup.getRetrieval() == Retrieval.ALL) {
                        break;
                    } else {
                        continue;
                    }
                }
                binaryMatch = true;
            }
            // we found the artifact: let's notify
            found = true;
            if (lookup.getRetrieval() == Retrieval.ALL) {
                suffixesToFind.remove(suffix);
            }
            // let's see if we can extract some information
            switch(addArtifactInfo(artifact, name, version, suffix, memberName, mvd, lookup)) {
                case INFO_FOUND:
                    foundInfo = true;
                    break;
                case NO_MATCH:
                    continue;
                case OTHER:
                    // nothing;
                    break;
            }
        }
        // read the artifact's information
        if (((found && memberName == null) || foundInfo) && (lookup.getRetrieval() == Retrieval.ANY || suffixesToFind.isEmpty()) && (!binaryShouldMatch || binaryMatch)) {
            mvd.setRemote(root.isRemote());
            mvd.setOrigin(getDisplayString());
            result.addVersion(mvd);
        }
    }
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ContentFinderDelegate(org.eclipse.ceylon.cmr.api.ContentFinderDelegate) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node)

Example 35 with Node

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

the class JarUtils method descriptor.

@Override
public Node descriptor(Node artifact) {
    Node parent = NodeUtils.firstParent(artifact);
    Node descriptor = parent.getChild(ArtifactContext.MODULE_XML);
    if (descriptor == null) {
        descriptor = parent.getChild(ArtifactContext.MODULE_PROPERTIES);
    }
    return descriptor;
}
Also used : 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