Search in sources :

Example 6 with RepositoryException

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

the class AbstractNodeRepositoryManager method uploadZipped.

private void uploadZipped(Node parent, ArtifactContext context, File folder) {
    File zippedFolder = null;
    try {
        try {
            zippedFolder = IOUtils.zipFolder(folder);
        } catch (IOException e) {
            throw new RepositoryException("Failed to zip folder for upload to Herd: " + folder, e);
        }
        ArtifactContext zippedContext = context.getZipContext();
        putArtifact(zippedContext, zippedFolder);
        ShaSigner.signArtifact(this, zippedContext, zippedFolder, log);
    } finally {
        if (zippedFolder != null) {
            FileUtil.deleteQuietly(zippedFolder);
        }
    }
}
Also used : RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) IOException(java.io.IOException) File(java.io.File)

Example 7 with RepositoryException

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

the class NpmContentStore method getTrueArtifactName.

private String getTrueArtifactName(Node parent) {
    final Node node;
    try {
        node = parent.getChild("package.json");
    } catch (NullPointerException ex) {
        return null;
    }
    try {
        File json = node.getContent(File.class);
        if (json.exists() && json.isFile() && json.canRead()) {
            // Parse json, get "main", that's the file we need
            Map<String, Object> descriptor = readNpmDescriptor(json);
            Object main = descriptor.get("main");
            if (main == null) {
                return "index.js";
            } else if (main instanceof String) {
                String string = (String) main;
                if (string.endsWith(".js")) {
                    return string;
                } else {
                    // what the rules really are
                    if (string.equals("lib") || string.endsWith("/lib")) {
                        return string + "/index.js";
                    } else {
                        return string + ".js";
                    }
                }
            } else {
                throw new RepositoryException("unexpected value for 'main' in npm descriptor: " + json);
            }
        } else {
            throw new RepositoryException("npm descriptor not found: " + json);
        }
    } catch (IOException ex) {
        throw new RepositoryException("error reading npm descriptor: " + out + "/package.json", ex);
    }
}
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 8 with RepositoryException

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

the class NpmContentStore method installNpmModule.

public void installNpmModule(Node node) {
    try {
        if (!out.exists()) {
            out.mkdirs();
        }
        ArtifactContext ac = ArtifactContext.fromNode(node);
        if (ac != null) {
            String name = ac.getName();
            if (name.contains(":")) {
                name = "@" + name.replace(':', '/');
            }
            String version = ac.getVersion();
            String module = version.isEmpty() ? name : name + "@" + version;
            if (log != null) {
                log.debug("installing npm module " + module + " in " + out);
            }
            String npmCmd = npmCommand != null ? npmCommand : System.getProperty(Constants.PROP_CEYLON_EXTCMD_NPM, "npm");
            ProcessBuilder pb = new ProcessBuilder().command(npmCmd, "install", "--silent", "--no-bin-links", module).directory(out.getParentFile()).inheritIO();
            Map<String, String> env = pb.environment();
            String pathVariableName = "PATH";
            for (String key : env.keySet()) {
                if (key.equalsIgnoreCase("path")) {
                    pathVariableName = key;
                    break;
                }
            }
            String pathForRunningNpm = path != null ? path : System.getProperty(Constants.PROP_CEYLON_EXTCMD_PATH, System.getenv("PATH"));
            env.put(pathVariableName, pathForRunningNpm);
            Process p = pb.start();
            p.waitFor();
            if (p.exitValue() != 0) {
                throw new RepositoryException("npm installer for '" + name + "' failed with exit code: " + p.exitValue());
            }
        }
    } catch (InterruptedException | IOException ex) {
        throw new RepositoryException("error running npm installer (make sure 'npm' is installed and available in your PATH)", ex);
    }
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException)

Example 9 with RepositoryException

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

the class Bug2414 method bug.

public static void bug(Artifact jarArtifact) {
    // locator.getService(RepositorySystem.class);
    final RepositorySystem system = null;
    // MavenRepositorySystemUtils.newSession();
    final DefaultRepositorySystemSession session = null;
    ModuleCopycat copycat = new ModuleCopycat(rmb.buildManager(), new RepositoryManager() {

        @Override
        public void putArtifact(ArtifactContext artifactContext, File file) throws RepositoryException {
            try {
                InstallRequest installRequest = new InstallRequest();
                installRequest.addArtifact(jarArtifact);
                InstallResult result = system.install(session, installRequest);
            } catch (InstallationException e) {
                throw new RepositoryException(e);
            }
        }
    });
}
Also used : RepositorySystem(org.eclipse.aether.RepositorySystem) DefaultRepositorySystemSession(org.eclipse.aether.DefaultRepositorySystemSession) InstallRequest(org.eclipse.aether.installation.InstallRequest) InstallationException(org.eclipse.aether.installation.InstallationException) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) ModuleCopycat(org.eclipse.ceylon.cmr.ceylon.ModuleCopycat) InstallResult(org.eclipse.aether.installation.InstallResult)

Example 10 with RepositoryException

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

the class Main method compile.

/**
 * Programmatic interface for main function.
 * @param args The command line parameters.
 */
@Override
public Result compile(String[] args, String[] classNames, Context context, List<JavaFileObject> fileObjects, Iterable<? extends Processor> processors) {
    context.put(Log.outKey, out);
    log = CeylonLog.instance(context);
    if (options == null) {
        // creates a new one
        options = Options.instance(context);
    }
    filenames = new LinkedHashSet<File>();
    classnames = new ListBuffer<String>();
    exitState = ExitState.cmderror();
    JavaCompiler comp = null;
    /* TODO: Logic below about what is an acceptable command line should be
         * updated to take annotation processing semantics into account. */
    try {
        if (args.length == 0 && fileObjects.isEmpty()) {
            // super.help();
            this.exitState = ExitState.cmderror();
            return CMDERR;
        }
        Collection<File> filenames = processArgs(CommandLine.parse(args), classNames);
        if (filenames == null) {
            // null signals an error in options, abort
            this.exitState = ExitState.cmderror();
            return CMDERR;
        } else if (filenames.isEmpty() && fileObjects.isEmpty() && classnames.isEmpty()) {
            // or version info
            if (options.get("-help") != null || options.get("-jhelp") != null || options.get("-X") != null || options.get("-version") != null || options.get("-fullversion") != null)
                return OK;
            error("err.no.source.files");
            this.exitState = ExitState.cmderror();
            return CMDERR;
        }
        // Set up the timer *after* we've processed to options
        // because it needs to know if we need logging or not
        timer = Timer.instance(context);
        timer.init();
        boolean forceStdOut = options.get("stdout") != null;
        if (forceStdOut) {
            out.flush();
            out = new PrintWriter(System.out, true);
        }
        context.put(Log.outKey, out);
        fileManager = context.get(JavaFileManager.class);
        try {
            comp = LanguageCompiler.instance(context);
        } catch (Overrides.OverrideException e) {
            CeylonLog.instance(context).error("ceylon.overrides", e.getMessage());
            this.exitState = new ExitState(ERROR, CeylonState.ERROR, 0, e);
            return CMDERR;
        }
        if (comp == null) {
            this.exitState = ExitState.systemError(null, null);
            return SYSERR;
        }
        if (!classnames.isEmpty()) {
            this.filenames.addAll(addModuleFiles(filenames));
            classnames.clear();
        }
        if (!this.filenames.isEmpty()) {
            // add filenames to fileObjects
            List<JavaFileObject> otherFiles = List.nil();
            JavacFileManager dfm = (JavacFileManager) fileManager;
            for (JavaFileObject fo : dfm.getJavaFileObjectsFromFiles(this.filenames)) {
                otherFiles = otherFiles.append(fo);
            }
            fileObjects = fileObjects.prependList(otherFiles);
        }
        if (fileObjects.isEmpty()) {
            error("err.no.source.files");
            this.exitState = ExitState.cmderror();
            return CMDERR;
        }
        comp.compile(fileObjects, classnames.toList(), processors);
        int errorCount = comp.errorCount();
        // ceylonBackendErrors = comp.log instanceof CeylonLog ? ((CeylonLog)comp.log).ceylonBackendErrors() : false;
        if (errorCount != 0) {
            this.exitState = ExitState.error(comp);
            return ERROR;
        }
    } catch (IOException ex) {
        ioMessage(ex);
        this.exitState = ExitState.systemError(null, ex);
        return SYSERR;
    } catch (OutOfMemoryError ex) {
        resourceMessage(ex);
        this.exitState = ExitState.systemError(null, ex);
        return SYSERR;
    } catch (StackOverflowError ex) {
        resourceMessage(ex);
        this.exitState = ExitState.systemError(null, ex);
        return SYSERR;
    } catch (FatalError ex) {
        this.exitState = ExitState.systemError(comp, ex);
        if (this.exitState.javacExitCode == SYSERR) {
            feMessage(ex);
        }
        return this.exitState.javacExitCode;
    } catch (AnnotationProcessingError ex) {
        apMessage(ex);
        this.exitState = ExitState.systemError(null, ex);
        return SYSERR;
    } catch (ClientCodeException ex) {
        // and javax.tools.JavaCompiler.CompilationTask#call
        throw new RuntimeException(ex.getCause());
    } catch (PropagatedException ex) {
        throw ex.getCause();
    } catch (RepositoryException ex) {
        // this should have logged an error, if so fine. if not we will have a problematic error code
        this.exitState = ExitState.abnormal(comp, ex, options);
        return ABNORMAL;
    } catch (Throwable ex) {
        // exceptions.
        if (comp == null || comp.errorCount() == 0 || options == null || options.get("dev") != null) {
            bugMessage(ex);
        }
        this.exitState = ExitState.abnormal(comp, ex, options);
        return ABNORMAL;
    } finally {
        if (comp != null)
            comp.close();
        filenames = null;
        options = null;
        if (timer != null) {
            timer.end();
        }
        timer = null;
    }
    this.exitState = ExitState.ok();
    return OK;
}
Also used : PropagatedException(org.eclipse.ceylon.langtools.tools.javac.util.PropagatedException) JavaFileObject(org.eclipse.ceylon.javax.tools.JavaFileObject) FatalError(org.eclipse.ceylon.langtools.tools.javac.util.FatalError) PrintWriter(java.io.PrintWriter) JavaFileManager(org.eclipse.ceylon.javax.tools.JavaFileManager) JavaCompiler(org.eclipse.ceylon.langtools.tools.javac.main.JavaCompiler) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) JavacFileManager(org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager) AnnotationProcessingError(org.eclipse.ceylon.langtools.tools.javac.processing.AnnotationProcessingError) ClientCodeException(org.eclipse.ceylon.langtools.tools.javac.util.ClientCodeException) Overrides(org.eclipse.ceylon.cmr.api.Overrides) File(java.io.File)

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