diff --git a/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptMojo.java b/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptMojo.java index ad1dd5412..5c2892d36 100644 --- a/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptMojo.java +++ b/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptMojo.java @@ -33,6 +33,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; import org.teavm.common.ThreadPoolFiniteExecutor; +import org.teavm.javascript.DirectoryBuildTarget; import org.teavm.javascript.JavascriptBuilder; import org.teavm.javascript.JavascriptBuilderFactory; import org.teavm.model.ClassHolderTransformer; @@ -69,7 +70,7 @@ public class BuildJavascriptMojo extends AbstractMojo { private String mainClass; @Parameter - private boolean runtimeSuppressed; + private RuntimeCopyOperation runtime = RuntimeCopyOperation.SEPARATE; @Parameter private boolean mainPageIncluded; @@ -103,8 +104,8 @@ public class BuildJavascriptMojo extends AbstractMojo { this.bytecodeLogging = bytecodeLogging; } - public void setRuntimeSuppressed(boolean runtimeSuppressed) { - this.runtimeSuppressed = runtimeSuppressed; + public void setRuntimeCopy(RuntimeCopyOperation runtimeCopy) { + this.runtime = runtimeCopy; } public void setMainPageIncluded(boolean mainPageIncluded) { @@ -156,10 +157,16 @@ public class BuildJavascriptMojo extends AbstractMojo { builder.entryPoint("main", new MethodReference(mainClass, mainMethodDesc)) .withValue(1, "java.lang.String"); targetDirectory.mkdirs(); - builder.build(targetDirectory, targetFileName); - builder.checkForMissingItems(); - log.info("JavaScript file successfully built"); - if (!runtimeSuppressed) { + try (FileWriter writer = new FileWriter(new File(targetDirectory, targetFileName))) { + if (runtime == RuntimeCopyOperation.MERGED) { + resourceToWriter("org/teavm/javascript/runtime.js", writer); + writer.append("\n"); + } + builder.build(writer, new DirectoryBuildTarget(targetDirectory)); + builder.checkForMissingItems(); + log.info("JavaScript file successfully built"); + } + if (runtime == RuntimeCopyOperation.SEPARATE) { resourceToFile("org/teavm/javascript/runtime.js", "runtime.js"); } if (mainPageIncluded) { @@ -255,4 +262,10 @@ public class BuildJavascriptMojo extends AbstractMojo { } } } + + private void resourceToWriter(String resource, Writer writer) throws IOException { + try (InputStream input = BuildJavascriptMojo.class.getClassLoader().getResourceAsStream(resource)) { + IOUtils.copy(input, writer, "UTF-8"); + } + } } diff --git a/teavm-maven-plugin/src/main/java/org/teavm/maven/RuntimeCopyOperation.java b/teavm-maven-plugin/src/main/java/org/teavm/maven/RuntimeCopyOperation.java new file mode 100644 index 000000000..7e8f0f598 --- /dev/null +++ b/teavm-maven-plugin/src/main/java/org/teavm/maven/RuntimeCopyOperation.java @@ -0,0 +1,26 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.maven; + +/** + * + * @author Alexey Andreev + */ +public enum RuntimeCopyOperation { + SEPARATE, + MERGED, + NONE +}