diff --git a/pom.xml b/pom.xml index e1e47c177..ea900f9c3 100644 --- a/pom.xml +++ b/pom.xml @@ -74,7 +74,7 @@ teavm-core teavm-classlib - teavm-maven-plugin + teavm-maven teavm-dom teavm-jso teavm-html4j diff --git a/teavm-dom/src/main/java/org/teavm/dom/ajax/ReadyStateChangeHandler.java b/teavm-dom/src/main/java/org/teavm/dom/ajax/ReadyStateChangeHandler.java new file mode 100644 index 000000000..6ad6e3074 --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/ajax/ReadyStateChangeHandler.java @@ -0,0 +1,29 @@ +/* + * 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.dom.ajax; + +import org.teavm.jso.JSFunctor; + +import org.teavm.jso.JSObject; + +/** + * + * @author Alexey Andreev + */ +@JSFunctor +public interface ReadyStateChangeHandler extends JSObject { + void stateChanged(); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/ajax/XMLHttpRequest.java b/teavm-dom/src/main/java/org/teavm/dom/ajax/XMLHttpRequest.java new file mode 100644 index 000000000..026a0129e --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/ajax/XMLHttpRequest.java @@ -0,0 +1,70 @@ +/* + * 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.dom.ajax; + +import org.teavm.dom.core.Document; +import org.teavm.jso.JSObject; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface XMLHttpRequest extends JSObject { + int UNSET = 0; + + int OPENED = 1; + + int HEADERS_RECEIVED = 2; + + int LOADING = 3; + + int DONE = 4; + + void open(String method, String url); + + void open(String method, String url, boolean async); + + void open(String method, String url, boolean async, String user); + + void open(String method, String url, boolean async, String user, String password); + + void send(); + + void send(String data); + + void setRequestHeader(String name, String value); + + String getAllResponseHeaders(); + + @JSProperty("onreadystatechange") + void setOnReadyStateChange(ReadyStateChangeHandler handler); + + @JSProperty + int getReadyState(); + + @JSProperty + String getResponseText(); + + @JSProperty + Document getResponseXML(); + + @JSProperty + Integer getStatus(); + + @JSProperty + String getStatusText(); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java b/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java index 7793a0dc5..3487cf32b 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java +++ b/teavm-dom/src/main/java/org/teavm/dom/browser/Window.java @@ -15,7 +15,9 @@ */ package org.teavm.dom.browser; +import org.teavm.dom.ajax.XMLHttpRequest; import org.teavm.dom.html.HTMLDocument; +import org.teavm.jso.JSConstructor; import org.teavm.jso.JSGlobal; import org.teavm.jso.JSObject; import org.teavm.jso.JSProperty; @@ -39,4 +41,7 @@ public interface Window extends JSGlobal { int setInterval(TimerHandler handler, int delay); void clearInterval(int timeoutId); + + @JSConstructor("XMLHttpRequest") + XMLHttpRequest createXMLHttpRequest(); } diff --git a/teavm-dom/src/main/java/org/teavm/dom/html/HTMLBodyElement.java b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLBodyElement.java new file mode 100644 index 000000000..bcd99ebff --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLBodyElement.java @@ -0,0 +1,47 @@ +/* + * 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.dom.html; + +import org.teavm.dom.events.EventListener; +import org.teavm.jso.JSProperty; + +/** + * + * @author Alexey Andreev + */ +public interface HTMLBodyElement extends HTMLElement { + @JSProperty("onbeforeunload") + void setOnBeforeUnload(EventListener listener); + + @JSProperty("onerror") + void setOnError(EventListener listener); + + @JSProperty("onload") + void setOnLoad(EventListener listener); + + @JSProperty("onmessage") + void setOnMessage(EventListener listener); + + @JSProperty("onoffline") + void setOnOffline(EventListener listener); + + @JSProperty("ononline") + void setOnOnline(EventListener listener); + + @JSProperty("ononunload") + void setOnUnload(EventListener listener); +} + diff --git a/teavm-dom/src/main/java/org/teavm/dom/html/HTMLButtonElement.java b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLButtonElement.java new file mode 100644 index 000000000..495ad674b --- /dev/null +++ b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLButtonElement.java @@ -0,0 +1,64 @@ +/* + * 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.dom.html; + +import org.teavm.jso.JSProperty; +import org.w3c.dom.html.HTMLFormElement; + +/** + * + * @author Alexey Andreev + */ +public interface HTMLButtonElement extends HTMLElement { + String TYPE_BUTTON = "button"; + + String TYPE_RESET = "reset"; + + String TYPE_SUBMIT = "submit"; + + @JSProperty + boolean isAutofocus(); + + @JSProperty + void setAutofocus(boolean autofocus); + + @JSProperty + boolean isDisabled(); + + @JSProperty + void setDisabled(boolean disabled); + + @JSProperty + HTMLFormElement getForm(); + + @JSProperty + String getName(); + + @JSProperty + void setName(String name); + + @JSProperty + String getValue(); + + @JSProperty + void setValue(String value); + + @JSProperty + String getType(); + + @JSProperty + void setType(String type); +} diff --git a/teavm-dom/src/main/java/org/teavm/dom/html/HTMLDocument.java b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLDocument.java index 3f1428f99..7578cd2af 100644 --- a/teavm-dom/src/main/java/org/teavm/dom/html/HTMLDocument.java +++ b/teavm-dom/src/main/java/org/teavm/dom/html/HTMLDocument.java @@ -32,4 +32,10 @@ public interface HTMLDocument extends Document { @Override HTMLElement getElementById(String elementId); + + @JSProperty + HTMLBodyElement getBody(); + + @JSProperty + HTMLElement getHead(); } diff --git a/teavm-eclipse/pom.xml b/teavm-eclipse/pom.xml index f17989015..a07bf89cb 100644 --- a/teavm-eclipse/pom.xml +++ b/teavm-eclipse/pom.xml @@ -25,8 +25,8 @@ teavm-eclipse pom - TeaVM Eclipse plugins - TeaVM plugins for Eclipse + TeaVM Eclipse integration + Aggregate project containing all plugins for integration TeaVM with Eclipse http://download.eclipse.org/releases/juno diff --git a/teavm-eclipse/teavm-eclipse-m2e-feature/feature.xml b/teavm-eclipse/teavm-eclipse-m2e-feature/feature.xml index 6caa530e0..3d9b7b606 100644 --- a/teavm-eclipse/teavm-eclipse-m2e-feature/feature.xml +++ b/teavm-eclipse/teavm-eclipse-m2e-feature/feature.xml @@ -5,27 +5,27 @@ version="0.2.0.qualifier" provider-name="Alexey Andreev <konsoletyper@gmail.com>"> - + TeaVM maven configuration support - + - - Copyright 2014 Alexey Andreev. + + Copyright 2014 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 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, + 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. - + - + Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ @@ -229,7 +229,11 @@ limitations under the License. - + + + + 0.2-SNAPSHOT teavm-eclipse-m2e-plugin - eclipse-plugin 0.2.0-SNAPSHOT + eclipse-plugin + + TeaVM m2e plugin + Contains plugin that automatically configures TeaVM builder from pom.xml + org.teavm diff --git a/teavm-eclipse/teavm-eclipse-plugin/pom.xml b/teavm-eclipse/teavm-eclipse-plugin/pom.xml index 4d14d2ccd..ac5a0331d 100644 --- a/teavm-eclipse/teavm-eclipse-plugin/pom.xml +++ b/teavm-eclipse/teavm-eclipse-plugin/pom.xml @@ -25,8 +25,12 @@ teavm-eclipse-plugin 0.2.0-SNAPSHOT + eclipse-plugin + TeaVM Eclipse plugin + Contains TeaVM builder and TeaVM debugger for Eclipse + org.teavm diff --git a/teavm-jso/src/main/java/org/teavm/jso/plugin/JavascriptNativeProcessor.java b/teavm-jso/src/main/java/org/teavm/jso/plugin/JavascriptNativeProcessor.java index 3ae229c10..8751110e7 100644 --- a/teavm-jso/src/main/java/org/teavm/jso/plugin/JavascriptNativeProcessor.java +++ b/teavm-jso/src/main/java/org/teavm/jso/plugin/JavascriptNativeProcessor.java @@ -79,8 +79,14 @@ class JavascriptNativeProcessor { MethodReader method = getMethod(invoke.getMethod()); if (method.getAnnotations().get(JSProperty.class.getName()) != null) { if (isProperGetter(method.getDescriptor())) { - String propertyName = method.getName().charAt(0) == 'i' ? cutPrefix(method.getName(), 2) : + String propertyName; + AnnotationReader annot = method.getAnnotations().get(JSProperty.class.getName()); + if (annot.getValue("value") != null) { + propertyName = annot.getValue("value").getString(); + } else { + propertyName = method.getName().charAt(0) == 'i' ? cutPrefix(method.getName(), 2) : cutPrefix(method.getName(), 3); + } Variable result = invoke.getReceiver() != null ? program.createVariable() : null; addPropertyGet(propertyName, invoke.getInstance(), result); if (result != null) { @@ -88,8 +94,15 @@ class JavascriptNativeProcessor { copyVar(result, invoke.getReceiver()); } } else if (isProperSetter(method.getDescriptor())) { - Variable wrapped = wrap(invoke.getArguments().get(0), method.parameterType(0)); - addPropertySet(cutPrefix(method.getName(), 3), invoke.getInstance(), wrapped); + String propertyName; + AnnotationReader annot = method.getAnnotations().get(JSProperty.class.getName()); + if (annot.getValue("value") != null) { + propertyName = annot.getValue("value").getString(); + } else { + propertyName = cutPrefix(method.getName(), 3); + } + Variable wrapped = wrapArgument(invoke.getArguments().get(0), method.parameterType(0)); + addPropertySet(propertyName, invoke.getInstance(), wrapped); } else { throw new RuntimeException("Method " + invoke.getMethod() + " is not " + "a proper native JavaScript property declaration"); diff --git a/teavm-maven/.gitignore b/teavm-maven/.gitignore new file mode 100644 index 000000000..650751b26 --- /dev/null +++ b/teavm-maven/.gitignore @@ -0,0 +1,2 @@ +/.settings +/.project diff --git a/teavm-maven/pom.xml b/teavm-maven/pom.xml new file mode 100644 index 000000000..fd4fd7e55 --- /dev/null +++ b/teavm-maven/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + + org.teavm + teavm + 0.2-SNAPSHOT + + teavm-maven + + pom + + TeaVM maven + TeaVM maven integration aggregate project + http://teavm.org + + + teavm-maven-plugin + teavm-maven-webapp + + diff --git a/teavm-maven-plugin/.gitignore b/teavm-maven/teavm-maven-plugin/.gitignore similarity index 100% rename from teavm-maven-plugin/.gitignore rename to teavm-maven/teavm-maven-plugin/.gitignore diff --git a/teavm-maven-plugin/pom.xml b/teavm-maven/teavm-maven-plugin/pom.xml similarity index 98% rename from teavm-maven-plugin/pom.xml rename to teavm-maven/teavm-maven-plugin/pom.xml index 3af9a9958..109a66204 100644 --- a/teavm-maven-plugin/pom.xml +++ b/teavm-maven/teavm-maven-plugin/pom.xml @@ -19,7 +19,7 @@ org.teavm - teavm + teavm-maven 0.2-SNAPSHOT teavm-maven-plugin diff --git a/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptMojo.java b/teavm-maven/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptMojo.java similarity index 100% rename from teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptMojo.java rename to teavm-maven/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptMojo.java diff --git a/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptTestMojo.java b/teavm-maven/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptTestMojo.java similarity index 100% rename from teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptTestMojo.java rename to teavm-maven/teavm-maven-plugin/src/main/java/org/teavm/maven/BuildJavascriptTestMojo.java diff --git a/teavm-maven-plugin/src/main/java/org/teavm/maven/MavenTeaVMToolLog.java b/teavm-maven/teavm-maven-plugin/src/main/java/org/teavm/maven/MavenTeaVMToolLog.java similarity index 100% rename from teavm-maven-plugin/src/main/java/org/teavm/maven/MavenTeaVMToolLog.java rename to teavm-maven/teavm-maven-plugin/src/main/java/org/teavm/maven/MavenTeaVMToolLog.java diff --git a/teavm-maven-plugin/src/main/java/org/teavm/maven/MethodAliasArgument.java b/teavm-maven/teavm-maven-plugin/src/main/java/org/teavm/maven/MethodAliasArgument.java similarity index 100% rename from teavm-maven-plugin/src/main/java/org/teavm/maven/MethodAliasArgument.java rename to teavm-maven/teavm-maven-plugin/src/main/java/org/teavm/maven/MethodAliasArgument.java diff --git a/teavm-maven-plugin/src/main/java/org/teavm/maven/TestExceptionDependency.java b/teavm-maven/teavm-maven-plugin/src/main/java/org/teavm/maven/TestExceptionDependency.java similarity index 100% rename from teavm-maven-plugin/src/main/java/org/teavm/maven/TestExceptionDependency.java rename to teavm-maven/teavm-maven-plugin/src/main/java/org/teavm/maven/TestExceptionDependency.java diff --git a/teavm-maven-plugin/src/main/java/org/teavm/maven/TestExceptionPlugin.java b/teavm-maven/teavm-maven-plugin/src/main/java/org/teavm/maven/TestExceptionPlugin.java similarity index 100% rename from teavm-maven-plugin/src/main/java/org/teavm/maven/TestExceptionPlugin.java rename to teavm-maven/teavm-maven-plugin/src/main/java/org/teavm/maven/TestExceptionPlugin.java diff --git a/teavm-maven-plugin/src/test/java/.gitignore b/teavm-maven/teavm-maven-plugin/src/test/java/.gitignore similarity index 100% rename from teavm-maven-plugin/src/test/java/.gitignore rename to teavm-maven/teavm-maven-plugin/src/test/java/.gitignore diff --git a/teavm-maven-plugin/src/test/resources/.gitignore b/teavm-maven/teavm-maven-plugin/src/test/resources/.gitignore similarity index 100% rename from teavm-maven-plugin/src/test/resources/.gitignore rename to teavm-maven/teavm-maven-plugin/src/test/resources/.gitignore diff --git a/teavm-maven/teavm-maven-webapp/.gitignore b/teavm-maven/teavm-maven-webapp/.gitignore new file mode 100644 index 000000000..c708c363d --- /dev/null +++ b/teavm-maven/teavm-maven-webapp/.gitignore @@ -0,0 +1,4 @@ +/target +/.settings +/.classpath +/.project diff --git a/teavm-maven/teavm-maven-webapp/pom.xml b/teavm-maven/teavm-maven-webapp/pom.xml new file mode 100644 index 000000000..1a03701cc --- /dev/null +++ b/teavm-maven/teavm-maven-webapp/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + + org.teavm + teavm-maven + 0.2-SNAPSHOT + + teavm-maven-webapp + TeaVM maven web application archetype + + maven-archetype + + An archetype that creates a simple web application with enabled TeaVM + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + org.apache.maven.plugins + maven-archetype-plugin + 2.2 + + + + + \ No newline at end of file diff --git a/teavm-maven/teavm-maven-webapp/src/main/resources/META-INF/maven/archetype-metadata.xml b/teavm-maven/teavm-maven-webapp/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 000000000..d9360669a --- /dev/null +++ b/teavm-maven/teavm-maven-webapp/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,25 @@ + + + + + + + + + src/main/java + + + . + + pom.xml + + + + src/main/webapp + + + \ No newline at end of file diff --git a/teavm-maven/teavm-maven-webapp/src/main/resources/archetype-resources/pom.xml b/teavm-maven/teavm-maven-webapp/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 000000000..d62cdf9b7 --- /dev/null +++ b/teavm-maven/teavm-maven-webapp/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,109 @@ + + 4.0.0 + + ${groupId} + ${artifactId} + ${version} + war + + + 1.7 + 0.2-SNAPSHOT + + + + + + org.teavm + teavm-classlib + ${teavm.version} + + + + + org.teavm + teavm-jso + ${teavm.version} + + + + + org.teavm + teavm-dom + ${teavm.version} + + + + + javax.servlet + javax.servlet-api + 3.1.0 + provided + + + + + + + + maven-compiler-plugin + 3.1 + + ${java.version} + ${java.version} + + + + + + maven-war-plugin + 2.4 + + + + ${project.build.directory}/generated/js + + + + + + + + org.teavm + teavm-maven-plugin + ${teavm.version} + + + web-client + prepare-package + + build-javascript + + + + ${project.build.directory}/generated/js/teavm + + + ${package}.Client + + + SEPARATE + + + true + + + true + + + true + + + + + + + \ No newline at end of file diff --git a/teavm-maven/teavm-maven-webapp/src/main/resources/archetype-resources/src/main/java/Client.java b/teavm-maven/teavm-maven-webapp/src/main/resources/archetype-resources/src/main/java/Client.java new file mode 100644 index 000000000..15ca84491 --- /dev/null +++ b/teavm-maven/teavm-maven-webapp/src/main/resources/archetype-resources/src/main/java/Client.java @@ -0,0 +1,17 @@ +package ${package}; + +import org.teavm.dom.browser.Window; +import org.teavm.dom.html.HTMLDocument; +import org.teavm.dom.html.HTMLElement; +import org.teavm.jso.JS; + +public class Client { + private static Window window = (Window)JS.getGlobal(); + private static HTMLDocument document = window.getDocument(); + + public static void main(String[] args) { + HTMLElement div = document.createElement("div"); + div.appendChild(document.createTextNode("TeaVM generated element")); + document.getBody().appendChild(div); + } +} diff --git a/teavm-maven/teavm-maven-webapp/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml b/teavm-maven/teavm-maven-webapp/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 000000000..1fb824230 --- /dev/null +++ b/teavm-maven/teavm-maven-webapp/src/main/resources/archetype-resources/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/teavm-maven/teavm-maven-webapp/src/main/resources/archetype-resources/src/main/webapp/index.html b/teavm-maven/teavm-maven-webapp/src/main/resources/archetype-resources/src/main/webapp/index.html new file mode 100644 index 000000000..ef607a1c1 --- /dev/null +++ b/teavm-maven/teavm-maven-webapp/src/main/resources/archetype-resources/src/main/webapp/index.html @@ -0,0 +1,11 @@ + + + + Main page + + + + + + + \ No newline at end of file