Search in sources :

Example 91 with RepositoryManager

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

the class ModuleLoaderTest method testNoDots.

@Test
public void testNoDots() throws ModuleNotFoundException {
    CmrRepository repository = AetherRepository.createRepository(log, false, 60000);
    RepositoryManager manager = new SimpleRepositoryManager(repository, log);
    Map<String, String> extraModules = new HashMap<>();
    extraModules.put("maven:aopalliance:aopalliance", "1.0");
    TestableModuleLoader moduleLoader = new TestableModuleLoader(manager, null, extraModules, true);
    // org.antlr:stringtemplate:3.2.1
    // com.google.inject:guice:4.0
    moduleLoader.loadModule("maven:antlr:antlr", "2.7.7", ModuleScope.RUNTIME);
    // Check that we got them
    Assert.assertEquals("2.7.7", moduleLoader.getModuleVersion("maven:antlr:antlr"));
    Assert.assertEquals("1.0", moduleLoader.getModuleVersion("maven:aopalliance:aopalliance"));
}
Also used : SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) HashMap(java.util.HashMap) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) Test(org.junit.Test)

Example 92 with RepositoryManager

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

the class ModuleLoaderTest method testNoDotsFromMaven.

@Test
public void testNoDotsFromMaven() throws ModuleNotFoundException {
    CmrRepository repository = AetherRepository.createRepository(log, false, 60000);
    RepositoryManager manager = new SimpleRepositoryManager(repository, log);
    Map<String, String> extraModules = new HashMap<>();
    extraModules.put("org.antlr:stringtemplate", "3.2.1");
    TestableModuleLoader moduleLoader = new TestableModuleLoader(manager, null, extraModules, true);
    moduleLoader.loadModule("com.google.inject:guice", "4.0", ModuleScope.RUNTIME);
    // Check that we got them
    Assert.assertEquals("2.7.7", moduleLoader.getModuleVersion("maven:antlr:antlr"));
    Assert.assertEquals("1.0", moduleLoader.getModuleVersion("maven:aopalliance:aopalliance"));
}
Also used : SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) HashMap(java.util.HashMap) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) Test(org.junit.Test)

Example 93 with RepositoryManager

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

the class ModuleLoaderTest method testModuleLoaderDirectImportsNotExcluded.

@Test
public void testModuleLoaderDirectImportsNotExcluded() throws ModuleNotFoundException {
    CmrRepository repository = AetherRepository.createRepository(log, settings, false, 60000, null);
    RepositoryManager manager = new SimpleRepositoryManager(repository, log);
    Map<String, String> extraModules = new HashMap<>();
    extraModules.put("org.springframework.cloud:spring-cloud-starter-eureka-server", "1.1.0.RC1");
    TestableModuleLoader moduleLoader = new TestableModuleLoader(manager, null, extraModules, false);
    moduleLoader.loadModule("org.springframework.cloud:spring-cloud-starter-eureka-server", "1.1.0.RC1", ModuleScope.RUNTIME);
    // Those should not be there
    Assert.assertNull(moduleLoader.getModuleVersion("jackson-dataformat-xml:com.fasterxml.jackson.dataformat"));
    moduleLoader.cleanup();
    // now add a direct import
    moduleLoader.loadModule("com.fasterxml.jackson.dataformat:jackson-dataformat-xml", "2.6.5", ModuleScope.RUNTIME);
    // Should be there
    Assert.assertEquals("2.6.5", moduleLoader.getModuleVersion("com.fasterxml.jackson.dataformat:jackson-dataformat-xml"));
}
Also used : SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) HashMap(java.util.HashMap) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) Test(org.junit.Test)

Example 94 with RepositoryManager

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

the class CeylonCompileJsTool method run.

@Override
public void run() throws Exception {
    AppendableWriter writer = new AppendableWriter(getOutAppendable());
    final Options opts = new Options().cwd(cwd).repos(getRepositoryAsStrings()).sourceDirs(roots).resourceDirs(resources).resourceRootName(resourceRootName).systemRepo(systemRepo).outRepo(getOut()).user(user).pass(pass).optimize(optimize).modulify(modulify).comment(comments).verbose(getVerbose()).profile(profile).stdin(false).generateSourceArchive(!skipSrc).encoding(encoding).includeDependencies(includeDependencies).diagnosticListener(diagnosticListener).outWriter(writer).suppressWarnings(suppwarns);
    final TypeChecker typeChecker;
    if (opts.hasVerboseFlag("cmr")) {
        append("Using repositories: " + getRepositoryAsStrings());
        newline();
    }
    final RepositoryManager repoman = getRepositoryManager();
    long t0, t1, t2, t3, t4;
    final TypeCheckerBuilder tcb;
    List<File> onlySources = null;
    List<File> onlyResources = null;
    if (opts.isStdin()) {
        VirtualFile src = new VirtualFile() {

            @Override
            public boolean exists() {
                return true;
            }

            @Override
            public boolean isFolder() {
                return false;
            }

            @Override
            public String getName() {
                return "SCRIPT.ceylon";
            }

            @Override
            public String getPath() {
                return getName();
            }

            @Override
            public String getRelativePath(VirtualFile file) {
                return "";
            }

            @Override
            public InputStream getInputStream() {
                return System.in;
            }

            @Override
            public List<VirtualFile> getChildren() {
                return Collections.emptyList();
            }

            @Override
            public int hashCode() {
                return getPath().hashCode();
            }

            @Override
            public boolean equals(Object obj) {
                if (obj instanceof VirtualFile) {
                    return ((VirtualFile) obj).getPath().equals(getPath());
                } else {
                    return super.equals(obj);
                }
            }

            @Override
            public int compareTo(VirtualFile o) {
                return getPath().compareTo(o.getPath());
            }
        };
        t0 = System.nanoTime();
        tcb = new TypeCheckerBuilder().addSrcDirectory(src);
    } else {
        t0 = System.nanoTime();
        tcb = new TypeCheckerBuilder();
        SourceArgumentsResolver resolver = new SourceArgumentsResolver(roots, resources, Constants.CEYLON_SUFFIX, Constants.JS_SUFFIX);
        resolver.cwd(cwd).expandAndParse(files, Backend.JavaScript);
        if (includeDependencies != null && !COMPILE_NEVER.equals(includeDependencies)) {
            // Determine any dependencies that might need compiling as well
            SourceDependencyResolver sdr = new SourceDependencyResolver(getModuleVersionReader(), roots, Backends.JS);
            if (sdr.traverseDependencies(resolver.getSourceFiles())) {
                for (ModuleVersionDetails mvd : sdr.getAdditionalModules()) {
                    if (COMPILE_FORCE.equals(includeDependencies) || (COMPILE_CHECK.equals(includeDependencies) && shouldRecompile(getOfflineRepositoryManager(), mvd.getModule(), mvd.getVersion(), ModuleQuery.Type.JS, true)) || (COMPILE_ONCE.equals(includeDependencies) && shouldRecompile(getOfflineRepositoryManager(), mvd.getModule(), mvd.getVersion(), ModuleQuery.Type.JS, false))) {
                        files.add(mvd.getModule());
                        resolver.expandAndParse(files, Backend.JavaScript);
                    }
                }
            }
        }
        onlySources = resolver.getSourceFiles();
        onlyResources = resolver.getResourceFiles();
        if (onlySources.isEmpty()) {
            String msg = CeylonCompileJsMessages.msg("error.no.sources");
            if (ModuleWildcardsHelper.onlyGlobArgs(files)) {
                throw new NonFatalToolMessage(msg);
            } else {
                throw new ToolUsageError(msg);
            }
        }
        if (opts.isVerbose()) {
            append("Adding source directories to typechecker:" + roots).newline();
        }
        for (File root : roots) {
            File cwdRoot = applyCwd(root);
            if (cwdRoot.exists() && cwdRoot.isDirectory()) {
                tcb.addSrcDirectory(cwdRoot);
            }
        }
        tcb.setSourceFiles(onlySources);
        if (!resolver.getSourceModules().isEmpty()) {
            tcb.setModuleFilters(resolver.getSourceModules());
        }
        tcb.statistics(opts.isProfile());
        JsModuleManagerFactory.setVerbose(opts.hasVerboseFlag("loader"));
        tcb.moduleManagerFactory(new JsModuleManagerFactory(encoding));
    }
    // getting the type checker does process all types in the source directory
    tcb.verbose(opts.hasVerboseFlag("ast")).setRepositoryManager(repoman);
    tcb.usageWarnings(false).encoding(encoding);
    typeChecker = tcb.getTypeChecker();
    t1 = System.nanoTime();
    TypeCache.doWithoutCaching(new Runnable() {

        @Override
        public void run() {
            typeChecker.process(true);
        }
    });
    t2 = System.nanoTime();
    JsCompiler jsc = new JsCompiler(typeChecker, opts);
    if (onlySources != null) {
        if (opts.isVerbose()) {
            append("Only these files will be compiled: " + onlySources).newline();
        }
        jsc.setSourceFiles(onlySources);
    }
    if (onlyResources != null) {
        jsc.setResourceFiles(onlyResources);
    }
    t3 = System.nanoTime();
    if (!jsc.generate()) {
        if (jsc.getExitCode() != 0) {
            if (throwOnError)
                throw new RuntimeException("Compiler exited with non-zero exit code: " + jsc.getExitCode());
            else {
                jsc.printErrorsAndCount(writer);
                System.exit(jsc.getExitCode());
            }
        }
        int count = jsc.printErrorsAndCount(writer);
        String msg = (count > 1) ? "There were %d errors." : "There was %d error.";
        flush();
        throw new CompilerErrorException(String.format(msg, count));
    } else {
        // We still call this here for any warning there might be
        jsc.printErrorsAndCount(writer);
    }
    t4 = System.nanoTime();
    if (opts.isProfile() || opts.hasVerboseFlag("benchmark")) {
        System.err.println("PROFILING INFORMATION");
        System.err.printf("TypeChecker creation:   %6d nanos%n", t1 - t0);
        System.err.printf("TypeChecker processing: %6d nanos%n", t2 - t1);
        System.err.printf("JS compiler creation:   %6d nanos%n", t3 - t2);
        System.err.printf("JS compilation:         %6d nanos%n", t4 - t3);
        System.out.println("Compilation finished.");
    }
}
Also used : VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) Options(org.eclipse.ceylon.compiler.js.util.Options) DefaultToolOptions(org.eclipse.ceylon.common.config.DefaultToolOptions) JsModuleManagerFactory(org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory) SourceArgumentsResolver(org.eclipse.ceylon.common.tools.SourceArgumentsResolver) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) SourceDependencyResolver(org.eclipse.ceylon.common.tools.SourceDependencyResolver) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) NonFatalToolMessage(org.eclipse.ceylon.common.tool.NonFatalToolMessage) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File)

Example 95 with RepositoryManager

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