コード例 #1
0
ファイル: JetCompiler.java プロジェクト: vpesochi/kotlin
  private static List<File> kompilerClasspath(File kotlinHome, CompileContext context) {
    File libs = new File(kotlinHome, "lib");

    if (!libs.exists() || libs.isFile()) {
      context.addMessage(
          ERROR,
          "Broken compiler at '"
              + libs.getAbsolutePath()
              + "'. Make sure plugin is properly installed",
          "",
          -1,
          -1);
      return Collections.emptyList();
    }

    ArrayList<File> answer = new ArrayList<File>();
    File[] jars = libs.listFiles();
    if (jars != null) {
      for (File jar : jars) {
        if (jar.isFile() && jar.getName().endsWith(".jar")) {
          answer.add(jar);
        }
      }
    }

    return answer;
  }
コード例 #2
0
ファイル: JetCompiler.java プロジェクト: vpesochi/kotlin
  private void doCompile(
      CompileContext compileContext,
      Chunk<Module> moduleChunk,
      List<VirtualFile> files,
      Module module,
      boolean tests) {
    if (files.isEmpty()) return;

    VirtualFile mainOutput = compileContext.getModuleOutputDirectory(module);
    final VirtualFile outputDir =
        tests ? compileContext.getModuleOutputDirectoryForTests(module) : mainOutput;
    if (outputDir == null) {
      compileContext.addMessage(ERROR, "[Internal Error] No output directory", "", -1, -1);
      return;
    }

    File kotlinHome = PathUtil.getDefaultCompilerPath();
    if (kotlinHome == null) {
      compileContext.addMessage(
          ERROR, "Cannot find kotlinc home. Make sure plugin is properly installed", "", -1, -1);
      return;
    }

    ModuleChunk chunk =
        new ModuleChunk(
            (CompileContextEx) compileContext,
            moduleChunk,
            Collections.<Module, List<VirtualFile>>emptyMap());
    String moduleName = moduleChunk.getNodes().iterator().next().getName();

    // Filter the output we are writing to
    Set<VirtualFile> outputDirectoriesToFilter =
        Sets.newHashSet(compileContext.getModuleOutputDirectoryForTests(module));
    if (!tests) {
      outputDirectoriesToFilter.add(compileContext.getModuleOutputDirectory(module));
    }
    CharSequence script =
        generateModuleScript(
            moduleName, chunk, files, tests, mainOutput, outputDirectoriesToFilter);

    File scriptFile = new File(path(outputDir), "script.kts");
    try {
      FileUtil.writeToFile(scriptFile, script.toString());
    } catch (IOException e) {
      compileContext.addMessage(
          ERROR,
          "[Internal Error] Cannot write script to " + scriptFile.getAbsolutePath(),
          "",
          -1,
          -1);
      return;
    }

    if (RUN_OUT_OF_PROCESS) {
      runOutOfProcess(compileContext, outputDir, kotlinHome, scriptFile);
    } else {
      runInProcess(compileContext, outputDir, kotlinHome, scriptFile);
    }

    //        compileContext.addMessage(INFORMATION, "Generated module script:\n" +
    // script.toString(), "file://" + path(mainOutput), 0, 1);
  }