Search in sources :

Example 1 with OpenNode

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

the class RepoUsingTool method findCompiledVersions.

private Collection<ModuleVersionDetails> findCompiledVersions(RepositoryManager repoMgr, String name, Type type, Integer jvmBinaryMajor, Integer jvmBinaryMinor, Integer jsBinaryMajor, Integer jsBinaryMinor) throws IOException {
    String outRepo = DefaultToolOptions.getCompilerOutputRepo();
    if (outRepo != null) {
        File outDir = new File(outRepo);
        CmrRepository rep = null;
        List<CmrRepository> repositories = repoMgr.getRepositories();
        for (CmrRepository repository : repositories) {
            OpenNode root = repository.getRoot();
            // it has binaries if it is not a folder
            if (root.isRemote() || root.hasBinaries())
                continue;
            ContentStore service = root.getService(ContentStore.class);
            if (service == null)
                continue;
            ContentHandle content = service.peekContent(root);
            // again skip binaries
            if (content == null || content.hasBinaries())
                continue;
            File repoFile = content.getContentAsFile();
            if (repoFile != null && FileUtil.sameFile(repoFile, outDir)) {
                rep = repository;
                break;
            }
        }
        if (rep != null && rep.isSearchable()) {
            ModuleVersionQuery query = getModuleVersionQuery(null, name, null, type, jvmBinaryMajor, jvmBinaryMinor, jsBinaryMajor, jsBinaryMinor);
            ModuleVersionResult result = new ModuleVersionResult(query.getName());
            rep.completeVersions(query, result);
            NavigableMap<String, ModuleVersionDetails> outRepoVersions = result.getVersions();
            if (!outRepoVersions.isEmpty()) {
                return outRepoVersions.values();
            }
        }
    }
    return null;
}
Also used : ModuleVersionResult(org.eclipse.ceylon.cmr.api.ModuleVersionResult) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ContentHandle(org.eclipse.ceylon.cmr.spi.ContentHandle) ModuleVersionQuery(org.eclipse.ceylon.cmr.api.ModuleVersionQuery) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) ContentStore(org.eclipse.ceylon.cmr.spi.ContentStore)

Example 2 with OpenNode

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

the class AbstractNodeRepositoryManager method putArtifact.

public void putArtifact(ArtifactContext context, InputStream content) throws RepositoryException {
    try {
        final Node parent = getOrCreateParent(context);
        log.debug("Adding artifact " + context + " to cache " + cache.getDisplayString());
        log.debug(" -> " + NodeUtils.getFullPath(parent));
        final String[] names = cache.getArtifactNames(context);
        if (names.length != 1) {
            throw new RepositoryException("ArtifactContext should have a single suffix");
        }
        final String label = names[0];
        try {
            if (parent instanceof OpenNode) {
                final OpenNode on = (OpenNode) parent;
                if (on.addContent(label, content, context) == null)
                    addContent(context, parent, label, content);
            } else {
                addContent(context, parent, label, content);
            }
        } catch (IOException e) {
            throw new RepositoryException(e);
        }
        log.debug(" -> [done]");
    } finally {
        IOUtils.safeClose(content);
    }
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 3 with OpenNode

use of org.eclipse.ceylon.cmr.spi.OpenNode 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 4 with OpenNode

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

the class AbstractOpenNode method getChild.

@Override
public Node getChild(String label) {
    OpenNode child = children.get(label);
    if (child == null) {
        final String markerLabel = label + NODE_MARKER;
        final OpenNode marker = children.get(markerLabel);
        if (marker == null) {
            child = getNode(label, false);
            children.put(markerLabel, new MarkerNode(label, child));
        } else {
            return marker.getValue(Node.class);
        }
    }
    return child;
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 5 with OpenNode

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

the class AbstractOpenNode method getNode.

protected OpenNode getNode(String label, boolean create) {
    final StructureBuilder builder = findService(StructureBuilder.class);
    OpenNode child = create ? builder.create(this, label) : builder.find(this, label);
    if (child != null) {
        child = put(children, label, child);
    }
    return child;
}
Also used : StructureBuilder(org.eclipse.ceylon.cmr.spi.StructureBuilder) 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