1.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Thu May 15 11:38:27 2014 +0200
1.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/PageProcessor.java Mon Jun 09 15:57:14 2014 +0200
1.3 @@ -1329,6 +1329,7 @@
1.4 return ret;
1.5 }
1.6
1.7 + @ExtraJavaScript(processByteCode = false, resource = "")
1.8 private static class Prprt {
1.9 private final Element e;
1.10 private final AnnotationMirror tm;
2.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java Thu May 15 11:38:27 2014 +0200
2.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Canvas.java Mon Jun 09 15:57:14 2014 +0200
2.3 @@ -51,7 +51,7 @@
2.4 @JavaScriptBody(
2.5 args = {"el"},
2.6 body = "var e = window.document.getElementById(el._id());\n"
2.7 - + "return e.getContext('2d');\n")
2.8 + + "return e['getContext']('2d');\n")
2.9 private native static Object getContextImpl(Canvas el);
2.10
2.11 public GraphicsContext getContext() {
3.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Thu May 15 11:38:27 2014 +0200
3.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/Element.java Mon Jun 09 15:57:14 2014 +0200
3.3 @@ -69,7 +69,7 @@
3.4 body="var e = window.document.getElementById(this._id());\n"
3.5 + "e[ev._id()] = function(ev) {\n"
3.6 + " var d = ev ? ev : null;\n"
3.7 - + " r.onEvent__VLjava_lang_Object_2(d);\n"
3.8 + + " r['onEvent__VLjava_lang_Object_2'](d);\n"
3.9 + "};\n"
3.10 )
3.11 final void on(OnEvent ev, OnHandler r) {
4.1 --- a/javaquery/demo-calculator-dynamic/nbactions.xml Thu May 15 11:38:27 2014 +0200
4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
4.3 @@ -1,29 +0,0 @@
4.4 -<?xml version="1.0" encoding="UTF-8"?>
4.5 -<!--
4.6 -
4.7 - Back 2 Browser Bytecode Translator
4.8 - Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
4.9 -
4.10 - This program is free software: you can redistribute it and/or modify
4.11 - it under the terms of the GNU General Public License as published by
4.12 - the Free Software Foundation, version 2 of the License.
4.13 -
4.14 - This program is distributed in the hope that it will be useful,
4.15 - but WITHOUT ANY WARRANTY; without even the implied warranty of
4.16 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4.17 - GNU General Public License for more details.
4.18 -
4.19 - You should have received a copy of the GNU General Public License
4.20 - along with this program. Look for COPYING file in the top folder.
4.21 - If not, see http://opensource.org/licenses/GPL-2.0.
4.22 -
4.23 --->
4.24 -<actions>
4.25 - <action>
4.26 - <actionName>run</actionName>
4.27 - <goals>
4.28 - <goal>process-classes</goal>
4.29 - <goal>bck2brwsr:brwsr</goal>
4.30 - </goals>
4.31 - </action>
4.32 - </actions>
5.1 --- a/javaquery/demo-calculator-dynamic/pom.xml Thu May 15 11:38:27 2014 +0200
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,119 +0,0 @@
5.4 -<?xml version="1.0"?>
5.5 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5.6 - <modelVersion>4.0.0</modelVersion>
5.7 -
5.8 - <groupId>org.apidesign.bck2brwsr</groupId>
5.9 - <artifactId>demo.calculator</artifactId>
5.10 - <version>0.9-SNAPSHOT</version>
5.11 - <packaging>jar</packaging>
5.12 -
5.13 - <name>JavaQuery Demo - Calculator</name>
5.14 - <url>http://maven.apache.org</url>
5.15 -
5.16 - <properties>
5.17 - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5.18 - </properties>
5.19 - <build>
5.20 - <plugins>
5.21 - <plugin>
5.22 - <groupId>org.apidesign.bck2brwsr</groupId>
5.23 - <artifactId>bck2brwsr-maven-plugin</artifactId>
5.24 - <version>${project.version}</version>
5.25 - <executions>
5.26 - <execution>
5.27 - <goals>
5.28 - <goal>brwsr</goal>
5.29 - </goals>
5.30 - </execution>
5.31 - </executions>
5.32 - <configuration>
5.33 - <startpage>org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml</startpage>
5.34 - </configuration>
5.35 - </plugin>
5.36 - <plugin>
5.37 - <groupId>org.apache.maven.plugins</groupId>
5.38 - <artifactId>maven-compiler-plugin</artifactId>
5.39 - <version>2.3.2</version>
5.40 - <configuration>
5.41 - <source>1.7</source>
5.42 - <target>1.7</target>
5.43 - </configuration>
5.44 - </plugin>
5.45 - <plugin>
5.46 - <groupId>org.apache.maven.plugins</groupId>
5.47 - <artifactId>maven-jar-plugin</artifactId>
5.48 - <version>2.4</version>
5.49 - <configuration>
5.50 - <archive>
5.51 - <manifest>
5.52 - <addClasspath>true</addClasspath>
5.53 - <classpathPrefix>lib/</classpathPrefix>
5.54 - </manifest>
5.55 - </archive>
5.56 - </configuration>
5.57 - </plugin>
5.58 - <plugin>
5.59 - <groupId>org.apache.maven.plugins</groupId>
5.60 - <artifactId>maven-deploy-plugin</artifactId>
5.61 - <version>2.7</version>
5.62 - <configuration>
5.63 - <skip>true</skip>
5.64 - </configuration>
5.65 - </plugin>
5.66 - <plugin>
5.67 - <groupId>org.apache.maven.plugins</groupId>
5.68 - <artifactId>maven-javadoc-plugin</artifactId>
5.69 - <version>2.9</version>
5.70 - <configuration>
5.71 - <skip>true</skip>
5.72 - </configuration>
5.73 - </plugin>
5.74 - <plugin>
5.75 - <artifactId>maven-assembly-plugin</artifactId>
5.76 - <version>2.4</version>
5.77 - <executions>
5.78 - <execution>
5.79 - <id>distro-assembly</id>
5.80 - <phase>package</phase>
5.81 - <goals>
5.82 - <goal>single</goal>
5.83 - </goals>
5.84 - <configuration>
5.85 - <descriptors>
5.86 - <descriptor>src/main/assembly/bck2brwsr.xml</descriptor>
5.87 - </descriptors>
5.88 - </configuration>
5.89 - </execution>
5.90 - </executions>
5.91 - </plugin>
5.92 - </plugins>
5.93 - </build>
5.94 -
5.95 - <dependencies>
5.96 - <dependency>
5.97 - <groupId>org.apidesign.bck2brwsr</groupId>
5.98 - <artifactId>emul</artifactId>
5.99 - <version>${project.version}</version>
5.100 - <classifier>rt</classifier>
5.101 - </dependency>
5.102 - <dependency>
5.103 - <groupId>org.apidesign.bck2brwsr</groupId>
5.104 - <artifactId>javaquery.api</artifactId>
5.105 - <version>${project.version}</version>
5.106 - </dependency>
5.107 - <dependency>
5.108 - <groupId>org.testng</groupId>
5.109 - <artifactId>testng</artifactId>
5.110 - <version>6.5.2</version>
5.111 - <scope>test</scope>
5.112 - </dependency>
5.113 - <dependency>
5.114 - <groupId>org.apidesign.bck2brwsr</groupId>
5.115 - <artifactId>vm4brwsr</artifactId>
5.116 - <classifier>js</classifier>
5.117 - <type>zip</type>
5.118 - <version>${project.version}</version>
5.119 - <scope>provided</scope>
5.120 - </dependency>
5.121 - </dependencies>
5.122 -</project>
6.1 --- a/javaquery/demo-calculator-dynamic/src/main/assembly/bck2brwsr.xml Thu May 15 11:38:27 2014 +0200
6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
6.3 @@ -1,62 +0,0 @@
6.4 -<?xml version="1.0"?>
6.5 -<!--
6.6 -
6.7 - Back 2 Browser Bytecode Translator
6.8 - Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
6.9 -
6.10 - This program is free software: you can redistribute it and/or modify
6.11 - it under the terms of the GNU General Public License as published by
6.12 - the Free Software Foundation, version 2 of the License.
6.13 -
6.14 - This program is distributed in the hope that it will be useful,
6.15 - but WITHOUT ANY WARRANTY; without even the implied warranty of
6.16 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6.17 - GNU General Public License for more details.
6.18 -
6.19 - You should have received a copy of the GNU General Public License
6.20 - along with this program. Look for COPYING file in the top folder.
6.21 - If not, see http://opensource.org/licenses/GPL-2.0.
6.22 -
6.23 --->
6.24 -<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6.25 - xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
6.26 -
6.27 - <id>bck2brwsr</id>
6.28 - <formats>
6.29 - <format>zip</format>
6.30 - <format>dir</format>
6.31 - </formats>
6.32 - <baseDirectory>public_html</baseDirectory>
6.33 - <dependencySets>
6.34 - <dependencySet>
6.35 - <useProjectArtifact>false</useProjectArtifact>
6.36 - <scope>runtime</scope>
6.37 - <outputDirectory>lib</outputDirectory>
6.38 - <includes>
6.39 - <include>*:jar</include>
6.40 - <include>*:rt</include>
6.41 - </includes>
6.42 - </dependencySet>
6.43 - <dependencySet>
6.44 - <useProjectArtifact>false</useProjectArtifact>
6.45 - <scope>provided</scope>
6.46 - <includes>
6.47 - <include>*:js</include>
6.48 - </includes>
6.49 - <unpack>true</unpack>
6.50 - <outputDirectory>/</outputDirectory>
6.51 - </dependencySet>
6.52 - </dependencySets>
6.53 - <files>
6.54 - <file>
6.55 - <source>${project.build.directory}/${project.build.finalName}.jar</source>
6.56 - <outputDirectory>/</outputDirectory>
6.57 - </file>
6.58 - <file>
6.59 - <source>${project.build.directory}/classes/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml</source>
6.60 - <outputDirectory>/</outputDirectory>
6.61 - <destName>index.xhtml</destName>
6.62 - </file>
6.63 - </files>
6.64 -
6.65 -</assembly>
6.66 \ No newline at end of file
7.1 --- a/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/Calc.java Thu May 15 11:38:27 2014 +0200
7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
7.3 @@ -1,146 +0,0 @@
7.4 -/**
7.5 - * Back 2 Browser Bytecode Translator
7.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
7.7 - *
7.8 - * This program is free software: you can redistribute it and/or modify
7.9 - * it under the terms of the GNU General Public License as published by
7.10 - * the Free Software Foundation, version 2 of the License.
7.11 - *
7.12 - * This program is distributed in the hope that it will be useful,
7.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
7.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7.15 - * GNU General Public License for more details.
7.16 - *
7.17 - * You should have received a copy of the GNU General Public License
7.18 - * along with this program. Look for COPYING file in the top folder.
7.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
7.20 - */
7.21 -package org.apidesign.bck2brwsr.demo.calc;
7.22 -
7.23 -import java.util.List;
7.24 -import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
7.25 -import org.apidesign.bck2brwsr.htmlpage.api.On;
7.26 -import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*;
7.27 -import org.apidesign.bck2brwsr.htmlpage.api.OnFunction;
7.28 -import org.apidesign.bck2brwsr.htmlpage.api.Page;
7.29 -import org.apidesign.bck2brwsr.htmlpage.api.Property;
7.30 -
7.31 -/** HTML5 & Java demo showing the power of
7.32 - * <a href="http://wiki.apidesign.org/wiki/AnnotationProcessor">annotation processors</a>
7.33 - * as well as other goodies.
7.34 - *
7.35 - * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
7.36 - */
7.37 -@Page(xhtml="Calculator.xhtml", properties = {
7.38 - @Property(name = "memory", type = double.class),
7.39 - @Property(name = "display", type = double.class),
7.40 - @Property(name = "operation", type = String.class),
7.41 - @Property(name = "hover", type = boolean.class),
7.42 - @Property(name = "history", type = HistoryImpl.class, array = true)
7.43 -})
7.44 -public class Calc {
7.45 - static {
7.46 - new Calculator().applyBindings().setOperation("plus");
7.47 - }
7.48 -
7.49 - @On(event = CLICK, id="clear")
7.50 - static void clear(Calculator c) {
7.51 - c.setMemory(0);
7.52 - c.setOperation(null);
7.53 - c.setDisplay(0);
7.54 - }
7.55 -
7.56 - @On(event = CLICK, id= { "plus", "minus", "mul", "div" })
7.57 - static void applyOp(Calculator c, String id) {
7.58 - c.setMemory(c.getDisplay());
7.59 - c.setOperation(id);
7.60 - c.setDisplay(0);
7.61 - }
7.62 -
7.63 - @On(event = MOUSE_OVER, id= { "result" })
7.64 - static void attemptingIn(Calculator c) {
7.65 - c.setHover(true);
7.66 - }
7.67 - @On(event = MOUSE_OUT, id= { "result" })
7.68 - static void attemptingOut(Calculator c) {
7.69 - c.setHover(false);
7.70 - }
7.71 -
7.72 - @On(event = CLICK, id="result")
7.73 - static void computeTheValue(Calculator c) {
7.74 - final double newValue = compute(
7.75 - c.getOperation(),
7.76 - c.getMemory(),
7.77 - c.getDisplay()
7.78 - );
7.79 - c.setDisplay(newValue);
7.80 - if (!containsValue(c.getHistory(), newValue)) {
7.81 - History h = new History();
7.82 - h.setValue(newValue);
7.83 - h.setOperation(c.getOperation());
7.84 - c.getHistory().add(h);
7.85 - }
7.86 - c.setMemory(0);
7.87 - }
7.88 -
7.89 - @OnFunction
7.90 - static void recoverMemory(Calculator c, History data) {
7.91 - c.setDisplay(data.getValue());
7.92 - }
7.93 -
7.94 - @OnFunction
7.95 - static void removeMemory(Calculator c, History data) {
7.96 - c.getHistory().remove(data);
7.97 - }
7.98 -
7.99 - private static double compute(String op, double memory, double display) {
7.100 - switch (op) {
7.101 - case "plus": return memory + display;
7.102 - case "minus": return memory - display;
7.103 - case "mul": return memory * display;
7.104 - case "div": return memory / display;
7.105 - default: throw new IllegalStateException(op);
7.106 - }
7.107 - }
7.108 -
7.109 - @On(event = CLICK, id={"n0", "n1", "n2", "n3", "n4", "n5", "n6", "n7", "n8", "n9"})
7.110 - static void addDigit(String id, Calculator c) {
7.111 - id = id.substring(1);
7.112 -
7.113 - double v = c.getDisplay();
7.114 - if (v == 0.0) {
7.115 - c.setDisplay(Integer.parseInt(id));
7.116 - } else {
7.117 - String txt = Double.toString(v);
7.118 - if (txt.endsWith(".0")) {
7.119 - txt = txt.substring(0, txt.length() - 2);
7.120 - }
7.121 - txt = txt + id;
7.122 - c.setDisplay(Double.parseDouble(txt));
7.123 - }
7.124 - }
7.125 -
7.126 - @ComputedProperty
7.127 - public static String displayPreview(
7.128 - double display, boolean hover, double memory, String operation
7.129 - ) {
7.130 - if (!hover) {
7.131 - return "Type numbers and perform simple operations! Press '=' to get result.";
7.132 - }
7.133 - return "Attempt to compute " + memory + " " + operation + " " + display + " = " + compute(operation, memory, display);
7.134 - }
7.135 -
7.136 - @ComputedProperty
7.137 - static boolean emptyHistory(List<?> history) {
7.138 - return history.isEmpty();
7.139 - }
7.140 -
7.141 - private static boolean containsValue(List<History> arr, final double newValue) {
7.142 - for (History history : arr) {
7.143 - if (history.getValue() == newValue) {
7.144 - return true;
7.145 - }
7.146 - }
7.147 - return false;
7.148 - }
7.149 -}
8.1 --- a/javaquery/demo-calculator-dynamic/src/main/java/org/apidesign/bck2brwsr/demo/calc/HistoryImpl.java Thu May 15 11:38:27 2014 +0200
8.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
8.3 @@ -1,43 +0,0 @@
8.4 -/**
8.5 - * Back 2 Browser Bytecode Translator
8.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
8.7 - *
8.8 - * This program is free software: you can redistribute it and/or modify
8.9 - * it under the terms of the GNU General Public License as published by
8.10 - * the Free Software Foundation, version 2 of the License.
8.11 - *
8.12 - * This program is distributed in the hope that it will be useful,
8.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.15 - * GNU General Public License for more details.
8.16 - *
8.17 - * You should have received a copy of the GNU General Public License
8.18 - * along with this program. Look for COPYING file in the top folder.
8.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
8.20 - */
8.21 -package org.apidesign.bck2brwsr.demo.calc;
8.22 -
8.23 -import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty;
8.24 -import org.apidesign.bck2brwsr.htmlpage.api.Model;
8.25 -import org.apidesign.bck2brwsr.htmlpage.api.OnFunction;
8.26 -import org.apidesign.bck2brwsr.htmlpage.api.Property;
8.27 -
8.28 -/**
8.29 - *
8.30 - * @author Jaroslav Tulach <jtulach@netbeans.org>
8.31 - */
8.32 -@Model(className = "History", properties = {
8.33 - @Property(name = "value", type = double.class),
8.34 - @Property(name = "operation", type = String.class)
8.35 -})
8.36 -public class HistoryImpl {
8.37 - @ComputedProperty
8.38 - static String resultOf(String operation) {
8.39 - return "result of " + operation;
8.40 - }
8.41 -
8.42 - @OnFunction
8.43 - static void twice(History data) {
8.44 - data.setValue(2.0 * data.getValue());
8.45 - }
8.46 -}
9.1 --- a/javaquery/demo-calculator-dynamic/src/main/resources/org/apidesign/bck2brwsr/demo/calc/Calculator.xhtml Thu May 15 11:38:27 2014 +0200
9.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
9.3 @@ -1,102 +0,0 @@
9.4 -<?xml version="1.0" encoding="UTF-8"?>
9.5 -<!--
9.6 -
9.7 - Back 2 Browser Bytecode Translator
9.8 - Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
9.9 -
9.10 - This program is free software: you can redistribute it and/or modify
9.11 - it under the terms of the GNU General Public License as published by
9.12 - the Free Software Foundation, version 2 of the License.
9.13 -
9.14 - This program is distributed in the hope that it will be useful,
9.15 - but WITHOUT ANY WARRANTY; without even the implied warranty of
9.16 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9.17 - GNU General Public License for more details.
9.18 -
9.19 - You should have received a copy of the GNU General Public License
9.20 - along with this program. Look for COPYING file in the top folder.
9.21 - If not, see http://opensource.org/licenses/GPL-2.0.
9.22 -
9.23 --->
9.24 -<!DOCTYPE html>
9.25 -<html xmlns="http://www.w3.org/1999/xhtml">
9.26 - <head>
9.27 - <title>Simple Calculator in HTML5 and Java</title>
9.28 -
9.29 - <style type="text/css">
9.30 - body {color: #ffffff; background-color: #121e31; font-family: Monospaced}
9.31 - pre {color: #ffffff; background-color: #121e31; font-family: Monospaced}
9.32 - table {color: #ffffff; background-color: #121e31; font-family: Monospaced}
9.33 - .string {color: #e2ce00}
9.34 - a {color: #e2ce00}
9.35 - .ST1 {color: #0000cc; font-family: Monospaced; font-weight: bold}
9.36 - .ST0 {color: #0000ff}
9.37 - .comment {color: #428bdd}
9.38 - .keyword-directive {color: #f8bb00}
9.39 - .tag {color: #f8bb00}
9.40 - .ST0 {color: #628fb5; background-color: #1b3450}
9.41 - .sgml-comment {color: #808080}
9.42 - .value {color: #99006b}
9.43 - .argument {color: #007c00}
9.44 - .sgml-declaration {color: #bf9221}
9.45 - </style>
9.46 - </head>
9.47 - <body>
9.48 - <h1>Java and HTML5 - Together at Last!</h1>
9.49 - <table border="0" cellspacing="2">
9.50 - <tbody>
9.51 - <tr>
9.52 - <td colspan="4"><input data-bind="value: display" value="0"
9.53 - style="text-align: right"/>
9.54 - </td>
9.55 - </tr>
9.56 - <tr>
9.57 - <td><button id="n1">1</button></td>
9.58 - <td><button id="n2">2</button></td>
9.59 - <td><button id="n3">3</button></td>
9.60 - <td><button id="plus">+</button></td>
9.61 - </tr>
9.62 - <tr>
9.63 - <td><button id="n4">4</button></td>
9.64 - <td><button id="n5">5</button></td>
9.65 - <td><button id="n6">6</button></td>
9.66 - <td><button id="minus">-</button></td>
9.67 - </tr>
9.68 - <tr>
9.69 - <td><button id="n7">7</button></td>
9.70 - <td><button id="n8">8</button></td>
9.71 - <td><button id="n9">9</button></td>
9.72 - <td><button id="mul">*</button></td>
9.73 - </tr>
9.74 - <tr>
9.75 - <td><button id="clear">C</button></td>
9.76 - <td><button id="n0">0</button></td>
9.77 - <td><button id="result">=</button></td>
9.78 - <td><button id="div">/</button></td>
9.79 - </tr>
9.80 - </tbody>
9.81 - </table>
9.82 - <div data-bind="text: displayPreview"></div>
9.83 -
9.84 - <h4>Previous Results</h4>
9.85 -
9.86 - <div data-bind="if: emptyHistory">No results yet.</div>
9.87 - <ul data-bind="foreach: history">
9.88 - <li>
9.89 - <span data-bind="text: $data.value"></span> -
9.90 - <a href="#" data-bind="click: $root.recoverMemory">Use</a>
9.91 - <a href="#" data-bind="click: $root.removeMemory">Remove</a>
9.92 - <a href="#" data-bind="click: $data.twice">Double</a> -
9.93 - <span data-bind="text: $data.resultOf"></span>
9.94 - </li>
9.95 - </ul>
9.96 -
9.97 - <script src="bck2brwsr.js"></script>
9.98 - <script type="text/javascript">
9.99 - var vm = bck2brwsr('demo.calculator-0.6.jar');
9.100 - vm.loadClass('org.apidesign.bck2brwsr.demo.calc.Calc');
9.101 - </script>
9.102 -
9.103 - <hr/>
9.104 - </body>
9.105 -</html>
10.1 --- a/javaquery/demo-calculator-dynamic/src/test/java/org/apidesign/bck2brwsr/demo/calc/CalcTest.java Thu May 15 11:38:27 2014 +0200
10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
10.3 @@ -1,46 +0,0 @@
10.4 -/**
10.5 - * Back 2 Browser Bytecode Translator
10.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
10.7 - *
10.8 - * This program is free software: you can redistribute it and/or modify
10.9 - * it under the terms of the GNU General Public License as published by
10.10 - * the Free Software Foundation, version 2 of the License.
10.11 - *
10.12 - * This program is distributed in the hope that it will be useful,
10.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
10.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10.15 - * GNU General Public License for more details.
10.16 - *
10.17 - * You should have received a copy of the GNU General Public License
10.18 - * along with this program. Look for COPYING file in the top folder.
10.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
10.20 - */
10.21 -package org.apidesign.bck2brwsr.demo.calc;
10.22 -
10.23 -import static org.testng.Assert.*;
10.24 -import org.testng.annotations.BeforeMethod;
10.25 -import org.testng.annotations.Test;
10.26 -
10.27 -/** Demonstrating POJO testing of HTML page model.
10.28 - *
10.29 - * @author Jaroslav Tulach <jtulach@netbeans.org>
10.30 - */
10.31 -public class CalcTest {
10.32 - private Calculator model;
10.33 -
10.34 -
10.35 - @BeforeMethod
10.36 - public void initModel() {
10.37 - model = new Calculator().applyBindings();
10.38 - }
10.39 -
10.40 - @Test
10.41 - public void testSomeMethod() {
10.42 - model.setDisplay(10);
10.43 - Calc.applyOp(model, "plus");
10.44 - assertEquals(0.0, model.getDisplay(), "Cleared after pressing +");
10.45 - model.setDisplay(5);
10.46 - Calc.computeTheValue(model);
10.47 - assertEquals(15.0, model.getDisplay(), "Shows fifteen");
10.48 - }
10.49 -}
11.1 --- a/javaquery/demo-calculator/nbactions.xml Thu May 15 11:38:27 2014 +0200
11.2 +++ b/javaquery/demo-calculator/nbactions.xml Mon Jun 09 15:57:14 2014 +0200
11.3 @@ -23,10 +23,11 @@
11.4 <actionName>run</actionName>
11.5 <goals>
11.6 <goal>package</goal>
11.7 - <goal>bck2brwsr:brwsr</goal>
11.8 + <goal>bck2brwsr:show</goal>
11.9 </goals>
11.10 <properties>
11.11 <skipTests>true</skipTests>
11.12 + <bck2brwsr.obfuscationlevel>NONE</bck2brwsr.obfuscationlevel>
11.13 </properties>
11.14 </action>
11.15 </actions>
12.1 --- a/javaquery/demo-calculator/pom.xml Thu May 15 11:38:27 2014 +0200
12.2 +++ b/javaquery/demo-calculator/pom.xml Mon Jun 09 15:57:14 2014 +0200
12.3 @@ -12,7 +12,8 @@
12.4
12.5 <properties>
12.6 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
12.7 - <bck2brwsr.obfuscationlevel>MINIMAL</bck2brwsr.obfuscationlevel>
12.8 + <bck2brwsr.obfuscationlevel>FULL</bck2brwsr.obfuscationlevel>
12.9 + <netbeans.compile.on.save>NONE</netbeans.compile.on.save>
12.10 </properties>
12.11 <build>
12.12 <plugins>
12.13 @@ -23,16 +24,19 @@
12.14 <executions>
12.15 <execution>
12.16 <goals>
12.17 - <goal>j2js</goal>
12.18 - <goal>brwsr</goal>
12.19 + <goal>aot</goal>
12.20 + <goal>show</goal>
12.21 </goals>
12.22 </execution>
12.23 </executions>
12.24 <configuration>
12.25 <directory>${project.build.directory}/${project.build.finalName}-bck2brwsr/public_html/</directory>
12.26 <startpage>index.xhtml</startpage>
12.27 - <javascript>${project.build.directory}/bck2brwsr.js</javascript>
12.28 + <mainJavaScript>${project.build.directory}/calculator.js</mainJavaScript>
12.29 <obfuscation>${bck2brwsr.obfuscationlevel}</obfuscation>
12.30 + <exports>
12.31 + <param>org/apidesign/bck2brwsr/demo/calc/staticcompilation/</param>
12.32 + </exports>
12.33 </configuration>
12.34 </plugin>
12.35 <plugin>
13.1 --- a/javaquery/demo-calculator/src/main/assembly/bck2brwsr.xml Thu May 15 11:38:27 2014 +0200
13.2 +++ b/javaquery/demo-calculator/src/main/assembly/bck2brwsr.xml Mon Jun 09 15:57:14 2014 +0200
13.3 @@ -27,27 +27,19 @@
13.4 <format>dir</format>
13.5 </formats>
13.6 <baseDirectory>public_html</baseDirectory>
13.7 - <dependencySets>
13.8 - <dependencySet>
13.9 - <useProjectArtifact>false</useProjectArtifact>
13.10 - <scope>runtime</scope>
13.11 - <outputDirectory>lib</outputDirectory>
13.12 - <includes>
13.13 - <include>*:jar</include>
13.14 - <include>*:rt</include>
13.15 - </includes>
13.16 - </dependencySet>
13.17 - </dependencySets>
13.18 + <fileSets>
13.19 + <fileSet>
13.20 + <directory>${project.build.directory}</directory>
13.21 + <outputDirectory>/</outputDirectory>
13.22 + <includes>
13.23 + <include>bck2brwsr.js</include>
13.24 + <include>calculator.js</include>
13.25 + <include>lib/*.js</include>
13.26 + </includes>
13.27 + </fileSet>
13.28 + </fileSets>
13.29 <files>
13.30 <file>
13.31 - <source>${project.build.directory}/${project.build.finalName}.jar</source>
13.32 - <outputDirectory>/</outputDirectory>
13.33 - </file>
13.34 - <file>
13.35 - <source>${project.build.directory}/bck2brwsr.js</source>
13.36 - <outputDirectory>/</outputDirectory>
13.37 - </file>
13.38 - <file>
13.39 <source>${project.build.directory}/classes/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calculator.xhtml</source>
13.40 <outputDirectory>/</outputDirectory>
13.41 <destName>index.xhtml</destName>
14.1 --- a/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calc.java Thu May 15 11:38:27 2014 +0200
14.2 +++ b/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calc.java Mon Jun 09 15:57:14 2014 +0200
14.3 @@ -39,7 +39,7 @@
14.4 @Property(name = "history", type = double.class, array = true)
14.5 })
14.6 public class Calc {
14.7 - static {
14.8 + public static void main(String... args) throws Exception {
14.9 new Calculator().applyBindings().setOperation("plus");
14.10 }
14.11
15.1 --- a/javaquery/demo-calculator/src/main/java/org/apidesign/bck2brwsr/demo/calc/staticcompilation/package-info.java Thu May 15 11:38:27 2014 +0200
15.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
15.3 @@ -1,21 +0,0 @@
15.4 -/**
15.5 - * Back 2 Browser Bytecode Translator
15.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
15.7 - *
15.8 - * This program is free software: you can redistribute it and/or modify
15.9 - * it under the terms of the GNU General Public License as published by
15.10 - * the Free Software Foundation, version 2 of the License.
15.11 - *
15.12 - * This program is distributed in the hope that it will be useful,
15.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
15.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15.15 - * GNU General Public License for more details.
15.16 - *
15.17 - * You should have received a copy of the GNU General Public License
15.18 - * along with this program. Look for COPYING file in the top folder.
15.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
15.20 - */
15.21 -@Exported
15.22 -package org.apidesign.bck2brwsr.demo.calc.staticcompilation;
15.23 -
15.24 -import org.apidesign.bck2brwsr.core.Exported;
16.1 --- a/javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calculator.xhtml Thu May 15 11:38:27 2014 +0200
16.2 +++ b/javaquery/demo-calculator/src/main/resources/org/apidesign/bck2brwsr/demo/calc/staticcompilation/Calculator.xhtml Mon Jun 09 15:57:14 2014 +0200
16.3 @@ -91,8 +91,9 @@
16.4 <div data-bind="text: displayPreview"></div>
16.5 <script src="bck2brwsr.js"></script>
16.6 <script>
16.7 - var vm = bck2brwsr('demo.static.calculator-0.6.jar');
16.8 - vm.loadClass('org.apidesign.bck2brwsr.demo.calc.staticcompilation.Calc');
16.9 + var vm = bck2brwsr('calculator.js');
16.10 + var c = vm.loadClass('org.apidesign.bck2brwsr.demo.calc.staticcompilation.Calc');
16.11 + c.invoke('main');
16.12 </script>
16.13 </body>
16.14 </html>
17.1 --- a/javaquery/pom.xml Thu May 15 11:38:27 2014 +0200
17.2 +++ b/javaquery/pom.xml Mon Jun 09 15:57:14 2014 +0200
17.3 @@ -14,6 +14,5 @@
17.4 <modules>
17.5 <module>api</module>
17.6 <module>demo-calculator</module>
17.7 - <module>demo-calculator-dynamic</module>
17.8 </modules>
17.9 </project>
18.1 --- a/ko/archetype-test/pom.xml Thu May 15 11:38:27 2014 +0200
18.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
18.3 @@ -1,48 +0,0 @@
18.4 -<?xml version="1.0"?>
18.5 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
18.6 - <modelVersion>4.0.0</modelVersion>
18.7 - <parent>
18.8 - <groupId>org.apidesign.bck2brwsr</groupId>
18.9 - <artifactId>ko</artifactId>
18.10 - <version>0.9-SNAPSHOT</version>
18.11 - </parent>
18.12 - <groupId>org.apidesign.bck2brwsr</groupId>
18.13 - <artifactId>ko-archetype-test</artifactId>
18.14 - <version>0.9-SNAPSHOT</version>
18.15 - <name>Knockout Bck2Brwsr Archetype Test</name>
18.16 - <url>http://maven.apache.org</url>
18.17 - <description>Verifies the Knockout & net.java.html.json archetype behaves properly.</description>
18.18 - <properties>
18.19 - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18.20 - </properties>
18.21 - <dependencies>
18.22 - <dependency>
18.23 - <groupId>${project.groupId}</groupId>
18.24 - <artifactId>knockout4j-archetype</artifactId>
18.25 - <version>${project.version}</version>
18.26 - </dependency>
18.27 - <dependency>
18.28 - <groupId>org.testng</groupId>
18.29 - <artifactId>testng</artifactId>
18.30 - <scope>test</scope>
18.31 - </dependency>
18.32 - <dependency>
18.33 - <groupId>org.apache.maven.shared</groupId>
18.34 - <artifactId>maven-verifier</artifactId>
18.35 - <version>1.4</version>
18.36 - <scope>test</scope>
18.37 - </dependency>
18.38 - <dependency>
18.39 - <groupId>${project.groupId}</groupId>
18.40 - <artifactId>ko-fx</artifactId>
18.41 - <version>${project.version}</version>
18.42 - <scope>provided</scope>
18.43 - </dependency>
18.44 - <dependency>
18.45 - <groupId>${project.groupId}</groupId>
18.46 - <artifactId>ko-bck2brwsr</artifactId>
18.47 - <version>${project.version}</version>
18.48 - <scope>provided</scope>
18.49 - </dependency>
18.50 - </dependencies>
18.51 -</project>
19.1 --- a/ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/ArchetypeVersionTest.java Thu May 15 11:38:27 2014 +0200
19.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
19.3 @@ -1,140 +0,0 @@
19.4 -/**
19.5 - * Back 2 Browser Bytecode Translator
19.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
19.7 - *
19.8 - * This program is free software: you can redistribute it and/or modify
19.9 - * it under the terms of the GNU General Public License as published by
19.10 - * the Free Software Foundation, version 2 of the License.
19.11 - *
19.12 - * This program is distributed in the hope that it will be useful,
19.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
19.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19.15 - * GNU General Public License for more details.
19.16 - *
19.17 - * You should have received a copy of the GNU General Public License
19.18 - * along with this program. Look for COPYING file in the top folder.
19.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
19.20 - */
19.21 -package org.apidesign.bck2brwsr.ko.archetype.test;
19.22 -
19.23 -import java.io.IOException;
19.24 -import java.net.URL;
19.25 -import javax.xml.XMLConstants;
19.26 -import javax.xml.parsers.DocumentBuilderFactory;
19.27 -import javax.xml.parsers.ParserConfigurationException;
19.28 -import javax.xml.xpath.XPathConstants;
19.29 -import javax.xml.xpath.XPathExpression;
19.30 -import javax.xml.xpath.XPathExpressionException;
19.31 -import javax.xml.xpath.XPathFactory;
19.32 -import javax.xml.xpath.XPathFactoryConfigurationException;
19.33 -import org.testng.annotations.Test;
19.34 -import static org.testng.Assert.*;
19.35 -import org.testng.annotations.BeforeClass;
19.36 -import org.w3c.dom.Document;
19.37 -import org.w3c.dom.NodeList;
19.38 -import org.xml.sax.SAXException;
19.39 -
19.40 -/**
19.41 - *
19.42 - * @author Jaroslav Tulach <jtulach@netbeans.org>
19.43 - */
19.44 -public class ArchetypeVersionTest {
19.45 - private String version;
19.46 -
19.47 - public ArchetypeVersionTest() {
19.48 - }
19.49 -
19.50 - @BeforeClass public void readCurrentVersion() throws Exception {
19.51 - version = findCurrentVersion();
19.52 - assertFalse(version.isEmpty(), "There should be some version string");
19.53 - }
19.54 -
19.55 -
19.56 - @Test public void testComparePomDepsVersions() throws Exception {
19.57 - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
19.58 - URL r = l.getResource("archetype-resources/pom.xml");
19.59 - assertNotNull(r, "Archetype pom found");
19.60 -
19.61 - final XPathFactory fact = XPathFactory.newInstance();
19.62 - XPathExpression xp2 = fact.newXPath().compile(
19.63 - "//properties/net.java.html.version/text()"
19.64 - );
19.65 -
19.66 - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
19.67 - String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
19.68 -
19.69 - int snapshot = arch.indexOf("-SNAPSHOT");
19.70 - if (snapshot >= 0) {
19.71 - arch = arch.substring(0, snapshot);
19.72 - }
19.73 -
19.74 - assertTrue(arch.matches("[0-9\\.]+"), "net.java.html.json version seems valid: " + arch);
19.75 - }
19.76 -
19.77 - @Test public void testCheckLauncher() throws Exception {
19.78 - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
19.79 - URL r = l.getResource("archetype-resources/pom.xml");
19.80 - assertNotNull(r, "Archetype pom found");
19.81 -
19.82 - final XPathFactory fact = XPathFactory.newInstance();
19.83 - XPathExpression xp2 = fact.newXPath().compile(
19.84 - "//properties/bck2brwsr.launcher.version/text()"
19.85 - );
19.86 -
19.87 - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
19.88 - String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
19.89 -
19.90 - assertEquals(arch, version, "launcher dependency is on more recent version");
19.91 - }
19.92 -
19.93 - @Test public void testCheckBck2Brwsr() throws Exception {
19.94 - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
19.95 - URL r = l.getResource("archetype-resources/pom.xml");
19.96 - assertNotNull(r, "Archetype pom found");
19.97 -
19.98 - final XPathFactory fact = XPathFactory.newInstance();
19.99 - XPathExpression xp2 = fact.newXPath().compile(
19.100 - "//properties/bck2brwsr.version/text()"
19.101 - );
19.102 -
19.103 - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
19.104 - String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
19.105 -
19.106 - assertEquals(arch, version, "bck2brwsr dependency is on more recent version");
19.107 - }
19.108 -
19.109 - @Test public void testNbActions() throws Exception {
19.110 - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
19.111 - URL r = l.getResource("archetype-resources/nbactions.xml");
19.112 - assertNotNull(r, "Archetype nb file found");
19.113 -
19.114 - final XPathFactory fact = XPathFactory.newInstance();
19.115 - XPathExpression xp2 = fact.newXPath().compile(
19.116 - "//goal/text()"
19.117 - );
19.118 -
19.119 - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
19.120 - NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
19.121 -
19.122 - for (int i = 0; i < goals.getLength(); i++) {
19.123 - String s = goals.item(i).getTextContent();
19.124 - if (s.contains("apidesign")) {
19.125 - assertFalse(s.matches(".*apidesign.*[0-9].*"), "No numbers: " + s);
19.126 - }
19.127 - }
19.128 - }
19.129 -
19.130 - static String findCurrentVersion() throws XPathExpressionException, IOException, ParserConfigurationException, SAXException, XPathFactoryConfigurationException {
19.131 - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
19.132 - URL u = l.getResource("META-INF/maven/org.apidesign.bck2brwsr/knockout4j-archetype/pom.xml");
19.133 - assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path"));
19.134 -
19.135 - final XPathFactory fact = XPathFactory.newInstance();
19.136 - fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
19.137 -
19.138 - XPathExpression xp = fact.newXPath().compile("project/version/text()");
19.139 -
19.140 - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
19.141 - return xp.evaluate(dom);
19.142 - }
19.143 -}
20.1 --- a/ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/VerifyArchetypeTest.java Thu May 15 11:38:27 2014 +0200
20.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
20.3 @@ -1,133 +0,0 @@
20.4 -/**
20.5 - * Back 2 Browser Bytecode Translator
20.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
20.7 - *
20.8 - * This program is free software: you can redistribute it and/or modify
20.9 - * it under the terms of the GNU General Public License as published by
20.10 - * the Free Software Foundation, version 2 of the License.
20.11 - *
20.12 - * This program is distributed in the hope that it will be useful,
20.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
20.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20.15 - * GNU General Public License for more details.
20.16 - *
20.17 - * You should have received a copy of the GNU General Public License
20.18 - * along with this program. Look for COPYING file in the top folder.
20.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
20.20 - */
20.21 -package org.apidesign.bck2brwsr.ko.archetype.test;
20.22 -
20.23 -import java.io.File;
20.24 -import java.io.IOException;
20.25 -import java.io.InputStream;
20.26 -import java.util.Properties;
20.27 -import java.util.zip.ZipEntry;
20.28 -import java.util.zip.ZipFile;
20.29 -import org.apache.maven.it.Verifier;
20.30 -import org.testng.annotations.Test;
20.31 -import static org.testng.Assert.*;
20.32 -import org.testng.reporters.Files;
20.33 -
20.34 -/**
20.35 - *
20.36 - * @author Jaroslav Tulach <jtulach@netbeans.org>
20.37 - */
20.38 -public class VerifyArchetypeTest {
20.39 - @Test public void fxBrwsrCompiles() throws Exception {
20.40 - final File dir = new File("target/tests/fxcompile/").getAbsoluteFile();
20.41 - generateFromArchetype(dir);
20.42 -
20.43 - File created = new File(dir, "o-a-test");
20.44 - assertTrue(created.isDirectory(), "Project created");
20.45 - assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
20.46 -
20.47 - Verifier v = new Verifier(created.getAbsolutePath());
20.48 - v.executeGoal("verify");
20.49 -
20.50 - v.verifyErrorFreeLog();
20.51 -
20.52 - for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
20.53 - if (l.contains("j2js")) {
20.54 - fail("No pre-compilaton:\n" + l);
20.55 - }
20.56 - }
20.57 -
20.58 - v.verifyTextInLog("org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher");
20.59 - v.verifyTextInLog("fxcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-fxbrwsr.zip");
20.60 - }
20.61 -
20.62 - @Test public void bck2BrwsrCompiles() throws Exception {
20.63 - final File dir = new File("target/tests/b2bcompile/").getAbsoluteFile();
20.64 - generateFromArchetype(dir);
20.65 -
20.66 - File created = new File(dir, "o-a-test");
20.67 - assertTrue(created.isDirectory(), "Project created");
20.68 - assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
20.69 -
20.70 - Verifier v = new Verifier(created.getAbsolutePath());
20.71 - Properties sysProp = v.getSystemProperties();
20.72 - if (Boolean.getBoolean("java.awt.headless")) {
20.73 - sysProp.put("java.awt.headless", "true");
20.74 - }
20.75 - v.addCliOption("-Pbck2brwsr");
20.76 - v.executeGoal("verify");
20.77 -
20.78 - v.verifyErrorFreeLog();
20.79 -
20.80 - // no longer does pre-compilation to JavaScript
20.81 - // v.verifyTextInLog("j2js");
20.82 - // uses Bck2BrwsrLauncher
20.83 - v.verifyTextInLog("BaseHTTPLauncher showBrwsr");
20.84 - // building zip:
20.85 - v.verifyTextInLog("b2bcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
20.86 -
20.87 - for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
20.88 - if (l.contains("fxbrwsr")) {
20.89 - fail("No fxbrwsr:\n" + l);
20.90 - }
20.91 - }
20.92 -
20.93 - File zip = new File(new File(created, "target"), "o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
20.94 - assertTrue(zip.isFile(), "Zip file with website was created");
20.95 -
20.96 - ZipFile zf = new ZipFile(zip);
20.97 - final ZipEntry index = zf.getEntry("public_html/index.html");
20.98 - assertNotNull(index, "index.html found");
20.99 -
20.100 - String txt = readText(zf.getInputStream(index));
20.101 - final int beg = txt.indexOf("${");
20.102 - if (beg >= 0) {
20.103 - int end = txt.indexOf("}", beg);
20.104 - if (end < beg) {
20.105 - end = txt.length();
20.106 - }
20.107 - fail("No substitutions in index.html. Found: " + txt.substring(beg, end));
20.108 - }
20.109 - }
20.110 -
20.111 - private Verifier generateFromArchetype(final File dir, String... params) throws Exception {
20.112 - Verifier v = new Verifier(dir.getAbsolutePath());
20.113 - v.setAutoclean(false);
20.114 - v.setLogFileName("generate.log");
20.115 - v.deleteDirectory("");
20.116 - dir.mkdirs();
20.117 - Properties sysProp = v.getSystemProperties();
20.118 - sysProp.put("groupId", "org.apidesign.test");
20.119 - sysProp.put("artifactId", "o-a-test");
20.120 - sysProp.put("package", "org.apidesign.test.oat");
20.121 - sysProp.put("archetypeGroupId", "org.apidesign.bck2brwsr");
20.122 - sysProp.put("archetypeArtifactId", "knockout4j-archetype");
20.123 - sysProp.put("archetypeVersion", ArchetypeVersionTest.findCurrentVersion());
20.124 -
20.125 - for (String p : params) {
20.126 - v.addCliOption(p);
20.127 - }
20.128 - v.executeGoal("archetype:generate");
20.129 - v.verifyErrorFreeLog();
20.130 - return v;
20.131 - }
20.132 -
20.133 - private static String readText(InputStream is) throws IOException {
20.134 - return Files.readFile(is);
20.135 - }
20.136 -}
21.1 --- a/ko/archetype/pom.xml Thu May 15 11:38:27 2014 +0200
21.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
21.3 @@ -1,58 +0,0 @@
21.4 -<?xml version="1.0" encoding="UTF-8"?>
21.5 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21.6 - <modelVersion>4.0.0</modelVersion>
21.7 - <parent>
21.8 - <artifactId>ko</artifactId>
21.9 - <groupId>org.apidesign.bck2brwsr</groupId>
21.10 - <version>0.9-SNAPSHOT</version>
21.11 - </parent>
21.12 - <groupId>org.apidesign.bck2brwsr</groupId>
21.13 - <artifactId>knockout4j-archetype</artifactId>
21.14 - <version>0.9-SNAPSHOT</version>
21.15 - <packaging>jar</packaging>
21.16 - <name>Knockout Bck2Brwsr Maven Archetype</name>
21.17 - <description>
21.18 - HTML page with Knockout.js bindings driven by application model
21.19 - written in Java. Use your favorite language to code. Use
21.20 - HTML as a lightweight rendering toolkit. Deploy using JavaFX or
21.21 - bck2brwsr virtual machine.
21.22 - </description>
21.23 - <build>
21.24 - <resources>
21.25 - <resource>
21.26 - <directory>src/main/resources</directory>
21.27 - <filtering>true</filtering>
21.28 - <includes>
21.29 - <include>**/pom.xml</include>
21.30 - </includes>
21.31 - </resource>
21.32 - <resource>
21.33 - <directory>src/main/resources</directory>
21.34 - <filtering>false</filtering>
21.35 - <excludes>
21.36 - <exclude>**/pom.xml</exclude>
21.37 - </excludes>
21.38 - </resource>
21.39 - </resources>
21.40 - <plugins>
21.41 - <plugin>
21.42 - <groupId>org.apache.maven.plugins</groupId>
21.43 - <artifactId>maven-compiler-plugin</artifactId>
21.44 - <version>2.3.2</version>
21.45 - <configuration>
21.46 - <source>1.6</source>
21.47 - <target>1.6</target>
21.48 - </configuration>
21.49 - </plugin>
21.50 - <plugin>
21.51 - <groupId>org.apache.maven.plugins</groupId>
21.52 - <artifactId>maven-resources-plugin</artifactId>
21.53 - <version>2.6</version>
21.54 - <configuration>
21.55 - <escapeString>\</escapeString>
21.56 - <target>1.6</target>
21.57 - </configuration>
21.58 - </plugin>
21.59 - </plugins>
21.60 - </build>
21.61 -</project>
22.1 --- a/ko/archetype/src/main/java/org/apidesign/bck2brwsr/ko/archetype/package-info.java Thu May 15 11:38:27 2014 +0200
22.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
22.3 @@ -1,18 +0,0 @@
22.4 -/**
22.5 - * Back 2 Browser Bytecode Translator
22.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
22.7 - *
22.8 - * This program is free software: you can redistribute it and/or modify
22.9 - * it under the terms of the GNU General Public License as published by
22.10 - * the Free Software Foundation, version 2 of the License.
22.11 - *
22.12 - * This program is distributed in the hope that it will be useful,
22.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
22.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22.15 - * GNU General Public License for more details.
22.16 - *
22.17 - * You should have received a copy of the GNU General Public License
22.18 - * along with this program. Look for COPYING file in the top folder.
22.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
22.20 - */
22.21 -package org.apidesign.bck2brwsr.ko.archetype;
23.1 --- a/ko/archetype/src/main/resources/META-INF/maven/archetype-metadata.xml Thu May 15 11:38:27 2014 +0200
23.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
23.3 @@ -1,63 +0,0 @@
23.4 -<?xml version="1.0" encoding="UTF-8"?>
23.5 -<!--
23.6 -
23.7 - Back 2 Browser Bytecode Translator
23.8 - Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
23.9 -
23.10 - This program is free software: you can redistribute it and/or modify
23.11 - it under the terms of the GNU General Public License as published by
23.12 - the Free Software Foundation, version 2 of the License.
23.13 -
23.14 - This program is distributed in the hope that it will be useful,
23.15 - but WITHOUT ANY WARRANTY; without even the implied warranty of
23.16 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23.17 - GNU General Public License for more details.
23.18 -
23.19 - You should have received a copy of the GNU General Public License
23.20 - along with this program. Look for COPYING file in the top folder.
23.21 - If not, see http://opensource.org/licenses/GPL-2.0.
23.22 -
23.23 --->
23.24 -<archetype-descriptor name="FX/Bck2Brwsr Example">
23.25 - <fileSets>
23.26 - <fileSet filtered="true" packaged="true">
23.27 - <directory>src/main/java</directory>
23.28 - <includes>
23.29 - <include>**/*.java</include>
23.30 - </includes>
23.31 - </fileSet>
23.32 - <fileSet filtered="true" packaged="false">
23.33 - <directory>src/main/webapp/pages</directory>
23.34 - <includes>
23.35 - <include>**/*.xhtml</include>
23.36 - <include>**/*.html</include>
23.37 - <include>**/*.css</include>
23.38 - </includes>
23.39 - </fileSet>
23.40 - <fileSet filtered="true" packaged="true">
23.41 - <directory>src/test/java</directory>
23.42 - <includes>
23.43 - <include>**/*Test.java</include>
23.44 - </includes>
23.45 - </fileSet>
23.46 - <fileSet filtered="true" packaged="false">
23.47 - <directory>src/main/assembly</directory>
23.48 - <includes>
23.49 - <include>**/*.xml</include>
23.50 - </includes>
23.51 - </fileSet>
23.52 - <fileSet filtered="false" packaged="false">
23.53 - <directory></directory>
23.54 - <includes>
23.55 - <include>nbactions*.xml</include>
23.56 - </includes>
23.57 - </fileSet>
23.58 - <fileSet filtered="true" packaged="false">
23.59 - <directory>assembly</directory>
23.60 - <includes>
23.61 - <include>fxbrwsr-assembly.xml</include>
23.62 - <include>bck2brwsr-assembly.xml</include>
23.63 - </includes>
23.64 - </fileSet>
23.65 - </fileSets>
23.66 -</archetype-descriptor>
23.67 \ No newline at end of file
24.1 --- a/ko/archetype/src/main/resources/archetype-resources/nbactions-bck2brwsr.xml Thu May 15 11:38:27 2014 +0200
24.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
24.3 @@ -1,14 +0,0 @@
24.4 -<?xml version="1.0" encoding="UTF-8"?>
24.5 -<actions>
24.6 - <action>
24.7 - <actionName>run</actionName>
24.8 - <goals>
24.9 - <goal>package</goal>
24.10 - <goal>bck2brwsr:brwsr</goal>
24.11 - </goals>
24.12 - <properties>
24.13 - <skipTests>true</skipTests>
24.14 - <bck2brwsr.obfuscationlevel>NONE</bck2brwsr.obfuscationlevel>
24.15 - </properties>
24.16 - </action>
24.17 -</actions>
25.1 --- a/ko/archetype/src/main/resources/archetype-resources/nbactions-fxbrwsr.xml Thu May 15 11:38:27 2014 +0200
25.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
25.3 @@ -1,20 +0,0 @@
25.4 -<?xml version="1.0" encoding="UTF-8"?>
25.5 -<actions>
25.6 - <action>
25.7 - <actionName>run</actionName>
25.8 - <goals>
25.9 - <goal>process-classes</goal>
25.10 - <goal>bck2brwsr:brwsr</goal>
25.11 - </goals>
25.12 - </action>
25.13 - <action>
25.14 - <actionName>debug</actionName>
25.15 - <goals>
25.16 - <goal>process-classes</goal>
25.17 - <goal>bck2brwsr:brwsr</goal>
25.18 - </goals>
25.19 - <properties>
25.20 - <jpda.listen>maven</jpda.listen>
25.21 - </properties>
25.22 - </action>
25.23 -</actions>
26.1 --- a/ko/archetype/src/main/resources/archetype-resources/nbactions.xml Thu May 15 11:38:27 2014 +0200
26.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
26.3 @@ -1,20 +0,0 @@
26.4 -<?xml version="1.0" encoding="UTF-8"?>
26.5 -<actions>
26.6 - <action>
26.7 - <actionName>run</actionName>
26.8 - <goals>
26.9 - <goal>process-classes</goal>
26.10 - <goal>bck2brwsr:brwsr</goal>
26.11 - </goals>
26.12 - </action>
26.13 - <action>
26.14 - <actionName>debug</actionName>
26.15 - <goals>
26.16 - <goal>process-classes</goal>
26.17 - <goal>bck2brwsr:brwsr</goal>
26.18 - </goals>
26.19 - <properties>
26.20 - <jpda.listen>maven</jpda.listen>
26.21 - </properties>
26.22 - </action>
26.23 -</actions>
27.1 --- a/ko/archetype/src/main/resources/archetype-resources/pom.xml Thu May 15 11:38:27 2014 +0200
27.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
27.3 @@ -1,283 +0,0 @@
27.4 -<?xml version="1.0"?>
27.5 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
27.6 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
27.7 - <modelVersion>4.0.0</modelVersion>
27.8 -
27.9 - <groupId>\${groupId}</groupId>
27.10 - <artifactId>\${artifactId}</artifactId>
27.11 - <version>\${version}</version>
27.12 - <packaging>jar</packaging>
27.13 -
27.14 - <name>\${artifactId}</name>
27.15 -
27.16 - <repositories>
27.17 - <repository>
27.18 - <id>java.net</id>
27.19 - <name>Java.net</name>
27.20 - <url>https://maven.java.net/content/repositories/releases/</url>
27.21 - <snapshots>
27.22 - <enabled>true</enabled>
27.23 - </snapshots>
27.24 - </repository>
27.25 - <repository>
27.26 - <id>netbeans</id>
27.27 - <name>NetBeans</name>
27.28 - <url>http://bits.netbeans.org/maven2/</url>
27.29 - </repository>
27.30 - </repositories>
27.31 - <pluginRepositories>
27.32 - <pluginRepository>
27.33 - <id>java.net</id>
27.34 - <name>Java.net</name>
27.35 - <url>https://maven.java.net/content/repositories/releases/</url>
27.36 - <snapshots>
27.37 - <enabled>true</enabled>
27.38 - </snapshots>
27.39 - </pluginRepository>
27.40 - </pluginRepositories>
27.41 -
27.42 - <properties>
27.43 - <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
27.44 - <net.java.html.version>${net.java.html.version}</net.java.html.version>
27.45 - <bck2brwsr.version>${project.version}</bck2brwsr.version>
27.46 - <bck2brwsr.launcher.version>${project.version}</bck2brwsr.launcher.version>
27.47 - <bck2brwsr.obfuscationlevel>MINIMAL</bck2brwsr.obfuscationlevel>
27.48 - <brwsr.startpage>pages/index.html</brwsr.startpage>
27.49 - <netbeans.compile.on.save>none</netbeans.compile.on.save>
27.50 - </properties>
27.51 - <build>
27.52 - <plugins>
27.53 - <plugin>
27.54 - <groupId>org.apidesign.bck2brwsr</groupId>
27.55 - <artifactId>bck2brwsr-maven-plugin</artifactId>
27.56 - <version>\${bck2brwsr.launcher.version}</version>
27.57 - <executions>
27.58 - <execution>
27.59 - <goals>
27.60 - <goal>brwsr</goal>
27.61 - </goals>
27.62 - </execution>
27.63 - </executions>
27.64 - <configuration>
27.65 - <directory>\${basedir}/src/main/webapp/</directory>
27.66 - <startpage>${brwsr.startpage}</startpage>
27.67 - <launcher>${brwsr}</launcher>
27.68 - </configuration>
27.69 - </plugin>
27.70 - <plugin>
27.71 - <groupId>org.netbeans.html</groupId>
27.72 - <artifactId>html4j-maven-plugin</artifactId>
27.73 - <version>${net.java.html.version}</version>
27.74 - <executions>
27.75 - <execution>
27.76 - <id>js-classes</id>
27.77 - <goals>
27.78 - <goal>process-js-annotations</goal>
27.79 - </goals>
27.80 - </execution>
27.81 - </executions>
27.82 - </plugin>
27.83 - <plugin>
27.84 - <groupId>org.apache.maven.plugins</groupId>
27.85 - <artifactId>maven-compiler-plugin</artifactId>
27.86 - <version>2.3.2</version>
27.87 - <configuration>
27.88 - <source>1.7</source>
27.89 - <target>1.7</target>
27.90 - </configuration>
27.91 - </plugin>
27.92 - <plugin>
27.93 - <groupId>org.apache.maven.plugins</groupId>
27.94 - <artifactId>maven-surefire-plugin</artifactId>
27.95 - <version>2.14.1</version>
27.96 - <configuration>
27.97 - <systemPropertyVariables>
27.98 - <vmtest.brwsrs>\${brwsr}</vmtest.brwsrs>
27.99 - </systemPropertyVariables>
27.100 - </configuration>
27.101 - </plugin>
27.102 - <plugin>
27.103 - <groupId>org.apache.maven.plugins</groupId>
27.104 - <artifactId>maven-jar-plugin</artifactId>
27.105 - <version>2.4</version>
27.106 - <configuration>
27.107 - <archive>
27.108 - <manifest>
27.109 - <addClasspath>true</addClasspath>
27.110 - <classpathPrefix>lib/</classpathPrefix>
27.111 - </manifest>
27.112 - </archive>
27.113 - </configuration>
27.114 - </plugin>
27.115 - <plugin>
27.116 - <groupId>org.apache.maven.plugins</groupId>
27.117 - <artifactId>maven-deploy-plugin</artifactId>
27.118 - <version>2.7</version>
27.119 - <configuration>
27.120 - <skip>true</skip>
27.121 - </configuration>
27.122 - </plugin>
27.123 - </plugins>
27.124 - </build>
27.125 -
27.126 - <dependencies>
27.127 - <dependency>
27.128 - <groupId>org.testng</groupId>
27.129 - <artifactId>testng</artifactId>
27.130 - <version>6.7</version>
27.131 - <scope>test</scope>
27.132 - </dependency>
27.133 - <dependency>
27.134 - <groupId>org.apidesign.bck2brwsr</groupId>
27.135 - <artifactId>launcher.http</artifactId>
27.136 - <version>\${bck2brwsr.launcher.version}</version>
27.137 - <scope>test</scope>
27.138 - </dependency>
27.139 - <dependency>
27.140 - <groupId>org.apidesign.bck2brwsr</groupId>
27.141 - <artifactId>vmtest</artifactId>
27.142 - <version>\${bck2brwsr.version}</version>
27.143 - <scope>test</scope>
27.144 - </dependency>
27.145 - <dependency>
27.146 - <groupId>org.netbeans.html</groupId>
27.147 - <artifactId>net.java.html.json</artifactId>
27.148 - <version>\${net.java.html.version}</version>
27.149 - <type>jar</type>
27.150 - </dependency>
27.151 - <dependency>
27.152 - <groupId>org.netbeans.html</groupId>
27.153 - <artifactId>net.java.html.boot</artifactId>
27.154 - <version>\${net.java.html.version}</version>
27.155 - <type>jar</type>
27.156 - </dependency>
27.157 - </dependencies>
27.158 - <profiles>
27.159 - <profile>
27.160 - <id>fxbrwsr</id>
27.161 - <activation>
27.162 - <activeByDefault>true</activeByDefault>
27.163 - </activation>
27.164 - <properties>
27.165 - <brwsr>fxbrwsr</brwsr>
27.166 - </properties>
27.167 - <build>
27.168 - <plugins>
27.169 - <plugin>
27.170 - <groupId>org.apache.maven.plugins</groupId>
27.171 - <artifactId>maven-jar-plugin</artifactId>
27.172 - <version>2.4</version>
27.173 - <configuration>
27.174 - <archive>
27.175 - <manifest>
27.176 - <mainClass>org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher</mainClass>
27.177 - <addClasspath>true</addClasspath>
27.178 - <classpathPrefix>lib/</classpathPrefix>
27.179 - </manifest>
27.180 - <manifestEntries>
27.181 - <StartPage>\${brwsr.startpage}</StartPage>
27.182 - </manifestEntries>
27.183 - </archive>
27.184 - </configuration>
27.185 - </plugin>
27.186 - <plugin>
27.187 - <artifactId>maven-assembly-plugin</artifactId>
27.188 - <version>2.4</version>
27.189 - <executions>
27.190 - <execution>
27.191 - <id>distro-assembly</id>
27.192 - <phase>package</phase>
27.193 - <goals>
27.194 - <goal>single</goal>
27.195 - </goals>
27.196 - <configuration>
27.197 - <descriptors>
27.198 - <descriptor>src/main/assembly/fxbrwsr.xml</descriptor>
27.199 - </descriptors>
27.200 - </configuration>
27.201 - </execution>
27.202 - </executions>
27.203 - </plugin>
27.204 - </plugins>
27.205 - </build>
27.206 - <dependencies>
27.207 - <dependency>
27.208 - <groupId>org.netbeans.html</groupId>
27.209 - <artifactId>ko4j</artifactId>
27.210 - <version>\${net.java.html.version}</version>
27.211 - </dependency>
27.212 - <dependency>
27.213 - <groupId>org.apidesign.bck2brwsr</groupId>
27.214 - <artifactId>launcher.fx</artifactId>
27.215 - <version>\${bck2brwsr.launcher.version}</version>
27.216 - <scope>runtime</scope>
27.217 - </dependency>
27.218 - </dependencies>
27.219 - </profile>
27.220 - <profile>
27.221 - <id>bck2brwsr</id>
27.222 - <activation>
27.223 - <property>
27.224 - <name>brwsr</name>
27.225 - <value>bck2brwsr</value>
27.226 - </property>
27.227 - </activation>
27.228 - <build>
27.229 - <plugins>
27.230 - <plugin>
27.231 - <groupId>org.apache.maven.plugins</groupId>
27.232 - <artifactId>maven-compiler-plugin</artifactId>
27.233 - <configuration>
27.234 - <compilerArguments>
27.235 - <bootclasspath>netbeans.ignore.jdk.bootclasspath</bootclasspath>
27.236 - </compilerArguments>
27.237 - <testExcludes>
27.238 - <exclude>**/JsInteractionTest*</exclude>
27.239 - </testExcludes>
27.240 - </configuration>
27.241 - </plugin>
27.242 - <plugin>
27.243 - <artifactId>maven-assembly-plugin</artifactId>
27.244 - <version>2.4</version>
27.245 - <executions>
27.246 - <execution>
27.247 - <id>distro-assembly</id>
27.248 - <phase>package</phase>
27.249 - <goals>
27.250 - <goal>single</goal>
27.251 - </goals>
27.252 - <configuration>
27.253 - <descriptors>
27.254 - <descriptor>src/main/assembly/bck2brwsr.xml</descriptor>
27.255 - </descriptors>
27.256 - </configuration>
27.257 - </execution>
27.258 - </executions>
27.259 - </plugin>
27.260 - </plugins>
27.261 - </build>
27.262 - <dependencies>
27.263 - <dependency>
27.264 - <groupId>org.apidesign.bck2brwsr</groupId>
27.265 - <artifactId>emul</artifactId>
27.266 - <version>\${bck2brwsr.version}</version>
27.267 - <classifier>rt</classifier>
27.268 - </dependency>
27.269 - <dependency>
27.270 - <groupId>org.apidesign.bck2brwsr</groupId>
27.271 - <artifactId>ko-bck2brwsr</artifactId>
27.272 - <version>\${bck2brwsr.version}</version>
27.273 - <scope>runtime</scope>
27.274 - </dependency>
27.275 - <dependency>
27.276 - <groupId>org.apidesign.bck2brwsr</groupId>
27.277 - <artifactId>vm4brwsr</artifactId>
27.278 - <classifier>js</classifier>
27.279 - <type>zip</type>
27.280 - <version>\${bck2brwsr.version}</version>
27.281 - <scope>provided</scope>
27.282 - </dependency>
27.283 - </dependencies>
27.284 - </profile>
27.285 - </profiles>
27.286 -</project>
28.1 --- a/ko/archetype/src/main/resources/archetype-resources/src/main/assembly/bck2brwsr.xml Thu May 15 11:38:27 2014 +0200
28.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
28.3 @@ -1,43 +0,0 @@
28.4 -<?xml version="1.0"?>
28.5 -<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
28.6 - xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
28.7 -
28.8 - <id>bck2brwsr</id>
28.9 - <formats>
28.10 - <format>zip</format>
28.11 - </formats>
28.12 - <baseDirectory>public_html</baseDirectory>
28.13 - <dependencySets>
28.14 - <dependencySet>
28.15 - <useProjectArtifact>false</useProjectArtifact>
28.16 - <scope>runtime</scope>
28.17 - <outputDirectory>lib</outputDirectory>
28.18 - <includes>
28.19 - <include>*:jar</include>
28.20 - <include>*:rt</include>
28.21 - </includes>
28.22 - </dependencySet>
28.23 - <dependencySet>
28.24 - <useProjectArtifact>false</useProjectArtifact>
28.25 - <scope>provided</scope>
28.26 - <includes>
28.27 - <include>*:js</include>
28.28 - </includes>
28.29 - <unpack>true</unpack>
28.30 - <outputDirectory>/</outputDirectory>
28.31 - </dependencySet>
28.32 - </dependencySets>
28.33 - <fileSets>
28.34 - <fileSet>
28.35 - <directory>src/main/webapp/pages</directory>
28.36 - <outputDirectory>/</outputDirectory>
28.37 - <filtered>true</filtered>
28.38 - </fileSet>
28.39 - </fileSets>
28.40 - <files>
28.41 - <file>
28.42 - <source>${project.build.directory}/${project.build.finalName}.jar</source>
28.43 - <outputDirectory>/</outputDirectory>
28.44 - </file>
28.45 - </files>
28.46 -</assembly>
28.47 \ No newline at end of file
29.1 --- a/ko/archetype/src/main/resources/archetype-resources/src/main/assembly/fxbrwsr.xml Thu May 15 11:38:27 2014 +0200
29.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
29.3 @@ -1,33 +0,0 @@
29.4 -<?xml version="1.0"?>
29.5 -<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
29.6 - xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
29.7 -
29.8 - <id>fxbrwsr</id>
29.9 - <formats>
29.10 - <format>zip</format>
29.11 - </formats>
29.12 - <baseDirectory>${project.build.finalName}-fxbrwsr</baseDirectory>
29.13 - <dependencySets>
29.14 - <dependencySet>
29.15 - <useProjectArtifact>false</useProjectArtifact>
29.16 - <scope>runtime</scope>
29.17 - <outputDirectory>lib</outputDirectory>
29.18 - </dependencySet>
29.19 - </dependencySets>
29.20 - <files>
29.21 - <file>
29.22 - <source>${project.build.directory}/${project.build.finalName}.jar</source>
29.23 - <outputDirectory>/</outputDirectory>
29.24 - </file>
29.25 - </files>
29.26 - <fileSets>
29.27 - <fileSet>
29.28 - <directory>src/main/webapp/</directory>
29.29 - <outputDirectory>/</outputDirectory>
29.30 - <includes>
29.31 - <include>pages/**</include>
29.32 - </includes>
29.33 - <filtered>true</filtered>
29.34 - </fileSet>
29.35 - </fileSets>
29.36 -</assembly>
29.37 \ No newline at end of file
30.1 --- a/ko/archetype/src/main/resources/archetype-resources/src/main/java/DataModel.java Thu May 15 11:38:27 2014 +0200
30.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
30.3 @@ -1,45 +0,0 @@
30.4 -package ${package};
30.5 -
30.6 -import net.java.html.json.ComputedProperty;
30.7 -import net.java.html.json.Function;
30.8 -import net.java.html.json.Model;
30.9 -import net.java.html.json.Property;
30.10 -
30.11 -/** Model annotation generates class Data with
30.12 - * one message property, boolean property and read only words property
30.13 - */
30.14 -@Model(className = "Data", properties = {
30.15 - @Property(name = "message", type = String.class),
30.16 - @Property(name = "on", type = boolean.class)
30.17 -})
30.18 -final class DataModel {
30.19 - @ComputedProperty static java.util.List<String> words(String message) {
30.20 - String[] arr = new String[6];
30.21 - String[] words = message == null ? new String[0] : message.split(" ", 6);
30.22 - for (int i = 0; i < 6; i++) {
30.23 - arr[i] = words.length > i ? words[i] : "!";
30.24 - }
30.25 - return java.util.Arrays.asList(arr);
30.26 - }
30.27 -
30.28 - @Function static void turnOn(Data model) {
30.29 - model.setOn(true);
30.30 - }
30.31 -
30.32 - @Function static void turnOff(final Data model) {
30.33 - confirmByUser("Really turn off?", new Runnable() {
30.34 - @Override
30.35 - public void run() {
30.36 - model.setOn(false);
30.37 - }
30.38 - });
30.39 - }
30.40 -
30.41 - /** Shows direct interaction with JavaScript */
30.42 - @net.java.html.js.JavaScriptBody(
30.43 - args = { "msg", "callback" },
30.44 - javacall = true,
30.45 - body = "alert(msg); callback.@java.lang.Runnable::run()();"
30.46 - )
30.47 - static native void confirmByUser(String msg, Runnable callback);
30.48 -}
31.1 --- a/ko/archetype/src/main/resources/archetype-resources/src/main/java/Main.java Thu May 15 11:38:27 2014 +0200
31.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
31.3 @@ -1,15 +0,0 @@
31.4 -package ${package};
31.5 -
31.6 -public final class Main {
31.7 - private Main() {
31.8 - }
31.9 -
31.10 - /**
31.11 - * Called when the page is ready.
31.12 - */
31.13 - static {
31.14 - Data d = new Data();
31.15 - d.setMessage("Hello World from HTML and Java!");
31.16 - d.applyBindings();
31.17 - }
31.18 -}
32.1 --- a/ko/archetype/src/main/resources/archetype-resources/src/main/webapp/pages/index.html Thu May 15 11:38:27 2014 +0200
32.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
32.3 @@ -1,72 +0,0 @@
32.4 -<!DOCTYPE html>
32.5 -<html>
32.6 - <head>
32.7 - <title></title>
32.8 - <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
32.9 -
32.10 - <style type="text/css">
32.11 - @-webkit-keyframes spin {
32.12 - 0% { -webkit-transform: rotate(0deg); }
32.13 - 100% { -webkit-transform: rotate(360deg); }
32.14 - }
32.15 - @keyframes spin {
32.16 - 0% { transform: rotate(0deg); }
32.17 - 100% { transform: rotate(360deg); }
32.18 - }
32.19 -
32.20 - .rotate {
32.21 - -webkit-animation-name: spin;
32.22 - -webkit-animation-duration: 3s;
32.23 - -webkit-animation-iteration-count: infinite;
32.24 - -webkit-animation-direction: alternate;
32.25 -
32.26 - animation-name: spin;
32.27 - animation-duration: 3s;
32.28 - animation-iteration-count: infinite;
32.29 - animation-direction: alternate;
32.30 - }
32.31 -
32.32 - #scene {
32.33 - position: relative;
32.34 - top: 60px;
32.35 - text-align: center;
32.36 - }
32.37 -
32.38 - #words span {
32.39 - border: 1px solid #ccc;
32.40 - background: rgba(255,255,155,0.8);
32.41 - text-align: center;
32.42 - font-size: 30px;
32.43 - -webkit-box-shadow: inset 0 0 40px rgba(0,0,0,0.4);
32.44 - position: absolute;
32.45 - }
32.46 -
32.47 - #words span:nth-child(1) { left: 45%; top: 0px; }
32.48 - #words span:nth-child(2) { left: 25%; top: 100px; }
32.49 - #words span:nth-child(3) { left: 65%; top: 100px; }
32.50 - #words span:nth-child(4) { left: 10%; top: 200px; }
32.51 - #words span:nth-child(5) { left: 45%; top: 200px; }
32.52 - #words span:nth-child(6) { left: 80%; top: 200px; }
32.53 -
32.54 - </style>
32.55 -
32.56 - </head>
32.57 - <body>
32.58 - <h1>Words Demo</h1>
32.59 - <input data-bind="value: message, valueUpdate: 'afterkeydown'" size="80">
32.60 - <br>
32.61 - <button data-bind="enable: !on(), click: $root.turnOn">Start</button>
32.62 - <button data-bind="enable: on, click: $root.turnOff">Stop</button>
32.63 -
32.64 - <div id="scene">
32.65 - <span id="words" data-bind="foreach: words">
32.66 - <span data-bind="text: $data, css: { 'rotate' : $root.on } "></span>
32.67 - </span>
32.68 - </div>
32.69 - <script type="text/javascript" src="bck2brwsr.js"></script>
32.70 - <script>
32.71 - var vm = bck2brwsr('${project.build.finalName}.jar');
32.72 - vm.loadClass('${package}.Main');
32.73 - </script>
32.74 - </body>
32.75 -</html>
33.1 --- a/ko/archetype/src/main/resources/archetype-resources/src/test/java/DataModelTest.java Thu May 15 11:38:27 2014 +0200
33.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
33.3 @@ -1,16 +0,0 @@
33.4 -package ${package};
33.5 -
33.6 -import static org.testng.Assert.*;
33.7 -import org.testng.annotations.Test;
33.8 -
33.9 -public class DataModelTest {
33.10 - @Test public void areHelloWorldTwoWords() {
33.11 - Data model = new Data();
33.12 - model.setMessage("Hello World!");
33.13 -
33.14 - java.util.List<String> arr = model.getWords();
33.15 - assertEquals(arr.size(), 6, "Six words always");
33.16 - assertEquals("Hello", arr.get(0), "Hello is the first word");
33.17 - assertEquals("World!", arr.get(1), "World is the second word");
33.18 - }
33.19 -}
34.1 --- a/ko/archetype/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java Thu May 15 11:38:27 2014 +0200
34.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
34.3 @@ -1,38 +0,0 @@
34.4 -package ${package};
34.5 -
34.6 -import org.apidesign.bck2brwsr.vmtest.Compare;
34.7 -import org.apidesign.bck2brwsr.vmtest.VMTest;
34.8 -import org.testng.annotations.Factory;
34.9 -
34.10 -/** Bck2brwsr cares about compatibility with real Java. Whatever API is
34.11 - * supported by bck2brwsr, it needs to behave the same way as when running
34.12 - * in HotSpot VM.
34.13 - * <p>
34.14 - * There can be bugs, however. To help us fix them, we kindly ask you to
34.15 - * write an "inconsistency" test. A test that compares behavior of the API
34.16 - * between real VM and bck2brwsr VM. This class is skeleton of such test.
34.17 - */
34.18 -public class InconsistencyTest {
34.19 - /** A method to demonstrate inconsistency between bck2brwsr and HotSpot.
34.20 - * Make calls to an API that behaves strangely, return some result at
34.21 - * the end. No need to use any <code>assert</code>.
34.22 - *
34.23 - * @return value to compare between HotSpot and bck2brwsr
34.24 - */
34.25 - @Compare
34.26 - public int checkStringHashCode() throws Exception {
34.27 - return "Is string hashCode the same?".hashCode();
34.28 - }
34.29 -
34.30 - /** Factory method that creates a three tests for each method annotated with
34.31 - * {@link org.apidesign.bck2brwsr.vmtest.Compare}. One executes the code in
34.32 - * HotSpot, one in Rhino and the last one compares the results.
34.33 - *
34.34 - * @see org.apidesign.bck2brwsr.vmtest.VMTest
34.35 - */
34.36 - @Factory
34.37 - public static Object[] create() {
34.38 - return VMTest.create(InconsistencyTest.class);
34.39 - }
34.40 -
34.41 -}
35.1 --- a/ko/archetype/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java Thu May 15 11:38:27 2014 +0200
35.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
35.3 @@ -1,31 +0,0 @@
35.4 -package ${package};
35.5 -
35.6 -import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
35.7 -import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
35.8 -import org.apidesign.bck2brwsr.vmtest.VMTest;
35.9 -import org.testng.annotations.Factory;
35.10 -
35.11 -/** Sometimes it is useful to run tests inside of the real browser.
35.12 - * To do that just annotate your method with {@link org.apidesign.bck2brwsr.vmtest.BrwsrTest}
35.13 - * and that is it. If your code references elements on the HTML page,
35.14 - * you can pass in an {@link org.apidesign.bck2brwsr.vmtest.HtmlFragment} which
35.15 - * will be made available on the page before your test starts.
35.16 - */
35.17 -public class IntegrationTest {
35.18 -
35.19 - /** Write to testing code here. Use <code>assert</code> (but not TestNG's
35.20 - * Assert, as TestNG is not compiled with target 1.6 yet).
35.21 - */
35.22 - @HtmlFragment(
35.23 - "<h1>Put this snippet on the HTML page</h1>\n"
35.24 - )
35.25 - @BrwsrTest
35.26 - public void runThisTestInABrowser() {
35.27 - }
35.28 -
35.29 - @Factory
35.30 - public static Object[] create() {
35.31 - return VMTest.create(IntegrationTest.class);
35.32 - }
35.33 -
35.34 -}
36.1 --- a/ko/archetype/src/main/resources/archetype-resources/src/test/java/JsInteractionTest.java Thu May 15 11:38:27 2014 +0200
36.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
36.3 @@ -1,103 +0,0 @@
36.4 -package ${package};
36.5 -
36.6 -import java.io.Closeable;
36.7 -import java.io.Reader;
36.8 -import java.net.URL;
36.9 -import java.util.ArrayList;
36.10 -import java.util.List;
36.11 -import javax.script.Invocable;
36.12 -import javax.script.ScriptEngine;
36.13 -import javax.script.ScriptEngineManager;
36.14 -import javax.script.ScriptException;
36.15 -import org.apidesign.html.boot.spi.Fn;
36.16 -import static org.testng.Assert.assertEquals;
36.17 -import org.testng.annotations.AfterMethod;
36.18 -import org.testng.annotations.BeforeMethod;
36.19 -import org.testng.annotations.Test;
36.20 -
36.21 -/** Tests for behavior of @JavaScriptBody methods. Set your JavaScript
36.22 - * environment up (for example define <code>alert</code> or use some
36.23 - * emulation library like <em>env.js</em>), register script presenter
36.24 - * and then you can call methods that deal with JavaScript in your tests.
36.25 - */
36.26 -public class JsInteractionTest {
36.27 - private Closeable jsEngine;
36.28 - @BeforeMethod public void initializeJSEngine() throws Exception {
36.29 - jsEngine = Fn.activate(new ScriptPresenter());
36.30 - }
36.31 -
36.32 - @AfterMethod public void shutdownJSEngine() throws Exception {
36.33 - jsEngine.close();
36.34 - }
36.35 -
36.36 - @Test public void testCallbackFromJavaScript() throws Exception {
36.37 - class R implements Runnable {
36.38 - int called;
36.39 -
36.40 - @Override
36.41 - public void run() {
36.42 - called++;
36.43 - }
36.44 - }
36.45 - R callback = new R();
36.46 -
36.47 - DataModel.confirmByUser("Hello", callback);
36.48 -
36.49 - assertEquals(callback.called, 1, "One immediate callback");
36.50 - }
36.51 -
36.52 - private static class ScriptPresenter implements Fn.Presenter {
36.53 - private final ScriptEngine eng;
36.54 -
36.55 - public ScriptPresenter() throws ScriptException {
36.56 - eng = new ScriptEngineManager().getEngineByName("javascript");
36.57 - eng.eval("function alert(msg) { Packages.java.lang.System.out.println(msg); };");
36.58 - }
36.59 -
36.60 - @Override
36.61 - public Fn defineFn(String code, String... names) {
36.62 - StringBuilder sb = new StringBuilder();
36.63 - sb.append("(function() {");
36.64 - sb.append(" return function(");
36.65 - String sep = "";
36.66 - for (String n : names) {
36.67 - sb.append(sep).append(n);
36.68 - sep = ",";
36.69 - }
36.70 - sb.append(") {\n");
36.71 - sb.append(code);
36.72 - sb.append("};");
36.73 - sb.append("})()");
36.74 -
36.75 - final Object fn;
36.76 - try {
36.77 - fn = eng.eval(sb.toString());
36.78 - } catch (ScriptException ex) {
36.79 - throw new IllegalStateException(ex);
36.80 - }
36.81 - return new Fn(this) {
36.82 - @Override
36.83 - public Object invoke(Object thiz, Object... args) throws Exception {
36.84 - List<Object> all = new ArrayList<Object>(args.length + 1);
36.85 - all.add(thiz == null ? fn : thiz);
36.86 - for (int i = 0; i < args.length; i++) {
36.87 - all.add(args[i]);
36.88 - }
36.89 - Object ret = ((Invocable)eng).invokeMethod(fn, "call", all.toArray()); // NOI18N
36.90 - return fn.equals(ret) ? null : thiz;
36.91 - }
36.92 - };
36.93 - }
36.94 -
36.95 - @Override
36.96 - public void displayPage(URL page, Runnable onPageLoad) {
36.97 - // not really displaying anything
36.98 - onPageLoad.run();
36.99 - }
36.100 -
36.101 - @Override
36.102 - public void loadScript(Reader code) throws Exception {
36.103 - eng.eval(code);
36.104 - }
36.105 - }
36.106 -}
37.1 --- a/ko/pom.xml Thu May 15 11:38:27 2014 +0200
37.2 +++ b/ko/pom.xml Mon Jun 09 15:57:14 2014 +0200
37.3 @@ -12,8 +12,6 @@
37.4 <version>0.9-SNAPSHOT</version>
37.5 </parent>
37.6 <modules>
37.7 - <module>archetype</module>
37.8 - <module>archetype-test</module>
37.9 <module>bck2brwsr</module>
37.10 <module>fx</module>
37.11 </modules>
38.1 --- a/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java Thu May 15 11:38:27 2014 +0200
38.2 +++ b/launcher/fx/src/main/java/org/apidesign/bck2brwsr/launcher/BaseHTTPLauncher.java Mon Jun 09 15:57:14 2014 +0200
38.3 @@ -131,10 +131,12 @@
38.4 if (!startpage.startsWith("/")) {
38.5 startpage = "/" + startpage;
38.6 }
38.7 - String prefix = "";
38.8 - int last = startpage.lastIndexOf('/');
38.9 - if (last >= 0) {
38.10 - prefix = startpage.substring(0, last);
38.11 + String prefix = null;
38.12 + if (!new File(dir, "bck2brwsr.js").exists()) {
38.13 + int last = startpage.lastIndexOf('/');
38.14 + if (last >= 0) {
38.15 + prefix = startpage.substring(0, last);
38.16 + }
38.17 }
38.18 HttpServer s = initServer(dir.getPath(), addClasses, prefix);
38.19 try {
38.20 @@ -565,7 +567,7 @@
38.21
38.22 abstract void generateBck2BrwsrJS(StringBuilder sb, Res loader) throws IOException;
38.23 abstract String harnessResource();
38.24 - String compileJar(JarFile jar) throws IOException {
38.25 + String compileJar(URL jar) throws IOException {
38.26 return null;
38.27 }
38.28 String compileFromClassPath(URL f, Res loader) throws IOException {
38.29 @@ -585,8 +587,8 @@
38.30 final class Res {
38.31 private final Set<URL> ignore = new HashSet<URL>();
38.32
38.33 - String compileJar(JarFile jar, URL jarURL) throws IOException {
38.34 - String ret = BaseHTTPLauncher.this.compileJar(jar);
38.35 + String compileJar(URL jarURL) throws IOException {
38.36 + String ret = BaseHTTPLauncher.this.compileJar(jarURL);
38.37 ignore.add(jarURL);
38.38 return ret;
38.39 }
38.40 @@ -748,7 +750,7 @@
38.41 response.setCharacterEncoding("UTF-8");
38.42 if (url.getProtocol().equals("jar")) {
38.43 JarURLConnection juc = (JarURLConnection) url.openConnection();
38.44 - String s = loader.compileJar(juc.getJarFile(), juc.getJarFileURL());
38.45 + String s = loader.compileJar(juc.getJarFileURL());
38.46 if (s != null) {
38.47 Writer w = response.getWriter();
38.48 w.append(s);
38.49 @@ -757,6 +759,15 @@
38.50 }
38.51 }
38.52 if (url.getProtocol().equals("file")) {
38.53 + final String filePart = url.getFile();
38.54 + if (filePart.endsWith(res)) {
38.55 + url = new URL(
38.56 + url.getProtocol(),
38.57 + url.getHost(),
38.58 + url.getPort(),
38.59 + filePart.substring(0, filePart.length() - res.length())
38.60 + );
38.61 + }
38.62 String s = loader.compileFromClassPath(url);
38.63 if (s != null) {
38.64 Writer w = response.getWriter();
39.1 --- a/launcher/http/pom.xml Thu May 15 11:38:27 2014 +0200
39.2 +++ b/launcher/http/pom.xml Mon Jun 09 15:57:14 2014 +0200
39.3 @@ -67,5 +67,11 @@
39.4 <version>${project.version}</version>
39.5 <scope>test</scope>
39.6 </dependency>
39.7 + <dependency>
39.8 + <groupId>org.apidesign.bck2brwsr</groupId>
39.9 + <artifactId>aot</artifactId>
39.10 + <version>0.9-SNAPSHOT</version>
39.11 + <type>jar</type>
39.12 + </dependency>
39.13 </dependencies>
39.14 </project>
40.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Thu May 15 11:38:27 2014 +0200
40.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/Bck2BrwsrLauncher.java Mon Jun 09 15:57:14 2014 +0200
40.3 @@ -18,16 +18,14 @@
40.4 package org.apidesign.bck2brwsr.launcher;
40.5
40.6 import java.io.File;
40.7 -import java.io.FileReader;
40.8 import java.io.IOException;
40.9 -import java.io.InputStream;
40.10 import java.io.InputStreamReader;
40.11 import java.io.Reader;
40.12 import java.net.MalformedURLException;
40.13 +import java.net.URISyntaxException;
40.14 import java.net.URL;
40.15 import java.util.HashSet;
40.16 import java.util.Set;
40.17 -import java.util.jar.JarFile;
40.18 import java.util.logging.Level;
40.19
40.20 /**
40.21 @@ -48,8 +46,14 @@
40.22 }
40.23
40.24 @Override
40.25 - String compileJar(JarFile jar) throws IOException {
40.26 - return CompileCP.compileJAR(jar, testClasses);
40.27 + String compileJar(URL jar) throws IOException {
40.28 + File f;
40.29 + try {
40.30 + f = new File(jar.toURI());
40.31 + } catch (URISyntaxException ex) {
40.32 + throw new IOException(ex);
40.33 + }
40.34 + return CompileCP.compileJAR(f, testClasses);
40.35 }
40.36
40.37 @Override
40.38 @@ -122,7 +126,7 @@
40.39 + " args.unshift(ldCls);\n"
40.40 + " return prevvm.apply(null, args);\n"
40.41 + " };\n"
40.42 - + " global.bck2brwsr.registerExtension = prevvm.registerExtension;\n"
40.43 + + " global.bck2brwsr.register = prevvm.register;\n"
40.44 + "})(this);\n"
40.45 );
40.46 LOG.log(Level.INFO, "Serving bck2brwsr.js", b2b);
41.1 --- a/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java Thu May 15 11:38:27 2014 +0200
41.2 +++ b/launcher/http/src/main/java/org/apidesign/bck2brwsr/launcher/CompileCP.java Mon Jun 09 15:57:14 2014 +0200
41.3 @@ -17,25 +17,20 @@
41.4 */
41.5 package org.apidesign.bck2brwsr.launcher;
41.6
41.7 -import java.io.BufferedReader;
41.8 import java.io.File;
41.9 import java.io.IOException;
41.10 import java.io.InputStream;
41.11 -import java.io.InputStreamReader;
41.12 import java.io.StringWriter;
41.13 import java.net.JarURLConnection;
41.14 import java.net.URISyntaxException;
41.15 import java.net.URL;
41.16 import java.util.ArrayList;
41.17 import java.util.Enumeration;
41.18 -import java.util.HashSet;
41.19 import java.util.List;
41.20 import java.util.Set;
41.21 -import java.util.jar.JarEntry;
41.22 -import java.util.jar.JarFile;
41.23 import java.util.logging.Level;
41.24 import java.util.logging.Logger;
41.25 -import java.util.zip.ZipEntry;
41.26 +import org.apidesign.bck2brwsr.aot.Bck2BrwsrJars;
41.27 import org.apidesign.bck2brwsr.launcher.BaseHTTPLauncher.Res;
41.28 import org.apidesign.vm4brwsr.Bck2Brwsr;
41.29
41.30 @@ -45,42 +40,12 @@
41.31 */
41.32 class CompileCP {
41.33 private static final Logger LOG = Logger.getLogger(CompileCP.class.getName());
41.34 - static String compileJAR(final JarFile jar, Set<String> testClasses)
41.35 + static String compileJAR(final File jar, Set<String> testClasses)
41.36 throws IOException {
41.37 - List<String> arr = new ArrayList<>();
41.38 - List<String> classes = new ArrayList<>();
41.39 - Set<String> exported = new HashSet<String>();
41.40 - Set<String> keep = new HashSet<String>(testClasses);
41.41 - listJAR(jar, classes, arr, exported, keep);
41.42 - List<String> root = new ArrayList<>();
41.43 - for (String c : classes) {
41.44 - if (keep.contains(c)) {
41.45 - root.add(c);
41.46 - continue;
41.47 - }
41.48 - int slash = c.lastIndexOf('/');
41.49 - String pkg = c.substring(0, slash + 1);
41.50 - if (exported.contains(pkg)) {
41.51 - root.add(c);
41.52 - }
41.53 - }
41.54 -
41.55 StringWriter w = new StringWriter();
41.56 try {
41.57 - class JarRes extends EmulationResources implements Bck2Brwsr.Resources {
41.58 - @Override
41.59 - public InputStream get(String resource) throws IOException {
41.60 - InputStream is = jar.getInputStream(new ZipEntry(resource));
41.61 - return is == null ? super.get(resource) : is;
41.62 - }
41.63 - }
41.64 -
41.65 - Bck2Brwsr.newCompiler()
41.66 - .addClasses(classes.toArray(new String[0]))
41.67 - .addRootClasses(root.toArray(new String[0]))
41.68 - .addResources(arr.toArray(new String[0]))
41.69 - .library(true)
41.70 - .resources(new JarRes())
41.71 + Bck2BrwsrJars.configureFrom(null, jar)
41.72 + .addExported(testClasses.toArray(new String[0]))
41.73 .generate(w);
41.74 w.flush();
41.75 return w.toString();
41.76 @@ -100,10 +65,17 @@
41.77 } catch (URISyntaxException ex) {
41.78 throw new IOException(ex);
41.79 }
41.80 - for (String s : System.getProperty("java.class.path").split(File.pathSeparator)) {
41.81 - if (!f.getPath().startsWith(s)) {
41.82 - continue;
41.83 + String s = f.isDirectory() ? f.getPath() : null;
41.84 +
41.85 + for (String candidate : System.getProperty("java.class.path").split(File.pathSeparator)) {
41.86 + if (s != null) {
41.87 + break;
41.88 }
41.89 + if (f.getPath().startsWith(candidate)) {
41.90 + s = candidate;
41.91 + }
41.92 + }
41.93 + if (s != null) {
41.94 File root = new File(s);
41.95 List<String> arr = new ArrayList<>();
41.96 List<String> classes = new ArrayList<>();
41.97 @@ -113,7 +85,8 @@
41.98 Bck2Brwsr.newCompiler()
41.99 .addRootClasses(classes.toArray(new String[0]))
41.100 .addResources(arr.toArray(new String[0]))
41.101 - .library(true)
41.102 + .library()
41.103 + //.obfuscation(ObfuscationLevel.FULL)
41.104 .resources(new EmulationResources() {
41.105 @Override
41.106 public InputStream get(String resource) throws IOException {
41.107 @@ -136,56 +109,7 @@
41.108 return null;
41.109 }
41.110
41.111 - private static void listJAR(
41.112 - JarFile j, List<String> classes,
41.113 - List<String> resources, Set<String> exported, Set<String> keep
41.114 - ) throws IOException {
41.115 - Enumeration<JarEntry> en = j.entries();
41.116 - while (en.hasMoreElements()) {
41.117 - JarEntry e = en.nextElement();
41.118 - final String n = e.getName();
41.119 - if (n.endsWith("/")) {
41.120 - continue;
41.121 - }
41.122 - int last = n.lastIndexOf('/');
41.123 - String pkg = n.substring(0, last + 1);
41.124 - if (skipPkg(pkg)) {
41.125 - continue;
41.126 - }
41.127 - if (n.endsWith(".class")) {
41.128 - classes.add(n.substring(0, n.length() - 6));
41.129 - } else {
41.130 - resources.add(n);
41.131 - if (n.startsWith("META-INF/services/") && keep != null) {
41.132 - BufferedReader r = new BufferedReader(new InputStreamReader(j.getInputStream(e)));
41.133 - for (;;) {
41.134 - String l = r.readLine();
41.135 - if (l == null) {
41.136 - break;
41.137 - }
41.138 - if (l.startsWith("#")) {
41.139 - continue;
41.140 - }
41.141 - keep.add(l.replace('.', '/'));
41.142 - }
41.143 - }
41.144 - }
41.145 - }
41.146 - String exp = j.getManifest().getMainAttributes().getValue("Export-Package");
41.147 - if (exp != null && exported != null) {
41.148 - for (String def : exp.split(",")) {
41.149 - for (String sep : def.split(";")) {
41.150 - exported.add(sep.replace('.', '/') + "/");
41.151 - break;
41.152 - }
41.153 - }
41.154 - }
41.155 - }
41.156
41.157 - private static boolean skipPkg(String pkg) {
41.158 - return pkg.equals("org/apidesign/bck2brwsr/launcher/");
41.159 - }
41.160 -
41.161 private static void listDir(File f, String pref, List<String> classes, List<String> resources) throws IOException {
41.162 File[] arr = f.listFiles();
41.163 if (arr == null) {
41.164 @@ -203,21 +127,26 @@
41.165 }
41.166
41.167 static void compileVM(StringBuilder sb, final Res r) throws IOException {
41.168 - List<String> arr = new ArrayList<>();
41.169 - List<String> classes = new ArrayList<>();
41.170 -
41.171 - {
41.172 + final Bck2Brwsr rt;
41.173 + try {
41.174 URL u = r.get(InterruptedException.class.getName().replace('.', '/') + ".class", 0);
41.175 JarURLConnection juc = (JarURLConnection)u.openConnection();
41.176 - listJAR(juc.getJarFile(), classes, arr, null, null);
41.177 + rt = Bck2BrwsrJars.configureFrom(null, new File(juc.getJarFileURL().toURI()));
41.178 + } catch (URISyntaxException ex) {
41.179 + throw new IOException(ex);
41.180 }
41.181 - {
41.182 + final Bck2Brwsr all;
41.183 + try {
41.184 URL u = r.get(Bck2Brwsr.class.getName().replace('.', '/') + ".class", 0);
41.185 JarURLConnection juc = (JarURLConnection)u.openConnection();
41.186 - listJAR(juc.getJarFile(), classes, arr, null, null);
41.187 + all = Bck2BrwsrJars.configureFrom(rt, new File(juc.getJarFileURL().toURI()));
41.188 + } catch (URISyntaxException ex) {
41.189 + throw new IOException(ex);
41.190 }
41.191
41.192 - Bck2Brwsr.newCompiler().addRootClasses(classes.toArray(new String[0]))
41.193 + all
41.194 + .standalone(true)
41.195 + //.obfuscation(ObfuscationLevel.FULL)
41.196 .resources(new Bck2Brwsr.Resources() {
41.197 @Override
41.198 public InputStream get(String resource) throws IOException {
41.199 @@ -231,7 +160,7 @@
41.200
41.201 @Override
41.202 public InputStream get(String name) throws IOException {
41.203 - Enumeration<URL> en = CompileCP.class.getClassLoader().getResources(name);
41.204 + Enumeration<URL> en = Bck2BrwsrJars.class.getClassLoader().getResources(name);
41.205 URL u = null;
41.206 while (en.hasMoreElements()) {
41.207 u = en.nextElement();
41.208 @@ -241,10 +170,11 @@
41.209 return null;
41.210 }
41.211 if (u.toExternalForm().contains("/rt.jar!")) {
41.212 - LOG.warning(name + "No bootdelegation for ");
41.213 + LOG.log(Level.WARNING, "{0}No bootdelegation for ", name);
41.214 return null;
41.215 }
41.216 return u.openStream();
41.217 }
41.218 }
41.219 +
41.220 }
42.1 --- a/pom.xml Thu May 15 11:38:27 2014 +0200
42.2 +++ b/pom.xml Mon Jun 09 15:57:14 2014 +0200
42.3 @@ -15,7 +15,7 @@
42.4 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
42.5 <netbeans.version>RELEASE80</netbeans.version>
42.6 <license>COPYING</license>
42.7 - <net.java.html.version>0.7.6</net.java.html.version>
42.8 + <net.java.html.version>0.8.1</net.java.html.version>
42.9 <netbeans.compile.on.save>none</netbeans.compile.on.save>
42.10 </properties>
42.11 <modules>
43.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
43.2 +++ b/rt/aot/pom.xml Mon Jun 09 15:57:14 2014 +0200
43.3 @@ -0,0 +1,20 @@
43.4 +<?xml version="1.0" encoding="UTF-8"?>
43.5 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
43.6 + <modelVersion>4.0.0</modelVersion>
43.7 + <parent>
43.8 + <groupId>org.apidesign.bck2brwsr</groupId>
43.9 + <artifactId>rt</artifactId>
43.10 + <version>0.9-SNAPSHOT</version>
43.11 + </parent>
43.12 + <name>Ahead of Time Compilation</name>
43.13 + <artifactId>aot</artifactId>
43.14 + <packaging>jar</packaging>
43.15 + <dependencies>
43.16 + <dependency>
43.17 + <groupId>org.apidesign.bck2brwsr</groupId>
43.18 + <artifactId>vm4brwsr</artifactId>
43.19 + <version>${project.version}</version>
43.20 + <type>jar</type>
43.21 + </dependency>
43.22 + </dependencies>
43.23 +</project>
43.24 \ No newline at end of file
44.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
44.2 +++ b/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java Mon Jun 09 15:57:14 2014 +0200
44.3 @@ -0,0 +1,163 @@
44.4 +/**
44.5 + * Back 2 Browser Bytecode Translator
44.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
44.7 + *
44.8 + * This program is free software: you can redistribute it and/or modify
44.9 + * it under the terms of the GNU General Public License as published by
44.10 + * the Free Software Foundation, version 2 of the License.
44.11 + *
44.12 + * This program is distributed in the hope that it will be useful,
44.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
44.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44.15 + * GNU General Public License for more details.
44.16 + *
44.17 + * You should have received a copy of the GNU General Public License
44.18 + * along with this program. Look for COPYING file in the top folder.
44.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
44.20 + */
44.21 +package org.apidesign.bck2brwsr.aot;
44.22 +
44.23 +import java.io.BufferedReader;
44.24 +import java.io.File;
44.25 +import java.io.IOException;
44.26 +import java.io.InputStream;
44.27 +import java.io.InputStreamReader;
44.28 +import java.net.URL;
44.29 +import java.util.ArrayList;
44.30 +import java.util.Enumeration;
44.31 +import java.util.HashSet;
44.32 +import java.util.List;
44.33 +import java.util.Set;
44.34 +import java.util.jar.JarEntry;
44.35 +import java.util.jar.JarFile;
44.36 +import java.util.logging.Level;
44.37 +import java.util.logging.Logger;
44.38 +import java.util.zip.ZipEntry;
44.39 +import org.apidesign.vm4brwsr.Bck2Brwsr;
44.40 +
44.41 +/** Utilities to process JAR files and set a compiler
44.42 + * up.
44.43 + *
44.44 + * @since 0.9
44.45 + * @author Jaroslav Tulach
44.46 + */
44.47 +public final class Bck2BrwsrJars {
44.48 + private static final Logger LOG = Logger.getLogger(Bck2BrwsrJars.class.getName());
44.49 +
44.50 + private Bck2BrwsrJars() {
44.51 + }
44.52 +
44.53 + /** Creates new compiler pre-configured from the content of
44.54 + * provided JAR file. The compiler will compile all classes.
44.55 + * The system understands OSGi manifest entries and will export
44.56 + * all packages that are exported in the JAR file. The system
44.57 + * also recognizes META-INF/services and makes sure the file names
44.58 + * are not mangled.
44.59 + *
44.60 + * @param c the compiler to {@link Bck2Brwsr#addClasses(java.lang.String...) add classes},
44.61 + * {@link Bck2Brwsr#addResources(java.lang.String...) add resources} and
44.62 + * {@link Bck2Brwsr#addExported(java.lang.String...) exported objects} to.
44.63 + * Can be <code>null</code> - in such case an
44.64 + * {@link Bck2Brwsr#newCompiler() empty compiler} is constructed.
44.65 + * @param jar the file to process
44.66 + * @return newly configured compiler
44.67 + * @throws IOException if something goes wrong
44.68 + */
44.69 + public static Bck2Brwsr configureFrom(Bck2Brwsr c, File jar) throws IOException {
44.70 + final JarFile jf = new JarFile(jar);
44.71 + List<String> classes = new ArrayList<>();
44.72 + List<String> resources = new ArrayList<>();
44.73 + Set<String> exported = new HashSet<>();
44.74 +
44.75 + listJAR(jf, classes, resources, exported);
44.76 +
44.77 + String cp = jf.getManifest().getMainAttributes().getValue("Class-Path"); // NOI18N
44.78 + String[] classpath = cp == null ? new String[0] : cp.split(" ");
44.79 +
44.80 + class JarRes extends EmulationResources implements Bck2Brwsr.Resources {
44.81 +
44.82 + @Override
44.83 + public InputStream get(String resource) throws IOException {
44.84 + InputStream is = jf.getInputStream(new ZipEntry(resource));
44.85 + return is == null ? super.get(resource) : is;
44.86 + }
44.87 + }
44.88 + return Bck2Brwsr.newCompiler()
44.89 + .library(classpath)
44.90 + .addClasses(classes.toArray(new String[classes.size()]))
44.91 + .addExported(exported.toArray(new String[exported.size()]))
44.92 + .addResources(resources.toArray(new String[resources.size()]))
44.93 + .resources(new JarRes());
44.94 + }
44.95 +
44.96 + private static void listJAR(
44.97 + JarFile j, List<String> classes,
44.98 + List<String> resources, Set<String> keep
44.99 + ) throws IOException {
44.100 + Enumeration<JarEntry> en = j.entries();
44.101 + while (en.hasMoreElements()) {
44.102 + JarEntry e = en.nextElement();
44.103 + final String n = e.getName();
44.104 + if (n.endsWith("/")) {
44.105 + continue;
44.106 + }
44.107 + if (n.startsWith("META-INF/maven/")) {
44.108 + continue;
44.109 + }
44.110 + int last = n.lastIndexOf('/');
44.111 + String pkg = n.substring(0, last + 1);
44.112 + if (pkg.startsWith("java/")) {
44.113 + keep.add(pkg);
44.114 + }
44.115 + if (n.endsWith(".class")) {
44.116 + classes.add(n.substring(0, n.length() - 6));
44.117 + } else {
44.118 + resources.add(n);
44.119 + if (n.startsWith("META-INF/services/") && keep != null) {
44.120 + BufferedReader r = new BufferedReader(new InputStreamReader(j.getInputStream(e)));
44.121 + for (;;) {
44.122 + String l = r.readLine();
44.123 + if (l == null) {
44.124 + break;
44.125 + }
44.126 + if (l.startsWith("#")) {
44.127 + continue;
44.128 + }
44.129 + keep.add(l.replace('.', '/'));
44.130 + }
44.131 + }
44.132 + }
44.133 + }
44.134 + String exp = j.getManifest().getMainAttributes().getValue("Export-Package");
44.135 + if (exp != null && keep != null) {
44.136 + for (String def : exp.split(",")) {
44.137 + for (String sep : def.split(";")) {
44.138 + keep.add(sep.replace('.', '/') + "/");
44.139 + break;
44.140 + }
44.141 + }
44.142 + }
44.143 + }
44.144 +
44.145 + static class EmulationResources implements Bck2Brwsr.Resources {
44.146 +
44.147 + @Override
44.148 + public InputStream get(String name) throws IOException {
44.149 + Enumeration<URL> en = Bck2BrwsrJars.class.getClassLoader().getResources(name);
44.150 + URL u = null;
44.151 + while (en.hasMoreElements()) {
44.152 + u = en.nextElement();
44.153 + }
44.154 + if (u == null) {
44.155 + LOG.log(Level.WARNING, "Cannot find {0}", name);
44.156 + return null;
44.157 + }
44.158 + if (u.toExternalForm().contains("/rt.jar!")) {
44.159 + LOG.log(Level.WARNING, "{0}No bootdelegation for ", name);
44.160 + return null;
44.161 + }
44.162 + return u.openStream();
44.163 + }
44.164 + }
44.165 +
44.166 +}
45.1 --- a/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ResourcesTest.java Thu May 15 11:38:27 2014 +0200
45.2 +++ b/rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/tck/ResourcesTest.java Mon Jun 09 15:57:14 2014 +0200
45.3 @@ -51,7 +51,11 @@
45.4 }
45.5 }
45.6 assert different : "Not all manifests should look like first one:\n" + first;
45.7 - return "" + cnt;
45.8 + if (cnt > 40 && cnt < 50) {
45.9 + return "OK";
45.10 + } else {
45.11 + return "" + cnt;
45.12 + }
45.13 }
45.14
45.15 @Compare public String readResourceAsStream() throws Exception {
46.1 --- a/rt/emul/mini/src/main/java/java/lang/Boolean.java Thu May 15 11:38:27 2014 +0200
46.2 +++ b/rt/emul/mini/src/main/java/java/lang/Boolean.java Mon Jun 09 15:57:14 2014 +0200
46.3 @@ -289,8 +289,9 @@
46.4 initValueOf();
46.5 }
46.6 @JavaScriptBody(args = { }, body =
46.7 - "vm.java_lang_Boolean(false)" +
46.8 - ".valueOf = function() { return this._value() ? true : false; };"
46.9 + "var bc = vm.java_lang_Boolean(false);\n" +
46.10 + "bc.valueOf = function() { return this._value() ? true : false; };\n" +
46.11 + "bc.toString = function() { return this.valueOf().toString(); };\n"
46.12 )
46.13 private native static void initValueOf();
46.14 }
47.1 --- a/rt/emul/mini/src/main/java/java/lang/Class.java Thu May 15 11:38:27 2014 +0200
47.2 +++ b/rt/emul/mini/src/main/java/java/lang/Class.java Mon Jun 09 15:57:14 2014 +0200
47.3 @@ -34,6 +34,7 @@
47.4 import java.lang.reflect.Method;
47.5 import java.lang.reflect.TypeVariable;
47.6 import java.net.URL;
47.7 +import org.apidesign.bck2brwsr.core.Exported;
47.8 import org.apidesign.bck2brwsr.core.JavaScriptBody;
47.9 import org.apidesign.bck2brwsr.core.JavaScriptOnly;
47.10 import org.apidesign.bck2brwsr.emul.reflect.AnnotationImpl;
47.11 @@ -238,14 +239,18 @@
47.12 }
47.13
47.14 @JavaScriptBody(args = {"n", "c" }, body =
47.15 - "if (!vm[c]) {\n"
47.16 - + " if (vm.loadClass) {\n"
47.17 - + " vm.loadClass(n);\n"
47.18 + "var m = vm[c];\n"
47.19 + + "if (!m) {\n"
47.20 + + " var l = vm.loadClass ? vm.loadClass : exports ? exports.loadClass : null;\n"
47.21 + + " if (l) {\n"
47.22 + + " l(n);\n"
47.23 + " }\n"
47.24 - + " if (!vm[c]) return null;\n"
47.25 + + " if (vm[c]) m = vm[c];\n"
47.26 + + " else if (exports[c]) m = exports[c];\n"
47.27 + "}\n"
47.28 - + "vm[c](false);"
47.29 - + "return vm[c].$class;"
47.30 + + "if (!m) return null;"
47.31 + + "m(false);"
47.32 + + "return m.$class;"
47.33 )
47.34 private static native Class<?> loadCls(String n, String c);
47.35
47.36 @@ -300,9 +305,9 @@
47.37 @JavaScriptBody(args = { "self", "illegal" }, body =
47.38 "\nvar c = self.cnstr;"
47.39 + "\nif (c['cons__V']) {"
47.40 - + "\n if ((c.cons__V.access & 0x1) != 0) {"
47.41 + + "\n if ((c['cons__V'].access & 0x1) != 0) {"
47.42 + "\n var inst = c();"
47.43 - + "\n c.cons__V.call(inst);"
47.44 + + "\n c['cons__V'].call(inst);"
47.45 + "\n return inst;"
47.46 + "\n }"
47.47 + "\n return illegal;"
47.48 @@ -1739,9 +1744,17 @@
47.49 native static Class getPrimitiveClass(String type);
47.50
47.51 @JavaScriptBody(args = {}, body =
47.52 - "return this.desiredAssertionStatus ? this.desiredAssertionStatus : false;"
47.53 + "return this['desiredAssertionStatus'] ? this['desiredAssertionStatus'] : false;"
47.54 )
47.55 public native boolean desiredAssertionStatus();
47.56 +
47.57 + public boolean equals(Object obj) {
47.58 + if (isPrimitive() && obj instanceof Class) {
47.59 + Class c = ((Class)obj);
47.60 + return c.isPrimitive() && getName().equals(c.getName());
47.61 + }
47.62 + return super.equals(obj);
47.63 + }
47.64
47.65 static void registerNatives() {
47.66 boolean assertsOn = false;
47.67 @@ -1766,10 +1779,11 @@
47.68 )
47.69 static native Class<?> classFor(Object self);
47.70
47.71 + @Exported
47.72 @JavaScriptBody(args = { "self" }, body
47.73 - = "if (self.$hashCode) return self.$hashCode;\n"
47.74 - + "var h = self.computeHashCode__I ? self.computeHashCode__I() : Math.random() * Math.pow(2, 31);\n"
47.75 - + "return self.$hashCode = h & h;"
47.76 + = "if (self['$hashCode']) return self['$hashCode'];\n"
47.77 + + "var h = self['computeHashCode__I'] ? self['computeHashCode__I']() : Math.random() * Math.pow(2, 31);\n"
47.78 + + "return self['$hashCode'] = h & h;"
47.79 )
47.80 static native int defaultHashCode(Object self);
47.81
47.82 @@ -1798,6 +1812,7 @@
47.83 )
47.84 static native int toJS();
47.85
47.86 + @Exported
47.87 @JavaScriptOnly(name = "activate__Ljava_io_Closeable_2Lorg_apidesign_html_boot_spi_Fn$Presenter_2", value = "function() {\n"
47.88 + " return vm.org_apidesign_bck2brwsr_emul_lang_System(false).activate__Ljava_io_Closeable_2();"
47.89 + "}\n"
47.90 @@ -1818,6 +1833,7 @@
47.91 @JavaScriptBody(args = {"o"}, body = "return o ? o.toString() : null;")
47.92 private static native String msg(Object o);
47.93
47.94 + @Exported
47.95 @JavaScriptOnly(name = "bck2BrwsrThrwrbl", value = "c.bck2BrwsrCnvrt__Ljava_lang_Object_2Ljava_lang_Object_2")
47.96 private static void bck2BrwsrCnvrtVM() {
47.97 }
48.1 --- a/rt/emul/mini/src/main/java/java/lang/ClassLoader.java Thu May 15 11:38:27 2014 +0200
48.2 +++ b/rt/emul/mini/src/main/java/java/lang/ClassLoader.java Mon Jun 09 15:57:14 2014 +0200
48.3 @@ -897,7 +897,8 @@
48.4 }
48.5
48.6 @JavaScriptBody(args = { "name", "skip" }, body
48.7 - = "return (vm.loadBytes) ? vm.loadBytes(name, skip) : null;"
48.8 + = "var lb = vm.loadBytes ? vm.loadBytes : exports.loadBytes;"
48.9 + + "return lb ? lb(name, skip) : null;"
48.10 )
48.11 static native byte[] getResourceAsStream0(String name, int skip);
48.12
49.1 --- a/rt/emul/mini/src/main/java/java/lang/String.java Thu May 15 11:38:27 2014 +0200
49.2 +++ b/rt/emul/mini/src/main/java/java/lang/String.java Mon Jun 09 15:57:14 2014 +0200
49.3 @@ -30,6 +30,7 @@
49.4 import java.lang.reflect.Method;
49.5 import java.util.Comparator;
49.6 import java.util.Locale;
49.7 +import org.apidesign.bck2brwsr.core.Exported;
49.8 import org.apidesign.bck2brwsr.core.ExtraJavaScript;
49.9 import org.apidesign.bck2brwsr.core.JavaScriptBody;
49.10 import org.apidesign.bck2brwsr.core.JavaScriptOnly;
49.11 @@ -1457,7 +1458,7 @@
49.12 public int hashCode() {
49.13 return super.hashCode();
49.14 }
49.15 - int computeHashCode() {
49.16 + @Exported int computeHashCode() {
49.17 int h = 0;
49.18 if (h == 0 && length() > 0) {
49.19 int off = offset();
50.1 --- a/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/MethodImpl.java Thu May 15 11:38:27 2014 +0200
50.2 +++ b/rt/emul/mini/src/main/java/org/apidesign/bck2brwsr/emul/reflect/MethodImpl.java Mon Jun 09 15:57:14 2014 +0200
50.3 @@ -21,6 +21,7 @@
50.4 import java.lang.reflect.Constructor;
50.5 import java.lang.reflect.Method;
50.6 import java.util.Enumeration;
50.7 +import org.apidesign.bck2brwsr.core.Exported;
50.8 import org.apidesign.bck2brwsr.core.JavaScriptBody;
50.9
50.10 /** Utilities to work on methods.
50.11 @@ -126,7 +127,7 @@
50.12 }
50.13 return null;
50.14 }
50.15 -
50.16 +
50.17 public static Method[] findMethods(Class<?> clazz, int mask) {
50.18 Object[] namesAndData = findMethodData(clazz, "", false);
50.19 int cnt = 0;
50.20 @@ -137,6 +138,11 @@
50.21 if (middle == -1) {
50.22 continue;
50.23 }
50.24 + if (sig.startsWith("$") && sig.endsWith("$")) {
50.25 + // produced by Closure compiler in debug mode
50.26 + // needs to be ignored
50.27 + continue;
50.28 + }
50.29 String name = sig.substring(0, middle);
50.30 sig = sig.substring(middle + 2);
50.31 Class<?> cls = (Class<?>) namesAndData[i + 2];
50.32 @@ -152,7 +158,8 @@
50.33 }
50.34 return arr;
50.35 }
50.36 - static String toSignature(Method m) {
50.37 +
50.38 + @Exported static String toSignature(Method m) {
50.39 StringBuilder sb = new StringBuilder();
50.40 sb.append(m.getName()).append("__");
50.41 appendType(sb, m.getReturnType());
50.42 @@ -222,9 +229,17 @@
50.43 public static Enumeration<Class> signatureParser(final String sig) {
50.44 class E implements Enumeration<Class> {
50.45 int pos;
50.46 + int len;
50.47 +
50.48 + E() {
50.49 + len = sig.length();
50.50 + while (sig.charAt(len - 1) == '$') {
50.51 + len--;
50.52 + }
50.53 + }
50.54
50.55 public boolean hasMoreElements() {
50.56 - return pos < sig.length();
50.57 + return pos < len;
50.58 }
50.59
50.60 public Class nextElement() {
51.1 --- a/rt/mojo/pom.xml Thu May 15 11:38:27 2014 +0200
51.2 +++ b/rt/mojo/pom.xml Mon Jun 09 15:57:14 2014 +0200
51.3 @@ -91,5 +91,11 @@
51.4 <artifactId>launcher.fx</artifactId>
51.5 <version>${project.version}</version>
51.6 </dependency>
51.7 + <dependency>
51.8 + <groupId>org.apidesign.bck2brwsr</groupId>
51.9 + <artifactId>aot</artifactId>
51.10 + <version>0.9-SNAPSHOT</version>
51.11 + <type>jar</type>
51.12 + </dependency>
51.13 </dependencies>
51.14 </project>
52.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
52.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/AheadOfTime.java Mon Jun 09 15:57:14 2014 +0200
52.3 @@ -0,0 +1,182 @@
52.4 +/**
52.5 + * Back 2 Browser Bytecode Translator
52.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
52.7 + *
52.8 + * This program is free software: you can redistribute it and/or modify
52.9 + * it under the terms of the GNU General Public License as published by
52.10 + * the Free Software Foundation, version 2 of the License.
52.11 + *
52.12 + * This program is distributed in the hope that it will be useful,
52.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
52.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52.15 + * GNU General Public License for more details.
52.16 + *
52.17 + * You should have received a copy of the GNU General Public License
52.18 + * along with this program. Look for COPYING file in the top folder.
52.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
52.20 + */
52.21 +
52.22 +package org.apidesign.bck2brwsr.mojo;
52.23 +
52.24 +import java.io.File;
52.25 +import java.io.FileWriter;
52.26 +import java.io.IOException;
52.27 +import java.io.InputStream;
52.28 +import java.net.MalformedURLException;
52.29 +import java.net.URL;
52.30 +import java.net.URLClassLoader;
52.31 +import java.util.ArrayList;
52.32 +import java.util.Collection;
52.33 +import java.util.List;
52.34 +import org.apache.maven.artifact.Artifact;
52.35 +import org.apache.maven.plugin.AbstractMojo;
52.36 +import org.apache.maven.plugin.MojoExecutionException;
52.37 +import org.apache.maven.plugin.MojoFailureException;
52.38 +import org.apache.maven.plugins.annotations.LifecyclePhase;
52.39 +import org.apache.maven.plugins.annotations.Mojo;
52.40 +import org.apache.maven.plugins.annotations.Parameter;
52.41 +import org.apache.maven.plugins.annotations.ResolutionScope;
52.42 +import org.apache.maven.project.MavenProject;
52.43 +import org.apidesign.bck2brwsr.aot.Bck2BrwsrJars;
52.44 +import org.apidesign.vm4brwsr.Bck2Brwsr;
52.45 +import org.apidesign.vm4brwsr.ObfuscationLevel;
52.46 +
52.47 +/**
52.48 + *
52.49 + * @author Jaroslav Tulach
52.50 + * @since 0.9
52.51 + */
52.52 +@Mojo(name = "aot",
52.53 + requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME,
52.54 + defaultPhase = LifecyclePhase.PACKAGE
52.55 +)
52.56 +public class AheadOfTime extends AbstractMojo {
52.57 + @Parameter(defaultValue = "${project}")
52.58 + private MavenProject prj;
52.59 +
52.60 + @Parameter(defaultValue = "${project.build.directory}/${project.build.finalName}.jar")
52.61 + private File mainJar;
52.62 +
52.63 + @Parameter(defaultValue = "${project.build.directory}/${project.build.finalName}.js")
52.64 + private File mainJavaScript;
52.65 +
52.66 + @Parameter
52.67 + private String[] exports;
52.68 +
52.69 + /**
52.70 + * Directory where to generate ahead-of-time JavaScript files for
52.71 + * required libraries.
52.72 + */
52.73 + @Parameter(defaultValue = "lib")
52.74 + private String classPathPrefix;
52.75 +
52.76 + /** Root JavaScript file to generate */
52.77 + @Parameter(defaultValue="${project.build.directory}/bck2brwsr.js")
52.78 + private File vm;
52.79 +
52.80 + /**
52.81 + * The obfuscation level for the generated JavaScript file.
52.82 + *
52.83 + * @since 0.5
52.84 + */
52.85 + @Parameter(defaultValue = "NONE")
52.86 + private ObfuscationLevel obfuscation;
52.87 +
52.88 + @Override
52.89 + public void execute() throws MojoExecutionException, MojoFailureException {
52.90 + URLClassLoader loader;
52.91 + try {
52.92 + loader = buildClassLoader(mainJar, prj.getArtifacts());
52.93 + } catch (MalformedURLException ex) {
52.94 + throw new MojoFailureException("Can't initialize classloader");
52.95 + }
52.96 + for (Artifact a : prj.getArtifacts()) {
52.97 + if (a.getFile() == null) {
52.98 + continue;
52.99 + }
52.100 + String n = a.getFile().getName();
52.101 + if (!n.endsWith(".jar")) {
52.102 + continue;
52.103 + }
52.104 + if ("provided".equals(a.getScope())) {
52.105 + continue;
52.106 + }
52.107 + File aot = new File(prj.getBuild().getDirectory(), classPathPrefix);
52.108 + aot.mkdirs();
52.109 + File js = new File(aot, n.substring(0, n.length() - 4) + ".js");
52.110 + if (js.exists()) {
52.111 + getLog().info("Skipping " + js + " as it already exists.");
52.112 + continue;
52.113 + }
52.114 + try {
52.115 + getLog().info("Generating " + js);
52.116 + aotLibrary(a, js , loader);
52.117 + } catch (IOException ex) {
52.118 + throw new MojoFailureException("Can't compile" + a.getFile(), ex);
52.119 + }
52.120 + }
52.121 +
52.122 + try {
52.123 + if (mainJavaScript.exists()) {
52.124 + getLog().info("Skipping " + mainJavaScript + " as it already exists.");
52.125 + } else {
52.126 + getLog().info("Generating " + mainJavaScript);
52.127 + Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, mainJar);
52.128 + if (exports != null) {
52.129 + for (String e : exports) {
52.130 + c = c.addExported(e.replace('.', '/'));
52.131 + }
52.132 + }
52.133 + FileWriter w = new FileWriter(mainJavaScript);
52.134 + c.
52.135 + obfuscation(obfuscation).
52.136 + resources(loader).
52.137 + generate(w);
52.138 + w.close();
52.139 + }
52.140 + } catch (IOException ex) {
52.141 + throw new MojoFailureException("Cannot generate script for " + mainJar, ex);
52.142 + }
52.143 +
52.144 + try {
52.145 + FileWriter w = new FileWriter(vm);
52.146 + Bck2Brwsr.newCompiler().
52.147 + obfuscation(obfuscation).
52.148 + standalone(false).
52.149 + resources(new Bck2Brwsr.Resources() {
52.150 +
52.151 + @Override
52.152 + public InputStream get(String resource) throws IOException {
52.153 + return null;
52.154 + }
52.155 + }).
52.156 + generate(w);
52.157 + w.close();
52.158 +
52.159 + } catch (IOException ex) {
52.160 + throw new MojoExecutionException("Can't compile", ex);
52.161 + }
52.162 + }
52.163 +
52.164 + private void aotLibrary(Artifact a, File js, URLClassLoader loader) throws IOException {
52.165 + FileWriter w = new FileWriter(js);
52.166 + Bck2Brwsr c = Bck2BrwsrJars.configureFrom(null, a.getFile());
52.167 + c.
52.168 + obfuscation(obfuscation).
52.169 + resources(loader).
52.170 + generate(w);
52.171 + w.close();
52.172 + }
52.173 + private static URLClassLoader buildClassLoader(File root, Collection<Artifact> deps) throws MalformedURLException {
52.174 + List<URL> arr = new ArrayList<URL>();
52.175 + if (root != null) {
52.176 + arr.add(root.toURI().toURL());
52.177 + }
52.178 + for (Artifact a : deps) {
52.179 + if (a.getFile() != null) {
52.180 + arr.add(a.getFile().toURI().toURL());
52.181 + }
52.182 + }
52.183 + return new URLClassLoader(arr.toArray(new URL[0]), Java2JavaScript.class.getClassLoader());
52.184 + }
52.185 +}
53.1 --- a/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Java2JavaScript.java Thu May 15 11:38:27 2014 +0200
53.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/Java2JavaScript.java Mon Jun 09 15:57:14 2014 +0200
53.3 @@ -108,12 +108,14 @@
53.4 try {
53.5 URLClassLoader url = buildClassLoader(classes, prj.getArtifacts());
53.6 FileWriter w = new FileWriter(javascript);
53.7 - Bck2Brwsr.newCompiler().
53.8 + Bck2Brwsr c = Bck2Brwsr.newCompiler().
53.9 obfuscation(obfuscation).
53.10 - library(library).
53.11 resources(url, ignoreBootClassPath).
53.12 - addRootClasses(arr.toArray(new String[0])).
53.13 - generate(w);
53.14 + addRootClasses(arr.toArray(new String[0]));
53.15 + if (library) {
53.16 + c = c.library();
53.17 + }
53.18 + c.generate(w);
53.19 w.close();
53.20 } catch (IOException ex) {
53.21 throw new MojoExecutionException("Can't compile", ex);
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
54.2 +++ b/rt/mojo/src/main/java/org/apidesign/bck2brwsr/mojo/ShowMojo.java Mon Jun 09 15:57:14 2014 +0200
54.3 @@ -0,0 +1,84 @@
54.4 +/**
54.5 + * Back 2 Browser Bytecode Translator
54.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
54.7 + *
54.8 + * This program is free software: you can redistribute it and/or modify
54.9 + * it under the terms of the GNU General Public License as published by
54.10 + * the Free Software Foundation, version 2 of the License.
54.11 + *
54.12 + * This program is distributed in the hope that it will be useful,
54.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
54.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54.15 + * GNU General Public License for more details.
54.16 + *
54.17 + * You should have received a copy of the GNU General Public License
54.18 + * along with this program. Look for COPYING file in the top folder.
54.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
54.20 + */
54.21 +package org.apidesign.bck2brwsr.mojo;
54.22 +
54.23 +import java.io.Closeable;
54.24 +import org.apache.maven.plugin.AbstractMojo;
54.25 +
54.26 +import java.io.File;
54.27 +import java.io.IOException;
54.28 +import java.net.MalformedURLException;
54.29 +import java.net.URL;
54.30 +import java.net.URLClassLoader;
54.31 +import java.util.ArrayList;
54.32 +import java.util.Collection;
54.33 +import java.util.List;
54.34 +import org.apache.maven.artifact.Artifact;
54.35 +import org.apache.maven.model.Resource;
54.36 +import org.apache.maven.plugin.MojoExecutionException;
54.37 +import org.apache.maven.plugins.annotations.LifecyclePhase;
54.38 +import org.apache.maven.plugins.annotations.Mojo;
54.39 +import org.apache.maven.plugins.annotations.Parameter;
54.40 +import org.apache.maven.plugins.annotations.ResolutionScope;
54.41 +import org.apache.maven.project.MavenProject;
54.42 +import org.apidesign.bck2brwsr.launcher.Launcher;
54.43 +
54.44 +/** Executes given HTML page in a browser. */
54.45 +@Mojo(
54.46 + name="show",
54.47 + requiresDependencyResolution = ResolutionScope.RUNTIME,
54.48 + defaultPhase=LifecyclePhase.NONE
54.49 +)
54.50 +public class ShowMojo extends AbstractMojo {
54.51 + public ShowMojo() {
54.52 + }
54.53 +
54.54 + /** The identification of a launcher to use. Known values <code>fxbrwsr</code>,
54.55 + * <code>bck2brwsr</code>, or
54.56 + * name of an external process to execute.
54.57 + */
54.58 + @Parameter
54.59 + private String launcher;
54.60 +
54.61 +
54.62 + /** Resource to show as initial page */
54.63 + @Parameter
54.64 + private String startpage;
54.65 +
54.66 + /** Root of all pages, and files, etc. */
54.67 + @Parameter
54.68 + private File directory;
54.69 +
54.70 + @Override
54.71 + public void execute() throws MojoExecutionException {
54.72 + if (startpage == null) {
54.73 + throw new MojoExecutionException("You have to provide a start page");
54.74 + }
54.75 + if (directory == null) {
54.76 + throw new MojoExecutionException("You have to provide a root directory");
54.77 + }
54.78 + try {
54.79 + Closeable httpServer;
54.80 + httpServer = Launcher.showDir(launcher, directory, null, startpage);
54.81 + System.in.read();
54.82 + httpServer.close();
54.83 + } catch (IOException ex) {
54.84 + throw new MojoExecutionException("Can't show the browser", ex);
54.85 + }
54.86 + }
54.87 +}
55.1 --- a/rt/pom.xml Thu May 15 11:38:27 2014 +0200
55.2 +++ b/rt/pom.xml Mon Jun 09 15:57:14 2014 +0200
55.3 @@ -17,5 +17,6 @@
55.4 <module>mojo</module>
55.5 <module>vm</module>
55.6 <module>vmtest</module>
55.7 + <module>aot</module>
55.8 </modules>
55.9 </project>
56.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/Bck2Brwsr.java Thu May 15 11:38:27 2014 +0200
56.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/Bck2Brwsr.java Mon Jun 09 15:57:14 2014 +0200
56.3 @@ -19,7 +19,6 @@
56.4
56.5 import java.io.IOException;
56.6 import java.io.InputStream;
56.7 -import org.apidesign.bck2brwsr.core.Exported;
56.8
56.9 /** Build your own virtual machine! Use methods in this class to generate
56.10 * a skeleton JVM in JavaScript that contains pre-compiled classes of your
56.11 @@ -27,7 +26,7 @@
56.12 * be used to bootstrap and load the virtual machine: <pre>
56.13 * var vm = bck2brwsr();
56.14 * var main = vm.loadClass('org.your.pkg.Main');
56.15 - * main.main__V_3Ljava_lang_String_2(null);
56.16 + * main.invoke('main');
56.17 * </pre>
56.18 * In case one wants to initialize the virtual machine with ability to
56.19 * load classes lazily when needed, one can provide a loader function to
56.20 @@ -40,33 +39,52 @@
56.21 * function is asked for its byte code and the system dynamically transforms
56.22 * it to JavaScript.
56.23 * <p>
56.24 - * Instead of a loader function, one can also provide a URL to a JAR file.
56.25 + * Instead of a loader function, one can also provide a URL to a JAR file
56.26 + * or a library JavaScript file generated with {@link #library(java.lang.String...)}
56.27 + * option on.
56.28 * The <code>bck2brwsr</code> system will do its best to download the file
56.29 - * and provide loader function for it automatically.
56.30 + * and provide loader function for it automatically. In order to use
56.31 + * the JAR file <code>emul.zip</code> module needs to be available in the system.
56.32 * <p>
56.33 - * One can provide as many loader functions and JAR URL references as necessary.
56.34 + * One can provide as many loader functions and URL references as necessary.
56.35 * Then the initialization code would look like:<pre>
56.36 * var vm = bck2brwsr(url1, url2, fnctn1, url3, functn2);
56.37 * </pre>
56.38 * The provided URLs and loader functions will be consulted one by one.
56.39 + * <p>
56.40 + * The initialization of the <b>Bck2Brwsr</b> is done asynchronously since
56.41 + * version 0.9. E.g. call to <pre>
56.42 + * var vm = bck2brwsr('myapp.js');
56.43 + * var main = vm.loadClass('org.your.pkg.Main');
56.44 + * main.invoke('main');
56.45 + * </pre>
56.46 + * returns immediately and the call to the static main method will happen
56.47 + * once the virtual machine is initialized and the class available.
56.48 *
56.49 * @author Jaroslav Tulach <jtulach@netbeans.org>
56.50 */
56.51 public final class Bck2Brwsr {
56.52 private final ObfuscationLevel level;
56.53 - private final StringArray rootcls;
56.54 + private final StringArray exported;
56.55 private final StringArray classes;
56.56 private final StringArray resources;
56.57 private final Resources res;
56.58 - private final boolean extension;
56.59 + private final Boolean extension;
56.60 + private final StringArray classpath;
56.61
56.62 - private Bck2Brwsr(ObfuscationLevel level, StringArray rootcls, StringArray classes, StringArray resources, Resources res, boolean extension) {
56.63 + private Bck2Brwsr(
56.64 + ObfuscationLevel level,
56.65 + StringArray exported, StringArray classes, StringArray resources,
56.66 + Resources res,
56.67 + Boolean extension, StringArray classpath
56.68 + ) {
56.69 this.level = level;
56.70 - this.rootcls = rootcls;
56.71 + this.exported = exported;
56.72 this.classes = classes;
56.73 this.resources = resources;
56.74 this.res = res;
56.75 this.extension = extension;
56.76 + this.classpath = classpath;
56.77 }
56.78
56.79 /** Helper method to generate virtual machine from bytes served by a <code>resources</code>
56.80 @@ -103,7 +121,32 @@
56.81 * @since 0.5
56.82 */
56.83 public static Bck2Brwsr newCompiler() {
56.84 - return new Bck2Brwsr(ObfuscationLevel.NONE, new StringArray(), new StringArray(), new StringArray(), null, false);
56.85 + return new Bck2Brwsr(
56.86 + ObfuscationLevel.NONE,
56.87 + new StringArray(), new StringArray(), new StringArray(),
56.88 + null, false, null
56.89 + );
56.90 + }
56.91 +
56.92 + /** Adds exported classes or packages. If the string ends
56.93 + * with slash, it is considered a name of package. If it does not,
56.94 + * it is a name of a class (without <code>.class</code> suffix).
56.95 + * The exported classes are prevented from being obfuscated.
56.96 + * All public classes in exported packages are prevented from
56.97 + * being obfuscated. By listing the packages or classes in this
56.98 + * method, these classes are not guaranteed to be included in
56.99 + * the generated script. Use {@link #addClasses} to include
56.100 + * the classes.
56.101 + *
56.102 + * @param exported names of classes and packages to treat as exported
56.103 + * @return new instances of the Bck2Brwsr compiler which inherits
56.104 + * all values from <code>this</code> except list of exported classes
56.105 + */
56.106 + public Bck2Brwsr addExported(String... exported) {
56.107 + return new Bck2Brwsr(
56.108 + level, this.exported.addAndNew(exported),
56.109 + classes, resources, res, extension, classpath
56.110 + );
56.111 }
56.112
56.113 /** Adds additional classes
56.114 @@ -113,7 +156,7 @@
56.115 * generated virtual machine code accessible using their fully
56.116 * qualified name. This brings the same behavior as if the
56.117 * classes were added by {@link #addClasses(java.lang.String...) } and
56.118 - * were annotated with {@link Exported} annotation.
56.119 + * exported via {@link #addExported(java.lang.String...)}.
56.120 *
56.121 * @param classes the classes to add to the compilation
56.122 * @return new instance of the Bck2Brwsr compiler which inherits
56.123 @@ -122,10 +165,8 @@
56.124 public Bck2Brwsr addRootClasses(String... classes) {
56.125 if (classes.length == 0) {
56.126 return this;
56.127 - } else {
56.128 - return new Bck2Brwsr(level, rootcls.addAndNew(classes), this.classes, resources, res,
56.129 - extension);
56.130 - }
56.131 + }
56.132 + return addExported(classes).addClasses(classes);
56.133 }
56.134
56.135 /** Adds additional classes
56.136 @@ -143,8 +184,9 @@
56.137 if (classes.length == 0) {
56.138 return this;
56.139 } else {
56.140 - return new Bck2Brwsr(level, rootcls, this.classes.addAndNew(classes), resources, res,
56.141 - extension);
56.142 + return new Bck2Brwsr(level, exported,
56.143 + this.classes.addAndNew(classes), resources, res,
56.144 + extension, classpath);
56.145 }
56.146 }
56.147
56.148 @@ -163,8 +205,8 @@
56.149 if (resources.length == 0) {
56.150 return this;
56.151 } else {
56.152 - return new Bck2Brwsr(level, rootcls, this.classes,
56.153 - this.resources.addAndNew(resources), res, extension
56.154 + return new Bck2Brwsr(level, exported, this.classes,
56.155 + this.resources.addAndNew(resources), res, extension, classpath
56.156 );
56.157 }
56.158 }
56.159 @@ -178,7 +220,7 @@
56.160 * @since 0.5
56.161 */
56.162 public Bck2Brwsr obfuscation(ObfuscationLevel level) {
56.163 - return new Bck2Brwsr(level, rootcls, classes, resources, res, extension);
56.164 + return new Bck2Brwsr(level, exported, classes, resources, res, extension, classpath);
56.165 }
56.166
56.167 /** A way to change the provider of additional resources (classes) for the
56.168 @@ -190,7 +232,10 @@
56.169 * @since 0.5
56.170 */
56.171 public Bck2Brwsr resources(Resources res) {
56.172 - return new Bck2Brwsr(level, rootcls, classes, resources, res, extension);
56.173 + return new Bck2Brwsr(
56.174 + level, exported, classes, resources,
56.175 + res, extension, classpath
56.176 + );
56.177 }
56.178
56.179 /** Should one generate a library? By default the system generates
56.180 @@ -199,13 +244,41 @@
56.181 * By turning on the library mode, only classes explicitly listed
56.182 * will be included in the archive. The others will be referenced
56.183 * as external ones.
56.184 + * <p>
56.185 + * A library archive may specify its <em>classpath</em> - e.g. link to
56.186 + * other libraries that should also be included in the application.
56.187 + * One can specify the list of libraries as vararg to this method.
56.188 + * These are relative URL with respect to location of this library.
56.189 + * The runtime system then prefers seek for ".js" suffix of the library
56.190 + * and only then seeks for the classical ".jar" path.
56.191 *
56.192 - * @param library turn on the library mode?
56.193 + * @param classpath the array of JARs that are referenced by this library -
56.194 + * by default gets turned into
56.195 * @return new instance of the compiler with library flag changed
56.196 * @since 0.9
56.197 */
56.198 - public Bck2Brwsr library(boolean library) {
56.199 - return new Bck2Brwsr(level, rootcls, classes, resources, res, library);
56.200 + public Bck2Brwsr library(String... classpath) {
56.201 + return new Bck2Brwsr(
56.202 + level, exported, classes,
56.203 + resources, res, true,
56.204 + StringArray.asList(classpath)
56.205 + );
56.206 + }
56.207 +
56.208 + /** Turns on the standalone mode. E.g. acts like {@link #library(boolean) library(false)},
56.209 + * but also allows to specify whether the <em>Bck2Brwsr VM</em> should
56.210 + * be included at all. If not, only the skeleton of the launcher is
56.211 + * generated without any additional VM classes referenced.
56.212 + *
56.213 + * @param includeVM should the VM be compiled in, or left out
56.214 + * @return new instance of the compiler with standalone mode on
56.215 + * @since 0.9
56.216 + */
56.217 + public Bck2Brwsr standalone(boolean includeVM) {
56.218 + return new Bck2Brwsr(
56.219 + level, exported, classes, resources,
56.220 + res, includeVM ? false : null, null
56.221 + );
56.222 }
56.223
56.224 /** A way to change the provider of additional resources (classes) for the
56.225 @@ -264,20 +337,28 @@
56.226 return res != null ? res : new LdrRsrcs(Bck2Brwsr.class.getClassLoader(), false);
56.227 }
56.228
56.229 - String[] allClasses() {
56.230 - return classes.addAndNew(rootcls.toArray()).toArray();
56.231 - }
56.232 StringArray allResources() {
56.233 return resources;
56.234 }
56.235
56.236 -
56.237 - StringArray rootClasses() {
56.238 - return rootcls;
56.239 + StringArray classes() {
56.240 + return classes;
56.241 + }
56.242 +
56.243 + StringArray exported() {
56.244 + return exported;
56.245 }
56.246
56.247 boolean isExtension() {
56.248 - return extension;
56.249 + return Boolean.TRUE.equals(extension);
56.250 + }
56.251 +
56.252 + boolean includeVM() {
56.253 + return extension != null;
56.254 + }
56.255 +
56.256 + StringArray classpath() {
56.257 + return classpath;
56.258 }
56.259
56.260 /** Provider of resources (classes and other files). The
57.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Thu May 15 11:38:27 2014 +0200
57.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeToJavaScript.java Mon Jun 09 15:57:14 2014 +0200
57.3 @@ -96,10 +96,12 @@
57.4 }
57.5
57.6 protected String accessVirtualMethod(
57.7 - String object,
57.8 - String mangledName,
57.9 - String[] fieldInfoName) throws IOException {
57.10 - return object + "." + mangledName;
57.11 + String object,
57.12 + String mangledName,
57.13 + String[] fieldInfoName,
57.14 + int params
57.15 + ) throws IOException {
57.16 + return object + "." + mangledName + '(';
57.17 }
57.18
57.19 protected void declaredClass(ClassData classData, String mangledName)
57.20 @@ -229,17 +231,7 @@
57.21 }
57.22 for (MethodData m : jc.getMethods()) {
57.23 byte[] onlyArr = m.findAnnotationData(true);
57.24 - String[] only = findAnnotation(onlyArr, jc,
57.25 - "org.apidesign.bck2brwsr.core.JavaScriptOnly",
57.26 - "name", "value"
57.27 - );
57.28 - if (only != null) {
57.29 - if (only[0] != null && only[1] != null) {
57.30 - append("\n p.").append(only[0]).append(" = ")
57.31 - .append(only[1]).append(";");
57.32 - }
57.33 - continue;
57.34 - }
57.35 + if (javaScriptOnly(onlyArr)) continue;
57.36 String destObject;
57.37 String mn;
57.38 append("\n ");
57.39 @@ -301,17 +293,7 @@
57.40 append("\n }");
57.41 for (FieldData v : jc.getFields()) {
57.42 byte[] onlyArr = v.findAnnotationData(true);
57.43 - String[] only = findAnnotation(onlyArr, jc,
57.44 - "org.apidesign.bck2brwsr.core.JavaScriptOnly",
57.45 - "name", "value"
57.46 - );
57.47 - if (only != null) {
57.48 - if (only[0] != null && only[1] != null) {
57.49 - append("\n p.").append(only[0]).append(" = ")
57.50 - .append(only[1]).append(";");
57.51 - }
57.52 - continue;
57.53 - }
57.54 + if (javaScriptOnly(onlyArr)) continue;
57.55 if (!v.isStatic()) {
57.56 append("\n this.fld_").
57.57 append(className).append('_').
57.58 @@ -331,6 +313,25 @@
57.59 // }
57.60 return "";
57.61 }
57.62 +
57.63 + private boolean javaScriptOnly(byte[] anno) throws IOException {
57.64 + String[] only = findAnnotation(anno, jc,
57.65 + "org.apidesign.bck2brwsr.core.JavaScriptOnly",
57.66 + "name", "value"
57.67 + );
57.68 + if (only != null) {
57.69 + if (only[0] != null && only[1] != null) {
57.70 + append("\n p.").append(only[0]).append(" = ")
57.71 + .append(only[1]).append(";");
57.72 + }
57.73 + if (ExportedSymbols.isMarkedAsExported(anno, jc)) {
57.74 + append("\n p['").append(only[0]).append("'] = p.")
57.75 + .append(only[0]).append(";");
57.76 + }
57.77 + return true;
57.78 + }
57.79 + return false;
57.80 + }
57.81 private String generateStaticMethod(String destObject, MethodData m, StringArray toInitilize) throws IOException {
57.82 String jsb = javaScriptBody(destObject, m, true);
57.83 if (jsb != null) {
57.84 @@ -1599,6 +1600,7 @@
57.85 }
57.86
57.87 if (returnType[0] != 'V') {
57.88 + mapper.flush(this);
57.89 append("var ")
57.90 .append(mapper.pushT(VarType.fromFieldType(returnType[0])))
57.91 .append(" = ");
57.92 @@ -1654,8 +1656,7 @@
57.93 .append(" = ");
57.94 }
57.95
57.96 - append(accessVirtualMethod(vars[0].toString(), mn, mi));
57.97 - append('(');
57.98 + append(accessVirtualMethod(vars[0].toString(), mn, mi, numArguments));
57.99 String sep = "";
57.100 for (int j = 1; j < numArguments; ++j) {
57.101 append(sep);
58.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ClassPath.java Thu May 15 11:38:27 2014 +0200
58.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ClassPath.java Mon Jun 09 15:57:14 2014 +0200
58.3 @@ -21,6 +21,7 @@
58.4 import java.io.IOException;
58.5 import java.io.InputStream;
58.6 import java.net.URL;
58.7 +import org.apidesign.bck2brwsr.core.Exported;
58.8 import org.apidesign.bck2brwsr.core.JavaScriptBody;
58.9
58.10 /** Conversion from classpath to load function.
58.11 @@ -41,42 +42,51 @@
58.12 private static native Object set(Object arr, int index, Object value);
58.13
58.14 private static boolean doingToZip;
58.15 - public static byte[] loadFromCp(Object classpath, String res, int skip)
58.16 +
58.17 + static byte[] loadBytes(String resource, Object classpath, int skip)
58.18 throws IOException, ClassNotFoundException {
58.19 for (int i = 0; i < length(classpath); i++) {
58.20 - Object c = at(classpath, i);
58.21 - if (c instanceof String && !doingToZip) {
58.22 - try {
58.23 - doingToZip = true;
58.24 - String url = (String)c;
58.25 - final Bck2Brwsr.Resources z = toZip(url);
58.26 - c = set(classpath, i, z);
58.27 - final byte[] man = readBytes(z, "META-INF/MANIFEST.MF");
58.28 - if (man != null) {
58.29 - String mainClass = processClassPathAttr(man, url, classpath);
58.30 + byte[] arr = loadBytes(resource, classpath, i, skip);
58.31 + if (arr != null) {
58.32 + return arr;
58.33 + }
58.34 + }
58.35 + return null;
58.36 + }
58.37 + @Exported static byte[] loadBytes(String resource, Object classpath, int i, int skip)
58.38 + throws IOException, ClassNotFoundException {
58.39 + Object c = at(classpath, i);
58.40 + if (c instanceof String && !doingToZip) {
58.41 + try {
58.42 + doingToZip = true;
58.43 + String url = (String)c;
58.44 + final Bck2Brwsr.Resources z = toZip(url);
58.45 + c = set(classpath, i, z);
58.46 + final byte[] man = readBytes(z, "META-INF/MANIFEST.MF");
58.47 + if (man != null) {
58.48 + String mainClass = processClassPathAttr(man, url, classpath);
58.49 // if (mainClass != null) {
58.50 // Class.forName(mainClass);
58.51 // }
58.52 - }
58.53 - } catch (IOException ex) {
58.54 - set(classpath, i, ex);
58.55 - log("Cannot load " + c + " - " + ex.getClass().getName() + ":" + ex.getMessage());
58.56 - } finally {
58.57 - doingToZip = false;
58.58 }
58.59 + } catch (IOException ex) {
58.60 + set(classpath, i, ex);
58.61 + log("Cannot load " + c + " - " + ex.getClass().getName() + ":" + ex.getMessage());
58.62 + } finally {
58.63 + doingToZip = false;
58.64 }
58.65 - if (res != null) {
58.66 - byte[] checkRes;
58.67 - if (c instanceof Bck2Brwsr.Resources) {
58.68 - checkRes = readBytes((Bck2Brwsr.Resources)c, res);
58.69 - if (checkRes != null && --skip < 0) {
58.70 - return checkRes;
58.71 - }
58.72 - } else {
58.73 - checkRes = callFunction(c, res, skip);
58.74 - if (checkRes != null) {
58.75 - return checkRes;
58.76 - }
58.77 + }
58.78 + if (resource != null) {
58.79 + byte[] checkRes;
58.80 + if (c instanceof Bck2Brwsr.Resources) {
58.81 + checkRes = readBytes((Bck2Brwsr.Resources)c, resource);
58.82 + if (checkRes != null && --skip < 0) {
58.83 + return checkRes;
58.84 + }
58.85 + } else {
58.86 + checkRes = callFunction(c, resource, skip);
58.87 + if (checkRes != null) {
58.88 + return checkRes;
58.89 }
58.90 }
58.91 }
59.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ClosureWrapper.java Thu May 15 11:38:27 2014 +0200
59.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ClosureWrapper.java Mon Jun 09 15:57:14 2014 +0200
59.3 @@ -36,6 +36,7 @@
59.4 private static final String[] ARGS = {
59.5 "--compilation_level",
59.6 "SIMPLE_OPTIMIZATIONS",
59.7 + "--output_wrapper", "(function() {%output%})(this);",
59.8 "--js", "bck2brwsr-raw.js"
59.9 //, "--debug"
59.10 //, "--formatting", "PRETTY_PRINT"
59.11 @@ -157,7 +158,7 @@
59.12 private static final String[] FIXED_EXTERNS = {
59.13 "bck2brwsr",
59.14 "bck2BrwsrThrwrbl",
59.15 - "registerExtension",
59.16 + "register",
59.17 "$class",
59.18 "anno",
59.19 "array",
60.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/ExportedSymbols.java Thu May 15 11:38:27 2014 +0200
60.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/ExportedSymbols.java Mon Jun 09 15:57:14 2014 +0200
60.3 @@ -75,6 +75,9 @@
60.4 if (pkgName == null) {
60.5 return false;
60.6 }
60.7 + if (pkgName.startsWith("java/")) {
60.8 + return true;
60.9 + }
60.10
60.11 final Boolean cachedValue = isMarkedAsExportedCache.get(pkgName);
60.12 if (cachedValue != null) {
60.13 @@ -115,6 +118,9 @@
60.14 }
60.15
60.16 private boolean resolveIsMarkedAsExportedPackage(String pkgName) {
60.17 + if (exported.contains(pkgName + '/')) {
60.18 + return true;
60.19 + }
60.20 try {
60.21 final InputStream is =
60.22 resources.get(pkgName + "/package-info.class");
60.23 @@ -135,7 +141,7 @@
60.24 }
60.25 }
60.26
60.27 - private boolean isMarkedAsExported(byte[] arrData, ClassData cd)
60.28 + static boolean isMarkedAsExported(byte[] arrData, ClassData cd)
60.29 throws IOException {
60.30 if (arrData == null) {
60.31 return false;
61.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/Main.java Thu May 15 11:38:27 2014 +0200
61.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/Main.java Mon Jun 09 15:57:14 2014 +0200
61.3 @@ -105,11 +105,16 @@
61.4 }
61.5
61.6 try (Writer w = new BufferedWriter(new FileWriter(gt))) {
61.7 - Bck2Brwsr.newCompiler().library(createExtension).
61.8 + Bck2Brwsr c = Bck2Brwsr.newCompiler().
61.9 obfuscation(obfLevel).
61.10 addRootClasses(classes.toArray()).
61.11 - resources(new LdrRsrcs(Main.class.getClassLoader(), true)).
61.12 - generate(w);
61.13 + resources(new LdrRsrcs(Main.class.getClassLoader(), true));
61.14 +
61.15 + if (createExtension) {
61.16 + c = c.library();
61.17 + }
61.18 +
61.19 + c.generate(w);
61.20 }
61.21 }
61.22
62.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/StringArray.java Thu May 15 11:38:27 2014 +0200
62.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/StringArray.java Mon Jun 09 15:57:14 2014 +0200
62.3 @@ -103,6 +103,12 @@
62.4 }
62.5 arr = tmp;
62.6 }
62.7 + void remove(String item) {
62.8 + int f = indexOf(item);
62.9 + if (f != -1) {
62.10 + delete(f);
62.11 + }
62.12 + }
62.13
62.14 int indexOf(String ic) {
62.15 if (arr != null) for (int i = 0; i < arr.length; i++) {
63.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Thu May 15 11:38:27 2014 +0200
63.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VM.java Mon Jun 09 15:57:14 2014 +0200
63.3 @@ -34,19 +34,18 @@
63.4 private final Bck2Brwsr.Resources resources;
63.5 private final ExportedSymbols exportedSymbols;
63.6 private final StringArray invokerMethods;
63.7 + private final StringArray asBinary;
63.8
63.9 - private static final Class<?> FIXED_DEPENDENCIES[] = {
63.10 - Class.class,
63.11 - ArithmeticException.class,
63.12 - VM.class
63.13 - };
63.14 -
63.15 - private VM(Appendable out, Bck2Brwsr.Resources resources, StringArray explicitlyExported) {
63.16 + private VM(
63.17 + Appendable out, Bck2Brwsr.Resources resources,
63.18 + StringArray explicitlyExported, StringArray asBinary
63.19 + ) {
63.20 super(out);
63.21 this.resources = resources;
63.22 this.classDataCache = new ClassDataCache(resources);
63.23 this.exportedSymbols = new ExportedSymbols(resources, explicitlyExported);
63.24 this.invokerMethods = new StringArray();
63.25 + this.asBinary = asBinary;
63.26 }
63.27
63.28 static {
63.29 @@ -67,32 +66,41 @@
63.30 static void compile(Appendable out,
63.31 Bck2Brwsr config
63.32 ) throws IOException {
63.33 - String[] both = config.allClasses();
63.34 + String[] both = config.classes().toArray();
63.35
63.36 - VM vm = config.isExtension() ?
63.37 - new Extension(out, config.getResources(), both, config.rootClasses())
63.38 - :
63.39 - new Standalone(out, config.getResources(), config.rootClasses());
63.40 -
63.41 final StringArray fixedNames = new StringArray();
63.42 -
63.43 - for (final Class<?> fixedClass: FIXED_DEPENDENCIES) {
63.44 - fixedNames.add(fixedClass.getName().replace('.', '/'));
63.45 - }
63.46 -
63.47 - vm.doCompile(fixedNames.addAndNew(both), config.allResources());
63.48 + fixedNames.add(Object.class.getName().replace('.', '/'));
63.49 + fixedNames.add(Class.class.getName().replace('.', '/'));
63.50 + fixedNames.add(ArithmeticException.class.getName().replace('.', '/'));
63.51 +
63.52 + VM vm;
63.53 + if (config.isExtension()) {
63.54 + fixedNames.add(VM.class.getName().replace('.', '/'));
63.55 + vm = new Extension(out,
63.56 + config.getResources(), both, config.exported(),
63.57 + config.allResources(), config.classpath()
63.58 + );
63.59 + } else {
63.60 + if (config.includeVM()) {
63.61 + fixedNames.add(VM.class.getName().replace('.', '/'));
63.62 + }
63.63 + vm = new Standalone(out,
63.64 + config.getResources(), config.exported(),
63.65 + config.allResources()
63.66 + );
63.67 + }
63.68 + vm.doCompile(fixedNames.addAndNew(both));
63.69 }
63.70
63.71 - private void doCompile(StringArray names, StringArray asBinary) throws IOException {
63.72 + private void doCompile(StringArray names) throws IOException {
63.73 generatePrologue();
63.74 append(
63.75 "\n var invoker = {};");
63.76 generateBody(names);
63.77 for (String invokerMethod: invokerMethods.toArray()) {
63.78 - append("\n invoker." + invokerMethod + " = function(target) {"
63.79 - + "\n return function() {"
63.80 - + "\n return target['" + invokerMethod + "'].apply(target, arguments);"
63.81 - + "\n };"
63.82 + append("\n invoker." + invokerMethod + " = function() {"
63.83 + + "\n var target = arguments[0];"
63.84 + + "\n return target['" + invokerMethod + "'].apply(target, Array.prototype.slice.call(arguments, 1));"
63.85 + "\n };"
63.86 );
63.87 }
63.88 @@ -232,6 +240,7 @@
63.89 throw new IOException("Can't find " + resource);
63.90 }
63.91 readResource(emul, this);
63.92 + asBinary.remove(resource);
63.93 }
63.94 scripts = new StringArray();
63.95
63.96 @@ -249,47 +258,6 @@
63.97 }
63.98 }
63.99 }
63.100 -/*
63.101 - append(
63.102 - " return vm;\n"
63.103 - + " };\n"
63.104 - + " function mangleClass(name) {\n"
63.105 - + " return name.replace__Ljava_lang_String_2Ljava_lang_CharSequence_2Ljava_lang_CharSequence_2(\n"
63.106 - + " '_', '_1').replace__Ljava_lang_String_2CC('.','_');\n"
63.107 - + " };\n"
63.108 - + " global.bck2brwsr = function() {\n"
63.109 - + " var args = Array.prototype.slice.apply(arguments);\n"
63.110 - + " var vm = fillInVMSkeleton({});\n"
63.111 - + " var loader = {};\n"
63.112 - + " loader.vm = vm;\n"
63.113 - + " loader.loadClass = function(name) {\n"
63.114 - + " var attr = mangleClass(name);\n"
63.115 - + " var fn = vm[attr];\n"
63.116 - + " if (fn) return fn(false);\n"
63.117 - + " return vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
63.118 - + " load__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2(loader, name, args);\n"
63.119 - + " }\n"
63.120 - + " if (vm.loadClass) {\n"
63.121 - + " throw 'Cannot initialize the bck2brwsr VM twice!';\n"
63.122 - + " }\n"
63.123 - + " vm.loadClass = loader.loadClass;\n"
63.124 - + " vm._reload = function(name, byteCode) {;\n"
63.125 - + " var attr = mangleClass(name);\n"
63.126 - + " delete vm[attr];\n"
63.127 - + " return vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
63.128 - + " reload__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2_3B(loader, name, args, byteCode);\n"
63.129 - + " };\n"
63.130 - + " vm.loadBytes = function(name, skip) {\n"
63.131 - + " return vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
63.132 - + " loadBytes___3BLjava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2I(loader, name, args, typeof skip == 'number' ? skip : 0);\n"
63.133 - + " }\n"
63.134 - + " vm.java_lang_reflect_Array(false);\n"
63.135 - + " vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
63.136 - + " loadBytes___3BLjava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2I(loader, null, args, 0);\n"
63.137 - + " return loader;\n"
63.138 - + " };\n");
63.139 - append("}(this));");
63.140 -*/
63.141 }
63.142
63.143 private static void readResource(InputStream emul, Appendable out) throws IOException {
63.144 @@ -397,9 +365,11 @@
63.145
63.146 @Override
63.147 protected String accessVirtualMethod(
63.148 - String object,
63.149 - String mangledName,
63.150 - String[] fieldInfoName) throws IOException {
63.151 + String object,
63.152 + String mangledName,
63.153 + String[] fieldInfoName,
63.154 + int params
63.155 + ) throws IOException {
63.156 final ClassData referencedClass =
63.157 classDataCache.getClassData(fieldInfoName[0]);
63.158 final MethodData method =
63.159 @@ -413,17 +383,17 @@
63.160 || ((referencedClass.getAccessFlags()
63.161 & ByteCodeParser.ACC_FINAL) != 0)
63.162 || !isHierarchyExported(method))) {
63.163 - return object + "." + mangledName;
63.164 + return object + "." + mangledName + '(';
63.165 }
63.166
63.167 - return accessThroughInvoker(object, mangledName);
63.168 + return accessThroughInvoker(object, mangledName, params > 1 ? "," : "");
63.169 }
63.170
63.171 - private String accessThroughInvoker(String object, String mangledName) {
63.172 + private String accessThroughInvoker(String object, String mangledName, String sep) {
63.173 if (!invokerMethods.contains(mangledName)) {
63.174 invokerMethods.add(mangledName);
63.175 }
63.176 - return "invoker." + mangledName + '(' + object + ')';
63.177 + return "invoker." + mangledName + '(' + object + sep;
63.178 }
63.179
63.180 private boolean isHierarchyExported(final MethodData methodData)
63.181 @@ -457,7 +427,7 @@
63.182 : object + "['" + mangledName + "']";
63.183 }
63.184
63.185 - private static final class ExportedMethodFinder
63.186 + private final class ExportedMethodFinder
63.187 implements ClassDataCache.TraversalCallback<MethodData> {
63.188 private final ExportedSymbols exportedSymbols;
63.189 private MethodData found;
63.190 @@ -469,7 +439,10 @@
63.191 @Override
63.192 public boolean traverse(final MethodData methodData) {
63.193 try {
63.194 - if (exportedSymbols.isExported(methodData)) {
63.195 + if (
63.196 + exportedSymbols.isExported(methodData) ||
63.197 + isExternalClass(methodData.cls.getClassName())
63.198 + ) {
63.199 found = methodData;
63.200 return false;
63.201 }
63.202 @@ -485,8 +458,11 @@
63.203 }
63.204
63.205 private static final class Standalone extends VM {
63.206 - private Standalone(Appendable out, Bck2Brwsr.Resources resources, StringArray explicitlyExported) {
63.207 - super(out, resources, explicitlyExported);
63.208 + private Standalone(Appendable out,
63.209 + Bck2Brwsr.Resources resources,
63.210 + StringArray explicitlyExported, StringArray asBinary
63.211 + ) {
63.212 + super(out, resources, explicitlyExported, asBinary);
63.213 }
63.214
63.215 @Override
63.216 @@ -500,10 +476,65 @@
63.217 " return vm;\n"
63.218 + " };\n"
63.219 + " var extensions = [];\n"
63.220 + + " function replaceAll(s, target, replacement) {\n"
63.221 + + " var pos = 0;\n"
63.222 + + " for (;;) {\n"
63.223 + + " var indx = s.indexOf(target, pos);\n"
63.224 + + " if (indx === -1) {\n"
63.225 + + " return s;\n"
63.226 + + " }\n"
63.227 + + " pos = indx + replacement.length;\n"
63.228 + + " s = s.substring(0, indx) + replacement + s.substring(indx + target.length);\n"
63.229 + + " }\n"
63.230 + + " }\n"
63.231 + " function mangleClass(name) {\n"
63.232 - + " return name.replace__Ljava_lang_String_2Ljava_lang_CharSequence_2Ljava_lang_CharSequence_2(\n"
63.233 - + " '_', '_1').replace__Ljava_lang_String_2CC('.','_');\n"
63.234 + + " name = replaceAll(name, '_', '_1');\n"
63.235 + + " name = replaceAll(name, '.', '_');\n"
63.236 + + " return name;\n"
63.237 + " };\n"
63.238 + + " var pending = [];\n"
63.239 + + " var pendingClasses = [];\n"
63.240 + + " function extensionLoaded(ev) {\n"
63.241 + + " var at = pending.indexOf(ev.target);\n"
63.242 + + " pending.splice(at, 1);\n"
63.243 + + " if (pending.length === 0) {\n"
63.244 + + " for (var i = 0; i < pendingClasses.length; i += 3) {\n"
63.245 + + " invokeMethod(pendingClasses[i], pendingClasses[i + 1], pendingClasses[i + 2]);\n"
63.246 + + " }\n"
63.247 + + " pendingClasses = [];\n"
63.248 + + " }\n"
63.249 + + " }\n"
63.250 + + " function invokeMethod(vm, n, args) {\n"
63.251 + + " var clazz = vm.loadClass(n);\n"
63.252 + + " if (args) {\n"
63.253 + + " var seek = args[0];\n"
63.254 + + " var prefix = seek.indexOf('__') == -1 ? seek + '__' : seek;\n"
63.255 + + " args = Array.prototype.slice.call(args, 1);\n"
63.256 + + " var found = '';\n"
63.257 + + " for (var m in clazz) {\n"
63.258 + + " if (m.indexOf(prefix) === 0) {\n"
63.259 + + " return clazz[m].apply(null, args);\n"
63.260 + + " }\n"
63.261 + + " found += m.toString() + '\\n'\n"
63.262 + + " }\n"
63.263 + + " throw 'Cannot find ' + seek + ' in ' + n + ' found:\\n' + found;\n"
63.264 + + " }\n"
63.265 + + " }\n"
63.266 + + " function extensionError(ev) {\n"
63.267 + + " console.log('error loading ' + ev.target.src);\n"
63.268 + + " extensionLoaded(ev);\n"
63.269 + + " }\n"
63.270 + + " function loadExtension(url) {\n"
63.271 + + " if (url.substring(url.length - 4) == '.jar')\n"
63.272 + + " url = url.substring(0, url.length - 4) + '.js';\n"
63.273 + + " var script = document.createElement('script');\n"
63.274 + + " script.type = 'text/javascript';\n"
63.275 + + " script.src = url;\n"
63.276 + + " script.onload = extensionLoaded;\n"
63.277 + + " script.onerror = extensionError;\n"
63.278 + + " document.getElementsByTagName('head')[0].appendChild(script);\n"
63.279 + + " pending.push(script);\n"
63.280 + + " }\n"
63.281 + " global.bck2brwsr = function() {\n"
63.282 + " var args = Array.prototype.slice.apply(arguments);\n"
63.283 + " var resources = {};\n"
63.284 @@ -519,42 +550,17 @@
63.285 + " else resources[n].push(arr);\n"
63.286 + " }\n"
63.287 + " var vm = fillInVMSkeleton({ 'registerResource' : registerResource });\n"
63.288 + + " function initVM() {\n"
63.289 + + " var clsArray = vm['java_lang_reflect_Array'];\n"
63.290 + + " if (clsArray) clsArray(false);\n"
63.291 + + " }\n"
63.292 + " for (var i = 0; i < extensions.length; ++i) {\n"
63.293 + " extensions[i](vm);\n"
63.294 + " }\n"
63.295 + " vm['registerResource'] = null;\n"
63.296 + " var knownExtensions = extensions.length;\n"
63.297 + " var loader = {};\n"
63.298 - + " loader.vm = vm;\n"
63.299 - + " loader.loadClass = function(name) {\n"
63.300 - + " var attr = mangleClass(name);\n"
63.301 - + " var fn = vm[attr];\n"
63.302 - + " if (fn) return fn(false);\n"
63.303 - + " try {\n"
63.304 - + " return vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
63.305 - + " load__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2(loader, name, args);\n"
63.306 - + " } catch (err) {\n"
63.307 - + " while (knownExtensions < extensions.length) {\n"
63.308 - + " vm['registerResource'] = registerResource;\n"
63.309 - + " extensions[knownExtensions++](vm);\n"
63.310 - + " vm['registerResource'] = null;\n"
63.311 - + " }\n"
63.312 - + " fn = vm[attr];\n"
63.313 - + " if (fn) return fn(false);\n"
63.314 - + " throw err;\n"
63.315 - + " }\n"
63.316 - + " }\n"
63.317 - + " if (vm.loadClass) {\n"
63.318 - + " throw 'Cannot initialize the bck2brwsr VM twice!';\n"
63.319 - + " }\n"
63.320 - + " vm.loadClass = loader.loadClass;\n"
63.321 - + " vm._reload = function(name, byteCode) {;\n"
63.322 - + " var attr = mangleClass(name);\n"
63.323 - + " delete vm[attr];\n"
63.324 - + " return vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
63.325 - + " reload__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2_3B(loader, name, args, byteCode);\n"
63.326 - + " };\n"
63.327 - + " vm.loadBytes = function(name, skip) {\n"
63.328 + + " var loadBytes = function(name, skip) {\n"
63.329 + " skip = typeof skip == 'number' ? skip : 0;\n"
63.330 + " var arr = resources[name];\n"
63.331 + " if (arr) {\n"
63.332 @@ -564,25 +570,103 @@
63.333 + " } else {\n"
63.334 + " var arrSize = 0;\n"
63.335 + " };\n"
63.336 - + " var ret = vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
63.337 - + " loadBytes___3BLjava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2I(loader, name, args, skip);\n"
63.338 - + " if (ret !== null) return ret;\n"
63.339 + + " for (var i = 0; i < args.length; i++) {\n"
63.340 + + " var at = args[i];\n"
63.341 + + " if(!at) continue;\n"
63.342 + + " var ret;\n"
63.343 + + " if (typeof at === 'string' && at.substring(at.length - 3) === '.js') {\n"
63.344 + + " loadExtension(at);\n"
63.345 + + " args[i] = null;\n"
63.346 + + " } else if (typeof at === 'function') ret = at(name, skip);\n"
63.347 + + " else {\n"
63.348 + + " var cp = vm['org_apidesign_vm4brwsr_ClassPath'];\n"
63.349 + + " if (!cp) throw 'Core Java library not registered. Cannot load from ' + at;\n"
63.350 + + " ret = cp(false).\n"
63.351 + + " loadBytes___3BLjava_lang_String_2Ljava_lang_Object_2II(name, args, i, skip);\n"
63.352 + + " }\n"
63.353 + + " if (ret) return ret;\n"
63.354 + + " }\n"
63.355 + " while (knownExtensions < extensions.length) {\n"
63.356 + " vm['registerResource'] = registerResource;\n"
63.357 + " extensions[knownExtensions++](vm);\n"
63.358 + " vm['registerResource'] = null;\n"
63.359 + + " initVM();\n"
63.360 + " }\n"
63.361 + " var arr = resources[name];\n"
63.362 + " return (arr && arr.length > arrSize) ? arr[arrSize] : null;\n"
63.363 + " }\n"
63.364 - + " vm.java_lang_reflect_Array(false);\n"
63.365 - + " vm.org_apidesign_vm4brwsr_VMLazy(false).\n"
63.366 - + " loadBytes___3BLjava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2I(loader, null, args, 0);\n"
63.367 + + " var reload = function(name, arr, keep) {\n"
63.368 + + " if (!arr) throw 'Cannot find ' + name;\n"
63.369 + + " var lazy = vm['org_apidesign_vm4brwsr_VMLazy'];\n"
63.370 + + " if (!lazy) throw 'No bck2brwsr VM module to compile ' + name;\n"
63.371 + + " if (!keep) {\n"
63.372 + + " var attr = mangleClass(name);\n"
63.373 + + " delete vm[attr];\n"
63.374 + + " }\n"
63.375 + + " return lazy(false)\n"
63.376 + + " ['load__Ljava_lang_Object_2Ljava_lang_Object_2Ljava_lang_String_2_3Ljava_lang_Object_2_3B']\n"
63.377 + + " (vm, name, args, arr);\n"
63.378 + + " };\n"
63.379 + + " var loadClass = function(name) {\n"
63.380 + + " var attr = mangleClass(name);\n"
63.381 + + " var fn = vm[attr];\n"
63.382 + + " if (fn) return fn(false);\n"
63.383 + + " try {\n"
63.384 + + " var arr = loadBytes(replaceAll(name, '.', '/') + '.class');\n"
63.385 + + " return reload(name, arr, true);\n"
63.386 + + " } catch (err) {\n"
63.387 + + " fn = vm[attr];\n"
63.388 + + " if (fn) return fn(false);\n"
63.389 + + " throw err;\n"
63.390 + + " }\n"
63.391 + + " }\n"
63.392 + + " if (vm['loadClass']) {\n"
63.393 + + " throw 'Cannot initialize the bck2brwsr VM twice!';\n"
63.394 + + " }\n"
63.395 + + " vm['loadClass'] = loadClass;\n"
63.396 + + " vm['_reload'] = reload;\n"
63.397 + + " vm['loadBytes'] = loadBytes;\n"
63.398 + + " initVM();\n"
63.399 + + " loader.loadClass = function(name) {\n"
63.400 + + " if (pending.length === 0) {\n"
63.401 + + " try {\n"
63.402 + + " var c = loadClass(name);\n"
63.403 + + " c['invoke'] = function() {\n"
63.404 + + " return invokeMethod(vm, name, arguments);\n"
63.405 + + " };\n"
63.406 + + " return c;\n"
63.407 + + " } catch (err) {\n"
63.408 + + " if (pending.length === 0) throw err;\n"
63.409 + + " }\n"
63.410 + + " }\n"
63.411 + + " pendingClasses.push(vm);\n"
63.412 + + " pendingClasses.push(name);\n"
63.413 + + " pendingClasses.push(null);\n"
63.414 + + " return {\n"
63.415 + + " 'invoke' : function() {\n"
63.416 + + " if (pending.length === 0) {\n"
63.417 + + " invokeMethod(vm, name, arguments);\n"
63.418 + + " return;\n"
63.419 + + " }\n"
63.420 + + " pendingClasses.push(vm);\n"
63.421 + + " pendingClasses.push(name);\n"
63.422 + + " pendingClasses.push(arguments);\n"
63.423 + + " }\n"
63.424 + + " };\n"
63.425 + + " }\n"
63.426 + " return loader;\n"
63.427 + " };\n");
63.428 append(
63.429 - " global.bck2brwsr.registerExtension = function(extension) {\n"
63.430 + " global.bck2brwsr.register = function(config, extension) {\n"
63.431 + + " if (!config || config['magic'] !== 'kafíčko') {\n"
63.432 + + " console.log('Will not register: ' + extension);\n"
63.433 + + " return false;\n"
63.434 + + " }\n"
63.435 + " extensions.push(extension);\n"
63.436 + + " var cp = config['classpath'];\n"
63.437 + + " if (cp) for (var i = 0; i < cp.length; i++) {\n"
63.438 + + " loadExtension(cp[i]);\n"
63.439 + + " }\n"
63.440 + " return null;\n"
63.441 + " };\n");
63.442 append("}(this));");
63.443 @@ -601,17 +685,39 @@
63.444
63.445 private static final class Extension extends VM {
63.446 private final StringArray extensionClasses;
63.447 + private final StringArray classpath;
63.448
63.449 private Extension(Appendable out, Bck2Brwsr.Resources resources,
63.450 - String[] extClassesArray, StringArray explicitlyExported) {
63.451 - super(out, resources, explicitlyExported);
63.452 + String[] extClassesArray, StringArray explicitlyExported,
63.453 + StringArray asBinary, StringArray classpath
63.454 + ) {
63.455 + super(out, resources, explicitlyExported, asBinary);
63.456 this.extensionClasses = StringArray.asList(extClassesArray);
63.457 + this.classpath = classpath;
63.458 }
63.459
63.460 @Override
63.461 protected void generatePrologue() throws IOException {
63.462 - append("bck2brwsr.registerExtension(function(exports) {\n"
63.463 - + " var vm = {};\n");
63.464 + append(
63.465 + "bck2brwsr.register({\n"
63.466 + + " 'magic' : 'kafíčko'"
63.467 + );
63.468 + if (classpath != null && classpath.toArray().length > 0) {
63.469 + append(
63.470 + ",\n 'classpath' : [\n"
63.471 + );
63.472 + String sep = " ";
63.473 + for (String s : classpath.toArray()) {
63.474 + append(sep).append("'").append(s).append("'");
63.475 + sep = ",\n ";
63.476 + }
63.477 + append(
63.478 + "\n ]"
63.479 + );
63.480 + }
63.481 + append(
63.482 + "\n}, function(exports) {\n"
63.483 + + " var vm = {};\n");
63.484 append(" function link(n) {\n"
63.485 + " return function() {\n"
63.486 + " var cls = n['replace__Ljava_lang_String_2CC']"
64.1 --- a/rt/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java Thu May 15 11:38:27 2014 +0200
64.2 +++ b/rt/vm/src/main/java/org/apidesign/vm4brwsr/VMLazy.java Mon Jun 09 15:57:14 2014 +0200
64.3 @@ -20,6 +20,7 @@
64.4 import java.io.ByteArrayInputStream;
64.5 import java.io.IOException;
64.6 import java.io.InputStream;
64.7 +import org.apidesign.bck2brwsr.core.Exported;
64.8 import org.apidesign.bck2brwsr.core.JavaScriptBody;
64.9
64.10 /**
64.11 @@ -27,35 +28,31 @@
64.12 * @author Jaroslav Tulach <jtulach@netbeans.org>
64.13 */
64.14 final class VMLazy {
64.15 - private final Object loader;
64.16 + private final Object vm;
64.17 private final Object[] args;
64.18
64.19 - private VMLazy(Object loader, Object[] args) {
64.20 - this.loader = loader;
64.21 + private VMLazy(Object vm, Object[] args) {
64.22 + this.vm = vm;
64.23 this.args = args;
64.24 }
64.25
64.26 static void init() {
64.27 }
64.28
64.29 - static Object load(Object loader, String name, Object[] arguments)
64.30 + @Exported
64.31 + static Object load(Object loader, String name, Object[] arguments, byte[] arr)
64.32 throws IOException, ClassNotFoundException {
64.33 - return new VMLazy(loader, arguments).load(name, false);
64.34 + if (arr == null) {
64.35 + throw new ClassNotFoundException(name);
64.36 + }
64.37 + return new VMLazy(loader, arguments).defineClass(arr, name, false);
64.38 }
64.39
64.40 - static Object reload(Object loader, String name, Object[] arguments, byte[] arr)
64.41 - throws IOException, ClassNotFoundException {
64.42 - return new VMLazy(loader, arguments).defineClass(arr, name, false);
64.43 - }
64.44 -
64.45 - static byte[] loadBytes(Object loader, String name, Object[] arguments, int skip) throws Exception {
64.46 - return ClassPath.loadFromCp(arguments, name, skip);
64.47 - }
64.48 -
64.49 - private Object load(String name, boolean instance)
64.50 + @Exported
64.51 + Object load(String name, boolean instance)
64.52 throws IOException, ClassNotFoundException {
64.53 String res = name.replace('.', '/') + ".class";
64.54 - byte[] arr = ClassPath.loadFromCp(args, res, 0);
64.55 + byte[] arr = ClassPath.loadBytes(res, args, 0);
64.56 if (arr == null) {
64.57 throw new ClassNotFoundException(name);
64.58 }
64.59 @@ -65,33 +62,32 @@
64.60
64.61 private Object defineClass(byte[] arr, String name, boolean instance) throws IOException {
64.62 StringBuilder out = new StringBuilder(65535);
64.63 - out.append("var loader = arguments[0];\n");
64.64 - out.append("var vm = loader.vm;\n");
64.65 + out.append("var vm = arguments[0];\n");
64.66 int prelude = out.length();
64.67 String initCode = new Gen(this, out).compile(new ByteArrayInputStream(arr));
64.68 String code = out.toString().toString();
64.69 String under = name.replace('.', '_');
64.70 - Object fn = applyCode(loader, under, code, instance);
64.71 + Object fn = applyCode(vm, under, code, instance);
64.72
64.73 if (!initCode.isEmpty()) {
64.74 out.setLength(prelude);
64.75 out.append(initCode);
64.76 code = out.toString().toString();
64.77 - applyCode(loader, null, code, false);
64.78 + applyCode(vm, null, code, false);
64.79 }
64.80
64.81 return fn;
64.82 }
64.83
64.84 - @JavaScriptBody(args = {"loader", "name", "script", "instance" }, body =
64.85 + @JavaScriptBody(args = {"vm", "name", "script", "instance" }, body =
64.86 "try {\n" +
64.87 - " new Function(script)(loader, name);\n" +
64.88 + " new Function(script)(vm, name);\n" +
64.89 "} catch (ex) {\n" +
64.90 " throw 'Cannot compile ' + name + ' ' + ex + ' line: ' + ex.lineNumber + ' script:\\n' + script;\n" +
64.91 "}\n" +
64.92 "return name != null ? vm[name](instance) : null;\n"
64.93 )
64.94 - private static native Object applyCode(Object loader, String name, String script, boolean instance);
64.95 + private static native Object applyCode(Object vm, String name, String script, boolean instance);
64.96
64.97
64.98 private static final class Gen extends ByteCodeToJavaScript {
64.99 @@ -107,8 +103,7 @@
64.100 "var cls = n.replace__Ljava_lang_String_2CC('/','_').toString();"
64.101 + "\nvar dot = n.replace__Ljava_lang_String_2CC('/','.').toString();"
64.102 + "\nvar lazy = this._lazy();"
64.103 - + "\nvar loader = lazy._loader();"
64.104 - + "\nvar vm = loader.vm;"
64.105 + + "\nvar vm = lazy._vm();"
64.106 + "\nif (vm[cls]) return false;"
64.107 + "\nvm[cls] = function() {"
64.108 + "\n var instance = arguments.length == 0 || arguments[0] === true;"
64.109 @@ -126,7 +121,7 @@
64.110 resourcePath = "/" + resourcePath;
64.111 }
64.112 String code = readCode(resourcePath);
64.113 - applyCode(lazy.loader, null, code, false);
64.114 + applyCode(lazy.vm, null, code, false);
64.115 }
64.116
64.117 private String readCode(String resourcePath) throws IOException {
65.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
65.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementExternalInterfaceTest.java Mon Jun 09 15:57:14 2014 +0200
65.3 @@ -0,0 +1,58 @@
65.4 +/**
65.5 + * Back 2 Browser Bytecode Translator
65.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
65.7 + *
65.8 + * This program is free software: you can redistribute it and/or modify
65.9 + * it under the terms of the GNU General Public License as published by
65.10 + * the Free Software Foundation, version 2 of the License.
65.11 + *
65.12 + * This program is distributed in the hope that it will be useful,
65.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
65.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65.15 + * GNU General Public License for more details.
65.16 + *
65.17 + * You should have received a copy of the GNU General Public License
65.18 + * along with this program. Look for COPYING file in the top folder.
65.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
65.20 + */
65.21 +package org.apidesign.vm4brwsr;
65.22 +
65.23 +import javax.script.ScriptEngine;
65.24 +import org.testng.annotations.AfterClass;
65.25 +import org.testng.annotations.BeforeClass;
65.26 +import org.testng.annotations.Test;
65.27 +
65.28 +/** Tests whether private impl can implement public interface method
65.29 + * from another extension.
65.30 + *
65.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
65.32 + */
65.33 +public class ImplementExternalInterfaceTest {
65.34 + @Test public void checkHello() throws Exception {
65.35 + String exp = "Hello!";
65.36 +
65.37 + code.assertExec("Can extension implement class from another extension",
65.38 + ImplementFactory.class, "hello__Ljava_lang_String_2",
65.39 + exp
65.40 + );
65.41 + }
65.42 +
65.43 + private static TestVM code;
65.44 +
65.45 + @BeforeClass
65.46 + public static void compileTheCode() throws Exception {
65.47 + StringBuilder sb = new StringBuilder();
65.48 + ScriptEngine[] eng = { null };
65.49 + code = TestVM.compileClassAsExtension(sb, eng,
65.50 + "org/apidesign/vm4brwsr/extrnl/ImplementInterface", null, null
65.51 + );
65.52 + code = TestVM.compileClassesAsExtension(sb, eng, null, null,
65.53 + "org/apidesign/vm4brwsr/ImplementFactory",
65.54 + "org/apidesign/vm4brwsr/ImplementFactory$Impl"
65.55 + );
65.56 + }
65.57 + @AfterClass
65.58 + public static void releaseTheCode() {
65.59 + code = null;
65.60 + }
65.61 +}
66.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
66.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ImplementFactory.java Mon Jun 09 15:57:14 2014 +0200
66.3 @@ -0,0 +1,49 @@
66.4 +/**
66.5 + * Back 2 Browser Bytecode Translator
66.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
66.7 + *
66.8 + * This program is free software: you can redistribute it and/or modify
66.9 + * it under the terms of the GNU General Public License as published by
66.10 + * the Free Software Foundation, version 2 of the License.
66.11 + *
66.12 + * This program is distributed in the hope that it will be useful,
66.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
66.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66.15 + * GNU General Public License for more details.
66.16 + *
66.17 + * You should have received a copy of the GNU General Public License
66.18 + * along with this program. Look for COPYING file in the top folder.
66.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
66.20 + */
66.21 +package org.apidesign.vm4brwsr;
66.22 +
66.23 +import org.apidesign.vm4brwsr.extrnl.ImplementInterface;
66.24 +
66.25 +/**
66.26 + *
66.27 + * @author Jaroslav Tulach
66.28 + */
66.29 +public class ImplementFactory {
66.30 + private ImplementFactory() {
66.31 + }
66.32 +
66.33 + private static ImplementInterface create() {
66.34 + return new Impl();
66.35 + }
66.36 +
66.37 + public static String hello() {
66.38 + ImplementInterface i = create();
66.39 + return i.sayHello();
66.40 + }
66.41 +
66.42 + private static class Impl implements ImplementInterface {
66.43 +
66.44 + public Impl() {
66.45 + }
66.46 +
66.47 + @Override
66.48 + public String sayHello() {
66.49 + return "Hello!";
66.50 + }
66.51 + }
66.52 +}
67.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Thu May 15 11:38:27 2014 +0200
67.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/NumberTest.java Mon Jun 09 15:57:14 2014 +0200
67.3 @@ -216,6 +216,14 @@
67.4 false, 30
67.5 );
67.6 }
67.7 +
67.8 + @Test public void computeAround() throws Exception {
67.9 + double exp = Numbers.around(new Object(), 5, 8);
67.10 + assertExec("Computes the same value",
67.11 + Numbers.class, "around__ILjava_lang_Object_2II",
67.12 + exp, null, 5, 8
67.13 + );
67.14 + }
67.15
67.16 private static TestVM code;
67.17
68.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Thu May 15 11:38:27 2014 +0200
68.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/Numbers.java Mon Jun 09 15:57:14 2014 +0200
68.3 @@ -107,4 +107,19 @@
68.4
68.5 @JavaScriptBody(args = { "o" }, body = "return o.valueOf();")
68.6 private static native boolean bvalueOf(Object o);
68.7 +
68.8 + public static int around(Object model, int x, int y) {
68.9 + return minesAt(model, x - 1, y - 1)
68.10 + + minesAt(model, x - 1, y)
68.11 + + minesAt(model, x - 1, y + 1)
68.12 + + minesAt(model, x, y - 1)
68.13 + + minesAt(model, x, y + 1)
68.14 + + minesAt(model, x + 1, y - 1)
68.15 + + minesAt(model, x + 1, y)
68.16 + + minesAt(model, x + 1, y + 1);
68.17 + }
68.18 +
68.19 + private static int minesAt(Object model, int x, int y) {
68.20 + return x + y;
68.21 + }
68.22 }
69.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/Resources.java Thu May 15 11:38:27 2014 +0200
69.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/Resources.java Mon Jun 09 15:57:14 2014 +0200
69.3 @@ -21,12 +21,27 @@
69.4 import java.io.InputStream;
69.5 import java.net.URL;
69.6 import java.util.Enumeration;
69.7 +import net.java.html.js.JavaScriptBody;
69.8 +import net.java.html.js.JavaScriptResource;
69.9
69.10 /**
69.11 *
69.12 * @author Jaroslav Tulach <jtulach@netbeans.org>
69.13 */
69.14 +@JavaScriptResource("obj.js")
69.15 public class Resources {
69.16 + @JavaScriptBody(args = {}, body = "return obj;")
69.17 + static Object retObj() {
69.18 + return null;
69.19 + }
69.20 +
69.21 + public static boolean isObj() {
69.22 + return retObj() != null;
69.23 + }
69.24 + public static boolean isResource() {
69.25 + return Resources.class.getResource("obj.js") != null;
69.26 + }
69.27 +
69.28 public static String loadKO() throws IOException {
69.29 InputStream is = Resources.class.getResourceAsStream("ko.js");
69.30 return readIS(is, false);
70.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/ResourcesWithExtensionsTest.java Thu May 15 11:38:27 2014 +0200
70.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/ResourcesWithExtensionsTest.java Mon Jun 09 15:57:14 2014 +0200
70.3 @@ -45,6 +45,17 @@
70.4 exp
70.5 );
70.6 }
70.7 +
70.8 + @Test public void objJSResourceIsNotFound() throws Exception {
70.9 + assertExec("Objects from @JavaScriptResource resources are available",
70.10 + Resources.class, "isObj__Z", 1.0
70.11 + );
70.12 + }
70.13 + @Test public void objJSIsFound() throws Exception {
70.14 + assertExec("The resources used as @JavaScriptResource aren't available",
70.15 + Resources.class, "isResource__Z", 0.0
70.16 + );
70.17 + }
70.18
70.19 private static TestVM code;
70.20
71.1 --- a/rt/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java Thu May 15 11:38:27 2014 +0200
71.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/TestVM.java Mon Jun 09 15:57:14 2014 +0200
71.3 @@ -23,7 +23,12 @@
71.4 import java.io.IOException;
71.5 import java.io.InputStream;
71.6 import java.net.URL;
71.7 +import java.util.ArrayList;
71.8 +import java.util.Arrays;
71.9 import java.util.Enumeration;
71.10 +import java.util.HashSet;
71.11 +import java.util.List;
71.12 +import java.util.Set;
71.13 import javax.script.Invocable;
71.14 import javax.script.ScriptContext;
71.15 import javax.script.ScriptEngine;
71.16 @@ -60,7 +65,10 @@
71.17 Object ret = null;
71.18 try {
71.19 ret = code.invokeMethod(bck2brwsr, "loadClass", clazz.getName());
71.20 - ret = code.invokeMethod(ret, method, args);
71.21 + List<Object> ma = new ArrayList<>();
71.22 + ma.add(method);
71.23 + ma.addAll(Arrays.asList(args));
71.24 + ret = code.invokeMethod(ret, "invoke", ma.toArray());
71.25 } catch (ScriptException ex) {
71.26 fail("Execution failed in " + dumpJS(codeSeq) + ": " + ex.getMessage(), ex);
71.27 } catch (NoSuchMethodException ex) {
71.28 @@ -141,6 +149,12 @@
71.29 StringBuilder sb, ScriptEngine[] eng,
71.30 String name, final String resourceName, final String resourceContent
71.31 ) throws ScriptException, IOException {
71.32 + return compileClassesAsExtension(sb, eng, resourceName, resourceContent, name);
71.33 + }
71.34 + static TestVM compileClassesAsExtension(
71.35 + StringBuilder sb, ScriptEngine[] eng,
71.36 + final String resourceName, final String resourceContent, String... names
71.37 + ) throws ScriptException, IOException {
71.38 if (sb == null) {
71.39 sb = new StringBuilder();
71.40 }
71.41 @@ -150,6 +164,11 @@
71.42 eng[0] = js;
71.43 Bck2Brwsr.generate(sb, new EmulationResources());
71.44 }
71.45 + Set<String> exp = new HashSet<String>();
71.46 + for (String n : names) {
71.47 + int last = n.lastIndexOf('/');
71.48 + exp.add(n.substring(0, last + 1));
71.49 + }
71.50 Bck2Brwsr b2b = Bck2Brwsr.newCompiler().
71.51 resources(new EmulationResources() {
71.52 @Override
71.53 @@ -160,9 +179,11 @@
71.54 return super.get(name);
71.55 }
71.56 }).
71.57 - addRootClasses(name).
71.58 + addClasses(names).
71.59 + addResources("org/apidesign/vm4brwsr/obj.js").
71.60 + addExported(exp.toArray(new String[0])).
71.61 obfuscation(ObfuscationLevel.FULL).
71.62 - library(true);
71.63 + library();
71.64 if (resourceName != null) {
71.65 b2b = b2b.addResources(resourceName);
71.66 }
71.67 @@ -188,8 +209,7 @@
71.68 Bck2Brwsr b2b = Bck2Brwsr.newCompiler().
71.69 resources(new EmulationResources()).
71.70 addRootClasses(name).
71.71 - addResources(resources).
71.72 - library(false);
71.73 + addResources(resources);
71.74 b2b.generate(sb);
71.75 ScriptEngineManager sem = new ScriptEngineManager();
71.76 ScriptEngine js = sem.getEngineByExtension("js");
72.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
72.2 +++ b/rt/vm/src/test/java/org/apidesign/vm4brwsr/extrnl/ImplementInterface.java Mon Jun 09 15:57:14 2014 +0200
72.3 @@ -0,0 +1,26 @@
72.4 +/**
72.5 + * Back 2 Browser Bytecode Translator
72.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
72.7 + *
72.8 + * This program is free software: you can redistribute it and/or modify
72.9 + * it under the terms of the GNU General Public License as published by
72.10 + * the Free Software Foundation, version 2 of the License.
72.11 + *
72.12 + * This program is distributed in the hope that it will be useful,
72.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
72.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72.15 + * GNU General Public License for more details.
72.16 + *
72.17 + * You should have received a copy of the GNU General Public License
72.18 + * along with this program. Look for COPYING file in the top folder.
72.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
72.20 + */
72.21 +package org.apidesign.vm4brwsr.extrnl;
72.22 +
72.23 +/**
72.24 + *
72.25 + * @author Jaroslav Tulach
72.26 + */
72.27 +public interface ImplementInterface {
72.28 + public String sayHello();
72.29 +}
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
73.2 +++ b/rt/vm/src/test/resources/org/apidesign/vm4brwsr/obj.js Mon Jun 09 15:57:14 2014 +0200
73.3 @@ -0,0 +1,20 @@
73.4 +/*
73.5 + * Back 2 Browser Bytecode Translator
73.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
73.7 + *
73.8 + * This program is free software: you can redistribute it and/or modify
73.9 + * it under the terms of the GNU General Public License as published by
73.10 + * the Free Software Foundation, version 2 of the License.
73.11 + *
73.12 + * This program is distributed in the hope that it will be useful,
73.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
73.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73.15 + * GNU General Public License for more details.
73.16 + *
73.17 + * You should have received a copy of the GNU General Public License
73.18 + * along with this program. Look for COPYING file in the top folder.
73.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
73.20 + */
73.21 +var obj = {};
73.22 +
73.23 +