Search in sources :

Example 1 with ToolError

use of org.eclipse.ceylon.common.tool.ToolError in project ceylon by eclipse.

the class CeylonTool method handleException.

public static int handleException(CeylonTool mainTool, Exception ex) throws Exception {
    int result;
    if (ex instanceof NoSuchToolException) {
        result = SC_NO_SUCH_TOOL;
    } else if (ex instanceof ModelException) {
        result = SC_TOOL_CREATION;
    } else if (ex instanceof OptionArgumentException) {
        result = SC_ARGS;
    } else if (ex instanceof FatalToolError) {
        result = SC_TOOL_BUG;
    } else if (ex instanceof ToolError) {
        ToolError err = (ToolError) ex;
        result = err.isExitCodeProvided() ? err.getExitCode() : SC_TOOL_ERROR;
    } else {
        result = SC_TOOL_EXCEPTION;
    }
    Usage.handleException(mainTool, mainTool.getToolName(), ex);
    return result;
}
Also used : ModelException(org.eclipse.ceylon.common.tool.ModelException) OptionArgumentException(org.eclipse.ceylon.common.tool.OptionArgumentException) NoSuchToolException(org.eclipse.ceylon.common.tool.NoSuchToolException) ToolError(org.eclipse.ceylon.common.tool.ToolError) FatalToolError(org.eclipse.ceylon.common.tool.FatalToolError) FatalToolError(org.eclipse.ceylon.common.tool.FatalToolError)

Example 2 with ToolError

use of org.eclipse.ceylon.common.tool.ToolError in project ceylon by eclipse.

the class CeylonTool method runScript.

private void runScript(ScriptToolModel<?> model) {
    List<String> args = new ArrayList<String>(3 + toolArgs.size());
    if (OSUtil.isWindows()) {
        args.add("cmd.exe");
        args.add("/C");
    }
    args.add(model.getScriptName());
    args.addAll(toolArgs);
    ProcessBuilder processBuilder = new ProcessBuilder(args);
    setupScriptEnvironment(processBuilder, model.getScriptName());
    processBuilder.redirectError(Redirect.INHERIT);
    processBuilder.redirectInput(Redirect.INHERIT);
    if (OSUtil.isWindows()) {
        processBuilder.redirectOutput(Redirect.INHERIT);
    }
    if (getCwd() != null) {
        processBuilder.directory(getCwd());
    }
    try {
        Process process = processBuilder.start();
        if (!OSUtil.isWindows()) {
            InputStream in = process.getInputStream();
            InputStreamReader inread = new InputStreamReader(in);
            BufferedReader bufferedreader = new BufferedReader(inread);
            String line;
            while ((line = bufferedreader.readLine()) != null) {
                System.out.println(line);
            }
        }
        int exit = process.waitFor();
        if (exit != 0)
            throw new ToolError("Script " + model.getScriptName() + " returned error exit code " + exit) {

                private static final long serialVersionUID = -3812680804210059230L;
            };
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) ToolError(org.eclipse.ceylon.common.tool.ToolError) FatalToolError(org.eclipse.ceylon.common.tool.FatalToolError) ArrayList(java.util.ArrayList) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader)

Example 3 with ToolError

use of org.eclipse.ceylon.common.tool.ToolError in project ceylon by eclipse.

the class ImportJarToolTests method testMissingOptionalPackages.

@Test
public void testMissingOptionalPackages() throws Exception {
    // Jetty is compiled for JDK8
    Assume.assumeTrue("Runs on JDK8", JDKUtils.jdk == JDKUtils.JDK.JDK8);
    CeylonRepoManagerBuilder builder = CeylonUtils.repoManager();
    RepositoryManager repository = builder.buildManager();
    File artifact = repository.getArtifact(MavenArtifactContext.NAMESPACE, "org.eclipse.jetty:jetty-server", "9.3.2.v20150730");
    Assert.assertNotNull(artifact);
    ToolModel<CeylonImportJarTool> model = pluginLoader.loadToolModel("import-jar");
    Assert.assertNotNull(model);
    // no descriptor
    CeylonImportJarTool tool;
    StringBuilder b = new StringBuilder();
    // make sure we don't get a missing package with array shit in there: [Ljavax.servlet;
    try {
        tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
        tool.setOut(b);
        tool.run();
        Assert.fail();
    } catch (ToolUsageError e) {
        Assert.assertEquals("Problems were found, aborting. Try adding a descriptor file, see help for more information.", e.getMessage());
        Assert.assertEquals("The following JDK modules are used and could be declared as imports:\n" + "    java.base ... [shared]\n" + "    java.jdbc ... [shared]\n" + "    java.tls ... [shared]\n" + "    javax.naming\n" + "Modules containing the following packages need to be declared as imports:\n" + "(Tip: try running again with the '--show-suggestions' option)\n" + "    javax.servlet ... [shared]\n" + "    javax.servlet.descriptor ... [shared]\n" + "    javax.servlet.http ... [shared]\n" + "    org.eclipse.jetty.http ... [shared]\n" + "    org.eclipse.jetty.io ... [shared]\n" + "    org.eclipse.jetty.io.ssl ... [shared]\n" + "    org.eclipse.jetty.jmx ... [shared]\n" + "    org.eclipse.jetty.util ... [shared]\n" + "    org.eclipse.jetty.util.annotation ... [shared]\n" + "    org.eclipse.jetty.util.component ... [shared]\n" + "    org.eclipse.jetty.util.log ... [shared]\n" + "    org.eclipse.jetty.util.resource ... [shared]\n" + "    org.eclipse.jetty.util.ssl ... [shared]\n" + "    org.eclipse.jetty.util.statistic ... [shared]\n" + "    org.eclipse.jetty.util.thread ... [shared]\n", b.toString());
    }
    // all OK
    tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-module.properties", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
    tool.run();
    // with missing module
    tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-missing-optional-module.properties", // exact
    "--missing-dependency-packages", "org.eclipse.jetty:jetty-jmxnotfound/9.3.2.v20150730=org.eclipse.jetty.jmx", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
    tool.run();
    // with missing module
    tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-missing-optional-module.properties", // **
    "--missing-dependency-packages", "org.eclipse.jetty:jetty-jmxnotfound/9.3.2.v20150730=org.**.jmx", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
    tool.run();
    // with missing module
    tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-missing-optional-module.properties", // *
    "--missing-dependency-packages", "org.eclipse.jetty:jetty-jmxnotfound/9.3.2.v20150730=org.eclipse.jetty.jm*", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
    tool.run();
    try {
        // with missing module
        tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-missing-optional-module.properties", // * with dots
        "--missing-dependency-packages", "org.eclipse.jetty:jetty-jmxnotfound/9.3.2.v20150730=org.*.jmx", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
        tool.run();
        Assert.fail();
    } catch (ToolUsageError e) {
        Assert.assertEquals("Problems were found, aborting.", e.getMessage());
    }
    // with missing module
    tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-missing-optional-module.properties", // ?
    "--missing-dependency-packages", "org.eclipse.jetty:jetty-jmxnotfound/9.3.2.v20150730=org.eclipse.jetty.jm?", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
    tool.run();
    try {
        // with invalid pattern
        tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/jetty-server-missing-optional-module.properties", "--missing-dependency-packages", "org.eclipse.jetty:jetty-jmxnotfound", "org.eclipse.jetty.jetty-server/9.3.2.v20150730", artifact.getAbsolutePath()));
        tool.run();
        Assert.fail();
    } catch (ToolError e) {
        Assert.assertEquals("Invalid missing dependencies descriptor : 'org.eclipse.jetty:jetty-jmxnotfound'. 'Syntax is module-name/module-version=package-wildcard(,package-wildcard)*'.", e.getMessage());
    }
}
Also used : CeylonRepoManagerBuilder(org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder) ToolError(org.eclipse.ceylon.common.tool.ToolError) CeylonImportJarTool(org.eclipse.ceylon.tools.importjar.CeylonImportJarTool) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) File(java.io.File) Test(org.junit.Test)

Example 4 with ToolError

use of org.eclipse.ceylon.common.tool.ToolError in project ceylon by eclipse.

the class ClasspathToolTests method testRecursiveDependencies.

@Test
public void testRecursiveDependencies() throws Exception {
    ToolModel<CeylonClasspathTool> model = pluginLoader.loadToolModel("classpath");
    Assert.assertNotNull(model);
    CeylonClasspathTool tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("io.cayla.web/0.3.0"));
    try {
        tool.run();
    } catch (ToolError err) {
        Assert.assertEquals("Module conflict error prevented classpath generation: try running \"ceylon info --print-overrides io.cayla.web/0.3.0\" to display an override file you can use with \"ceylon classpath --overrides override.xml io.cayla.web/0.3.0\" or try with \"ceylon classpath --force io.cayla.web/0.3.0\" to select the latest versions", err.getMessage());
    }
}
Also used : ToolError(org.eclipse.ceylon.common.tool.ToolError) CeylonClasspathTool(org.eclipse.ceylon.tools.classpath.CeylonClasspathTool) Test(org.junit.Test)

Aggregations

ToolError (org.eclipse.ceylon.common.tool.ToolError)4 FatalToolError (org.eclipse.ceylon.common.tool.FatalToolError)2 Test (org.junit.Test)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)1 CeylonRepoManagerBuilder (org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder)1 ModelException (org.eclipse.ceylon.common.tool.ModelException)1 NoSuchToolException (org.eclipse.ceylon.common.tool.NoSuchToolException)1 OptionArgumentException (org.eclipse.ceylon.common.tool.OptionArgumentException)1 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)1 CeylonClasspathTool (org.eclipse.ceylon.tools.classpath.CeylonClasspathTool)1 CeylonImportJarTool (org.eclipse.ceylon.tools.importjar.CeylonImportJarTool)1