Search in sources :

Example 26 with Node

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

the class NodeUtils method toLabelPath.

/**
 * Return path queue, with root being on top.
 *
 * @param node the node
 * @return paths queue
 */
public static List<String> toLabelPath(Node node) {
    final LinkedList<String> paths = new LinkedList<String>();
    Node current = node;
    Node parent = firstParent(node);
    // ignore root path, should equal to ""
    while (parent != null) {
        paths.addFirst(current.getLabel());
        current = parent;
        parent = firstParent(current);
    }
    return paths;
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) LinkedList(java.util.LinkedList)

Example 27 with Node

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

the class RootRepositoryManager method artifactNotFound.

@Override
protected ArtifactResult artifactNotFound(ArtifactContext context) throws RepositoryException {
    boolean hasRemote = false;
    StringBuilder reps = new StringBuilder();
    for (CmrRepository rep : getRepositories()) {
        if (rep.getRoot().isRemote() && !isOffline(rep)) {
            hasRemote = true;
            reps.append(rep.getDisplayString());
            reps.append('\n');
        }
    }
    if (hasRemote && cache != null) {
        // Create a .missing file in the cache to mark that we tried to locate the file but it didn't exist
        Node parent = cache.findParent(context);
        if (parent != null) {
            context.toNode(parent);
            try {
                // fileContentStore cannot be null if we have a cache
                File parentDir = fileContentStore.getFile(parent);
                String[] names = cache.getArtifactNames(context);
                File missingFile = new File(parentDir, names[0].concat(MISSING));
                if (!missingFile.exists()) {
                    if (context.getSearchRepository() == cache) {
                        ArtifactContext unpreferred = new ArtifactContext(context.getNamespace(), context.getName(), context.getVersion(), context.getSuffixes());
                        unpreferred.copySettingsFrom(context);
                        return getArtifactResult(unpreferred);
                    } else {
                        FileUtil.mkdirs(parentDir);
                        try (FileWriter writer = new FileWriter(missingFile, false)) {
                            // We write the list of remote repositories we tried
                            // This is not currently used but might be useful in the future
                            writer.write(reps.toString());
                        } catch (IOException e) {
                            log.error(e.toString());
                        }
                    }
                }
            } finally {
                ArtifactContext.removeNode(parent);
            }
        }
    }
    return super.artifactNotFound(context);
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) FileWriter(java.io.FileWriter) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) IOException(java.io.IOException) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File)

Example 28 with Node

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

the class RootRepositoryManager method removeNode.

@Override
protected void removeNode(Node parent, String child) throws IOException {
    final Node node = parent.getChild(child);
    if (fileContentStore != null) {
        try {
            if (node != null) {
                final Node sl = parent.getChild(child + SHA1 + LOCAL);
                if (sl != null) {
                    fileContentStore.removeFile(sl);
                }
                final Node origin = parent.getChild(child + ORIGIN);
                if (origin != null) {
                    fileContentStore.removeFile(origin);
                }
                final Node descriptor = Configuration.getResolvers(this).descriptor(node);
                if (descriptor != null) {
                    fileContentStore.removeFile(descriptor);
                }
            }
        } catch (Exception ignored) {
        }
    }
    try {
        super.removeNode(parent, child);
    } finally {
        if (node != null) {
            fileContentStore.removeFile(node);
        }
    }
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) IOException(java.io.IOException) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException)

Example 29 with Node

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

the class AbstractNodeRepositoryManager method putFolder.

@Override
protected void putFolder(ArtifactContext context, File folder) throws RepositoryException {
    Node parent = getOrCreateParent(context);
    log.debug("Adding folder " + context + " to cache " + cache.getDisplayString());
    log.debug(" -> " + NodeUtils.getFullPath(parent));
    // fast-path for Herd
    if (!canHandleFolders()) {
        uploadZipped(parent, context, folder);
        return;
    }
    final String[] names = cache.getArtifactNames(context);
    if (names.length != 1) {
        throw new RepositoryException("ArtifactContext should have a single suffix");
    }
    final String label = names[0];
    if (parent instanceof OpenNode) {
        final OpenNode on = (OpenNode) parent;
        final OpenNode curent = on.createNode(label);
        try {
            for (// ignore folder, it should match new root
            File f : // ignore folder, it should match new root
            folder.listFiles()) putFiles(curent, f, context);
        } catch (RepositoryException e) {
            throw e;
        } catch (Exception e) {
            removeArtifact(context);
            throw new RepositoryException(e);
        }
    } else {
        throw new RepositoryException("Cannot put folder [" + folder + "] to non-open node: " + context);
    }
    log.debug(" -> [done]");
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) File(java.io.File) IOException(java.io.IOException) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 30 with Node

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

the class AbstractOpenNode method removeNode.

@Override
public Node removeNode(String label) {
    // get node, so we actually have the right instance to fully remove
    final Node node = getChild(label);
    if (node != null) {
        children.remove(label);
        children.remove(label + NODE_MARKER);
    }
    return node;
}
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