Search in sources :

Example 1 with ContentFinderDelegate

use of org.eclipse.ceylon.cmr.api.ContentFinderDelegate 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 2 with ContentFinderDelegate

use of org.eclipse.ceylon.cmr.api.ContentFinderDelegate 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)

Aggregations

ContentFinderDelegate (org.eclipse.ceylon.cmr.api.ContentFinderDelegate)2 Node (org.eclipse.ceylon.cmr.spi.Node)2 OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)2 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)1