コード例 #1
0
  @SuppressWarnings("deprecation")
  public boolean compile(CompilerOptions options, CompilationListener listener) {
    CeyloncTool compiler = new CeyloncTool();
    com.redhat.ceylon.compiler.java.runtime.tools.impl.JavaCompilerImpl.CompilationListenerAdapter
        diagnosticListener =
            new com.redhat.ceylon.compiler.java.runtime.tools.impl.JavaCompilerImpl
                .CompilationListenerAdapter(listener);
    Writer writer = null;
    // FIXME: allow the user to capture stdout
    if (!options.isVerbose()) {
      // 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;
  }
コード例 #2
0
 @Ignore("M5: requires more bootstrap work, current support dates from summer 2011")
 @Test
 public void compileRuntime() {
   String sourcePath = "../ceylon.language/src";
   String[] packages = {"ceylon.language", "ceylon.language.descriptor"};
   java.util.List<File> sourceFiles = new ArrayList<File>();
   for (String pkg : packages) {
     File pkgDir = new File(sourcePath, pkg.replaceAll("\\.", "/"));
     for (File src : pkgDir.listFiles()) {
       if (src.isFile() && src.getName().toLowerCase().endsWith(".ceylon")) 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);
   CeyloncTaskImpl task =
       (CeyloncTaskImpl)
           compiler.getTask(
               null,
               fileManager,
               null,
               Arrays.asList(
                   "-sourcepath",
                   sourcePath,
                   "-d",
                   "build/classes-runtime",
                   "-Xbootstrapceylon",
                   "-verbose"),
               null,
               compilationUnits1);
   Boolean result = task.call();
   Assert.assertEquals("Compilation failed", Boolean.TRUE, result);
 }
コード例 #3
0
 @Test
 public void compileSDK() {
   String[] modules = {
     "collection", "dbc", "file", "interop.java", "io", "json", "math", "net", "process",
   };
   String sourcePrefix = "../ceylon-sdk/";
   // don't run this if the SDK is not checked out
   File sdkFile = new File(sourcePrefix);
   if (!sdkFile.exists()) return;
   StringBuilder sourcePath = new StringBuilder();
   java.util.List<String> moduleNames = new ArrayList<String>(modules.length);
   for (String module : modules) {
     moduleNames.add("ceylon." + module);
     if (sourcePath.length() > 0) sourcePath.append(File.pathSeparator);
     sourcePath.append(sourcePrefix).append(module).append(File.separator).append("source");
   }
   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);
   CeyloncTaskImpl task =
       (CeyloncTaskImpl)
           compiler.getTask(
               null,
               fileManager,
               null,
               Arrays.asList("-sourcepath", sourcePath.toString(), "-d", "build/classes-sdk"),
               moduleNames,
               null);
   Boolean result = task.call();
   Assert.assertEquals("Compilation failed", Boolean.TRUE, result);
 }