Search in sources :

Example 46 with RepositoryManager

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

the class CeylonDocToolTests method compileSdkJavaFiles.

/**
 * This is disgusting, but the current CeylonDoc doesn't handle source files, so we need to compile them first,
 * and we do it using javac to avoid compiling the whole SDK for one java file.
 */
private void compileSdkJavaFiles() throws FileNotFoundException, IOException {
    // put it all in a special folder
    File dir = new File("build", "CeylonDocToolTest/" + name.getMethodName());
    if (dir.exists()) {
        FileUtil.delete(dir);
    }
    dir.mkdirs();
    // download a required jar
    RepositoryManager repoManager = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").buildManager();
    File jbossModulesModule = repoManager.getArtifact(new ArtifactContext(null, "org.jboss.modules", Versions.DEPENDENCY_JBOSS_MODULES_VERSION, ".jar"));
    File runtimeModule = repoManager.getArtifact(new ArtifactContext(null, "ceylon.runtime", Versions.CEYLON_VERSION_NUMBER, ".jar"));
    File modelModule = repoManager.getArtifact(new ArtifactContext(null, "org.eclipse.ceylon.model", Versions.CEYLON_VERSION_NUMBER, ".jar"));
    File undertowCoreModule = repoManager.getArtifact(new ArtifactContext(null, "io.undertow.core", "1.3.5.Final", ".jar"));
    File languageModule = repoManager.getArtifact(new ArtifactContext(null, AbstractModelLoader.CEYLON_LANGUAGE, TypeChecker.LANGUAGE_MODULE_VERSION, ".car"));
    // fire up the java compiler
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    assertNotNull("Missing Java compiler, this test is probably being run with a JRE instead of a JDK!", compiler);
    List<String> options = Arrays.asList("-sourcepath", "../../ceylon-sdk/source", "-d", dir.getAbsolutePath(), "-classpath", undertowCoreModule.getAbsolutePath() + File.pathSeparator + jbossModulesModule.getAbsolutePath() + File.pathSeparator + runtimeModule.getAbsolutePath() + File.pathSeparator + modelModule.getAbsolutePath() + File.pathSeparator + languageModule.getAbsolutePath());
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    String[] fileNames = new String[] { "ceylon/interop/java/internal/javaBooleanArray_.java", "ceylon/interop/java/internal/javaByteArray_.java", "ceylon/interop/java/internal/javaCharArray_.java", "ceylon/interop/java/internal/javaDoubleArray_.java", "ceylon/interop/java/internal/javaFloatArray_.java", "ceylon/interop/java/internal/javaIntArray_.java", "ceylon/interop/java/internal/javaLongArray_.java", "ceylon/interop/java/internal/javaObjectArray_.java", "ceylon/interop/java/internal/javaShortArray_.java", "ceylon/interop/java/internal/javaStringArray_.java", "ceylon/interop/java/internal/synchronize_.java" };
    List<String> qualifiedNames = new ArrayList<String>(fileNames.length);
    for (String name : fileNames) {
        qualifiedNames.add("../../ceylon-sdk/source/" + name);
    }
    Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjectsFromStrings(qualifiedNames);
    CompilationTask task = compiler.getTask(null, null, null, options, null, fileObjects);
    Boolean ret = task.call();
    Assert.assertEquals("Compilation failed", Boolean.TRUE, ret);
    // now we need to zip it up
    makeCarFromClassFiles(dir, fileNames, "ceylon.test", Versions.CEYLON_VERSION_NUMBER);
    makeCarFromClassFiles(dir, fileNames, "ceylon.http.server", Versions.CEYLON_VERSION_NUMBER);
    makeCarFromClassFiles(dir, fileNames, "ceylon.interop.java", Versions.CEYLON_VERSION_NUMBER);
    makeCarFromClassFiles(dir, fileNames, "ceylon.transaction", Versions.CEYLON_VERSION_NUMBER);
}
Also used : ArrayList(java.util.ArrayList) JavaCompiler(org.eclipse.ceylon.javax.tools.JavaCompiler) StandardJavaFileManager(org.eclipse.ceylon.javax.tools.StandardJavaFileManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) File(java.io.File) CompilationTask(org.eclipse.ceylon.javax.tools.JavaCompiler.CompilationTask)

Example 47 with RepositoryManager

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

the class MainForTest method main.

/**
 * Files that are not under a proper module structure are
 * placed under a <nomodule> module.
 */
public static void main(String[] args) throws Exception {
    long start = System.nanoTime();
    RepositoryManager repositoryManager = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").outRepo("test/modules").logger(new LeakingLogger()).buildManager();
    TypeChecker typeChecker = new TypeCheckerBuilder().statistics(true).verbose(false).addSrcDirectory(new File("test/main")).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    int errors = typeChecker.getErrors();
    Tree.CompilationUnit compilationUnit = typeChecker.getPhasedUnitFromRelativePath("ceylon/language/Object.ceylon").getCompilationUnit();
    if (compilationUnit == null) {
        throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for files in .src");
    }
    compilationUnit = typeChecker.getPhasedUnitFromRelativePath("capture/Capture.ceylon").getCompilationUnit();
    if (compilationUnit == null) {
        throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for files in real src dir");
    }
    compilationUnit = typeChecker.getPhasedUnitFromRelativePath("org/eclipse/sample/multisource/Boo.ceylon").getCompilationUnit();
    Module module = compilationUnit.getUnit().getPackage().getModule();
    if (!"org.eclipse.sample.multisource".equals(module.getNameAsString())) {
        throw new RuntimeException("Unable to extract module name");
    }
    if (!"0.2".equals(module.getVersion())) {
        throw new RuntimeException("Unable to extract module version");
    }
    typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(new File("test/main/capture")).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    errors += typeChecker.getErrors();
    compilationUnit = typeChecker.getPhasedUnitFromRelativePath("Capture.ceylon").getCompilationUnit();
    if (compilationUnit == null) {
        throw new RuntimeException("Failed to pass getCompilationUnitFromRelativePath for top level files (no package) in real src dir");
    }
    typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(new File("test/moduledep1")).addSrcDirectory(new File("test/moduledep2")).addSrcDirectory(new File("test/moduletest")).addSrcDirectory(new File("test/restricted")).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    errors += typeChecker.getErrors();
    ClosableVirtualFile latestZippedLanguageSourceFile = MainHelper.getLatestZippedLanguageSourceFile();
    typeChecker = new TypeCheckerBuilder().verbose(false).addSrcDirectory(latestZippedLanguageSourceFile).setRepositoryManager(repositoryManager).getTypeChecker();
    typeChecker.process();
    errors += typeChecker.getErrors();
    latestZippedLanguageSourceFile.close();
    System.out.println("Tests took " + ((System.nanoTime() - start) / 1000000) + " ms");
    if (errors > 0) {
        System.exit(1);
    }
}
Also used : ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) LeakingLogger(org.eclipse.ceylon.compiler.typechecker.io.cmr.impl.LeakingLogger) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) Module(org.eclipse.ceylon.model.typechecker.model.Module) ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) File(java.io.File)

Example 48 with RepositoryManager

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

the class CeylonP2Tool method run.

@Override
public void run() throws Exception {
    RepositoryManager repoManager = getRepositoryManager();
    Map<String, ModuleInfo> allModules = new HashMap<>();
    for (ModuleSpec module : modules) {
        String version = findModuleVersion(module);
        msg("collecting.modules", module.toString());
        newline();
        collectModules(repoManager, module.getName(), version, allModules);
    }
    // now purge empty modules
    purgeMissingModules(allModules);
    Map<String, Feature> features = collectFeatures();
    Map<String, Category> categoriesByName = null;
    if (categories != null) {
        categoriesByName = parseCategories(features);
    }
    msg("generating.artifacts");
    newline();
    printArtifacts(allModules, features);
    msg("generating.content");
    newline();
    printContent(allModules, features, categoriesByName);
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) HashMap(java.util.HashMap) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager)

Example 49 with RepositoryManager

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

the class CompileSomething method main.

public static void main(String[] x) throws IOException {
    final Options opts = new Options().outRepo("/tmp/modules").addRepo("compiler-js/build/runtime").addRepo("../ceylon.ast/modules").addRepo("../ceylon-sdk/modules").addRepo("compiler-js/build/test/proto").addRepo("npm:").optimize(true).verbose("all").generateSourceArchive(false).suppressWarnings(EnumUtil.enumsFromStrings(Warning.class, Arrays.asList("unusedImport"))).addSrcDir("/tmp/source");
    final TypeCheckerBuilder tcb = new TypeCheckerBuilder().statistics(false).encoding("UTF-8");
    for (File sd : opts.getSrcDirs()) {
        tcb.addSrcDirectory(sd);
    }
    final RepositoryManager repoman = CeylonUtils.repoManager().systemRepo(opts.getSystemRepo()).userRepos(opts.getRepos()).outRepo(opts.getOutRepo()).buildManager();
    tcb.setRepositoryManager(repoman);
    JsModuleManagerFactory.setVerbose(true);
    tcb.moduleManagerFactory(new JsModuleManagerFactory("UTF-8"));
    final TypeChecker tc = tcb.getTypeChecker();
    TypeCache.setEnabled(false);
    tc.process(true);
    TypeCache.setEnabled(true);
    final JsCompiler jsc = new JsCompiler(tc, opts);
    ArrayList<File> individualSources = new ArrayList<>();
    for (File srcdir : opts.getSrcDirs()) {
        for (File sd : srcdir.listFiles()) {
            if (sd.isFile() && sd.getName().endsWith(".js") || !individualSources.isEmpty()) {
                System.out.println("Especificando archivos para incluir fuentes js");
                individualSources.addAll(Arrays.asList(srcdir.listFiles()));
                break;
            }
        }
    }
    if (!individualSources.isEmpty()) {
        jsc.setSourceFiles(individualSources);
    }
    jsc.stopOnErrors(true);
    boolean ok = jsc.generate();
    jsc.printErrors(new java.io.PrintWriter(System.out));
    if (ok) {
        System.out.println("OK");
    } else {
        System.out.println("EXIT CODE: " + jsc.getExitCode());
    }
}
Also used : Options(org.eclipse.ceylon.compiler.js.util.Options) JsModuleManagerFactory(org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) ArrayList(java.util.ArrayList) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) File(java.io.File) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler)

Example 50 with RepositoryManager

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

the class TestJavaDeps method testJavaDependencies.

@Test
public void testJavaDependencies() throws IOException {
    final RepositoryManager repoman = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").outRepo("test-modules").buildManager();
    final TypeCheckerBuilder builder = new TypeCheckerBuilder().setRepositoryManager(repoman).addSrcDirectory(new File("src/test/resources/javadeps"));
    final TypeChecker tc = builder.getTypeChecker();
    tc.process();
    final Options opts = new Options().addSrcDir("src/test/resources/javadeps").outRepo("./build").comment(false).generateSourceArchive(false).encoding("UTF-8");
    final JsCompiler comp = new JsCompiler(tc, opts);
    comp.generate();
}
Also used : Options(org.eclipse.ceylon.compiler.js.util.Options) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) File(java.io.File) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler) 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