Search in sources :

Example 11 with CeylonImportJarTool

use of org.eclipse.ceylon.tools.importjar.CeylonImportJarTool in project ceylon by eclipse.

the class ImportJarToolTests method testNonexistentJar.

@Test
public void testNonexistentJar() {
    ToolModel<CeylonImportJarTool> model = pluginLoader.loadToolModel("import-jar");
    Assert.assertNotNull(model);
    try {
        CeylonImportJarTool tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("test/1.0", "test/src/org/eclipse/ceylon/tools/test/nonexistent.jar"));
        Assert.fail();
    } catch (ImportJarException e) {
        String jarName = "test/src/org/eclipse/ceylon/tools/test/nonexistent.jar";
        jarName = jarName.replace('/', File.separatorChar);
        Assert.assertEquals("Jar file " + jarName + " does not exist", e.getMessage());
    }
}
Also used : ImportJarException(org.eclipse.ceylon.tools.importjar.ImportJarException) CeylonImportJarTool(org.eclipse.ceylon.tools.importjar.CeylonImportJarTool) Test(org.junit.Test)

Example 12 with CeylonImportJarTool

use of org.eclipse.ceylon.tools.importjar.CeylonImportJarTool 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 13 with CeylonImportJarTool

use of org.eclipse.ceylon.tools.importjar.CeylonImportJarTool 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 14 with CeylonImportJarTool

use of org.eclipse.ceylon.tools.importjar.CeylonImportJarTool in project ceylon by eclipse.

the class ImportJarToolTests method testSourceJarWithXmlDescriptor.

@Test
public void testSourceJarWithXmlDescriptor() throws Exception {
    FileUtil.delete(destFile("importtest"));
    ToolModel<CeylonImportJarTool> model = pluginLoader.loadToolModel("import-jar");
    Assert.assertNotNull(model);
    CeylonImportJarTool tool = pluginFactory.bindArguments(model, getMainTool(), toolOptions("--descriptor", "test/src/org/eclipse/ceylon/tools/test/test-descriptor.xml", "source.import.test/1.0", "test/src/org/eclipse/ceylon/tools/test/test.jar", "test/src/org/eclipse/ceylon/tools/test/test-source.jar"));
    tool.run();
    File jarFile = destFile("source/import/test/1.0/source.import.test-1.0.jar");
    File sha1JarFile = destFile("source/import/test/1.0/source.import.test-1.0.jar.sha1");
    File sourceJarFile = destFile("source/import/test/1.0/source.import.test-1.0-sources.jar");
    File sha1SourceJarFile = destFile("source/import/test/1.0/source.import.test-1.0-sources.jar.sha1");
    File moduleXml = destFile("source/import/test/1.0/module.xml");
    File sha1ModuleXml = destFile("source/import/test/1.0/module.xml");
    Assert.assertTrue(jarFile.exists() && sha1JarFile.exists());
    Assert.assertTrue(sourceJarFile.exists() && sha1SourceJarFile.exists());
    Assert.assertTrue(moduleXml.exists());
    Assert.assertTrue(sha1ModuleXml.exists());
}
Also used : CeylonImportJarTool(org.eclipse.ceylon.tools.importjar.CeylonImportJarTool) File(java.io.File) Test(org.junit.Test)

Example 15 with CeylonImportJarTool

use of org.eclipse.ceylon.tools.importjar.CeylonImportJarTool 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)

Aggregations

CeylonImportJarTool (org.eclipse.ceylon.tools.importjar.CeylonImportJarTool)23 Test (org.junit.Test)22 File (java.io.File)12 ImportJarException (org.eclipse.ceylon.tools.importjar.ImportJarException)6 OptionArgumentException (org.eclipse.ceylon.common.tool.OptionArgumentException)3 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)3 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)1 MavenArtifactContext (org.eclipse.ceylon.cmr.api.MavenArtifactContext)1 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)1 CeylonRepoManagerBuilder (org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder)1 ToolError (org.eclipse.ceylon.common.tool.ToolError)1