예제 #1
0
  private CompilerConfiguration createConfiguration(
      @Nullable String stdlib,
      @Nullable String[] classpath,
      @Nullable String[] externalAnnotationsPath,
      @NotNull String[] sourceRoots,
      boolean enableInline,
      boolean enableOptimization) {
    KotlinPaths paths = getKotlinPathsForAntTask();
    CompilerConfiguration configuration = new CompilerConfiguration();
    configuration.addAll(CLASSPATH_KEY, PathUtil.getJdkClassesRoots());
    if ((stdlib != null) && (stdlib.trim().length() > 0)) {
      configuration.add(CLASSPATH_KEY, new File(stdlib));
    } else {
      File path = paths.getRuntimePath();
      if (path.exists()) {
        configuration.add(CLASSPATH_KEY, path);
      }
    }
    if ((classpath != null) && (classpath.length > 0)) {
      for (String path : classpath) {
        configuration.add(CLASSPATH_KEY, new File(path));
      }
    }
    if ((externalAnnotationsPath != null) && (externalAnnotationsPath.length > 0)) {
      for (String path : externalAnnotationsPath) {
        configuration.add(ANNOTATIONS_PATH_KEY, new File(path));
      }
    }
    File jdkAnnotationsPath = paths.getJdkAnnotationsPath();
    if (jdkAnnotationsPath.exists()) {
      configuration.add(ANNOTATIONS_PATH_KEY, jdkAnnotationsPath);
    }

    configuration.addAll(CommonConfigurationKeys.SOURCE_ROOTS_KEY, Arrays.asList(sourceRoots));
    for (String sourceRoot : sourceRoots) {
      File file = new File(sourceRoot);
      if (!file.isFile() || !"kt".equals(FileUtilRt.getExtension(file.getName()))) {
        configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, file);
      }
    }
    configuration.put(
        CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
        MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR);

    configuration.put(ENABLE_INLINE, enableInline);
    configuration.put(ENABLE_OPTIMIZATION, enableOptimization);

    // lets register any compiler plugins
    configuration.addAll(CLIConfigurationKeys.COMPILER_PLUGINS, getCompilerPlugins());
    return configuration;
  }
예제 #2
0
  public static List<File> kompilerClasspath(KotlinPaths paths, MessageCollector messageCollector) {
    File libs = paths.getLibPath();

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

    ArrayList<File> answer = new ArrayList<File>();
    answer.add(new File(libs, "kotlin-compiler.jar"));
    answer.add(new File(libs, "kotlin-runtime.jar"));
    return answer;
  }