Search in sources :

Example 6 with ToolUsageError

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

the class ImportJarToolTests method testBug1630.

@Test
public void testBug1630() throws Exception {
    FileUtil.delete(destFile("importtest"));
    ToolModel<CeylonImportJarTool> model = pluginLoader.loadToolModel("import-jar");
    Assert.assertNotNull(model);
    try {
        CeylonImportJarTool tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--dry-run", "--descriptor", "test/src/org/eclipse/ceylon/tools/test/test-descriptor.properties", "importtest/1.0", "test/src/org/eclipse/ceylon/tools/test/test2.jar"));
        tool.run();
        Assert.fail();
    } catch (ToolUsageError e) {
        Assert.assertEquals("Problems were found, aborting.", e.getMessage());
    }
}
Also used : CeylonImportJarTool(org.eclipse.ceylon.tools.importjar.CeylonImportJarTool) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) Test(org.junit.Test)

Example 7 with ToolUsageError

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

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

the class ImportJarToolTests method testWithUnknownModule.

@Test
public void testWithUnknownModule() throws Exception {
    FileUtil.delete(destFile("importtest"));
    ToolModel<CeylonImportJarTool> model = pluginLoader.loadToolModel("import-jar");
    Assert.assertNotNull(model);
    try {
        CeylonImportJarTool tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/test-descriptor-unknown.properties", "importtest/1.0", "test/src/org/eclipse/ceylon/tools/test/test.jar"));
        tool.run();
        Assert.fail();
    } catch (ToolUsageError e) {
        Assert.assertEquals("Problems were found, aborting.", e.getMessage());
    }
}
Also used : CeylonImportJarTool(org.eclipse.ceylon.tools.importjar.CeylonImportJarTool) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) Test(org.junit.Test)

Example 9 with ToolUsageError

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

the class ClasspathToolTests method testMissingModule.

@Test
public void testMissingModule() throws Exception {
    ToolModel<CeylonClasspathTool> model = pluginLoader.loadToolModel("classpath");
    Assert.assertNotNull(model);
    CeylonClasspathTool tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("naskduhqwedmansd"));
    try {
        tool.run();
        Assert.fail();
    } catch (ToolUsageError x) {
        Assert.assertTrue(x.getMessage().contains("Module naskduhqwedmansd not found"));
    }
}
Also used : ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) CeylonClasspathTool(org.eclipse.ceylon.tools.classpath.CeylonClasspathTool) Test(org.junit.Test)

Example 10 with ToolUsageError

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

the class CeylonHelpTool method startPager.

private Process startPager() {
    // find out the pager process, same process as in git
    // first try ceylon-specific pager env var
    String pager = System.getenv("CEYLON_PAGER");
    if (pager == null) {
        // first try tool-specific option
        String option = CeylonConfig.get().getOption("help.pager");
        // if it's neither true nor false it's a pager program
        if (option != null && !CeylonConfig.isTrueish(option) && !CeylonConfig.isFalsish(option))
            pager = option;
    }
    if (pager == null) {
        // then try general option
        String option = CeylonConfig.get().getOption("defaults.pager");
        // if it's neither true nor false it's a pager program
        if (option != null && !CeylonConfig.isTrueish(option) && !CeylonConfig.isFalsish(option))
            pager = option;
    }
    // then try general pager env var
    if (pager == null)
        pager = System.getenv("PAGER");
    // default to less
    if (pager == null)
        pager = "less";
    // make sure we don't page for cat
    if (!pager.equals("cat")) {
        // start the pager process
        ProcessBuilder pb = new ProcessBuilder(pager);
        pb.redirectError(Redirect.INHERIT);
        pb.redirectOutput(Redirect.INHERIT);
        try {
            return pb.start();
        } catch (IOException e) {
            throw new ToolUsageError("Could not start pager process '" + pager + "'. Try fixing your $CEYLON_PAGER or $PAGER environment variable or invoke with the --no-pager command-line option.", e);
        }
    }
    return null;
}
Also used : ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) IOException(java.io.IOException)

Aggregations

ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)20 File (java.io.File)9 IOException (java.io.IOException)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)5 ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)4 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)3 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)3 CeylonImportJarTool (org.eclipse.ceylon.tools.importjar.CeylonImportJarTool)3 List (java.util.List)2 ModuleGraph (org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph)2 Module (org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph.Module)2 NonFatalToolMessage (org.eclipse.ceylon.common.tool.NonFatalToolMessage)2 SourceArgumentsResolver (org.eclipse.ceylon.common.tools.SourceArgumentsResolver)2 SourceDependencyResolver (org.eclipse.ceylon.common.tools.SourceDependencyResolver)2 CeylonClasspathTool (org.eclipse.ceylon.tools.classpath.CeylonClasspathTool)2 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)1