Search in sources :

Example 6 with CeyloncTool

use of org.eclipse.ceylon.compiler.java.tools.CeyloncTool in project ceylon by eclipse.

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("-out"))
        options.addAll(Arrays.asList("-out", destDir));
    if (!options.contains("-src"))
        options.addAll(Arrays.asList("-src", getSourcePath()));
    if (!options.contains("-cacherep"))
        options.addAll(Arrays.asList("-cacherep", getCachePath()));
    if (!options.contains("-sysrep"))
        options.addAll(Arrays.asList("-sysrep", getSysRepPath()));
    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(org.eclipse.ceylon.compiler.java.tools.CeyloncTool) ZipFile(java.util.zip.ZipFile) File(java.io.File) CeyloncFileManager(org.eclipse.ceylon.compiler.java.tools.CeyloncFileManager) LinkedList(java.util.LinkedList)

Example 7 with CeyloncTool

use of org.eclipse.ceylon.compiler.java.tools.CeyloncTool in project ceylon by eclipse.

the class CeylonDocToolTests method compileJavaModule.

private void compileJavaModule(String pathname, String... fileNames) throws Exception {
    CeyloncTool compiler = new CeyloncTool();
    List<String> options = Arrays.asList("-src", pathname, "-out", "build/ceylon-cars", "-sysrep", "../dist/dist/repo", "-cp", CompilerTests.getClassPathAsPath());
    JavacFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    List<String> qualifiedNames = new ArrayList<String>(fileNames.length);
    for (String name : fileNames) {
        qualifiedNames.add(pathname + File.separator + name);
    }
    Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjectsFromStrings(qualifiedNames);
    JavacTask task = compiler.getTask(null, null, null, options, null, fileObjects);
    Boolean ret = task.call();
    Assert.assertEquals("Compilation failed", Boolean.TRUE, ret);
}
Also used : JavacFileManager(org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager) CeyloncTool(org.eclipse.ceylon.compiler.java.tools.CeyloncTool) ArrayList(java.util.ArrayList) JavacTask(org.eclipse.ceylon.langtools.source.util.JavacTask)

Example 8 with CeyloncTool

use of org.eclipse.ceylon.compiler.java.tools.CeyloncTool in project ceylon by eclipse.

the class CeylonDocToolTests method compile.

private void compile(String pathname, String destDir, String moduleName) throws Exception {
    CeyloncTool compiler = new CeyloncTool();
    List<String> options = Arrays.asList("-src", pathname, "-out", destDir, "-sysrep", "../dist/dist/repo", "-cp", CompilerTests.getClassPathAsPath());
    JavacTask task = compiler.getTask(null, null, null, options, Arrays.asList(moduleName), null);
    Boolean ret = task.call();
    Assert.assertEquals("Compilation failed", Boolean.TRUE, ret);
}
Also used : CeyloncTool(org.eclipse.ceylon.compiler.java.tools.CeyloncTool) JavacTask(org.eclipse.ceylon.langtools.source.util.JavacTask)

Example 9 with CeyloncTool

use of org.eclipse.ceylon.compiler.java.tools.CeyloncTool in project ceylon by eclipse.

the class JavaCompilerImpl method compile.

@SuppressWarnings("deprecation")
@Override
public boolean compile(CompilerOptions options, CompilationListener listener) {
    CeyloncTool compiler = new CeyloncTool();
    CompilationListenerAdapter diagnosticListener = new CompilationListenerAdapter(listener);
    Writer writer = options.getOutWriter();
    if (!options.isVerbose() && writer == null) {
        // make the tool shut the hell up
        writer = new NullWriter();
    }
    JavacFileManager fileManager = compiler.getStandardFileManager(writer, diagnosticListener, null, null);
    Iterable<? extends JavaFileObject> compilationUnits = fileManager.getJavaFileObjectsFromFiles(options.getFiles());
    CeyloncTaskImpl compilerTask = compiler.getTask(null, fileManager, diagnosticListener, translateOptions(options), options.getModules(), compilationUnits);
    compilerTask.setTaskListener(diagnosticListener);
    ExitState state = compilerTask.call2();
    // print any helpful info if required
    if (options.isVerbose() && state.abortingException != null)
        state.abortingException.printStackTrace();
    return state.ceylonState == CeylonState.OK;
}
Also used : JavacFileManager(org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager) ExitState(org.eclipse.ceylon.compiler.java.launcher.Main.ExitState) CeyloncTool(org.eclipse.ceylon.compiler.java.tools.CeyloncTool) CeyloncTaskImpl(org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl) Writer(java.io.Writer)

Aggregations

CeyloncTool (org.eclipse.ceylon.compiler.java.tools.CeyloncTool)9 ArrayList (java.util.ArrayList)7 File (java.io.File)6 CeyloncFileManager (org.eclipse.ceylon.compiler.java.tools.CeyloncFileManager)6 CeyloncTaskImpl (org.eclipse.ceylon.compiler.java.tools.CeyloncTaskImpl)6 ErrorCollector (org.eclipse.ceylon.compiler.java.test.ErrorCollector)3 Test (org.junit.Test)3 LinkedList (java.util.LinkedList)2 JavacTask (org.eclipse.ceylon.langtools.source.util.JavacTask)2 JavacFileManager (org.eclipse.ceylon.langtools.tools.javac.file.JavacFileManager)2 FileFilter (java.io.FileFilter)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 ZipFile (java.util.zip.ZipFile)1 ExitState (org.eclipse.ceylon.compiler.java.launcher.Main.ExitState)1 Ignore (org.junit.Ignore)1