Search in sources :

Example 1 with JsModuleManagerFactory

use of org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory in project ceylon by eclipse.

the class MainForJsTest method main.

public static void main(String[] args) throws Exception {
    String distRepo = "../dist/dist/repo";
    final Options opts = new Options().addRepo(distRepo).outRepo("build/test/proto");
    System.out.println("Typechecking Ceylon test code...");
    JsModuleManagerFactory.setVerbose(true);
    TypeCheckerBuilder tcb = new TypeCheckerBuilder().verbose(false).moduleManagerFactory(new JsModuleManagerFactory(null)).usageWarnings(false);
    final ArrayList<File> excludes = new ArrayList<>();
    final ArrayList<File> resfiles = new ArrayList<>();
    final ArrayList<File> resdirs = new ArrayList<>();
    for (String dir : args) {
        final File d = new File(dir.charAt(1) == ':' ? dir.substring(2) : dir);
        if (dir.startsWith("X:")) {
            excludes.add(d);
        } else if (dir.startsWith("R:")) {
            resdirs.add(d);
        } else if (dir.startsWith("r:")) {
            resfiles.add(d);
        } else if (dir.startsWith("c:")) {
            opts.cwd(d);
        } else {
            tcb.addSrcDirectory(d);
            opts.addSrcDir(d);
        }
    }
    final RepositoryManager repoman = CeylonUtils.repoManager().cwd(opts.getCwd()).systemRepo(opts.getSystemRepo()).userRepos(opts.getRepos()).outRepo(opts.getOutRepo()).buildManager();
    tcb.setRepositoryManager(repoman);
    final TypeChecker typeChecker = tcb.getTypeChecker();
    for (File x : excludes) {
        String ap = x.getPath();
        // Fix for Windows
        if ('/' != File.separatorChar) {
            ap = ap.replace(File.separatorChar, '/');
        }
        for (PhasedUnit pu : typeChecker.getPhasedUnits().getPhasedUnits()) {
            if (pu.getUnit().getFullPath().startsWith(ap)) {
                typeChecker.getPhasedUnits().removePhasedUnitForRelativePath(pu.getPathRelativeToSrcDir());
            }
        }
    }
    TypeCache.doWithoutCaching(new Runnable() {

        @Override
        public void run() {
            typeChecker.process();
        }
    });
    if (typeChecker.getErrors() > 0) {
        System.exit(1);
    }
    System.out.println("Compiling in prototype style");
    opts.resourceDirs(resdirs);
    JsCompiler jsc = new JsCompiler(typeChecker, opts).stopOnErrors(true);
    ArrayList<File> sources = new ArrayList<>();
    for (String dir : args) {
        // The arg is src/test/ceylon for example
        addFilesToList(new File(dir), sources);
    }
    Collections.sort(sources);
    jsc.setSourceFiles(sources);
    jsc.setResourceFiles(resfiles);
    PrintWriter writer = new PrintWriter(System.out);
    if (!jsc.generate()) {
        jsc.printErrorsAndCount(writer);
    }
}
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) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) PhasedUnit(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) File(java.io.File) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler) PrintWriter(java.io.PrintWriter)

Example 2 with JsModuleManagerFactory

use of org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory in project ceylon by eclipse.

the class TestModuleManager method loadJsModel.

private static void loadJsModel() {
    if (jstc == null) {
        System.out.println("Pass 2: Loading model from JS");
        final RepositoryManager repoman = CeylonUtils.repoManager().cwd(options.getCwd()).systemRepo(options.getSystemRepo()).userRepos(options.getRepos()).outRepo(options.getOutRepo()).buildManager();
        // .verbose(true);
        TypeCheckerBuilder tcb = new TypeCheckerBuilder().usageWarnings(false);
        tcb.moduleManagerFactory(new JsModuleManagerFactory((String) null));
        tcb.addSrcDirectory(new java.io.File("src/test/resources/loader/pass2"));
        tcb.setRepositoryManager(repoman);
        jstc = tcb.getTypeChecker();
        jstc.process();
    }
}
Also used : JsModuleManagerFactory(org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)

Example 3 with JsModuleManagerFactory

use of org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory 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 4 with JsModuleManagerFactory

use of org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory in project ceylon by eclipse.

the class TestMultipackages method test.

@Test
public void test() throws IOException {
    // Compile module with 2 packages
    System.out.println("Compiling usemulti");
    TypeCheckerBuilder tcb = new TypeCheckerBuilder().usageWarnings(false);
    tcb.moduleManagerFactory(new JsModuleManagerFactory("UTF-8"));
    tcb.addSrcDirectory(new java.io.File("src/test/resources/multi/pass2"));
    tcb.setRepositoryManager(repoman);
    TypeChecker tc = tcb.getTypeChecker();
    tc.process();
    Options options = new Options().addRepo("build/test/test_modules").outRepo("build/test/test_modules").addSrcDir("src/test/resources/multi/pass2").verbose("");
    JsCompiler compiler = new JsCompiler(tc, options);
    compiler.stopOnErrors(false);
    compiler.generate();
}
Also used : JsModuleManagerFactory(org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory) Options(org.eclipse.ceylon.compiler.js.util.Options) TypeChecker(org.eclipse.ceylon.compiler.typechecker.TypeChecker) TypeCheckerBuilder(org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder) JsCompiler(org.eclipse.ceylon.compiler.js.JsCompiler) Test(org.junit.Test)

Example 5 with JsModuleManagerFactory

use of org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory in project ceylon by eclipse.

the class TestSiteVariance method typeChecker.

private TypeChecker typeChecker(Options opts) {
    final RepositoryManager repoman = CeylonUtils.repoManager().userRepos(opts.getRepos()).outRepo(opts.getOutRepo()).buildManager();
    final TypeCheckerBuilder builder = new TypeCheckerBuilder().moduleManagerFactory(new JsModuleManagerFactory("UTF-8"));
    for (File sd : opts.getSrcDirs()) {
        builder.addSrcDirectory(sd);
    }
    builder.setRepositoryManager(repoman);
    final TypeChecker tc = builder.getTypeChecker();
    JsModuleManagerFactory.setVerbose(true);
    tc.process();
    return tc;
}
Also used : JsModuleManagerFactory(org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory) 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)

Aggregations

JsModuleManagerFactory (org.eclipse.ceylon.compiler.js.loader.JsModuleManagerFactory)6 TypeCheckerBuilder (org.eclipse.ceylon.compiler.typechecker.TypeCheckerBuilder)6 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)5 TypeChecker (org.eclipse.ceylon.compiler.typechecker.TypeChecker)5 File (java.io.File)4 Options (org.eclipse.ceylon.compiler.js.util.Options)4 JsCompiler (org.eclipse.ceylon.compiler.js.JsCompiler)3 ArrayList (java.util.ArrayList)2 PrintWriter (java.io.PrintWriter)1 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)1 DefaultToolOptions (org.eclipse.ceylon.common.config.DefaultToolOptions)1 NonFatalToolMessage (org.eclipse.ceylon.common.tool.NonFatalToolMessage)1 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)1 SourceArgumentsResolver (org.eclipse.ceylon.common.tools.SourceArgumentsResolver)1 SourceDependencyResolver (org.eclipse.ceylon.common.tools.SourceDependencyResolver)1 PhasedUnit (org.eclipse.ceylon.compiler.typechecker.context.PhasedUnit)1 VirtualFile (org.eclipse.ceylon.compiler.typechecker.io.VirtualFile)1 Test (org.junit.Test)1