Search in sources :

Example 6 with CeyloncTool

use of com.redhat.ceylon.compiler.java.tools.CeyloncTool in project ceylon-compiler by ceylon.

the class MiscTests method compileRuntime.

@Test
public void compileRuntime() {
    cleanCars("build/classes-runtime");
    java.util.List<File> sourceFiles = new ArrayList<File>();
    String ceylonSourcePath = "../ceylon.language/src";
    String javaSourcePath = "../ceylon.language/runtime";
    String[] ceylonPackages = { "ceylon.language", "ceylon.language.meta", "ceylon.language.impl", "ceylon.language.meta.declaration", "ceylon.language.meta.model", "ceylon.language.serialization" };
    // Native files
    FileFilter exceptions = new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            String filename = pathname.getName();
            filename = filename.substring(0, filename.lastIndexOf('.'));
            for (String s : new String[] { "Boolean", "Integer", "Float", "Character", "String", "Byte", "Array", "Tuple", "Exception", "AssertionError", "Callable", "flatten", "className", "integerRangeByIterable", "modules", "printStackTrace", "process", "Throwable", "type", "typeLiteral", "classDeclaration", "reach", "unflatten", "serialization", "PartialImpl" }) {
                if (s.equals(filename)) {
                    return true;
                }
            }
            if (filename.equals("annotations") && pathname.getParentFile().getName().equals("meta")) {
                return true;
            }
            return false;
        }
    };
    String[] extras = new String[] { "true", "false" };
    String[] modelExtras = new String[] { "classDeclaration", "annotations", "modules", "type", "typeLiteral" };
    String[] s11nExtras = new String[] { "PartialImpl" };
    for (String pkg : ceylonPackages) {
        File pkgDir = new File(ceylonSourcePath, pkg.replaceAll("\\.", "/"));
        File javaPkgDir = new File(javaSourcePath, pkg.replaceAll("\\.", "/"));
        File[] files = pkgDir.listFiles();
        if (files != null) {
            for (File src : files) {
                if (src.isFile() && src.getName().toLowerCase().endsWith(".ceylon")) {
                    String baseName = src.getName().substring(0, src.getName().length() - 7);
                    if (!exceptions.accept(src)) {
                        sourceFiles.add(src);
                    } else {
                        addJavaSourceFile(baseName, sourceFiles, javaPkgDir, false);
                    }
                }
            }
        }
    }
    // add extra files that are in Java
    File javaPkgDir = new File(javaSourcePath, "ceylon/language");
    for (String extra : extras) addJavaSourceFile(extra, sourceFiles, javaPkgDir, true);
    File javaModelPkgDir = new File(javaSourcePath, "ceylon/language/meta");
    for (String extra : modelExtras) addJavaSourceFile(extra, sourceFiles, javaModelPkgDir, true);
    File javaS11nPkgDir = new File(javaSourcePath, "ceylon/language/serialization");
    for (String extra : s11nExtras) addJavaSourceFile(extra, sourceFiles, javaS11nPkgDir, true);
    File javaS11nEPkgDir = new File(javaSourcePath, "ceylon/language/impl");
    for (String extra : new String[] { "reach" }) addJavaSourceFile(extra, sourceFiles, javaS11nEPkgDir, true);
    String[] javaPackages = { "com/redhat/ceylon/compiler/java", "com/redhat/ceylon/compiler/java/language", "com/redhat/ceylon/compiler/java/metadata", "com/redhat/ceylon/compiler/java/runtime/ide", "com/redhat/ceylon/compiler/java/runtime/metamodel", "com/redhat/ceylon/compiler/java/runtime/model", "com/redhat/ceylon/compiler/java/runtime/metamodel/decl", "com/redhat/ceylon/compiler/java/runtime/metamodel/meta", "com/redhat/ceylon/compiler/java/runtime/serialization" };
    for (String pkg : javaPackages) {
        File pkgDir = new File(javaSourcePath, pkg.replaceAll("\\.", "/"));
        File[] files = pkgDir.listFiles();
        if (files != null) {
            for (File src : files) {
                if (src.isFile() && src.getName().toLowerCase().endsWith(".java")) {
                    sourceFiles.add(src);
                }
            }
        }
    }
    CeyloncTool compiler;
    try {
        compiler = new CeyloncTool();
    } catch (VerifyError e) {
        System.err.println("ERROR: Cannot run tests! Did you maybe forget to configure the -Xbootclasspath/p: parameter?");
        throw e;
    }
    CeyloncFileManager fileManager = (CeyloncFileManager) compiler.getStandardFileManager(null, null, null);
    Iterable<? extends JavaFileObject> compilationUnits1 = fileManager.getJavaFileObjectsFromFiles(sourceFiles);
    String compilerSourcePath = ceylonSourcePath + File.pathSeparator + javaSourcePath;
    CeyloncTaskImpl task = (CeyloncTaskImpl) compiler.getTask(null, fileManager, null, Arrays.asList("-sourcepath", compilerSourcePath, "-d", "build/classes-runtime", "-Xbootstrapceylon", "-cp", getClassPathAsPathExcludingLanguageModule(), "-suppress-warnings", "ceylonNamespace"), null, compilationUnits1);
    Boolean result = task.call();
    Assert.assertEquals("Compilation failed", Boolean.TRUE, result);
}
Also used : ArrayList(java.util.ArrayList) CeyloncTool(com.redhat.ceylon.compiler.java.tools.CeyloncTool) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) FileFilter(java.io.FileFilter) File(java.io.File) CeyloncFileManager(com.redhat.ceylon.compiler.java.tools.CeyloncFileManager) Test(org.junit.Test)

Example 7 with CeyloncTool

use of com.redhat.ceylon.compiler.java.tools.CeyloncTool in project ceylon-compiler by ceylon.

the class MiscTests method debugIncrementalCompilationBug.

/**
     * This test is for when we need to debug an incremental compilation error from the IDE, to make
     * sure it is indeed a bug and find which bug it is, do not enable it by default, it's only there
     * for debugging purpose. Once the bug is found, add it where it belongs (not here).
     */
@Ignore
@Test
public void debugIncrementalCompilationBug() {
    java.util.List<File> sourceFiles = new ArrayList<File>();
    String sdkSourcePath = "../ceylon-sdk/source";
    String testSourcePath = "../ceylon-sdk/test-source";
    for (String s : new String[] { "../ceylon-sdk/source/ceylon/json/StringPrinter.ceylon", "../ceylon-sdk/test-source/test/ceylon/json/print.ceylon", "../ceylon-sdk/source/ceylon/json/Array.ceylon", "../ceylon-sdk/test-source/test/ceylon/json/use.ceylon", "../ceylon-sdk/source/ceylon/net/uri/Path.ceylon", "../ceylon-sdk/test-source/test/ceylon/net/run.ceylon", "../ceylon-sdk/source/ceylon/json/Printer.ceylon", "../ceylon-sdk/source/ceylon/json/Object.ceylon", "../ceylon-sdk/source/ceylon/net/uri/Query.ceylon", "../ceylon-sdk/test-source/test/ceylon/json/run.ceylon", "../ceylon-sdk/test-source/test/ceylon/net/connection.ceylon", "../ceylon-sdk/source/ceylon/json/parse.ceylon", "../ceylon-sdk/test-source/test/ceylon/json/parse.ceylon", "../ceylon-sdk/source/ceylon/net/uri/PathSegment.ceylon" }) {
        sourceFiles.add(new File(s));
    }
    CeyloncTool compiler;
    try {
        compiler = new CeyloncTool();
    } catch (VerifyError e) {
        System.err.println("ERROR: Cannot run tests! Did you maybe forget to configure the -Xbootclasspath/p: parameter?");
        throw e;
    }
    CeyloncFileManager fileManager = (CeyloncFileManager) compiler.getStandardFileManager(null, null, null);
    Iterable<? extends JavaFileObject> compilationUnits1 = fileManager.getJavaFileObjectsFromFiles(sourceFiles);
    String compilerSourcePath = sdkSourcePath + File.pathSeparator + testSourcePath;
    CeyloncTaskImpl task = (CeyloncTaskImpl) compiler.getTask(null, fileManager, null, Arrays.asList("-sourcepath", compilerSourcePath, "-d", "../ceylon-sdk/modules"), null, compilationUnits1);
    Boolean result = task.call();
    Assert.assertEquals("Compilation failed", Boolean.TRUE, result);
}
Also used : ArrayList(java.util.ArrayList) CeyloncTool(com.redhat.ceylon.compiler.java.tools.CeyloncTool) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) File(java.io.File) CeyloncFileManager(com.redhat.ceylon.compiler.java.tools.CeyloncFileManager) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with CeyloncTool

use of com.redhat.ceylon.compiler.java.tools.CeyloncTool in project ceylon-compiler by ceylon.

the class CompilerTests method getCompilerTask.

protected CeyloncTaskImpl getCompilerTask(List<String> initialOptions, DiagnosticListener<? super FileObject> diagnosticListener, List<String> modules, String... sourcePaths) {
    java.util.List<File> sourceFiles = new ArrayList<File>(sourcePaths.length);
    for (String file : sourcePaths) {
        sourceFiles.add(new File(getPackagePath(), file));
    }
    CeyloncTool runCompiler = makeCompiler();
    CeyloncFileManager runFileManager = makeFileManager(runCompiler, diagnosticListener);
    // make sure the destination repo exists
    new File(destDir).mkdirs();
    List<String> options = new LinkedList<String>();
    options.addAll(initialOptions);
    if (!options.contains("-src"))
        options.addAll(Arrays.asList("-src", getSourcePath()));
    if (!options.contains("-cacherep"))
        options.addAll(Arrays.asList("-cacherep", getCachePath()));
    if (!options.contains("-cp"))
        options.addAll(Arrays.asList("-cp", getClassPathAsPath()));
    boolean hasVerbose = false;
    for (String option : options) {
        if (option.startsWith("-verbose")) {
            hasVerbose = true;
            break;
        }
    }
    if (!hasVerbose)
        options.add("-verbose:ast,code");
    Iterable<? extends JavaFileObject> compilationUnits1 = runFileManager.getJavaFileObjectsFromFiles(sourceFiles);
    return runCompiler.getTask(null, runFileManager, diagnosticListener, options, modules, compilationUnits1);
}
Also used : ArrayList(java.util.ArrayList) CeyloncTool(com.redhat.ceylon.compiler.java.tools.CeyloncTool) File(java.io.File) CeyloncFileManager(com.redhat.ceylon.compiler.java.tools.CeyloncFileManager) LinkedList(java.util.LinkedList)

Aggregations

CeyloncTool (com.redhat.ceylon.compiler.java.tools.CeyloncTool)8 ArrayList (java.util.ArrayList)7 CeyloncFileManager (com.redhat.ceylon.compiler.java.tools.CeyloncFileManager)6 File (java.io.File)6 CeyloncTaskImpl (com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl)5 ErrorCollector (com.redhat.ceylon.compiler.java.test.ErrorCollector)3 Test (org.junit.Test)3 JavacTask (com.sun.source.util.JavacTask)2 LinkedList (java.util.LinkedList)2 JavacFileManager (com.sun.tools.javac.file.JavacFileManager)1 FileFilter (java.io.FileFilter)1 StringWriter (java.io.StringWriter)1 Ignore (org.junit.Ignore)1