Adds ability to merge runtime.js into classes.js

This commit is contained in:
konsoletyper 2014-03-04 17:42:36 +04:00
parent 4701250154
commit a1565015c8
2 changed files with 46 additions and 7 deletions

View File

@ -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);
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 (!runtimeSuppressed) {
}
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");
}
}
}

View File

@ -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
}