Search in sources :

Example 11 with Node

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

the class AbstractRepository method containsAnyArtifact.

/*
     * This method is almost like containsArtifact but it scans for any type of artifact and records
     * the specific one we want in an out param. It's also not recursive so it only scans the current children.
     */
private boolean containsAnyArtifact(Node moduleNode, Node versionNode, ModuleQuery query, Ret ret) {
    boolean foundArtifact = false;
    String version = versionNode.getLabel();
    String module = toModuleName(moduleNode);
    for (Node child : versionNode.getChildren()) {
        String name = child.getLabel();
        // Winner of the less aptly-named method
        boolean isFolder = !child.hasBinaries();
        if (isFolder) {
        // we don't recurse
        } else if (isArtifactOfType(name, child, module, version, query) && matchesSearch(name, child, versionNode, query)) {
            // we found what we were looking for
            ret.foundRightType = true;
            return true;
        } else if (isArtifact(name, module, version)) {
            // we found something, but not the type we wanted
            foundArtifact = true;
        }
    }
    return foundArtifact;
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node)

Example 12 with Node

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

the class AbstractRepository method hasChildrenContainingArtifact.

private boolean hasChildrenContainingArtifact(Node node, ModuleQuery lookup, Ret ret) {
    // We don't look directly at our children, we want the children's children, because if there's
    // nothing in those children it means either this is an empty folder, or its children contain
    // artifacts (in which case we don't want to match it since its name must be a version component),
    // or we could only find artifacts of the wrong type.
    // This allows us to never match the default module, since it's at "/default/default.car" which
    // cannot match this rule. Normal modules always have at least one "/name/version/bla.car".
    boolean found = false;
    for (Node child : node.getChildren()) {
        String name = child.getLabel();
        // Winner of the less aptly-named method
        boolean isFolder = !child.hasBinaries();
        if (isFolder && !ArtifactContext.isDirectoryName(name) && containsArtifact(node, child, lookup, ret)) {
            // stop if we found the right type
            if (ret.foundRightType)
                return true;
            // keep looking for the other versions, perhaps we will find the right type
            found = true;
        }
    }
    return found;
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node)

Example 13 with Node

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

the class AbstractRepository method searchModules.

private void searchModules(Node parent, ModuleQuery query, ModuleSearchResult result, Ret ret) throws GetOut {
    List<Node> sortedChildren = new ArrayList<Node>();
    for (Node child : parent.getChildren()) sortedChildren.add(child);
    Collections.sort(sortedChildren, AlphabeticalNodeComparator);
    for (Node child : sortedChildren) {
        // Winner of the less aptly-named method
        boolean isFolder = !child.hasBinaries();
        // ignore non-folders
        if (!isFolder)
            continue;
        // is it a module? does it contains artifacts?
        ret.foundRightType = false;
        if (!ArtifactContext.isDirectoryName(child.getLabel())) {
            // safety check
            if (hasChildrenContainingAnyArtifact(child, query, ret)) {
                // does it contain an artifact of the type we're looking for?
                if (ret.foundRightType) {
                    // check if we were already done but were checking for a next results
                    if (ret.stopSearching) {
                        // we already found enough results but were checking if there
                        // were more results to be found for paging, so record that
                        // and stop
                        result.setHasMoreResults(true);
                        throw new GetOut();
                    }
                    // are we interested in this result or did we need to skip it?
                    String moduleName = toModuleName(child);
                    ModuleVersionDetails mvd = getSearchResult(moduleName, child, query);
                    if (mvd != null) {
                        if (query.getStart() == null || ret.found++ >= query.getStart()) {
                            result.addResult(moduleName, mvd);
                            // stop if we're done searching
                            if (query.getStart() != null && query.getCount() != null && ret.found >= query.getStart() + query.getCount()) {
                                // we're done, but we want to see if there's at least one more result
                                // to be found so we can tell clients there's a next page
                                ret.stopSearching = true;
                            }
                        }
                    }
                }
            } else {
                // it doesn't contain artifacts, it's probably leading to modules
                searchModules(child, query, result, ret);
            }
        }
    }
}
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 14 with Node

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

the class AbstractRepository method hasChildrenContainingAnyArtifact.

/*
     * This method is almost like hasChildrenContainingArtifact but it scans for any type of artifact and records
     * the specific one we want in an out param
     */
private boolean hasChildrenContainingAnyArtifact(Node moduleNode, ModuleQuery query, Ret ret) {
    // We don't look directly at our children, we want the children's children, because if there's
    // nothing in those children it means either this is an empty folder, or its children contain
    // artifacts (in which case we don't want to match it since its name must be a version component),
    // or we could only find artifacts of the wrong type.
    // This allows us to never match the default module, since it's at "/default/default.car" which
    // cannot match this rule. Normal modules always have at least one "/name/version/bla.car".
    boolean retBool = false;
    for (Node versionNode : moduleNode.getChildren()) {
        String name = versionNode.getLabel();
        // Winner of the less aptly-named method
        boolean isFolder = !versionNode.hasBinaries();
        if (isFolder && !ArtifactContext.isDirectoryName(name) && containsAnyArtifact(moduleNode, versionNode, query, ret)) {
            retBool = true;
            // we found an artifact
            if (ret.foundRightType) {
                // we're done
                return true;
            }
        // else try other versions before giving up on finding the right type
        }
    }
    // done with versions
    return retBool;
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node)

Example 15 with Node

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

the class AbstractRepository method containsArtifact.

private boolean containsArtifact(Node moduleNode, Node versionNode, ModuleQuery lookup, Ret ret) {
    String module = toModuleName(moduleNode);
    String version = versionNode.getLabel();
    boolean foundArtifact = false;
    for (Node child : versionNode.getChildren()) {
        String name = child.getLabel();
        // Winner of the less aptly-named method
        boolean isFolder = !child.hasBinaries();
        if (isFolder) {
        // do not recurse
        } else if (isArtifactOfType(name, child, module, version, lookup)) {
            // we found what we were looking for
            ret.foundRightType = true;
            return true;
        } else if (isArtifact(name, module, version)) {
            // we found something, but not the type we wanted
            foundArtifact = true;
        }
    }
    return foundArtifact;
}
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