Search in sources :

Example 1 with CeylonRepoManagerBuilder

use of org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder in project ceylon by eclipse.

the class ToolLoader method loadModule.

public ClassLoader loadModule(String name, String version, String overrides) {
    try {
        // Ok, now for something really crappy to force loading of the required module
        String loaderClassName;
        if (loader.getClass().getName().equals("org.jboss.modules.ModuleClassLoader") || loader.getClass().getName().equals("ceylon.modules.jboss.runtime.CeylonModuleClassLoader")) {
            // If we run using the Ceylon runtime
            loaderClassName = "org.eclipse.ceylon.module.loader.JBossModuleLoader";
        } else {
            // If we run in a normal Java environment
            loaderClassName = "org.eclipse.ceylon.module.loader.FlatpathModuleLoader";
        }
        Class<?> loaderClass = loader.loadClass(loaderClassName);
        CeylonRepoManagerBuilder repositoryManagerBuilder = CeylonUtils.repoManager();
        if (overrides != null)
            repositoryManagerBuilder.overrides(overrides);
        RepositoryManager repositoryManager = repositoryManagerBuilder.buildManager();
        Constructor<?> loaderConstr = loaderClass.getConstructor(RepositoryManager.class, ClassLoader.class);
        Object modLoader = loaderConstr.newInstance(repositoryManager, loader);
        Method loadMth = loaderClass.getMethod("loadModule", String.class, String.class);
        ClassLoader mcl = (ClassLoader) loadMth.invoke(modLoader, name, version);
        return mcl;
    } catch (ReflectiveOperationException e) {
        Throwable cause = (e.getCause() != null) ? e.getCause() : e;
        throw new ToolError("Could not load module '" + name + "/" + version + "' because: " + cause.toString(), e) {
        };
    }
}
Also used : CeylonRepoManagerBuilder(org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) Method(java.lang.reflect.Method)

Example 2 with CeylonRepoManagerBuilder

use of org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder 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 3 with CeylonRepoManagerBuilder

use of org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder in project ceylon by eclipse.

the class CMRTests method testMavenFileResolver.

@Test
public void testMavenFileResolver() throws ZipException, IOException {
    CeylonRepoManagerBuilder builder = CeylonUtils.repoManager();
    RepositoryManager repository = builder.buildManager();
    String groupId = "javax.el";
    String artifactId = "javax.el-api";
    String version = "3.0.0";
    String coord = groupId + ":" + artifactId;
    File artifact = repository.getArtifact(MavenArtifactContext.NAMESPACE, coord, version);
    Assert.assertNotNull(artifact);
    try (ZipFile zf = new ZipFile(artifact)) {
        String descriptorPath = String.format("META-INF/maven/%s/%s/pom.xml", groupId, artifactId);
        ZipEntry entry = zf.getEntry(descriptorPath);
        Assert.assertNotNull(entry);
        try (InputStream is = zf.getInputStream(entry)) {
            DependencyResolver resolver = new MavenDependencyResolver();
            ModuleInfo info = resolver.resolveFromInputStream(is, coord, version, null);
            Assert.assertNotNull(info);
            // FIXME: find one with dependencies
            System.err.println(info.getDependencies());
        }
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) CeylonRepoManagerBuilder(org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) MavenDependencyResolver(org.eclipse.ceylon.cmr.maven.MavenDependencyResolver) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File) MavenDependencyResolver(org.eclipse.ceylon.cmr.maven.MavenDependencyResolver) DependencyResolver(org.eclipse.ceylon.cmr.api.DependencyResolver) Test(org.junit.Test)

Example 4 with CeylonRepoManagerBuilder

use of org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder in project ceylon by eclipse.

the class ImportJarToolTests method testSystemRepositoryModuleDescriptors.

@Test
public void testSystemRepositoryModuleDescriptors() throws Exception {
    CeylonRepoManagerBuilder builder = CeylonUtils.repoManager();
    builder.outRepo(destDir.getPath()).cacheRepo(cacheDir.getPath()).systemRepo(getSysRepPath());
    final RepositoryManager repository = builder.buildManager();
    final Path repoPath = Paths.get(getSysRepPath());
    Files.walkFileTree(repoPath, new SimpleFileVisitor<Path>() {

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            if (file.getFileName().toString().endsWith(".jar") || file.getFileName().toString().endsWith(".car")) {
                System.err.println("Checking file " + file);
                Path p = repoPath.relativize(file.getParent());
                String module = p.getParent().toString().replace('/', '.');
                String version = p.getFileName().toString();
                try {
                    checkModuleDescriptor(repository, module, version);
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
            return super.visitFile(file, attrs);
        }
    });
}
Also used : Path(java.nio.file.Path) CeylonRepoManagerBuilder(org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) OptionArgumentException(org.eclipse.ceylon.common.tool.OptionArgumentException) IOException(java.io.IOException) ImportJarException(org.eclipse.ceylon.tools.importjar.ImportJarException) Test(org.junit.Test)

Aggregations

RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)4 CeylonRepoManagerBuilder (org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder)4 Test (org.junit.Test)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Method (java.lang.reflect.Method)1 FileVisitResult (java.nio.file.FileVisitResult)1 Path (java.nio.file.Path)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 JarFile (java.util.jar.JarFile)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 DependencyResolver (org.eclipse.ceylon.cmr.api.DependencyResolver)1 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)1 MavenDependencyResolver (org.eclipse.ceylon.cmr.maven.MavenDependencyResolver)1 OptionArgumentException (org.eclipse.ceylon.common.tool.OptionArgumentException)1 ToolError (org.eclipse.ceylon.common.tool.ToolError)1 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)1