/** * {@code CompileEnvironment#compileModules} wrapper. * * @param module compilation module file * @param jar compilation destination jar * @param includeRuntime whether Kotlin runtime library is included in destination jar * @param stdlib "kotlin-runtime.jar" path * @param classpath compilation classpath, can be <code>null</code> or empty * @param enableInline * @param enableOptimization */ public void moduleToJar( @NotNull String module, @NotNull String jar, boolean includeRuntime, @Nullable String stdlib, @Nullable String[] classpath, @Nullable String[] externalAnnotationsPath, boolean enableInline, boolean enableOptimization) { try { ModuleScriptData moduleScriptData = loadModuleDescriptions( getKotlinPathsForAntTask(), module, MessageCollectorPlainTextToStream.PLAIN_TEXT_TO_SYSTEM_ERR); List<Module> modules = moduleScriptData.getModules(); List<String> sourcesRoots = new ArrayList<String>(); for (Module m : modules) { sourcesRoots.addAll(m.getSourceFiles()); } CompilerConfiguration configuration = createConfiguration( stdlib, classpath, externalAnnotationsPath, sourcesRoots.toArray(new String[0]), enableInline, enableOptimization); File directory = new File(module).getParentFile(); boolean success = KotlinToJVMBytecodeCompiler.compileModules( configuration, modules, directory, new File(jar), includeRuntime); if (!success) { throw new CompileEnvironmentException(errorMessage(new String[] {module}, false)); } } catch (Exception e) { throw new CompileEnvironmentException(errorMessage(new String[] {module}, true), e); } }
/** * {@code CompileEnvironment#compileBunchOfSources} wrapper. * * @param src compilation source (directories or files) * @param output compilation destination directory * @param stdlib "kotlin-runtime.jar" path * @param classpath compilation classpath, can be <code>null</code> or empty */ public void sourcesToDir( @NotNull String[] src, @NotNull String output, @Nullable String stdlib, @Nullable String[] classpath, @Nullable String[] externalAnnotationsPath, boolean enableInline, boolean enableOptimization) { try { JetCoreEnvironment environment = env(stdlib, classpath, externalAnnotationsPath, src, enableInline, enableOptimization); boolean success = KotlinToJVMBytecodeCompiler.compileBunchOfSources( environment, null, new File(output), true); if (!success) { throw new CompileEnvironmentException(errorMessage(src, false)); } } catch (Exception e) { throw new CompileEnvironmentException(errorMessage(src, true), e); } }