コード例 #1
0
 private String dubImportPath(String rootPath) {
   String pathUrl = VirtualFileManager.constructUrl(LocalFileSystem.PROTOCOL, rootPath);
   VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(pathUrl);
   if (file == null) {
     return null;
   }
   final List<String> sourcesDir = new ArrayList<>();
   VfsUtilCore.visitChildrenRecursively(
       file,
       new VirtualFileVisitor() {
         @Override
         public boolean visitFile(@NotNull VirtualFile file) {
           if (file.isDirectory()) {
             if (file.getName().equals("source")) {
               sourcesDir.add("source");
             }
             if (file.getName().equals("src")) {
               sourcesDir.add("src");
             }
           }
           return true;
         }
       });
   return sourcesDir.isEmpty() ? null : rootPath + File.separator + sourcesDir.get(0);
 }
コード例 #2
0
ファイル: JetCompiler.java プロジェクト: vpesochi/kotlin
  private static URLClassLoader createClassloader(File kotlinHome, CompileContext context) {
    List<File> jars = kompilerClasspath(kotlinHome, context);
    URL[] urls = new URL[jars.size()];
    for (int i = 0; i < urls.length; i++) {
      try {
        urls[i] = jars.get(i).toURI().toURL();
      } catch (MalformedURLException e) {
        throw new RuntimeException(
            e); // Checked exceptions are great! I love them, and I love brilliant library designers
        // too!
      }
    }

    return new URLClassLoader(urls, null);
  }
コード例 #3
0
ファイル: JetCompiler.java プロジェクト: vpesochi/kotlin
  @Override
  public void compile(
      final CompileContext compileContext,
      Chunk<Module> moduleChunk,
      final VirtualFile[] virtualFiles,
      OutputSink outputSink) {
    if (virtualFiles.length == 0) return;

    List<VirtualFile> productionFiles = new ArrayList<VirtualFile>();
    List<VirtualFile> testFiles = new ArrayList<VirtualFile>();
    for (VirtualFile file : virtualFiles) {
      final boolean inTests = ((CompileContextEx) compileContext).isInTestSourceContent(file);
      if (inTests) {
        testFiles.add(file);
      } else {
        productionFiles.add(file);
      }
    }

    final Module module = compileContext.getModuleByFile(virtualFiles[0]);

    doCompile(compileContext, moduleChunk, productionFiles, module, false);
    doCompile(compileContext, moduleChunk, testFiles, module, true);
  }
コード例 #4
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);
  }