Search in sources :

Example 41 with RepositoryManager

use of org.eclipse.ceylon.cmr.api.RepositoryManager in project ceylon by eclipse.

the class AetherTestCase method testListVersionsAether.

@Test
public void testListVersionsAether() throws Exception {
    CmrRepository repository = createAetherRepository();
    RepositoryManager manager = new SimpleRepositoryManager(repository, log);
    ModuleVersionQuery lookup = new ModuleVersionQuery("com.sparkjava:spark-core", "1.", Type.JAR);
    ModuleVersionResult result = manager.completeVersions(lookup);
    Assert.assertEquals(3, result.getVersions().size());
    Assert.assertNotNull(result.getVersions().get("1.0"));
    Assert.assertNotNull(result.getVersions().get("1.1"));
    Assert.assertNotNull(result.getVersions().get("1.1.1"));
    for (ModuleVersionDetails res : result.getVersions().values()) {
        Assert.assertEquals("Spark\nA Sinatra inspired java web framework\nhttp://www.sparkjava.com", res.getDoc());
        Assert.assertEquals("The Apache Software License, Version 2.0\nhttp://www.apache.org/licenses/LICENSE-2.0.txt", res.getLicense());
        NavigableSet<ModuleDependencyInfo> deps = res.getDependencies();
        List<ModuleDependencyInfo> compileDeps = new ArrayList<>(deps.size());
        for (ModuleDependencyInfo dep : res.getDependencies()) {
            if (dep.getModuleScope() == ModuleScope.COMPILE || dep.getModuleScope() == ModuleScope.PROVIDED)
                compileDeps.add(dep);
        }
        Assert.assertEquals(4, compileDeps.size());
    }
    lookup = new ModuleVersionQuery("com.sparkjava:spark-core", null, Type.JAR);
    result = manager.completeVersions(lookup);
    // Count the version up to 2.3
    int cnt = 0;
    for (ModuleVersionDetails mvd : result.getVersions().values()) {
        cnt++;
        if ("2.3".equals(mvd.getVersion())) {
            break;
        }
    }
    Assert.assertEquals(7, cnt);
    // now check that we only downloaded the POMs for that, and not the jars
    File repo = new File("build/test-classes/maven-settings/repository");
    File folder = new File(repo, "com/sparkjava/spark-core/1.0");
    Assert.assertTrue(new File(folder, "spark-core-1.0.pom").exists());
    Assert.assertFalse(new File(folder, "spark-core-1.0.jar").exists());
    Assert.assertFalse(new File(repo, "org/eclipse/jetty/jetty-server/9.0.2.v20130417/jetty-server-9.0.2.v20130417.jar").exists());
    // this one has a conflict if we do resolve it non-lazily
    lookup = new ModuleVersionQuery("org.hibernate:hibernate-validator", "3.", Type.JAR);
    result = manager.completeVersions(lookup);
    Assert.assertEquals(4, result.getVersions().size());
}
Also used : ModuleVersionResult(org.eclipse.ceylon.cmr.api.ModuleVersionResult) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ArrayList(java.util.ArrayList) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ModuleVersionQuery(org.eclipse.ceylon.cmr.api.ModuleVersionQuery) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) Test(org.junit.Test)

Example 42 with RepositoryManager

use of org.eclipse.ceylon.cmr.api.RepositoryManager in project ceylon by eclipse.

the class AetherTestCase method testReplaceOverrides.

@Test
public void testReplaceOverrides() throws Throwable {
    CmrRepository repository = createAetherRepository();
    RepositoryManager manager = new SimpleRepositoryManager(repository, log, RepositoryManagerBuilder.parseOverrides(getOverridesFileName()));
    ArtifactResult result = manager.getArtifactResult(MavenArtifactContext.NAMESPACE, "org.apache.camel:camel-core", "2.9.2");
    Assert.assertNotNull(result);
    Assert.assertEquals(result.name(), "org.osgi:org.osgi.core");
    File artifact = result.artifact();
    boolean exists = false;
    try {
        Assert.assertNotNull(artifact);
        Assert.assertTrue(artifact.exists());
        exists = true;
        List<ArtifactResult> deps = result.dependencies();
        Assert.assertEquals(deps.size(), 0);
    } finally {
        if (exists) {
            // delete this one
            Assert.assertTrue(artifact.delete());
        }
    }
}
Also used : SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) Test(org.junit.Test)

Example 43 with RepositoryManager

use of org.eclipse.ceylon.cmr.api.RepositoryManager in project ceylon by eclipse.

the class ModelLoaderTests method verifyRuntimeClassLoading.

protected void verifyRuntimeClassLoading(RunnableTest test) {
    RepositoryManager repoManager = CeylonUtils.repoManager().systemRepo(getSysRepPath()).buildManager();
    VFS vfs = new VFS();
    org.eclipse.ceylon.compiler.typechecker.context.Context context = new org.eclipse.ceylon.compiler.typechecker.context.Context(repoManager, vfs);
    RuntimeModuleManager moduleManager = new RuntimeModuleManager(null);
    context.setModules(new Modules());
    moduleManager.initCoreModules(new Modules());
    moduleManager.loadModule(AbstractModelLoader.CEYLON_LANGUAGE, Versions.CEYLON_VERSION_NUMBER, repoManager.getArtifactResult(null, "ceylon.language", Versions.CEYLON_VERSION_NUMBER), getClass().getClassLoader());
    RuntimeModelLoader modelLoader = moduleManager.getModelLoader();
    modelLoader.setupWithNoStandardModules();
    modelLoader.loadStandardModules();
    test.test(modelLoader);
}
Also used : Context(org.eclipse.ceylon.langtools.tools.javac.util.Context) VFS(org.eclipse.ceylon.compiler.typechecker.io.VFS) RuntimeModuleManager(org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModuleManager) Modules(org.eclipse.ceylon.model.typechecker.model.Modules) RuntimeModelLoader(org.eclipse.ceylon.compiler.java.runtime.model.RuntimeModelLoader) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager)

Example 44 with RepositoryManager

use of org.eclipse.ceylon.cmr.api.RepositoryManager 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 45 with RepositoryManager

use of org.eclipse.ceylon.cmr.api.RepositoryManager in project ceylon by eclipse.

the class CeylonEnter method addOutputModuleToClassPath.

public void addOutputModuleToClassPath(Module module) {
    RepositoryManager repositoryManager = fileManager.getOutputRepositoryManager();
    ArtifactResult artifact = null;
    try {
        ArtifactContext ctx = new ArtifactContext(null, module.getNameAsString(), module.getVersion(), ArtifactContext.CAR, ArtifactContext.JAR);
        artifact = repositoryManager.getArtifactResult(ctx);
    } catch (InvalidArchiveException e) {
        log.warning("ceylon", "Module car " + e.getPath() + " obtained from repository " + e.getRepository() + " has an invalid SHA1 signature:" + " it will be overwritten but if the problem" + " persists you need to remove it and rebuild the module, since it may be corrupted.");
    } catch (Exception e) {
        String moduleName = module.getNameAsString();
        if (!module.isDefaultModule())
            moduleName += "/" + module.getVersion();
        log.error("ceylon", "Exception occured while trying to resolve module " + moduleName);
        e.printStackTrace();
    }
    if (artifact == null || JarUtils.isValidJar(artifact.artifact())) {
        addModuleToClassPath(module, false, artifact);
    } else {
        log.warning("ceylon", "Module car " + artifact.artifact() + " obtained from repository " + artifact.repository() + " could not be read:" + " it will be overwritten but if the problem" + " persists you need to remove it and rebuild the module, since it may be corrupted.");
    }
}
Also used : InvalidArchiveException(org.eclipse.ceylon.cmr.impl.InvalidArchiveException) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) InvalidArchiveException(org.eclipse.ceylon.cmr.impl.InvalidArchiveException) IOException(java.io.IOException) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Aggregations

RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)95 Test (org.junit.Test)71 SimpleRepositoryManager (org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager)68 File (java.io.File)47 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)32 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)26 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)23 ModuleDetails (org.eclipse.ceylon.cmr.api.ModuleSearchResult.ModuleDetails)14 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)11 RepositoryManagerBuilder (org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder)8 HashMap (java.util.HashMap)7 TypeChecker (org.eclipse.ceylon.compiler.typechecker.TypeChecker)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ArrayList (java.util.ArrayList)5 JsModuleManagerFactory (org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory)5 ModuleSearchResult (org.eclipse.ceylon.cmr.api.ModuleSearchResult)4 CeylonRepoManagerBuilder (org.eclipse.ceylon.cmr.ceylon.CeylonUtils.CeylonRepoManagerBuilder)4 IOException (java.io.IOException)3 Manifest (java.util.jar.Manifest)3 DefaultRepository (org.eclipse.ceylon.cmr.impl.DefaultRepository)3