Search in sources :

Example 11 with RepositoryException

use of org.eclipse.ceylon.model.cmr.RepositoryException in project ceylon by eclipse.

the class JvmBackendUtil method loadStaticMetamodel.

public static void loadStaticMetamodel(InputStream is, List<String> dexEntries, StaticMetamodelLoader staticMetamodelLoader) {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) {
        String line;
        ModuleSpec module = null;
        SortedSet<String> packages = new TreeSet<>();
        List<ArtifactResult> imports = new LinkedList<ArtifactResult>();
        while ((line = reader.readLine()) != null) {
            if (line.startsWith("=")) {
                if (module != null)
                    finishLoadingModule(module, packages, imports, dexEntries, staticMetamodelLoader);
                module = ModuleSpec.parse(line.substring(1));
                packages.clear();
                imports.clear();
                continue;
            }
            boolean _optional = false;
            boolean _shared = false;
            if (line.startsWith("?")) {
                _optional = true;
                line = line.substring(1);
            }
            if (line.startsWith("+")) {
                _shared = true;
                line = line.substring(1);
            }
            // SERIOUSLY!!
            final boolean optional = _optional;
            final boolean shared = _shared;
            if (line.startsWith("@")) {
                packages.add(line.substring(1));
                continue;
            }
            // it's an import
            ModuleSpec importSpec = ModuleSpec.parse(line);
            final String namespace = ModuleUtil.getNamespaceFromUri(importSpec.getName());
            final String name = ModuleUtil.getModuleNameFromUri(importSpec.getName());
            final String version = importSpec.getVersion();
            imports.add(new ArtifactResult() {

                @Override
                public String namespace() {
                    return namespace;
                }

                @Override
                public String name() {
                    return name;
                }

                @Override
                public String version() {
                    return version;
                }

                @Override
                public boolean optional() {
                    return optional;
                }

                @Override
                public boolean exported() {
                    return shared;
                }

                @Override
                public ArtifactResultType type() {
                    // Is this important?
                    return ArtifactResultType.OTHER;
                }

                @Override
                public VisibilityType visibilityType() {
                    return VisibilityType.STRICT;
                }

                @Override
                public File artifact() throws RepositoryException {
                    return null;
                }

                @Override
                public PathFilter filter() {
                    return null;
                }

                @Override
                public List<ArtifactResult> dependencies() throws RepositoryException {
                    return null;
                }

                @Override
                public String artifactId() {
                    return ModuleUtil.getMavenArtifactIdIfMavenModule(name);
                }

                @Override
                public String groupId() {
                    return ModuleUtil.getMavenGroupIdIfMavenModule(name);
                }

                @Override
                public String classifier() {
                    return ModuleUtil.getMavenClassifierIfMavenModule(name);
                }

                @Override
                public String repositoryDisplayString() {
                    return "Android dependency";
                }

                @Override
                public Repository repository() {
                    return null;
                }

                @Override
                public ModuleScope moduleScope() {
                    return ModuleScope.COMPILE;
                }

                @Override
                public List<Exclusion> getExclusions() {
                    return null;
                }
            });
        }
        if (module != null)
            finishLoadingModule(module, packages, imports, dexEntries, staticMetamodelLoader);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : PathFilter(org.eclipse.ceylon.model.cmr.PathFilter) InputStreamReader(java.io.InputStreamReader) ModuleScope(org.eclipse.ceylon.model.cmr.ModuleScope) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) LinkedList(java.util.LinkedList) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) Repository(org.eclipse.ceylon.model.cmr.Repository) ArtifactResultType(org.eclipse.ceylon.model.cmr.ArtifactResultType) ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) VisibilityType(org.eclipse.ceylon.model.cmr.VisibilityType) TreeSet(java.util.TreeSet) BufferedReader(java.io.BufferedReader) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 12 with RepositoryException

use of org.eclipse.ceylon.model.cmr.RepositoryException in project ceylon by eclipse.

the class RootRepositoryManager method getArtifactResult.

@Override
protected ArtifactResult getArtifactResult(ArtifactContext context, Node node) throws RepositoryException {
    if (node.isRemote()) {
        final boolean forceOp = context.isForceOperation();
        try {
            // just force the ops
            context.setForceOperation(true);
            log.debug("Looking up artifact " + context + " from " + node + " to cache it");
            SizedInputStream sizedInputStream = node.getSizedInputStream();
            // in theory we should not have nodes with null streams, but at least provide a helpful exception
            if (sizedInputStream == null) {
                throw new RepositoryException("Node " + node + " for repository " + this + " returned a null stream");
            }
            try {
                log.debug(" -> Found it, now caching it");
                final File file = putContent(context, node, sizedInputStream.getInputStream(), sizedInputStream.getSize());
                log.debug("    Caching done: " + file);
                String repositoryDisplayString = NodeUtils.getRepositoryDisplayString(node);
                File originalRepoFile = new File(file.getParentFile(), file.getName().concat(ORIGIN));
                FileWriter writer = new FileWriter(originalRepoFile, false);
                try {
                    writer.write(repositoryDisplayString);
                    writer.close();
                } catch (IOException e) {
                    log.error(e.toString());
                }
                // we expect the remote nodes to support Ceylon module info
                return new FileArtifactResult(NodeUtils.getRepository(node), this, context.getName(), context.getVersion(), file, repositoryDisplayString);
            } finally {
                IOUtils.safeClose(sizedInputStream.getInputStream());
            }
        } catch (IOException e) {
            throw new RepositoryException(e);
        } finally {
            context.setForceOperation(forceOp);
        }
    } else {
        return toArtifactResult(node);
    }
}
Also used : FileWriter(java.io.FileWriter) SizedInputStream(org.eclipse.ceylon.cmr.spi.SizedInputStream) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) File(java.io.File)

Example 13 with RepositoryException

use of org.eclipse.ceylon.model.cmr.RepositoryException 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 14 with RepositoryException

use of org.eclipse.ceylon.model.cmr.RepositoryException in project ceylon by eclipse.

the class CachingRepositoryManager method putArtifact.

@Override
public void putArtifact(ArtifactContext context, InputStream content) throws RepositoryException {
    // first copy to local
    caching.putArtifact(context, content);
    // should be here
    final File file = caching.getArtifact(context);
    try {
        // upload
        super.putArtifact(context, new FileInputStream(file));
    } catch (RepositoryException e) {
        throw e;
    } catch (Exception e) {
        throw new RepositoryException(e);
    }
}
Also used : RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException)

Example 15 with RepositoryException

use of org.eclipse.ceylon.model.cmr.RepositoryException in project ceylon by eclipse.

the class CachingRepositoryManager method getArtifactResult.

protected ArtifactResult getArtifactResult(ArtifactContext context, Node node) throws RepositoryException {
    try {
        ArtifactResult result = caching.getArtifactResult(context);
        if (result != null) {
            boolean valid = false;
            File file = result.artifact();
            if (file.exists()) {
                long lm = node.getLastModified();
                valid = (lm == -1 || lm < file.lastModified());
            }
            if (valid) {
                return result;
            }
        }
        final boolean previous = context.isForceOperation();
        context.setForceOperation(true);
        try {
            // Make sure we'll have only one suffix
            context.setSuffixes(ArtifactContext.getSuffixFromNode(node));
            caching.putArtifact(context, node.getInputStream());
        } finally {
            context.setForceOperation(previous);
        }
        return caching.getArtifactResult(context);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Aggregations

RepositoryException (org.eclipse.ceylon.model.cmr.RepositoryException)16 IOException (java.io.IOException)15 File (java.io.File)11 Node (org.eclipse.ceylon.cmr.spi.Node)5 OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)5 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)3 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)3 ZipFile (java.util.zip.ZipFile)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 ZipEntry (java.util.zip.ZipEntry)1 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)1