From c09106fe6831446ca42ac68dc9d7923b06f7a4d4 Mon Sep 17 00:00:00 2001 From: James Strachan Date: Mon, 25 Jun 2012 10:03:46 +0100 Subject: [PATCH] fixed the JS maven plugin so it can generate a single JS file with all the required kotlin JS inside --- .../kotlin/maven/K2JSCompilerMojo.java | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java index c16feb6ba0f..fcc022ab026 100644 --- a/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java +++ b/libraries/tools/kotlin-maven-plugin/src/main/java/org/jetbrains/kotlin/maven/K2JSCompilerMojo.java @@ -85,13 +85,22 @@ public class K2JSCompilerMojo extends KotlinCompileMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { - if (appendLibraryJS != null && appendLibraryJS.booleanValue()) { - getLog().info("Appending Kotlin Library JS to the generated file " + outputFile); - - appendFile(KOTLIN_JS_LIB_ECMA3); - appendFile(KOTLIN_JS_LIB); - } super.execute(); + if (appendLibraryJS != null && appendLibraryJS.booleanValue()) { + try { + Charset charset = Charset.defaultCharset(); + File file = new File(outputFile); + String text = Files.toString(file, charset); + StringBuilder builder = new StringBuilder(); + appendFile(KOTLIN_JS_LIB_ECMA3, builder); + appendFile(KOTLIN_JS_LIB, builder); + builder.append("\n"); + builder.append(text); + Files.write(builder.toString(), file, charset); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage(), e); + } + } if (copyLibraryJS != null && copyLibraryJS.booleanValue()) { getLog().info("Copying kotlin JS library to " + outputKotlinJSDir); @@ -101,7 +110,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo { } } - protected void appendFile(String jsLib) throws MojoExecutionException { + protected void appendFile(String jsLib, StringBuilder builder) throws MojoExecutionException { // lets copy the kotlin library into the output directory try { final InputStream inputStream = MetaInfServices.loadClasspathResource(jsLib); @@ -115,8 +124,7 @@ public class K2JSCompilerMojo extends KotlinCompileMojo { } }; String text = "\n" + FileUtil.loadTextAndClose(inputStream); - Charset charset = Charset.defaultCharset(); - Files.append(text, new File(outputFile), charset); + builder.append(text); } } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e);