mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Always embed runtime into generated file. Remove 'runtime' build property
This commit is contained in:
parent
63b2440e48
commit
4d2c075c07
|
@ -67,6 +67,10 @@
|
||||||
<artifactId>jackson-annotations</artifactId>
|
<artifactId>jackson-annotations</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mozilla</groupId>
|
||||||
|
<artifactId>rhino</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.teavm.backend.javascript.codegen.SourceWriter;
|
||||||
import org.teavm.backend.javascript.codegen.SourceWriterBuilder;
|
import org.teavm.backend.javascript.codegen.SourceWriterBuilder;
|
||||||
import org.teavm.backend.javascript.rendering.Renderer;
|
import org.teavm.backend.javascript.rendering.Renderer;
|
||||||
import org.teavm.backend.javascript.rendering.RenderingContext;
|
import org.teavm.backend.javascript.rendering.RenderingContext;
|
||||||
|
import org.teavm.backend.javascript.rendering.RuntimeRenderer;
|
||||||
import org.teavm.backend.javascript.spi.GeneratedBy;
|
import org.teavm.backend.javascript.spi.GeneratedBy;
|
||||||
import org.teavm.backend.javascript.spi.Generator;
|
import org.teavm.backend.javascript.spi.Generator;
|
||||||
import org.teavm.backend.javascript.spi.InjectedBy;
|
import org.teavm.backend.javascript.spi.InjectedBy;
|
||||||
|
@ -292,6 +293,7 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
|
||||||
renderingContext.setMinifying(minifying);
|
renderingContext.setMinifying(minifying);
|
||||||
Renderer renderer = new Renderer(sourceWriter, asyncMethods, asyncFamilyMethods,
|
Renderer renderer = new Renderer(sourceWriter, asyncMethods, asyncFamilyMethods,
|
||||||
controller.getDiagnostics(), renderingContext);
|
controller.getDiagnostics(), renderingContext);
|
||||||
|
RuntimeRenderer runtimeRenderer = new RuntimeRenderer(naming, sourceWriter);
|
||||||
renderer.setProperties(controller.getProperties());
|
renderer.setProperties(controller.getProperties());
|
||||||
renderer.setMinifying(minifying);
|
renderer.setMinifying(minifying);
|
||||||
if (debugEmitter != null) {
|
if (debugEmitter != null) {
|
||||||
|
@ -319,7 +321,7 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost {
|
||||||
int start = sourceWriter.getOffset();
|
int start = sourceWriter.getOffset();
|
||||||
sourceWriter.append("\"use strict\";").newLine();
|
sourceWriter.append("\"use strict\";").newLine();
|
||||||
renderer.prepare(clsNodes);
|
renderer.prepare(clsNodes);
|
||||||
renderer.renderRuntime();
|
runtimeRenderer.renderRuntime();
|
||||||
renderer.render(clsNodes);
|
renderer.render(clsNodes);
|
||||||
renderer.renderStringPool();
|
renderer.renderStringPool();
|
||||||
renderer.renderStringConstants();
|
renderer.renderStringConstants();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2015 Alexey Andreev.
|
* Copyright 2018 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.jso.impl;
|
package org.teavm.backend.javascript.rendering;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -276,6 +276,7 @@ public class AstWriter {
|
||||||
private void print(AstRoot node) throws IOException {
|
private void print(AstRoot node) throws IOException {
|
||||||
for (Node child : node) {
|
for (Node child : node) {
|
||||||
print((AstNode) child);
|
print((AstNode) child);
|
||||||
|
writer.softNewLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2015 Alexey Andreev.
|
* Copyright 2018 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.jso.impl;
|
package org.teavm.backend.javascript.rendering;
|
||||||
|
|
||||||
import org.mozilla.javascript.CompilerEnvirons;
|
import org.mozilla.javascript.CompilerEnvirons;
|
||||||
import org.mozilla.javascript.ErrorReporter;
|
import org.mozilla.javascript.ErrorReporter;
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2015 Alexey Andreev.
|
* Copyright 2018 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,10 +13,10 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.jso.impl;
|
package org.teavm.backend.javascript.rendering;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
interface NameEmitter {
|
public interface NameEmitter {
|
||||||
void emit(int precedence) throws IOException;
|
void emit(int precedence) throws IOException;
|
||||||
}
|
}
|
|
@ -193,106 +193,6 @@ public class Renderer implements RenderingManager {
|
||||||
sizeByClass.put(className, sizeByClass.getOrDefault(className, 0) + sz);
|
sizeByClass.put(className, sizeByClass.getOrDefault(className, 0) + sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderRuntime() throws RenderingException {
|
|
||||||
try {
|
|
||||||
renderSetCloneMethod();
|
|
||||||
renderRuntimeCls();
|
|
||||||
renderRuntimeString();
|
|
||||||
renderRuntimeUnwrapString();
|
|
||||||
renderRuntimeObjcls();
|
|
||||||
renderRuntimeNullCheck();
|
|
||||||
renderRuntimeIntern();
|
|
||||||
renderRuntimeThreads();
|
|
||||||
} catch (NamingException e) {
|
|
||||||
throw new RenderingException("Error rendering runtime methods. See a cause for details", e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RenderingException("IO error", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderSetCloneMethod() throws IOException {
|
|
||||||
writer.append("function $rt_setCloneMethod(target, f)").ws().append("{").softNewLine().indent();
|
|
||||||
writer.append("target.").appendMethod("clone", Object.class).ws().append('=').ws().append("f;").
|
|
||||||
softNewLine();
|
|
||||||
writer.outdent().append("}").newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderRuntimeCls() throws IOException {
|
|
||||||
writer.append("function $rt_cls(cls)").ws().append("{").softNewLine().indent();
|
|
||||||
writer.append("return ").appendMethodBody("java.lang.Class", "getClass",
|
|
||||||
ValueType.object("org.teavm.platform.PlatformClass"),
|
|
||||||
ValueType.object("java.lang.Class")).append("(cls);")
|
|
||||||
.softNewLine();
|
|
||||||
writer.outdent().append("}").newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderRuntimeString() throws IOException {
|
|
||||||
MethodReference stringCons = new MethodReference(String.class, "<init>", char[].class, void.class);
|
|
||||||
writer.append("function $rt_str(str) {").indent().softNewLine();
|
|
||||||
writer.append("if (str === null) {").indent().softNewLine();
|
|
||||||
writer.append("return null;").softNewLine();
|
|
||||||
writer.outdent().append("}").softNewLine();
|
|
||||||
writer.append("var characters = $rt_createCharArray(str.length);").softNewLine();
|
|
||||||
writer.append("var charsBuffer = characters.data;").softNewLine();
|
|
||||||
writer.append("for (var i = 0; i < str.length; i = (i + 1) | 0) {").indent().softNewLine();
|
|
||||||
writer.append("charsBuffer[i] = str.charCodeAt(i) & 0xFFFF;").softNewLine();
|
|
||||||
writer.outdent().append("}").softNewLine();
|
|
||||||
writer.append("return ").append(naming.getNameForInit(stringCons)).append("(characters);").softNewLine();
|
|
||||||
writer.outdent().append("}").newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderRuntimeUnwrapString() throws IOException {
|
|
||||||
MethodReference stringLen = new MethodReference(String.class, "length", int.class);
|
|
||||||
MethodReference getChars = new MethodReference(String.class, "getChars", int.class, int.class,
|
|
||||||
char[].class, int.class, void.class);
|
|
||||||
writer.append("function $rt_ustr(str) {").indent().softNewLine();
|
|
||||||
writer.append("if (str === null) {").indent().softNewLine();
|
|
||||||
writer.append("return null;").softNewLine();
|
|
||||||
writer.outdent().append("}").softNewLine();
|
|
||||||
writer.append("var result = \"\";").softNewLine();
|
|
||||||
writer.append("var sz = ").appendMethodBody(stringLen).append("(str);").softNewLine();
|
|
||||||
writer.append("var array = $rt_createCharArray(sz);").softNewLine();
|
|
||||||
writer.appendMethodBody(getChars).append("(str, 0, sz, array, 0);").softNewLine();
|
|
||||||
writer.append("for (var i = 0; i < sz; i = (i + 1) | 0) {").indent().softNewLine();
|
|
||||||
writer.append("result += String.fromCharCode(array.data[i]);").softNewLine();
|
|
||||||
writer.outdent().append("}").softNewLine();
|
|
||||||
writer.append("return result;").softNewLine();
|
|
||||||
writer.outdent().append("}").newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderRuntimeNullCheck() throws IOException {
|
|
||||||
writer.append("function $rt_nullCheck(val) {").indent().softNewLine();
|
|
||||||
writer.append("if (val === null) {").indent().softNewLine();
|
|
||||||
writer.append("$rt_throw(").append(naming.getNameForInit(new MethodReference(NullPointerException.class,
|
|
||||||
"<init>", void.class))).append("());").softNewLine();
|
|
||||||
writer.outdent().append("}").softNewLine();
|
|
||||||
writer.append("return val;").softNewLine();
|
|
||||||
writer.outdent().append("}").newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderRuntimeIntern() throws IOException {
|
|
||||||
writer.append("function $rt_intern(str) {").indent().softNewLine();
|
|
||||||
writer.append("return ").appendMethodBody(new MethodReference(String.class, "intern", String.class))
|
|
||||||
.append("(str);").softNewLine();
|
|
||||||
writer.outdent().append("}").newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderRuntimeObjcls() throws IOException {
|
|
||||||
writer.append("function $rt_objcls() { return ").appendClass("java.lang.Object").append("; }").newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderRuntimeThreads() throws IOException {
|
|
||||||
writer.append("function $rt_getThread()").ws().append("{").indent().softNewLine();
|
|
||||||
writer.append("return ").appendMethodBody(Thread.class, "currentThread", Thread.class).append("();")
|
|
||||||
.softNewLine();
|
|
||||||
writer.outdent().append("}").newLine();
|
|
||||||
|
|
||||||
writer.append("function $rt_setThread(t)").ws().append("{").indent().softNewLine();
|
|
||||||
writer.append("return ").appendMethodBody(Thread.class, "setCurrentThread", Thread.class, void.class)
|
|
||||||
.append("(t);").softNewLine();
|
|
||||||
writer.outdent().append("}").newLine();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void renderRuntimeAliases() throws IOException {
|
private void renderRuntimeAliases() throws IOException {
|
||||||
String[] names = { "$rt_throw", "$rt_compare", "$rt_nullCheck", "$rt_cls", "$rt_createArray",
|
String[] names = { "$rt_throw", "$rt_compare", "$rt_nullCheck", "$rt_cls", "$rt_createArray",
|
||||||
"$rt_isInstance", "$rt_nativeThread", "$rt_suspending", "$rt_resuming", "$rt_invalidPointer",
|
"$rt_isInstance", "$rt_nativeThread", "$rt_suspending", "$rt_resuming", "$rt_invalidPointer",
|
||||||
|
|
|
@ -0,0 +1,163 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018 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.backend.javascript.rendering;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import org.mozilla.javascript.CompilerEnvirons;
|
||||||
|
import org.mozilla.javascript.Context;
|
||||||
|
import org.mozilla.javascript.ast.AstRoot;
|
||||||
|
import org.teavm.backend.javascript.codegen.NamingException;
|
||||||
|
import org.teavm.backend.javascript.codegen.NamingStrategy;
|
||||||
|
import org.teavm.backend.javascript.codegen.SourceWriter;
|
||||||
|
import org.teavm.model.MethodReference;
|
||||||
|
import org.teavm.model.ValueType;
|
||||||
|
import org.teavm.vm.RenderingException;
|
||||||
|
|
||||||
|
public class RuntimeRenderer {
|
||||||
|
private final NamingStrategy naming;
|
||||||
|
private final SourceWriter writer;
|
||||||
|
|
||||||
|
public RuntimeRenderer(NamingStrategy naming, SourceWriter writer) {
|
||||||
|
this.naming = naming;
|
||||||
|
this.writer = writer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void renderRuntime() throws RenderingException {
|
||||||
|
try {
|
||||||
|
renderHandWrittenRuntime();
|
||||||
|
renderSetCloneMethod();
|
||||||
|
renderRuntimeCls();
|
||||||
|
renderRuntimeString();
|
||||||
|
renderRuntimeUnwrapString();
|
||||||
|
renderRuntimeObjcls();
|
||||||
|
renderRuntimeNullCheck();
|
||||||
|
renderRuntimeIntern();
|
||||||
|
renderRuntimeThreads();
|
||||||
|
} catch (NamingException e) {
|
||||||
|
throw new RenderingException("Error rendering runtime methods. See a cause for details", e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RenderingException("IO error", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderHandWrittenRuntime() throws IOException {
|
||||||
|
AstRoot ast = parseRuntime();
|
||||||
|
ast.visit(new StringConstantElimination());
|
||||||
|
AstWriter astWriter = new AstWriter(writer);
|
||||||
|
astWriter.hoist(ast);
|
||||||
|
astWriter.print(ast);
|
||||||
|
}
|
||||||
|
|
||||||
|
private AstRoot parseRuntime() throws IOException {
|
||||||
|
CompilerEnvirons env = new CompilerEnvirons();
|
||||||
|
env.setRecoverFromErrors(true);
|
||||||
|
env.setLanguageVersion(Context.VERSION_1_8);
|
||||||
|
JSParser factory = new JSParser(env);
|
||||||
|
|
||||||
|
ClassLoader loader = RuntimeRenderer.class.getClassLoader();
|
||||||
|
try (InputStream input = loader.getResourceAsStream("org/teavm/backend/javascript/runtime.js");
|
||||||
|
Reader reader = new InputStreamReader(input, StandardCharsets.UTF_8)) {
|
||||||
|
return factory.parse(reader, null, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderSetCloneMethod() throws IOException {
|
||||||
|
writer.append("function $rt_setCloneMethod(target, f)").ws().append("{").softNewLine().indent();
|
||||||
|
writer.append("target.").appendMethod("clone", Object.class).ws().append('=').ws().append("f;").
|
||||||
|
softNewLine();
|
||||||
|
writer.outdent().append("}").newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderRuntimeCls() throws IOException {
|
||||||
|
writer.append("function $rt_cls(cls)").ws().append("{").softNewLine().indent();
|
||||||
|
writer.append("return ").appendMethodBody("java.lang.Class", "getClass",
|
||||||
|
ValueType.object("org.teavm.platform.PlatformClass"),
|
||||||
|
ValueType.object("java.lang.Class")).append("(cls);")
|
||||||
|
.softNewLine();
|
||||||
|
writer.outdent().append("}").newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderRuntimeString() throws IOException {
|
||||||
|
MethodReference stringCons = new MethodReference(String.class, "<init>", char[].class, void.class);
|
||||||
|
writer.append("function $rt_str(str) {").indent().softNewLine();
|
||||||
|
writer.append("if (str === null) {").indent().softNewLine();
|
||||||
|
writer.append("return null;").softNewLine();
|
||||||
|
writer.outdent().append("}").softNewLine();
|
||||||
|
writer.append("var characters = $rt_createCharArray(str.length);").softNewLine();
|
||||||
|
writer.append("var charsBuffer = characters.data;").softNewLine();
|
||||||
|
writer.append("for (var i = 0; i < str.length; i = (i + 1) | 0) {").indent().softNewLine();
|
||||||
|
writer.append("charsBuffer[i] = str.charCodeAt(i) & 0xFFFF;").softNewLine();
|
||||||
|
writer.outdent().append("}").softNewLine();
|
||||||
|
writer.append("return ").append(naming.getNameForInit(stringCons)).append("(characters);").softNewLine();
|
||||||
|
writer.outdent().append("}").newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderRuntimeUnwrapString() throws IOException {
|
||||||
|
MethodReference stringLen = new MethodReference(String.class, "length", int.class);
|
||||||
|
MethodReference getChars = new MethodReference(String.class, "getChars", int.class, int.class,
|
||||||
|
char[].class, int.class, void.class);
|
||||||
|
writer.append("function $rt_ustr(str) {").indent().softNewLine();
|
||||||
|
writer.append("if (str === null) {").indent().softNewLine();
|
||||||
|
writer.append("return null;").softNewLine();
|
||||||
|
writer.outdent().append("}").softNewLine();
|
||||||
|
writer.append("var result = \"\";").softNewLine();
|
||||||
|
writer.append("var sz = ").appendMethodBody(stringLen).append("(str);").softNewLine();
|
||||||
|
writer.append("var array = $rt_createCharArray(sz);").softNewLine();
|
||||||
|
writer.appendMethodBody(getChars).append("(str, 0, sz, array, 0);").softNewLine();
|
||||||
|
writer.append("for (var i = 0; i < sz; i = (i + 1) | 0) {").indent().softNewLine();
|
||||||
|
writer.append("result += String.fromCharCode(array.data[i]);").softNewLine();
|
||||||
|
writer.outdent().append("}").softNewLine();
|
||||||
|
writer.append("return result;").softNewLine();
|
||||||
|
writer.outdent().append("}").newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderRuntimeNullCheck() throws IOException {
|
||||||
|
writer.append("function $rt_nullCheck(val) {").indent().softNewLine();
|
||||||
|
writer.append("if (val === null) {").indent().softNewLine();
|
||||||
|
writer.append("$rt_throw(").append(naming.getNameForInit(new MethodReference(NullPointerException.class,
|
||||||
|
"<init>", void.class))).append("());").softNewLine();
|
||||||
|
writer.outdent().append("}").softNewLine();
|
||||||
|
writer.append("return val;").softNewLine();
|
||||||
|
writer.outdent().append("}").newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderRuntimeIntern() throws IOException {
|
||||||
|
writer.append("function $rt_intern(str) {").indent().softNewLine();
|
||||||
|
writer.append("return ").appendMethodBody(new MethodReference(String.class, "intern", String.class))
|
||||||
|
.append("(str);").softNewLine();
|
||||||
|
writer.outdent().append("}").newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderRuntimeObjcls() throws IOException {
|
||||||
|
writer.append("function $rt_objcls() { return ").appendClass("java.lang.Object").append("; }").newLine();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderRuntimeThreads() throws IOException {
|
||||||
|
writer.append("function $rt_getThread()").ws().append("{").indent().softNewLine();
|
||||||
|
writer.append("return ").appendMethodBody(Thread.class, "currentThread", Thread.class).append("();")
|
||||||
|
.softNewLine();
|
||||||
|
writer.outdent().append("}").newLine();
|
||||||
|
|
||||||
|
writer.append("function $rt_setThread(t)").ws().append("{").indent().softNewLine();
|
||||||
|
writer.append("return ").appendMethodBody(Thread.class, "setCurrentThread", Thread.class, void.class)
|
||||||
|
.append("(t);").softNewLine();
|
||||||
|
writer.outdent().append("}").newLine();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2018 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.backend.javascript.rendering;
|
||||||
|
|
||||||
|
import org.mozilla.javascript.Node;
|
||||||
|
import org.mozilla.javascript.ast.AstNode;
|
||||||
|
import org.mozilla.javascript.ast.AstRoot;
|
||||||
|
import org.mozilla.javascript.ast.Block;
|
||||||
|
import org.mozilla.javascript.ast.ExpressionStatement;
|
||||||
|
import org.mozilla.javascript.ast.NodeVisitor;
|
||||||
|
import org.mozilla.javascript.ast.Scope;
|
||||||
|
import org.mozilla.javascript.ast.StringLiteral;
|
||||||
|
|
||||||
|
public class StringConstantElimination implements NodeVisitor {
|
||||||
|
@Override
|
||||||
|
public boolean visit(AstNode astNode) {
|
||||||
|
if (astNode instanceof Block || astNode instanceof Scope || astNode instanceof AstRoot) {
|
||||||
|
handle(astNode);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handle(AstNode block) {
|
||||||
|
Node child = block.getFirstChild();
|
||||||
|
while (child != null) {
|
||||||
|
Node next = child.getNext();
|
||||||
|
if (child instanceof ExpressionStatement) {
|
||||||
|
ExpressionStatement statement = (ExpressionStatement) child;
|
||||||
|
if (statement.getExpression() instanceof StringLiteral) {
|
||||||
|
block.removeChild(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
child = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2015 Alexey Andreev.
|
* Copyright 2018 Alexey Andreev.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -13,10 +13,10 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package org.teavm.jso.plugin;
|
package org.teavm.backend.javascript.rendering;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.assertThat;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -25,8 +25,6 @@ import org.mozilla.javascript.Context;
|
||||||
import org.mozilla.javascript.ast.AstRoot;
|
import org.mozilla.javascript.ast.AstRoot;
|
||||||
import org.teavm.backend.javascript.codegen.SourceWriter;
|
import org.teavm.backend.javascript.codegen.SourceWriter;
|
||||||
import org.teavm.backend.javascript.codegen.SourceWriterBuilder;
|
import org.teavm.backend.javascript.codegen.SourceWriterBuilder;
|
||||||
import org.teavm.jso.impl.AstWriter;
|
|
||||||
import org.teavm.jso.impl.JSParser;
|
|
||||||
|
|
||||||
public class AstWriterTest {
|
public class AstWriterTest {
|
||||||
private StringBuilder sb = new StringBuilder();
|
private StringBuilder sb = new StringBuilder();
|
|
@ -39,11 +39,6 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xs
|
||||||
<artifactId>teavm-jso-apis</artifactId>
|
<artifactId>teavm-jso-apis</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>${project.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.mozilla</groupId>
|
|
||||||
<artifactId>rhino</artifactId>
|
|
||||||
<version>1.7.7</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.mozilla.javascript.Node;
|
||||||
import org.mozilla.javascript.ast.AstNode;
|
import org.mozilla.javascript.ast.AstNode;
|
||||||
import org.mozilla.javascript.ast.Block;
|
import org.mozilla.javascript.ast.Block;
|
||||||
import org.teavm.backend.javascript.codegen.SourceWriter;
|
import org.teavm.backend.javascript.codegen.SourceWriter;
|
||||||
|
import org.teavm.backend.javascript.rendering.AstWriter;
|
||||||
import org.teavm.backend.javascript.rendering.Precedence;
|
import org.teavm.backend.javascript.rendering.Precedence;
|
||||||
import org.teavm.backend.javascript.spi.GeneratorContext;
|
import org.teavm.backend.javascript.spi.GeneratorContext;
|
||||||
import org.teavm.backend.javascript.spi.InjectorContext;
|
import org.teavm.backend.javascript.spi.InjectorContext;
|
||||||
|
@ -30,7 +31,7 @@ class JSBodyAstEmitter implements JSBodyEmitter {
|
||||||
private AstNode ast;
|
private AstNode ast;
|
||||||
private String[] parameterNames;
|
private String[] parameterNames;
|
||||||
|
|
||||||
public JSBodyAstEmitter(boolean isStatic, AstNode ast, String[] parameterNames) {
|
JSBodyAstEmitter(boolean isStatic, AstNode ast, String[] parameterNames) {
|
||||||
this.isStatic = isStatic;
|
this.isStatic = isStatic;
|
||||||
this.ast = ast;
|
this.ast = ast;
|
||||||
this.parameterNames = parameterNames;
|
this.parameterNames = parameterNames;
|
||||||
|
|
|
@ -30,6 +30,7 @@ import org.mozilla.javascript.Context;
|
||||||
import org.mozilla.javascript.ast.AstNode;
|
import org.mozilla.javascript.ast.AstNode;
|
||||||
import org.mozilla.javascript.ast.AstRoot;
|
import org.mozilla.javascript.ast.AstRoot;
|
||||||
import org.mozilla.javascript.ast.FunctionNode;
|
import org.mozilla.javascript.ast.FunctionNode;
|
||||||
|
import org.teavm.backend.javascript.rendering.JSParser;
|
||||||
import org.teavm.cache.NoCache;
|
import org.teavm.cache.NoCache;
|
||||||
import org.teavm.diagnostics.Diagnostics;
|
import org.teavm.diagnostics.Diagnostics;
|
||||||
import org.teavm.interop.Sync;
|
import org.teavm.interop.Sync;
|
||||||
|
|
6
pom.xml
6
pom.xml
|
@ -72,6 +72,7 @@
|
||||||
<jackson.version>2.6.2</jackson.version>
|
<jackson.version>2.6.2</jackson.version>
|
||||||
<idea.version>2017.3.5</idea.version>
|
<idea.version>2017.3.5</idea.version>
|
||||||
<asm.version>6.1.1</asm.version>
|
<asm.version>6.1.1</asm.version>
|
||||||
|
<rhino.version>1.7.7</rhino.version>
|
||||||
|
|
||||||
<teavm.test.incremental>false</teavm.test.incremental>
|
<teavm.test.incremental>false</teavm.test.incremental>
|
||||||
<teavm.test.threads>1</teavm.test.threads>
|
<teavm.test.threads>1</teavm.test.threads>
|
||||||
|
@ -201,6 +202,11 @@
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson.version}</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mozilla</groupId>
|
||||||
|
<artifactId>rhino</artifactId>
|
||||||
|
<version>${rhino.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</dependencyManagement>
|
</dependencyManagement>
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,6 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
||||||
<mainClass>org.teavm.samples.async.AsyncProgram</mainClass>
|
<mainClass>org.teavm.samples.async.AsyncProgram</mainClass>
|
||||||
<runtime>SEPARATE</runtime>
|
|
||||||
<minifying>false</minifying>
|
<minifying>false</minifying>
|
||||||
<debugInformationGenerated>true</debugInformationGenerated>
|
<debugInformationGenerated>true</debugInformationGenerated>
|
||||||
<sourceMapsGenerated>true</sourceMapsGenerated>
|
<sourceMapsGenerated>true</sourceMapsGenerated>
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
<head>
|
<head>
|
||||||
<title>Continuation-passing style demo</title>
|
<title>Continuation-passing style demo</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
|
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/stdout.js"></script>
|
<script type="text/javascript" charset="utf-8" src="teavm/stdout.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8" src="highlight.pack.js"></script>
|
<script type="text/javascript" charset="utf-8" src="highlight.pack.js"></script>
|
||||||
|
|
|
@ -149,7 +149,6 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
||||||
<mainClass>org.teavm.samples.benchmark.teavm.BenchmarkStarter</mainClass>
|
<mainClass>org.teavm.samples.benchmark.teavm.BenchmarkStarter</mainClass>
|
||||||
<runtime>SEPARATE</runtime>
|
|
||||||
<minifying>true</minifying>
|
<minifying>true</minifying>
|
||||||
<debugInformationGenerated>true</debugInformationGenerated>
|
<debugInformationGenerated>true</debugInformationGenerated>
|
||||||
<optimizationLevel>FULL</optimizationLevel>
|
<optimizationLevel>FULL</optimizationLevel>
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||||
<title>TeaVM jbox2d benchmark</title>
|
<title>TeaVM jbox2d benchmark</title>
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
|
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="main()">
|
<body onload="main()">
|
||||||
|
|
|
@ -76,7 +76,6 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
||||||
<mainClass>org.teavm.samples.hello.Client</mainClass>
|
<mainClass>org.teavm.samples.hello.Client</mainClass>
|
||||||
<runtime>SEPARATE</runtime>
|
|
||||||
<minifying>false</minifying>
|
<minifying>false</minifying>
|
||||||
<debugInformationGenerated>true</debugInformationGenerated>
|
<debugInformationGenerated>true</debugInformationGenerated>
|
||||||
<sourceMapsGenerated>true</sourceMapsGenerated>
|
<sourceMapsGenerated>true</sourceMapsGenerated>
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
<head>
|
<head>
|
||||||
<title>Hello web application</title>
|
<title>Hello web application</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
|
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="main()">
|
<body onload="main()">
|
||||||
|
|
|
@ -97,7 +97,6 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
||||||
<mainClass>org.teavm.samples.kotlin.HelloKt</mainClass>
|
<mainClass>org.teavm.samples.kotlin.HelloKt</mainClass>
|
||||||
<runtime>SEPARATE</runtime>
|
|
||||||
<minifying>false</minifying>
|
<minifying>false</minifying>
|
||||||
<debugInformationGenerated>true</debugInformationGenerated>
|
<debugInformationGenerated>true</debugInformationGenerated>
|
||||||
<sourceMapsGenerated>true</sourceMapsGenerated>
|
<sourceMapsGenerated>true</sourceMapsGenerated>
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
<head>
|
<head>
|
||||||
<title>Hello kotlin</title>
|
<title>Hello kotlin</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
|
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="main()">
|
<body onload="main()">
|
||||||
|
|
|
@ -71,7 +71,6 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
||||||
<mainClass>org.teavm.samples.scala.Client</mainClass>
|
<mainClass>org.teavm.samples.scala.Client</mainClass>
|
||||||
<runtime>SEPARATE</runtime>
|
|
||||||
<minifying>false</minifying>
|
<minifying>false</minifying>
|
||||||
<debugInformationGenerated>true</debugInformationGenerated>
|
<debugInformationGenerated>true</debugInformationGenerated>
|
||||||
<sourceMapsGenerated>true</sourceMapsGenerated>
|
<sourceMapsGenerated>true</sourceMapsGenerated>
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
<head>
|
<head>
|
||||||
<title>Hello Scala</title>
|
<title>Hello Scala</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
|
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="calculator.css">
|
<link rel="stylesheet" type="text/css" href="calculator.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
<head>
|
<head>
|
||||||
<title>Web Storage web application</title>
|
<title>Web Storage web application</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
|
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body onload="main()">
|
<body onload="main()">
|
||||||
|
|
|
@ -76,7 +76,6 @@
|
||||||
<configuration>
|
<configuration>
|
||||||
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
|
||||||
<mainClass>org.teavm.samples.video.Player</mainClass>
|
<mainClass>org.teavm.samples.video.Player</mainClass>
|
||||||
<runtime>SEPARATE</runtime>
|
|
||||||
<minifying>false</minifying>
|
<minifying>false</minifying>
|
||||||
<debugInformationGenerated>true</debugInformationGenerated>
|
<debugInformationGenerated>true</debugInformationGenerated>
|
||||||
<sourceMapsGenerated>true</sourceMapsGenerated>
|
<sourceMapsGenerated>true</sourceMapsGenerated>
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
<head>
|
<head>
|
||||||
<title>HTML5 Video web application</title>
|
<title>HTML5 Video web application</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/runtime.js"></script>
|
|
||||||
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
<script type="text/javascript" charset="utf-8" src="teavm/classes.js"></script>
|
||||||
<link href="style.css" rel="stylesheet" type="text/css">
|
<link href="style.css" rel="stylesheet" type="text/css">
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -20,7 +20,6 @@ import * as http from "http";
|
||||||
import {server as WebSocketServer} from "websocket";
|
import {server as WebSocketServer} from "websocket";
|
||||||
|
|
||||||
const TEST_FILE_NAME = "test.js";
|
const TEST_FILE_NAME = "test.js";
|
||||||
const RUNTIME_FILE_NAME = "runtime.js";
|
|
||||||
const WASM_RUNTIME_FILE_NAME = "test.wasm-runtime.js";
|
const WASM_RUNTIME_FILE_NAME = "test.wasm-runtime.js";
|
||||||
const TEST_FILES = [
|
const TEST_FILES = [
|
||||||
{ file: TEST_FILE_NAME, name: "simple", type: "js" },
|
{ file: TEST_FILE_NAME, name: "simple", type: "js" },
|
||||||
|
@ -122,7 +121,7 @@ async function serveFile(path, response) {
|
||||||
|
|
||||||
async function walkDir(path, name, suite) {
|
async function walkDir(path, name, suite) {
|
||||||
const files = await fs.readdir(rootDir + "/" + path);
|
const files = await fs.readdir(rootDir + "/" + path);
|
||||||
if (files.includes(WASM_RUNTIME_FILE_NAME) || files.includes(RUNTIME_FILE_NAME)) {
|
if (files.includes(WASM_RUNTIME_FILE_NAME) || files.includes("test.js")) {
|
||||||
for (const { file: fileName, name: profileName, type: type } of TEST_FILES) {
|
for (const { file: fileName, name: profileName, type: type } of TEST_FILES) {
|
||||||
if (files.includes(fileName)) {
|
if (files.includes(fileName)) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
|
@ -46,7 +46,6 @@ import org.apache.commons.cli.Options;
|
||||||
import org.apache.commons.cli.ParseException;
|
import org.apache.commons.cli.ParseException;
|
||||||
import org.apache.commons.cli.PosixParser;
|
import org.apache.commons.cli.PosixParser;
|
||||||
import org.teavm.backend.wasm.render.WasmBinaryVersion;
|
import org.teavm.backend.wasm.render.WasmBinaryVersion;
|
||||||
import org.teavm.tooling.RuntimeCopyOperation;
|
|
||||||
import org.teavm.tooling.TeaVMTargetType;
|
import org.teavm.tooling.TeaVMTargetType;
|
||||||
import org.teavm.tooling.TeaVMTool;
|
import org.teavm.tooling.TeaVMTool;
|
||||||
import org.teavm.tooling.TeaVMToolException;
|
import org.teavm.tooling.TeaVMToolException;
|
||||||
|
@ -231,22 +230,6 @@ public final class TeaVMRunner {
|
||||||
} else {
|
} else {
|
||||||
tool.setMinifying(false);
|
tool.setMinifying(false);
|
||||||
}
|
}
|
||||||
if (commandLine.hasOption("r")) {
|
|
||||||
switch (commandLine.getOptionValue("r")) {
|
|
||||||
case "separate":
|
|
||||||
tool.setRuntime(RuntimeCopyOperation.SEPARATE);
|
|
||||||
break;
|
|
||||||
case "merge":
|
|
||||||
tool.setRuntime(RuntimeCopyOperation.MERGED);
|
|
||||||
break;
|
|
||||||
case "none":
|
|
||||||
tool.setRuntime(RuntimeCopyOperation.NONE);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
System.err.println("Wrong parameter for -r option specified");
|
|
||||||
printUsage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseDebugOptions() {
|
private void parseDebugOptions() {
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.tooling;
|
|
||||||
|
|
||||||
public enum RuntimeCopyOperation {
|
|
||||||
SEPARATE,
|
|
||||||
MERGED,
|
|
||||||
NONE
|
|
||||||
}
|
|
|
@ -15,16 +15,14 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.tooling;
|
package org.teavm.tooling;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.StringWriter;
|
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -32,10 +30,8 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.teavm.backend.c.CTarget;
|
import org.teavm.backend.c.CTarget;
|
||||||
import org.teavm.backend.javascript.JavaScriptTarget;
|
import org.teavm.backend.javascript.JavaScriptTarget;
|
||||||
import org.teavm.backend.javascript.rendering.RenderingManager;
|
|
||||||
import org.teavm.backend.wasm.WasmTarget;
|
import org.teavm.backend.wasm.WasmTarget;
|
||||||
import org.teavm.backend.wasm.render.WasmBinaryVersion;
|
import org.teavm.backend.wasm.render.WasmBinaryVersion;
|
||||||
import org.teavm.cache.DiskCachedClassHolderSource;
|
import org.teavm.cache.DiskCachedClassHolderSource;
|
||||||
|
@ -65,7 +61,6 @@ import org.teavm.vm.TeaVMBuilder;
|
||||||
import org.teavm.vm.TeaVMOptimizationLevel;
|
import org.teavm.vm.TeaVMOptimizationLevel;
|
||||||
import org.teavm.vm.TeaVMProgressListener;
|
import org.teavm.vm.TeaVMProgressListener;
|
||||||
import org.teavm.vm.TeaVMTarget;
|
import org.teavm.vm.TeaVMTarget;
|
||||||
import org.teavm.vm.spi.AbstractRendererListener;
|
|
||||||
|
|
||||||
public class TeaVMTool implements BaseTeaVMTool {
|
public class TeaVMTool implements BaseTeaVMTool {
|
||||||
private File targetDirectory = new File(".");
|
private File targetDirectory = new File(".");
|
||||||
|
@ -73,7 +68,6 @@ public class TeaVMTool implements BaseTeaVMTool {
|
||||||
private String targetFileName = "";
|
private String targetFileName = "";
|
||||||
private boolean minifying = true;
|
private boolean minifying = true;
|
||||||
private String mainClass;
|
private String mainClass;
|
||||||
private RuntimeCopyOperation runtime = RuntimeCopyOperation.SEPARATE;
|
|
||||||
private Properties properties = new Properties();
|
private Properties properties = new Properties();
|
||||||
private boolean debugInformationGenerated;
|
private boolean debugInformationGenerated;
|
||||||
private boolean sourceMapsFileGenerated;
|
private boolean sourceMapsFileGenerated;
|
||||||
|
@ -145,14 +139,6 @@ public class TeaVMTool implements BaseTeaVMTool {
|
||||||
this.mainClass = mainClass;
|
this.mainClass = mainClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RuntimeCopyOperation getRuntime() {
|
|
||||||
return runtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRuntime(RuntimeCopyOperation runtime) {
|
|
||||||
this.runtime = runtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDebugInformationGenerated() {
|
public boolean isDebugInformationGenerated() {
|
||||||
return debugInformationGenerated;
|
return debugInformationGenerated;
|
||||||
}
|
}
|
||||||
|
@ -407,9 +393,6 @@ public class TeaVMTool implements BaseTeaVMTool {
|
||||||
}
|
}
|
||||||
targetDirectory.mkdirs();
|
targetDirectory.mkdirs();
|
||||||
|
|
||||||
if (runtime == RuntimeCopyOperation.MERGED) {
|
|
||||||
javaScriptTarget.add(runtimeInjector);
|
|
||||||
}
|
|
||||||
BuildTarget buildTarget = new DirectoryBuildTarget(targetDirectory);
|
BuildTarget buildTarget = new DirectoryBuildTarget(targetDirectory);
|
||||||
String outputName = getResolvedTargetFileName();
|
String outputName = getResolvedTargetFileName();
|
||||||
vm.build(buildTarget, outputName);
|
vm.build(buildTarget, outputName);
|
||||||
|
@ -495,7 +478,8 @@ public class TeaVMTool implements BaseTeaVMTool {
|
||||||
String sourceMapsFileName = getResolvedTargetFileName() + ".map";
|
String sourceMapsFileName = getResolvedTargetFileName() + ".map";
|
||||||
writer.append("\n//# sourceMappingURL=").append(sourceMapsFileName);
|
writer.append("\n//# sourceMappingURL=").append(sourceMapsFileName);
|
||||||
File sourceMapsFile = new File(targetDirectory, sourceMapsFileName);
|
File sourceMapsFile = new File(targetDirectory, sourceMapsFileName);
|
||||||
try (Writer sourceMapsOut = new OutputStreamWriter(new FileOutputStream(sourceMapsFile), "UTF-8")) {
|
try (Writer sourceMapsOut = new OutputStreamWriter(new FileOutputStream(sourceMapsFile),
|
||||||
|
StandardCharsets.UTF_8)) {
|
||||||
debugInfo.writeAsSourceMaps(sourceMapsOut, "src", getResolvedTargetFileName());
|
debugInfo.writeAsSourceMaps(sourceMapsOut, "src", getResolvedTargetFileName());
|
||||||
}
|
}
|
||||||
generatedFiles.add(sourceMapsFile);
|
generatedFiles.add(sourceMapsFile);
|
||||||
|
@ -505,10 +489,6 @@ public class TeaVMTool implements BaseTeaVMTool {
|
||||||
copySourceFiles();
|
copySourceFiles();
|
||||||
log.info("Source files successfully written");
|
log.info("Source files successfully written");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (runtime == RuntimeCopyOperation.SEPARATE) {
|
|
||||||
resourceToFile("org/teavm/backend/javascript/runtime.js", "runtime.js");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printStats() {
|
private void printStats() {
|
||||||
|
@ -536,30 +516,4 @@ public class TeaVMTool implements BaseTeaVMTool {
|
||||||
copier.setLog(log);
|
copier.setLog(log);
|
||||||
copier.copy(new File(targetDirectory, "src"));
|
copier.copy(new File(targetDirectory, "src"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private AbstractRendererListener runtimeInjector = new AbstractRendererListener() {
|
|
||||||
@Override
|
|
||||||
public void begin(RenderingManager manager, BuildTarget buildTarget) throws IOException {
|
|
||||||
StringWriter writer = new StringWriter();
|
|
||||||
resourceToWriter("org/teavm/backend/javascript/runtime.js", writer);
|
|
||||||
writer.close();
|
|
||||||
manager.getWriter().append(writer.toString()).newLine();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void resourceToFile(String resource, String fileName) throws IOException {
|
|
||||||
try (InputStream input = TeaVMTool.class.getClassLoader().getResourceAsStream(resource)) {
|
|
||||||
File outputFile = new File(targetDirectory, fileName);
|
|
||||||
try (OutputStream output = new BufferedOutputStream(new FileOutputStream(outputFile))) {
|
|
||||||
IOUtils.copy(new BufferedInputStream(input), output);
|
|
||||||
}
|
|
||||||
generatedFiles.add(outputFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resourceToWriter(String resource, Writer writer) throws IOException {
|
|
||||||
try (InputStream input = TeaVMTool.class.getClassLoader().getResourceAsStream(resource)) {
|
|
||||||
IOUtils.copy(new BufferedInputStream(input), writer, "UTF-8");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;
|
||||||
import org.teavm.eclipse.TeaVMEclipsePlugin;
|
import org.teavm.eclipse.TeaVMEclipsePlugin;
|
||||||
import org.teavm.eclipse.TeaVMProfile;
|
import org.teavm.eclipse.TeaVMProfile;
|
||||||
import org.teavm.eclipse.TeaVMProjectSettings;
|
import org.teavm.eclipse.TeaVMProjectSettings;
|
||||||
import org.teavm.eclipse.TeaVMRuntimeMode;
|
|
||||||
|
|
||||||
public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
|
public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
|
||||||
private static final String TOOL_ID = "teavm-eclipse-m2e-plugin.tool";
|
private static final String TOOL_ID = "teavm-eclipse-m2e-plugin.tool";
|
||||||
|
@ -88,7 +87,7 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
|
||||||
|
|
||||||
private void configureProfile(MojoExecution execution, TeaVMProfile profile, IProgressMonitor monitor)
|
private void configureProfile(MojoExecution execution, TeaVMProfile profile, IProgressMonitor monitor)
|
||||||
throws CoreException {
|
throws CoreException {
|
||||||
monitor.beginTask("Configuring profile " + profile.getName(), 110);
|
monitor.beginTask("Configuring profile " + profile.getName(), 100);
|
||||||
String buildDir = getProjectBuildDirectory();
|
String buildDir = getProjectBuildDirectory();
|
||||||
|
|
||||||
String mainClass = maven.getMojoParameterValue(mavenSession, execution, "mainClass", String.class);
|
String mainClass = maven.getMojoParameterValue(mavenSession, execution, "mainClass", String.class);
|
||||||
|
@ -104,10 +103,6 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
|
||||||
profile.setTargetFileName(targetFileName != null ? targetFileName : "classes.js");
|
profile.setTargetFileName(targetFileName != null ? targetFileName : "classes.js");
|
||||||
monitor.worked(10);
|
monitor.worked(10);
|
||||||
|
|
||||||
String runtime = maven.getMojoParameterValue(mavenSession, execution, "runtime", String.class);
|
|
||||||
profile.setRuntimeMode(runtime != null ? getRuntimeMode(runtime) : TeaVMRuntimeMode.SEPARATE);
|
|
||||||
monitor.worked(10);
|
|
||||||
|
|
||||||
Properties properties = maven.getMojoParameterValue(mavenSession, execution, "properties", Properties.class);
|
Properties properties = maven.getMojoParameterValue(mavenSession, execution, "properties", Properties.class);
|
||||||
profile.setProperties(properties != null ? properties : new Properties());
|
profile.setProperties(properties != null ? properties : new Properties());
|
||||||
monitor.worked(10);
|
monitor.worked(10);
|
||||||
|
@ -184,19 +179,6 @@ public class TeaVMProjectConfigurator extends AbstractProjectConfigurator {
|
||||||
return varManager.generateVariableExpression("workspace_loc", path) + suffix;
|
return varManager.generateVariableExpression("workspace_loc", path) + suffix;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TeaVMRuntimeMode getRuntimeMode(String name) {
|
|
||||||
switch (name) {
|
|
||||||
case "SEPARATE":
|
|
||||||
return TeaVMRuntimeMode.SEPARATE;
|
|
||||||
case "MERGED":
|
|
||||||
return TeaVMRuntimeMode.MERGE;
|
|
||||||
case "NONE":
|
|
||||||
return TeaVMRuntimeMode.NONE;
|
|
||||||
default:
|
|
||||||
return TeaVMRuntimeMode.NONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getIdForProfile(MojoExecution pluginExecution) {
|
private String getIdForProfile(MojoExecution pluginExecution) {
|
||||||
String executionId = pluginExecution.getExecutionId();
|
String executionId = pluginExecution.getExecutionId();
|
||||||
if (executionId != null && usedExecutionIds.add(executionId)) {
|
if (executionId != null && usedExecutionIds.add(executionId)) {
|
||||||
|
|
|
@ -32,7 +32,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
|
||||||
public static final String MAIN_CLASS = "mainClass";
|
public static final String MAIN_CLASS = "mainClass";
|
||||||
public static final String TARGET_DIRECTORY = "targetDirectory";
|
public static final String TARGET_DIRECTORY = "targetDirectory";
|
||||||
public static final String TARGET_FILE_NAME = "targetFileName";
|
public static final String TARGET_FILE_NAME = "targetFileName";
|
||||||
public static final String RUNTIME = "runtime";
|
|
||||||
public static final String MINIFYING = "minifying";
|
public static final String MINIFYING = "minifying";
|
||||||
public static final String INCREMENTAL = "incremental";
|
public static final String INCREMENTAL = "incremental";
|
||||||
public static final String CACHE_DIRECTORY = "cacheDirectory";
|
public static final String CACHE_DIRECTORY = "cacheDirectory";
|
||||||
|
@ -155,7 +154,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
|
||||||
private String mainClass;
|
private String mainClass;
|
||||||
private String targetDirectory;
|
private String targetDirectory;
|
||||||
private String targetFileName;
|
private String targetFileName;
|
||||||
private TeaVMRuntimeMode runtimeMode = TeaVMRuntimeMode.SEPARATE;
|
|
||||||
private boolean incremental;
|
private boolean incremental;
|
||||||
private String cacheDirectory;
|
private String cacheDirectory;
|
||||||
private boolean sourceMapsGenerated;
|
private boolean sourceMapsGenerated;
|
||||||
|
@ -222,16 +220,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
|
||||||
this.targetFileName = targetFileName;
|
this.targetFileName = targetFileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public TeaVMRuntimeMode getRuntimeMode() {
|
|
||||||
return runtimeMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setRuntimeMode(TeaVMRuntimeMode runtimeMode) {
|
|
||||||
this.runtimeMode = runtimeMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isIncremental() {
|
public boolean isIncremental() {
|
||||||
return incremental;
|
return incremental;
|
||||||
|
@ -332,7 +320,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
|
||||||
mainClass = preferences.get(MAIN_CLASS, "");
|
mainClass = preferences.get(MAIN_CLASS, "");
|
||||||
targetDirectory = preferences.get(TARGET_DIRECTORY, "");
|
targetDirectory = preferences.get(TARGET_DIRECTORY, "");
|
||||||
targetFileName = preferences.get(TARGET_FILE_NAME, "");
|
targetFileName = preferences.get(TARGET_FILE_NAME, "");
|
||||||
runtimeMode = TeaVMRuntimeMode.valueOf(preferences.get(RUNTIME, TeaVMRuntimeMode.SEPARATE.name()));
|
|
||||||
incremental = preferences.getBoolean(INCREMENTAL, false);
|
incremental = preferences.getBoolean(INCREMENTAL, false);
|
||||||
cacheDirectory = preferences.get(CACHE_DIRECTORY, "");
|
cacheDirectory = preferences.get(CACHE_DIRECTORY, "");
|
||||||
sourceMapsGenerated = preferences.getBoolean(SOURCE_MAPS, true);
|
sourceMapsGenerated = preferences.getBoolean(SOURCE_MAPS, true);
|
||||||
|
@ -357,7 +344,6 @@ public class PreferencesBasedTeaVMProjectSettings implements TeaVMProjectSetting
|
||||||
preferences.put(MAIN_CLASS, mainClass);
|
preferences.put(MAIN_CLASS, mainClass);
|
||||||
preferences.put(TARGET_DIRECTORY, targetDirectory);
|
preferences.put(TARGET_DIRECTORY, targetDirectory);
|
||||||
preferences.put(TARGET_FILE_NAME, targetFileName);
|
preferences.put(TARGET_FILE_NAME, targetFileName);
|
||||||
preferences.put(RUNTIME, runtimeMode.name());
|
|
||||||
preferences.putBoolean(INCREMENTAL, incremental);
|
preferences.putBoolean(INCREMENTAL, incremental);
|
||||||
preferences.put(CACHE_DIRECTORY, cacheDirectory);
|
preferences.put(CACHE_DIRECTORY, cacheDirectory);
|
||||||
preferences.putBoolean(SOURCE_MAPS, sourceMapsGenerated);
|
preferences.putBoolean(SOURCE_MAPS, sourceMapsGenerated);
|
||||||
|
|
|
@ -39,10 +39,6 @@ public interface TeaVMProfile {
|
||||||
|
|
||||||
void setTargetFileName(String targetFileName);
|
void setTargetFileName(String targetFileName);
|
||||||
|
|
||||||
TeaVMRuntimeMode getRuntimeMode();
|
|
||||||
|
|
||||||
void setRuntimeMode(TeaVMRuntimeMode runtimeMode);
|
|
||||||
|
|
||||||
boolean isIncremental();
|
boolean isIncremental();
|
||||||
|
|
||||||
void setIncremental(boolean incremental);
|
void setIncremental(boolean incremental);
|
||||||
|
|
|
@ -70,7 +70,6 @@ import org.teavm.model.FieldReference;
|
||||||
import org.teavm.model.MethodReference;
|
import org.teavm.model.MethodReference;
|
||||||
import org.teavm.model.TextLocation;
|
import org.teavm.model.TextLocation;
|
||||||
import org.teavm.model.ValueType;
|
import org.teavm.model.ValueType;
|
||||||
import org.teavm.tooling.RuntimeCopyOperation;
|
|
||||||
import org.teavm.tooling.TeaVMTool;
|
import org.teavm.tooling.TeaVMTool;
|
||||||
import org.teavm.tooling.TeaVMToolException;
|
import org.teavm.tooling.TeaVMToolException;
|
||||||
import org.teavm.tooling.sources.DirectorySourceFileProvider;
|
import org.teavm.tooling.sources.DirectorySourceFileProvider;
|
||||||
|
@ -152,7 +151,6 @@ public class TeaVMProjectBuilder extends IncrementalProjectBuilder {
|
||||||
tool.setTargetDirectory(new File(varManager.performStringSubstitution(targetDir, false)));
|
tool.setTargetDirectory(new File(varManager.performStringSubstitution(targetDir, false)));
|
||||||
tool.setTargetFileName(profile.getTargetFileName());
|
tool.setTargetFileName(profile.getTargetFileName());
|
||||||
tool.setMinifying(false);
|
tool.setMinifying(false);
|
||||||
tool.setRuntime(mapRuntime(profile.getRuntimeMode()));
|
|
||||||
tool.setMainClass(profile.getMainClass());
|
tool.setMainClass(profile.getMainClass());
|
||||||
tool.getProperties().putAll(profile.getProperties());
|
tool.getProperties().putAll(profile.getProperties());
|
||||||
tool.setIncremental(profile.isIncremental());
|
tool.setIncremental(profile.isIncremental());
|
||||||
|
@ -209,17 +207,6 @@ public class TeaVMProjectBuilder extends IncrementalProjectBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private RuntimeCopyOperation mapRuntime(TeaVMRuntimeMode runtimeMode) {
|
|
||||||
switch (runtimeMode) {
|
|
||||||
case MERGE:
|
|
||||||
return RuntimeCopyOperation.MERGED;
|
|
||||||
case SEPARATE:
|
|
||||||
return RuntimeCopyOperation.SEPARATE;
|
|
||||||
default:
|
|
||||||
return RuntimeCopyOperation.NONE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void classesToResources(ProfileData profileData, TeaVMTool tool) {
|
private void classesToResources(ProfileData profileData, TeaVMTool tool) {
|
||||||
Set<String> resourcePaths = new HashSet<>();
|
Set<String> resourcePaths = new HashSet<>();
|
||||||
for (String className : tool.getClasses()) {
|
for (String className : tool.getClasses()) {
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.eclipse;
|
|
||||||
|
|
||||||
public enum TeaVMRuntimeMode {
|
|
||||||
SEPARATE,
|
|
||||||
MERGE,
|
|
||||||
NONE
|
|
||||||
}
|
|
|
@ -66,11 +66,8 @@ import org.eclipse.ui.model.WorkbenchLabelProvider;
|
||||||
import org.eclipse.ui.views.navigator.ResourceComparator;
|
import org.eclipse.ui.views.navigator.ResourceComparator;
|
||||||
import org.teavm.eclipse.TeaVMProfile;
|
import org.teavm.eclipse.TeaVMProfile;
|
||||||
import org.teavm.eclipse.TeaVMProjectSettings;
|
import org.teavm.eclipse.TeaVMProjectSettings;
|
||||||
import org.teavm.eclipse.TeaVMRuntimeMode;
|
|
||||||
|
|
||||||
public class TeaVMProfileDialog extends Dialog {
|
public class TeaVMProfileDialog extends Dialog {
|
||||||
private static List<TeaVMRuntimeMode> runtimeModes = Arrays.asList(TeaVMRuntimeMode.SEPARATE,
|
|
||||||
TeaVMRuntimeMode.MERGE, TeaVMRuntimeMode.NONE);
|
|
||||||
private TabFolder tabFolder;
|
private TabFolder tabFolder;
|
||||||
private Text nameField;
|
private Text nameField;
|
||||||
private Text mainClassField;
|
private Text mainClassField;
|
||||||
|
@ -79,7 +76,6 @@ public class TeaVMProfileDialog extends Dialog {
|
||||||
private Button targetDirectoryWorkspaceButton;
|
private Button targetDirectoryWorkspaceButton;
|
||||||
private Button targetDirectoryFileSystemButton;
|
private Button targetDirectoryFileSystemButton;
|
||||||
private Text targetFileNameField;
|
private Text targetFileNameField;
|
||||||
private Combo runtimeField;
|
|
||||||
private Button incrementalButton;
|
private Button incrementalButton;
|
||||||
private Text cacheDirectoryField;
|
private Text cacheDirectoryField;
|
||||||
private Button cacheDirectoryWorkspaceButton;
|
private Button cacheDirectoryWorkspaceButton;
|
||||||
|
@ -176,7 +172,6 @@ public class TeaVMProfileDialog extends Dialog {
|
||||||
Group group = createGroup(parent, "Output settings", 4, false);
|
Group group = createGroup(parent, "Output settings", 4, false);
|
||||||
createTargetDirectoryField(group);
|
createTargetDirectoryField(group);
|
||||||
createTargetFileNameField(group);
|
createTargetFileNameField(group);
|
||||||
createRuntimeField(group);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createIncrementalGroup(Composite parent) {
|
private void createIncrementalGroup(Composite parent) {
|
||||||
|
@ -425,17 +420,6 @@ public class TeaVMProfileDialog extends Dialog {
|
||||||
targetFileNameField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
|
targetFileNameField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createRuntimeField(Composite container) {
|
|
||||||
Label label = new Label(container, SWT.NONE);
|
|
||||||
label.setText("Attach &runtime:");
|
|
||||||
|
|
||||||
runtimeField = new Combo(container, SWT.DROP_DOWN | SWT.READ_ONLY);
|
|
||||||
runtimeField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 3, 1));
|
|
||||||
runtimeField.add("as a separate file (runtime.js)");
|
|
||||||
runtimeField.add("merge into output file");
|
|
||||||
runtimeField.add("don't attach");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createIncrementalField(Composite container) {
|
private void createIncrementalField(Composite container) {
|
||||||
incrementalButton = new Button(container, SWT.CHECK);
|
incrementalButton = new Button(container, SWT.CHECK);
|
||||||
incrementalButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
|
incrementalButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 4, 1));
|
||||||
|
@ -626,7 +610,6 @@ public class TeaVMProfileDialog extends Dialog {
|
||||||
mainClassField.setText(profile.getMainClass() != null ? profile.getMainClass() : "");
|
mainClassField.setText(profile.getMainClass() != null ? profile.getMainClass() : "");
|
||||||
targetDirectoryField.setText(profile.getTargetDirectory());
|
targetDirectoryField.setText(profile.getTargetDirectory());
|
||||||
targetFileNameField.setText(profile.getTargetFileName());
|
targetFileNameField.setText(profile.getTargetFileName());
|
||||||
runtimeField.select(runtimeModes.indexOf(profile.getRuntimeMode()));
|
|
||||||
incrementalButton.setSelection(profile.isIncremental());
|
incrementalButton.setSelection(profile.isIncremental());
|
||||||
cacheDirectoryField.setText(profile.getCacheDirectory());
|
cacheDirectoryField.setText(profile.getCacheDirectory());
|
||||||
debugInformationButton.setSelection(profile.isDebugInformationGenerated());
|
debugInformationButton.setSelection(profile.isDebugInformationGenerated());
|
||||||
|
@ -663,7 +646,6 @@ public class TeaVMProfileDialog extends Dialog {
|
||||||
profile.setMainClass(!mainClass.isEmpty() ? mainClass : null);
|
profile.setMainClass(!mainClass.isEmpty() ? mainClass : null);
|
||||||
profile.setTargetDirectory(targetDirectoryField.getText());
|
profile.setTargetDirectory(targetDirectoryField.getText());
|
||||||
profile.setTargetFileName(targetFileNameField.getText().trim());
|
profile.setTargetFileName(targetFileNameField.getText().trim());
|
||||||
profile.setRuntimeMode(runtimeModes.get(runtimeField.getSelectionIndex()));
|
|
||||||
profile.setIncremental(incrementalButton.getSelection());
|
profile.setIncremental(incrementalButton.getSelection());
|
||||||
profile.setCacheDirectory(cacheDirectoryField.getText());
|
profile.setCacheDirectory(cacheDirectoryField.getText());
|
||||||
profile.setDebugInformationGenerated(debugInformationButton.getSelection());
|
profile.setDebugInformationGenerated(debugInformationButton.getSelection());
|
||||||
|
|
|
@ -58,7 +58,6 @@ class HtmlUnitRunStrategy implements TestRunStrategy {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
page.get().executeJavaScript(readFile(new File(run.getBaseDirectory(), "runtime.js")));
|
|
||||||
page.get().executeJavaScript(readFile(new File(run.getBaseDirectory(), run.getFileName())));
|
page.get().executeJavaScript(readFile(new File(run.getBaseDirectory(), run.getFileName())));
|
||||||
|
|
||||||
AsyncResult asyncResult = new AsyncResult();
|
AsyncResult asyncResult = new AsyncResult();
|
||||||
|
|
|
@ -424,7 +424,6 @@ public class TeaVMTestRunner extends Runner implements Filterable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void copyJsFilesTo(File path) throws IOException {
|
private void copyJsFilesTo(File path) throws IOException {
|
||||||
resourceToFile("org/teavm/backend/javascript/runtime.js", new File(path, "runtime.js"));
|
|
||||||
resourceToFile("org/teavm/backend/wasm/wasm-runtime.js", new File(path, "test.wasm-runtime.js"));
|
resourceToFile("org/teavm/backend/wasm/wasm-runtime.js", new File(path, "test.wasm-runtime.js"));
|
||||||
resourceToFile("teavm-run-test.html", new File(path, "run-test.html"));
|
resourceToFile("teavm-run-test.html", new File(path, "run-test.html"));
|
||||||
resourceToFile("teavm-run-test-wasm.html", new File(path, "run-test-wasm.html"));
|
resourceToFile("teavm-run-test-wasm.html", new File(path, "run-test-wasm.html"));
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
|
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<script type="text/javascript" src="runtime.js"></script>
|
|
||||||
<script type="text/javascript" src="test.js"></script>
|
<script type="text/javascript" src="test.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$rt_startThread(function() {
|
$rt_startThread(function() {
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.apache.maven.plugins.annotations.Mojo;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||||
import org.teavm.backend.wasm.render.WasmBinaryVersion;
|
import org.teavm.backend.wasm.render.WasmBinaryVersion;
|
||||||
import org.teavm.tooling.RuntimeCopyOperation;
|
|
||||||
import org.teavm.tooling.TeaVMTargetType;
|
import org.teavm.tooling.TeaVMTargetType;
|
||||||
import org.teavm.tooling.TeaVMTool;
|
import org.teavm.tooling.TeaVMTool;
|
||||||
import org.teavm.tooling.TeaVMToolException;
|
import org.teavm.tooling.TeaVMToolException;
|
||||||
|
@ -55,9 +54,6 @@ public class TeaVMCompileMojo extends AbstractTeaVMMojo {
|
||||||
@Parameter
|
@Parameter
|
||||||
private boolean stopOnErrors = true;
|
private boolean stopOnErrors = true;
|
||||||
|
|
||||||
@Parameter
|
|
||||||
protected RuntimeCopyOperation runtime = RuntimeCopyOperation.SEPARATE;
|
|
||||||
|
|
||||||
@Parameter
|
@Parameter
|
||||||
private TeaVMOptimizationLevel optimizationLevel = TeaVMOptimizationLevel.SIMPLE;
|
private TeaVMOptimizationLevel optimizationLevel = TeaVMOptimizationLevel.SIMPLE;
|
||||||
|
|
||||||
|
@ -84,7 +80,6 @@ public class TeaVMCompileMojo extends AbstractTeaVMMojo {
|
||||||
tool.setLog(new MavenTeaVMToolLog(log));
|
tool.setLog(new MavenTeaVMToolLog(log));
|
||||||
try {
|
try {
|
||||||
tool.setMainClass(mainClass);
|
tool.setMainClass(mainClass);
|
||||||
tool.setRuntime(runtime);
|
|
||||||
if (!targetFileName.isEmpty()) {
|
if (!targetFileName.isEmpty()) {
|
||||||
tool.setTargetFileName(targetFileName);
|
tool.setTargetFileName(targetFileName);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user