Search in sources :

Example 6 with CeyloncTaskImpl

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

the class CompilerTests method compareWithJavaSource.

protected void compareWithJavaSource(List<String> options, String java, String... ceylon) {
    // make a compiler task
    // FIXME: runFileManager.setSourcePath(dir);
    ErrorCollector collector = new ErrorCollector();
    CeyloncTaskImpl task = getCompilerTask(options, collector, ceylon);
    // grab the CU after we've completed it
    class Listener implements TaskListener {

        JCCompilationUnit compilationUnit;

        private String compilerSrc;

        @Override
        public void started(TaskEvent e) {
        }

        @Override
        public void finished(TaskEvent e) {
            if (e.getKind() == Kind.ENTER) {
                if (compilationUnit == null) {
                    compilationUnit = (JCCompilationUnit) e.getCompilationUnit();
                    // for some reason compilationUnit is full here in the listener, but empty as soon
                    // as the compile task is done. probably to clean up for the gc?
                    compilerSrc = normalizeLineEndings(compilationUnit.toString());
                }
            }
        }
    }
    Listener listener = new Listener();
    task.setTaskListener(listener);
    // now compile it all the way
    assertCompilesOk(collector, task.call2());
    // now look at what we expected
    File expectedSrcFile = new File(getPackagePath(), java);
    String expectedSrc = normalizeLineEndings(readFile(expectedSrcFile)).trim();
    String compiledSrc = listener.compilerSrc.trim();
    // THIS IS FOR INTERNAL USE ONLY!!!
    // Can be used to do batch updating of known correct tests
    // Uncomment only when you know what you're doing!
    //        if (expectedSrc != null && compiledSrc != null && !expectedSrc.equals(compiledSrc)) {
    //            writeFile(expectedSrcFile, compiledSrc);
    //            expectedSrc = compiledSrc;
    //        }
    Assert.assertEquals("Source code differs", expectedSrc, compiledSrc);
}
Also used : JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) TaskListener(com.sun.source.util.TaskListener) DiagnosticListener(javax.tools.DiagnosticListener) TaskEvent(com.sun.source.util.TaskEvent) TaskListener(com.sun.source.util.TaskListener) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) File(java.io.File)

Example 7 with CeyloncTaskImpl

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

the class CompilerTests method compareWithJavaSourceWithPositions.

protected void compareWithJavaSourceWithPositions(String name) {
    // make a compiler task
    // FIXME: runFileManager.setSourcePath(dir);
    CeyloncTaskImpl task = getCompilerTask(new String[] { name + ".ceylon" });
    // grab the CU after we've completed it
    class Listener implements TaskListener {

        JCCompilationUnit compilationUnit;

        private String compilerSrc;

        private JavaPositionsRetriever javaPositionsRetriever = new JavaPositionsRetriever();

        @Override
        public void started(TaskEvent e) {
            AbstractTransformer.trackNodePositions(javaPositionsRetriever);
        }

        @Override
        public void finished(TaskEvent e) {
            if (e.getKind() == Kind.ENTER) {
                if (compilationUnit == null) {
                    compilationUnit = (JCCompilationUnit) e.getCompilationUnit();
                    // for some reason compilationUnit is full here in the listener, but empty as soon
                    // as the compile task is done. probably to clean up for the gc?
                    javaPositionsRetriever.retrieve(compilationUnit);
                    compilerSrc = normalizeLineEndings(javaPositionsRetriever.getJavaSourceCodeWithCeylonPositions());
                    AbstractTransformer.trackNodePositions(null);
                }
            }
        }
    }
    Listener listener = new Listener();
    task.setTaskListener(listener);
    // now compile it all the way
    ExitState exitState = task.call2();
    Assert.assertEquals("Compilation failed", CeylonState.OK, exitState.ceylonState);
    // now look at what we expected
    String expectedSrc = normalizeLineEndings(readFile(new File(getPackagePath(), name + ".src"))).trim();
    String compiledSrc = listener.compilerSrc.trim();
    Assert.assertEquals("Source code differs", expectedSrc, compiledSrc);
}
Also used : JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) TaskListener(com.sun.source.util.TaskListener) DiagnosticListener(javax.tools.DiagnosticListener) ExitState(com.redhat.ceylon.compiler.java.launcher.Main.ExitState) TaskEvent(com.sun.source.util.TaskEvent) TaskListener(com.sun.source.util.TaskListener) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) JavaPositionsRetriever(com.redhat.ceylon.compiler.java.codegen.JavaPositionsRetriever) File(java.io.File)

Example 8 with CeyloncTaskImpl

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

the class CompilerTests method compareWithJavaSourceWithLines.

protected void compareWithJavaSourceWithLines(String name) {
    // make a compiler task
    // FIXME: runFileManager.setSourcePath(dir);
    CeyloncTaskImpl task = getCompilerTask(new String[] { name + ".ceylon" });
    // grab the CU after we've completed it
    class Listener implements TaskListener {

        JCCompilationUnit compilationUnit;

        private String compilerSrc;

        private JavaPositionsRetriever javaPositionsRetriever = new JavaPositionsRetriever();

        @Override
        public void started(TaskEvent e) {
        }

        @Override
        public void finished(TaskEvent e) {
            if (e.getKind() == Kind.ENTER) {
                if (compilationUnit == null) {
                    compilationUnit = (JCCompilationUnit) e.getCompilationUnit();
                    // for some reason compilationUnit is full here in the listener, but empty as soon
                    // as the compile task is done. probably to clean up for the gc?
                    javaPositionsRetriever.retrieve(compilationUnit);
                    compilerSrc = normalizeLineEndings(javaPositionsRetriever.getJavaSourceCodeWithCeylonLines());
                    AbstractTransformer.trackNodePositions(null);
                }
            }
        }
    }
    Listener listener = new Listener();
    task.setTaskListener(listener);
    // now compile it all the way
    ExitState exitState = task.call2();
    Assert.assertEquals("Compilation failed", exitState.ceylonState, CeylonState.OK);
    // now look at what we expected
    String expectedSrc = normalizeLineEndings(readFile(new File(getPackagePath(), name + ".src"))).trim();
    String compiledSrc = listener.compilerSrc.trim();
    Assert.assertEquals("Source code differs", expectedSrc, compiledSrc);
}
Also used : JCCompilationUnit(com.sun.tools.javac.tree.JCTree.JCCompilationUnit) TaskListener(com.sun.source.util.TaskListener) DiagnosticListener(javax.tools.DiagnosticListener) ExitState(com.redhat.ceylon.compiler.java.launcher.Main.ExitState) TaskEvent(com.sun.source.util.TaskEvent) TaskListener(com.sun.source.util.TaskListener) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) JavaPositionsRetriever(com.redhat.ceylon.compiler.java.codegen.JavaPositionsRetriever) File(java.io.File)

Example 9 with CeyloncTaskImpl

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

the class CMRTests method testMdlDependenciesNoOverride.

@Test
public void testMdlDependenciesNoOverride() throws IOException {
    CeyloncTaskImpl ceylonTask = getCompilerTask(Arrays.asList("-out", destDir), "modules/overrides/module.ceylon", "modules/overrides/test.ceylon");
    assertEquals("Compilation failed", Boolean.TRUE, ceylonTask.call());
}
Also used : CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) Test(org.junit.Test)

Example 10 with CeyloncTaskImpl

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

the class MiscTests method compileSDKOnly.

private void compileSDKOnly(String[] modules, String[] extraModules) {
    String sourceDir = "../ceylon-sdk/source";
    // don't run this if the SDK is not checked out
    File sdkFile = new File(sourceDir);
    if (!sdkFile.exists())
        return;
    java.util.List<String> moduleNames = new ArrayList<String>(modules.length);
    for (String module : modules) {
        moduleNames.add("ceylon." + module);
    }
    for (String module : extraModules) {
        moduleNames.add(module);
    }
    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;
    }
    ErrorCollector errorCollector = new ErrorCollector();
    CeyloncFileManager fileManager = (CeyloncFileManager) compiler.getStandardFileManager(null, null, null);
    CeyloncTaskImpl task = (CeyloncTaskImpl) compiler.getTask(null, fileManager, errorCollector, Arrays.asList("-sourcepath", sourceDir, "-d", "build/classes-sdk", "-suppress-warnings", "ceylonNamespace", "-cp", getClassPathAsPath()), moduleNames, null);
    Boolean result = task.call();
    Assert.assertEquals("Compilation of SDK itself failed: " + errorCollector.getAssertionFailureMessage(), Boolean.TRUE, result);
}
Also used : ArrayList(java.util.ArrayList) CeyloncTool(com.redhat.ceylon.compiler.java.tools.CeyloncTool) ErrorCollector(com.redhat.ceylon.compiler.java.test.ErrorCollector) CeyloncTaskImpl(com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl) File(java.io.File) CeyloncFileManager(com.redhat.ceylon.compiler.java.tools.CeyloncFileManager)

Aggregations

CeyloncTaskImpl (com.redhat.ceylon.compiler.java.tools.CeyloncTaskImpl)53 Test (org.junit.Test)43 File (java.io.File)27 JarFile (java.util.jar.JarFile)19 ErrorCollector (com.redhat.ceylon.compiler.java.test.ErrorCollector)18 LinkedList (java.util.LinkedList)18 ZipEntry (java.util.zip.ZipEntry)13 CompilerError (com.redhat.ceylon.compiler.java.test.CompilerError)11 ZipFile (java.util.zip.ZipFile)8 ExitState (com.redhat.ceylon.compiler.java.launcher.Main.ExitState)6 CeyloncFileManager (com.redhat.ceylon.compiler.java.tools.CeyloncFileManager)5 CeyloncTool (com.redhat.ceylon.compiler.java.tools.CeyloncTool)5 ArrayList (java.util.ArrayList)5 TaskEvent (com.sun.source.util.TaskEvent)4 TaskListener (com.sun.source.util.TaskListener)4 Module (com.redhat.ceylon.model.typechecker.model.Module)3 JCCompilationUnit (com.sun.tools.javac.tree.JCTree.JCCompilationUnit)3 DiagnosticListener (javax.tools.DiagnosticListener)3 Ignore (org.junit.Ignore)3 JavaPositionsRetriever (com.redhat.ceylon.compiler.java.codegen.JavaPositionsRetriever)2