Search in sources :

Example 1 with OptionArgumentException

use of org.eclipse.ceylon.common.tool.OptionArgumentException 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 OptionArgumentException

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

the class ToolFactoryTest method testSubtool.

@Test
public void testSubtool() {
    ToolModel<TestSubtoolTool> model = pluginLoader.loadToolModel("subtool");
    TestSubtoolTool ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool1"));
    Assert.assertEquals(TestSubtoolTool.Subtool1.class, ex.getAction().getClass());
    ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool1", "--foo"));
    Assert.assertEquals(TestSubtoolTool.Subtool1.class, ex.getAction().getClass());
    try {
        ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool1", "--bar"));
        Assert.fail();
    } catch (OptionArgumentException e) {
        Assert.assertEquals("Unrecognised long option '--bar' to command 'subtool1'", e.getMessage());
    }
    ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool2"));
    Assert.assertEquals(TestSubtoolTool.Subtool2.class, ex.getAction().getClass());
    ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool2", "--bar"));
    Assert.assertEquals(TestSubtoolTool.Subtool2.class, ex.getAction().getClass());
    try {
        ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool2", "--foo"));
        Assert.fail();
    } catch (OptionArgumentException e) {
        Assert.assertEquals("Unrecognised long option '--foo' to command 'subtool2'", e.getMessage());
    }
    try {
        ex = pluginFactory.bindArguments(model, getMainTool(), Arrays.asList("subtool3"));
        Assert.fail();
    } catch (OptionArgumentException e) {
        String message = e.getMessage();
        Assert.assertTrue(message, message.startsWith("Invalid value 'subtool3' given for argument 'action'"));
    // Assert.assertTrue(message, message.contains("subtool1"));
    // Assert.assertTrue(message, message.contains("subtool2"));
    }
}
Also used : OptionArgumentException(org.eclipse.ceylon.common.tool.OptionArgumentException) TestSubtoolTool(org.eclipse.ceylon.common.tool.example.TestSubtoolTool) Test(org.junit.Test)

Example 3 with OptionArgumentException

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

the class ImportJarToolTests method testJarOnly.

@Test
public void testJarOnly() {
    ToolModel<CeylonImportJarTool> model = pluginLoader.loadToolModel("import-jar");
    Assert.assertNotNull(model);
    try {
        CeylonImportJarTool tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("my.jar"));
        Assert.fail();
    } catch (OptionArgumentException e) {
        Assert.assertEquals("Invalid value 'my.jar' given for argument 'module' to command 'import-jar'", e.getMessage());
    }
}
Also used : OptionArgumentException(org.eclipse.ceylon.common.tool.OptionArgumentException) CeylonImportJarTool(org.eclipse.ceylon.tools.importjar.CeylonImportJarTool) Test(org.junit.Test)

Example 4 with OptionArgumentException

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

the class ImportJarToolTests method testNoArgs.

@Test
public void testNoArgs() {
    ToolModel<CeylonImportJarTool> model = pluginLoader.loadToolModel("import-jar");
    Assert.assertNotNull(model);
    try {
        CeylonImportJarTool tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions());
        Assert.fail();
    } catch (OptionArgumentException e) {
        Assert.assertEquals("Argument 'module' to command 'import-jar' should appear at least 1 time(s)", e.getMessage());
    }
}
Also used : OptionArgumentException(org.eclipse.ceylon.common.tool.OptionArgumentException) CeylonImportJarTool(org.eclipse.ceylon.tools.importjar.CeylonImportJarTool) Test(org.junit.Test)

Example 5 with OptionArgumentException

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

the class SrcToolTests method testNoArgs.

@Test
public void testNoArgs() throws Exception {
    ToolModel<CeylonSrcTool> model = pluginLoader.loadToolModel("src");
    Assert.assertNotNull(model);
    try {
        CeylonSrcTool tool = pluginFactory.bindArguments(model, getMainTool(), Collections.<String>emptyList());
        Assert.fail();
    } catch (OptionArgumentException e) {
    // asserting this is thrown
    }
}
Also used : CeylonSrcTool(org.eclipse.ceylon.tools.src.CeylonSrcTool) OptionArgumentException(org.eclipse.ceylon.common.tool.OptionArgumentException) Test(org.junit.Test)

Aggregations

OptionArgumentException (org.eclipse.ceylon.common.tool.OptionArgumentException)19 Test (org.junit.Test)18 CeylonCompileTool (org.eclipse.ceylon.compiler.CeylonCompileTool)8 CeylonImportJarTool (org.eclipse.ceylon.tools.importjar.CeylonImportJarTool)3 CeylonRunTool (ceylon.modules.bootstrap.CeylonRunTool)1 AbstractToolTest (org.eclipse.ceylon.common.tool.AbstractToolTest)1 FatalToolError (org.eclipse.ceylon.common.tool.FatalToolError)1 ModelException (org.eclipse.ceylon.common.tool.ModelException)1 NoSuchToolException (org.eclipse.ceylon.common.tool.NoSuchToolException)1 ToolError (org.eclipse.ceylon.common.tool.ToolError)1 TestSubtoolTool (org.eclipse.ceylon.common.tool.example.TestSubtoolTool)1 CeylonHelpTool (org.eclipse.ceylon.common.tools.help.CeylonHelpTool)1 CeylonClasspathTool (org.eclipse.ceylon.tools.classpath.CeylonClasspathTool)1 CeylonInfoTool (org.eclipse.ceylon.tools.info.CeylonInfoTool)1 CeylonMavenExportTool (org.eclipse.ceylon.tools.maven.export.CeylonMavenExportTool)1 CeylonSrcTool (org.eclipse.ceylon.tools.src.CeylonSrcTool)1