Search in sources :

Example 1 with Node

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

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

the class AbstractNodeRepositoryManager method isSameFile.

// Check if the source file and destination node point to the same file
@Override
public boolean isSameFile(ArtifactContext context, File srcFile) throws RepositoryException {
    boolean same = false;
    if (!cache.getRoot().isRemote()) {
        Node dstParent = getOrCreateParent(context);
        Node newChild = dstParent.getChild(srcFile.getName());
        if (newChild != null) {
            try {
                File existing = newChild.getContent(File.class);
                same = FileUtil.sameFile(srcFile, existing);
            } catch (IOException e) {
                throw new RepositoryException(e);
            }
        }
    }
    return same;
}
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) File(java.io.File)

Example 3 with Node

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

the class AbstractNodeRepositoryManager method getArtifactResult.

public ArtifactResult getArtifactResult(ArtifactContext context) throws RepositoryException {
    context = applyOverrides(context);
    final Node node = getLeafNode(context);
    if (node != null) {
        String foundSuffix = ArtifactContext.getSuffixFromNode(node);
        // First handle all the artifact we didn't find
        ArtifactResult result = handleNotFound(context, foundSuffix);
        if (result != null) {
            // Seems we were able to find this artifact anyway, so lets return it
            return result;
        } else {
            // Now return the artifact we found
            // Make sure we'll have only one suffix
            context.setSuffixes(foundSuffix);
            if (ArtifactContext.isDirectoryName(node.getLabel())) {
                return getFolder(context, node);
            } else {
                return getArtifactResult(context, node);
            }
        }
    } else {
        return handleNotFound(context, null);
    }
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 4 with Node

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

the class AbstractNodeRepositoryManager method removeArtifact.

public void removeArtifact(ArtifactContext context) throws RepositoryException {
    Node parent = getFromCacheNode(context, false);
    log.debug("Remove artifact " + context + " to repository " + cache.getDisplayString());
    if (parent != null) {
        final String[] labels = cache.getArtifactNames(context);
        for (String label : labels) {
            try {
                removeNode(parent, label);
            } catch (IOException e) {
                throw new RepositoryException(e);
            }
        }
        log.debug(" -> [done]");
    } else {
        log.debug(" -> No such artifact: " + context);
    }
}
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)

Example 5 with Node

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

the class AbstractNodeRepositoryManager method fromRepository.

protected Node fromRepository(CmrRepository repository, ArtifactContext context, boolean addLeaf) {
    log.debug(" Trying repository " + repository.getDisplayString());
    Node node = repository.findParent(context);
    if (node != null) {
        if (addLeaf) {
            Node parent = node;
            context.toNode(parent);
            NodeUtils.keepRepository(parent, repository);
            try {
                String[] names = repository.getArtifactNames(context);
                for (String name : names) {
                    node = parent.getChild(name);
                    if (node != null) {
                        break;
                    }
                }
            } finally {
                ArtifactContext.removeNode(parent);
            }
        }
        if (node != null) {
            NodeUtils.keepRepository(node, repository);
            log.debug("  -> Found at " + NodeUtils.getFullPath(node));
        }
    }
    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