# HG changeset patch # User Jaroslav Tulach # Date 1461297407 -7200 # Node ID a0f15cb8c73074efb6e4ae828ff5a2a0fc42f800 # Parent 0e2b05057c97921b543ef47a9cd09d2ef8fd8f44 Switching to newer version of the libraries diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-android/nbactions.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-android/nbactions.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,67 @@ + + + + + run + + clean + package + android:deploy + android:run + + + true + + + + debug + + clean + package + android:deploy + android:run + + + true + ${jpda.attach.port} + true + + + + CUSTOM-android-run + Run in Android + + clean + package + android:deploy + android:run + + + true + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-android/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-android/pom.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,204 @@ + + + 4.0.0 + + + org.apidesign.demo + chat-pom + 1.0-SNAPSHOT + + + org.apidesign.demo + chat-android + 1.0-SNAPSHOT + apk + + chat Client for Android + + + 4.1.1.4 + 4.2.0 + 19 + false + + + + + org.netbeans.html + html4j-maven-plugin + ${net.java.html.version} + + + js-classes + + process-js-annotations + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + org.apache.maven.plugins + maven-dependency-plugin + 2.9 + + + unpack + process-resources + + unpack-dependencies + + + + + zip + webpages + true + target/generated-sources/combined-assets/pages + */** + + + + com.filmon.maven + image-maven-plugin + 1.1 + + + initialize + + scale + + + target/res + + + src/main/icons/launcher.png + drawable-hdpi/ic_launcher.png + 72 + + + src/main/icons/launcher.png + drawable-mdpi/ic_launcher.png + 48 + + + src/main/icons/launcher.png + drawable-xhdpi/ic_launcher.png + 96 + + + src/main/icons/launcher.png + drawable-xxhdpi/ic_launcher.png + 144 + + + + + + + + com.simpligility.maven.plugins + android-maven-plugin + ${android.plugin.version} + true + + ${debug} + target/res + + ${android.platform.version} + + + + services/org.netbeans.** + + + true + + + + apk + + apk + dex + + + + + + + + + org.apidesign.demo + chat + ${project.version} + + + org.netbeans.html + net.java.html.boot.fx + + + + + com.google.android + android + ${platform.version} + provided + + + com.dukescript.presenters + android + 0.9.1 + jar + + + org.netbeans.html + net.java.html.boot + + + org.netbeans.html + net.java.html.sound + + + + + org.netbeans.html + ko4j + ${net.java.html.version} + + + org.netbeans.html + net.java.html.boot + ${net.java.html.version} + + + org.netbeans.html + net.java.html.sound + ${net.java.html.version} + + + org.netbeans.html + ko-ws-tyrus + ${net.java.html.version} + + + org.json-osgi + de.twentyeleven.skysail + + + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-android/src/main/AndroidManifest.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-android/src/main/AndroidManifest.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-android/src/main/icons/launcher.png Binary file chat/client-android/src/main/icons/launcher.png has changed diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-android/src/main/java/org/apidesign/demo/chat/AndroidMain.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-android/src/main/java/org/apidesign/demo/chat/AndroidMain.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,33 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat; + +public class AndroidMain { + private AndroidMain() { + } + + public static void main(String... args) throws Exception { + ChatClient.onPageLoad(); + } +} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-ios/nbactions.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-ios/nbactions.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,93 @@ + + + + + run + + package + robovm:ipad-sim + + + true + + + + debug + + package + robovm:ipad-sim + + + true + clientmode + ${jpda.address} + true + + + + CUSTOM-ipad-sim + Run in iPad Simulator + + package + robovm:ipad-sim + + + true + + + + CUSTOM-iphone-sim + Run in iPhone Simulator + + package + robovm:iphone-sim + + + true + + + + CUSTOM-ios-device + Run on iOS Device + + package + robovm:ios-device + + + true + + + + CUSTOM-create-ipa + Create iOS Package Archive + + clean + package + robovm:create-ipa + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-ios/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-ios/pom.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,256 @@ + + + 4.0.0 + + + org.apidesign.demo + chat-pom + 1.0-SNAPSHOT + + + org.apidesign.demo + chat-ios + 1.0-SNAPSHOT + jar + + chat Client for iOS + + + org.apidesign.demo.chat.iOSMain + none + 1.6.0 + + + + + org.netbeans.html + html4j-maven-plugin + ${net.java.html.version} + + + js-classes + + process-js-annotations + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + org.apache.maven.plugins + maven-dependency-plugin + 2.9 + + + unpack + process-resources + + unpack-dependencies + + + + + zip + webpages + true + target/web/pages + */** + + + + com.filmon.maven + image-maven-plugin + 1.2.1 + + + + scale + crop + + + target/images + + + src/main/icons/launcher.png + Icon.png + 57 + + + src/main/icons/launcher.png + Icon@2.png + 114 + + + src/main/icons/launcher.png + Icon-60.png + 60 + + + src/main/icons/launcher.png + Icon-60@2.png + 120 + + + src/main/icons/launcher.png + Icon-72.png + 72 + + + src/main/icons/launcher.png + Icon-76.png + 76 + + + src/main/icons/launcher.png + Default@2x.png + 240 + 640 + 960 + white + + + src/main/icons/launcher.png + Default-568h@2x.png + 240 + 640 + 1136 + white + + + src/main/icons/launcher.png + Default.png + 120 + 320 + 480 + white + + + src/main/icons/launcher.png + Default@2x-Landscape.png + 240 + 960 + 640 + white + + + src/main/icons/launcher.png + Default-568h@2x-Landscape.png + 240 + 1136 + 640 + white + + + src/main/icons/launcher.png + Default-Landscape.png + 120 + 480 + 320 + white + + + + + + + + org.robovm + robovm-maven-plugin + ${robovm.version} + + + ${project.mainclass} + + java.util.logging.ConsoleHandler + java.util.logging.SimpleFormatter + + chat + + target/web/pages/ + + / + target/images/ + + *.png + + + + ios + + false + + + + + + + + org.apidesign.demo + chat + ${project.version} + + + org.netbeans.html + net.java.html.boot.fx + + + + + com.dukescript.presenters + ios + 0.9.1 + runtime + + + org.netbeans.html + net.java.html.geo + + + org.netbeans.html + net.java.html.boot + + + + + org.netbeans.html + net.java.html.geo + ${net.java.html.version} + runtime + + + org.robovm + robovm-cocoatouch + ${robovm.version} + jar + + + org.robovm + robovm-rt + ${robovm.version} + jar + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-ios/src/main/icons/launcher.png Binary file chat/client-ios/src/main/icons/launcher.png has changed diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-ios/src/main/java/org/apidesign/demo/chat/iOSMain.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-ios/src/main/java/org/apidesign/demo/chat/iOSMain.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,32 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat; + +final class iOSMain { + public static void main(String... args) throws Exception { + Main.main(args); + } +} + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-netbeans/nbactions.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-netbeans/nbactions.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,74 @@ + + + + + run + + package + nbm:cluster + nbm:run-platform + + + true + + + + debug + + package + nbm:cluster + nbm:run-platform + + + true + true + -J-Xdebug -J-Xrunjdwp:transport=dt_socket,suspend=n,server=n,address=${jpda.address} + true + + + + CUSTOM-nbrwsr-run + Run in NetBeans + + clean + package + nbm:cluster + nbm:run-ide + + + true + + + + CUSTOM-nbrwsr-nbm + Build NetBeans NBM file + + clean + install + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-netbeans/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-netbeans/pom.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,221 @@ + + + 4.0.0 + + + org.apidesign.demo + chat-pom + 1.0-SNAPSHOT + + + org.apidesign.demo + chat-nb + 1.0-SNAPSHOT + nbm-application + + chat Client for NetBeans + + + RELEASE81 + none + org.apidesign.demo.chat.NbMain + + + + netbeans + NetBeans + http://bits.netbeans.org/maven2/ + + + dev + NetBeans + http://bits.netbeans.org/nexus/content/repositories/snapshots/ + + true + + + + + + + org.netbeans.html + html4j-maven-plugin + ${net.java.html.version} + + + js-classes + + process-js-annotations + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + + default-compile + process-sources + + compile + + + + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + jar + + jar + + prepare-package + + + + + true + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.9 + + + unpack + generate-sources + + unpack + + + + + + + org.apidesign.demo + chat + ${project.version} + zip + webpages + true + ${project.build.directory}/classes/org/apidesign/demo/chat + + + + + + org.codehaus.mojo + nbm-maven-plugin + 3.14.1 + true + + + default-manifest + process-classes + + manifest + + + true + chat + chat + false + + + + default-nbm + package + + nbm + + + true + extra + false + + + + + true + netbeans + chat + false + ${project.build.directory} + + + + com.filmon.maven + image-maven-plugin + 1.1 + + + + scale + + + target/classes/org/apidesign/demo/chat + + + src/main/icons/launcher.png + icon.png + 16 + + + src/main/icons/launcher.png + icon24.png + 24 + + + + + + + + + + + org.apidesign.demo + chat + ${project.version} + + + org.netbeans.html + net.java.html.boot.fx + + + + + org.netbeans.html + net.java.html.boot + ${net.java.html.version} + + + org.netbeans.html + net.java.html.boot.fx + ${net.java.html.version} + runtime + + + org.netbeans.api + org-netbeans-api-htmlui + ${netbeans.version} + + + org.netbeans.cluster + platform + ${netbeans.version} + pom + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-netbeans/src/main/icons/launcher.png Binary file chat/client-netbeans/src/main/icons/launcher.png has changed diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-netbeans/src/main/java/org/apidesign/demo/chat/NbMain.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-netbeans/src/main/java/org/apidesign/demo/chat/NbMain.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,51 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat; + +import org.netbeans.api.htmlui.OpenHTMLRegistration; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; + +public class NbMain { + private NbMain() { + } + + @ActionID( + category = "Games", + id = "org.apidesign.demo.chat.OpenPage" + ) + @OpenHTMLRegistration( + url="index.html", + displayName = "Open Your Page", + iconBase = "org/apidesign/demo/chat/icon.png" + ) + @ActionReferences({ + @ActionReference(path = "Menu/Window"), + @ActionReference(path = "Toolbars/Games") + }) + public static void onPageLoad() throws Exception { + Main.onPageLoad(); + } +} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-web/nbactions.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-web/nbactions.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,76 @@ + + + + + run + + jar + + + package + bck2brwsr:show + + + true + + + + debug + + jar + + + package + bck2brwsr:show + + + true + NONE + maven + + + + CUSTOM-bck2brwsr-show + Run in a Browser + + package + bck2brwsr:show + + + true + NONE + + + + CUSTOM-bck2brwsr-web + Package for website + + clean + package + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-web/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-web/pom.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,189 @@ + + + 4.0.0 + + + org.apidesign.demo + chat-pom + 1.0-SNAPSHOT + + + org.apidesign.demo + chat-web + 1.0-SNAPSHOT + jar + + chat Client for Web + + + none + org.apidesign.demo.chat.BrowserMain + initialize bck2brwsr --> +<script type="text/javascript" src="bck2brwsr.js"></script> +<script> + var vm = bck2brwsr('chat.js'); + var c = vm.loadClass('org.apidesign.demo.chat.BrowserMain'); + c.invoke('main'); +</script> +<!-- end of initialization + + + + + org.netbeans.html + html4j-maven-plugin + ${net.java.html.version} + + + js-classes + + process-js-annotations + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + netbeans.ignore.jdk.bootclasspath + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + ${project.mainclass} + true + lib/ + false + + + + + + org.apidesign.bck2brwsr + bck2brwsr-maven-plugin + ${bck2brwsr.version} + + + + brwsr + aot + + + + + ${bck2brwsr.obfuscationlevel} + ${project.build.directory}/${project.build.finalName}-bck2brwsr/public_html/ + index.html + lib + ${project.build.directory}/chat.js + + ${project.mainclass} + + + + + maven-assembly-plugin + 2.4 + + + distro-assembly + package + + single + + + + src/main/assembly/bck2brwsr.xml + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.9 + + + unpack + process-resources + + unpack-dependencies + + + + + zip + webpages + true + target/web/pages + */** + + + + + + + org.apidesign.demo + chat + ${project.version} + + + org.netbeans.html + net.java.html.boot.fx + + + + + org.apidesign.bck2brwsr + emul + ${bck2brwsr.version} + rt + + + org.netbeans.html + net.java.html.boot + ${net.java.html.version} + + + asm + org.ow2.asm + + + + + org.apidesign.bck2brwsr + emul + ${bck2brwsr.version} + bck2brwsr + provided + + + org.apidesign.demo + chat-js + ${project.version} + bck2brwsr + provided + jar + + + org.apidesign.bck2brwsr + ko-bck2brwsr + ${bck2brwsr.version} + bck2brwsr + provided + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-web/src/main/assembly/bck2brwsr.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-web/src/main/assembly/bck2brwsr.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,61 @@ + + + + + bck2brwsr + + zip + dir + + public_html + + + target/web/pages + / + + index.html + + + + target/web/pages + / + true + + index.html + + + + ${project.build.directory} + / + + *.js + lib/*.js + + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client-web/src/main/java/org/apidesign/demo/chat/BrowserMain.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client-web/src/main/java/org/apidesign/demo/chat/BrowserMain.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,33 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat; + +public class BrowserMain { + private BrowserMain() { + } + + public static void main(String... args) throws Exception { + Main.onPageLoad(); + } +} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/bck2brwsr-assembly.xml --- a/chat/client/bck2brwsr-assembly.xml Thu Aug 14 07:51:33 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ - - - - - bck2brwsr - - zip - - client - - - false - runtime - lib - - *:jar - *:rt - - - - false - provided - - *:js - - true - / - - - - - ${project.build.directory}/${project.build.finalName}.jar - / - - - ${project.build.directory}/classes/org/apidesign/html/chatserver/client/chat.html - / - index.html - - - - diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/nbactions.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client/nbactions.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,57 @@ + + + + + run + + process-classes + exec:exec + + + + debug + + process-classes + exec:exec + + + true + -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} + + + + CUSTOM-Build Desktop App + Build Desktop App + + clean + package + + + desktop + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/pom.xml --- a/chat/client/pom.xml Thu Aug 14 07:51:33 2014 +0200 +++ b/chat/client/pom.xml Fri Apr 22 05:56:47 2016 +0200 @@ -1,135 +1,220 @@ - - + + 4.0.0 + - chat-demo - org.apidesign.html - 1.0-SNAPSHOT + org.apidesign.demo + chat-pom + 1.0-SNAPSHOT - org.apidesign.html.demo - chat-client + org.apidesign.demo + chat 1.0-SNAPSHOT - jar + bundle - Chat Client Bck2Brwsr - - - - java.net - Java.net - https://maven.java.net/content/repositories/releases/ - - - - - netbeans - NetBeans - http://bits.netbeans.org/maven2/ - - - - - java.net - Java.net - https://maven.java.net/content/repositories/releases/ - - - - + chat General Client Code - UTF-8 + all + org.apidesign.demo.chat.Main + ${java.home}/bin/java + -Ddebug=false - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - - - true - lib/ - - - - - - maven-assembly-plugin - 2.4 - - - distro-assembly - package - - single - - - - bck2brwsr-assembly.xml - - - - - + + org.apache.felix + maven-bundle-plugin + 2.4.0 + true + + + org.apidesign.demo.chat + org.apidesign.demo.chat + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + ${project.mainclass} + true + lib/ + false + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + ${exec.java.bin} + test + + -classpath + + -javaagent:${project.build.directory}/springloaded.jar + -noverify + -Dbrowser.rootdir=${basedir}/src/main/webapp/ + -Dnetbeans.inspect.port=${netbeans.inspect.port} + ${exec.debug.arg} + ${project.mainclass} + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.10 + + + copy + package + + copy + + + + + org.springframework + springloaded + 1.2.3.RELEASE + jar + false + springloaded.jar + + + ${project.build.directory} + + + + + + maven-assembly-plugin + 2.4 + + + web-pages + package + + single + + + + src/main/assembly/webpages.xml + + + + + - - org.netbeans.html - net.java.html.json - ${net.java.html.version} - jar + org.apidesign.demo + chat-js + ${project.version} - ${project.groupId} - chat-model - ${project.version} + org.apidesign.demo + chat-shared + ${project.version} + + + org.netbeans.html + net.java.html + ${net.java.html.version} + + + org.netbeans.html + net.java.html.json + ${net.java.html.version} + + + org.netbeans.html + net.java.html.boot + ${net.java.html.version} + + + org.netbeans.html + net.java.html.sound + ${net.java.html.version} + + + org.netbeans.html + ko4j + ${net.java.html.version} + runtime org.testng testng - 6.8 + test + + + org.netbeans.html + net.java.html.boot.script + ${net.java.html.version} test jar - org.apidesign.bck2brwsr - emul - ${bck2brwsr.version} - rt - runtime - - - org.apidesign.bck2brwsr - vm4brwsr - ${bck2brwsr.version} - zip - js + org.netbeans.html + net.java.html.boot.fx + ${net.java.html.version} provided - - org.apidesign.bck2brwsr - ko-bck2brwsr - ${bck2brwsr.version} - runtime - - - ko4j - org.netbeans.html - jar - ${net.java.html.version} - runtime - - - net.java.html.boot - org.netbeans.html - jar - ${net.java.html.version} - runtime - + + + desktop + + + org.netbeans.html + net.java.html.boot.fx + ${net.java.html.version} + runtime + + + + + + maven-assembly-plugin + 2.4 + + + distro-assembly + package + + single + + + + src/main/assembly/javafx.xml + + + + + + + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/src/main/assembly/javafx.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client/src/main/assembly/javafx.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,57 @@ + + + + + javafx + + zip + + ${project.build.finalName}-app + + + false + runtime + lib + + + + + ${project.build.directory}/${project.build.finalName}.jar + / + + + + + src/main/webapp/ + / + + pages/** + + + + \ No newline at end of file diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/src/main/assembly/webpages.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client/src/main/assembly/webpages.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,42 @@ + + + + + webpages + + zip + + / + + + src/main/webapp/pages + / + false + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/src/main/java/org/apidesign/demo/chat/ChatClient.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client/src/main/java/org/apidesign/demo/chat/ChatClient.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,107 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat; + +import net.java.html.json.ComputedProperty; +import net.java.html.json.Function; +import net.java.html.json.Model; +import net.java.html.json.OnReceive; +import net.java.html.json.Property; +import org.apidesign.demo.chat.shared.Message; +import org.apidesign.demo.chat.shared.Query; + +/** + * + * @author Jaroslav Tulach + */ +@Model(className = "ChatModel", targetId = "", properties = { + @Property(name = "user", type = String.class), + @Property(name = "comment", type = String.class), + @Property(name = "url", type = String.class), + @Property(name = "msgs", type = Message.class, array = true) +}) +class ChatClient { + @ComputedProperty + static boolean sendEnabled(String user, String comment) { + boolean res = user != null && comment != null && !user.isEmpty() && !comment.isEmpty(); + return res; + } + + @Function + static void submit(ChatModel m) { + if (!sendEnabled(m.getUser(), m.getComment())) { + return; + } + Message msg = new Message(); + msg.setUser(m.getUser()); + msg.setComment(m.getComment()); + m.postComment(m.getUrl(), msg); + } + + static void cantChat(ChatModel model, Exception err) { + model.getMsgs().add(new Message("System", err.getMessage(), 0)); + } + + + @OnReceive(url = "{url}/chat", method = "POST", data = Message.class, onError = "cantChat") + static void postComment(ChatModel m, Message addedMessage) { + if (addedMessage.getComment().equals(m.getComment())) { + m.setComment(""); + } + } + + @OnReceive(url = "{url}/chat?since=0") + static void initialRead(ChatModel m, Query q) { + m.getMsgs().clear(); + m.getMsgs().addAll(q.getMessages()); + moreMessages(m); + } + + @OnReceive(url = "{url}/chat?since={since}") + static void updateMsgs(ChatModel m, Query q) { + m.getMsgs().addAll(q.getMessages()); + moreMessages(m); + } + + private static void moreMessages(ChatModel m) { + long now = 0; + for (Message msg : m.getMsgs()) { + if (now < msg.getSince()) { + now = msg.getSince(); + } + } + m.updateMsgs(m.getUrl(), "" + (now + 1)); + } + + public static void onPageLoad() { + ChatModel chm = new ChatModel(); + chm.setUrl("http://localhost:8080"); + Message m = new Message(); + m.setComment("Waiting for messages from the server..."); + m.setUser("system"); + chm.getMsgs().add(m); + chm.applyBindings(); + chm.initialRead(chm.getUrl()); + } +} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/src/main/java/org/apidesign/demo/chat/Main.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client/src/main/java/org/apidesign/demo/chat/Main.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,48 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat; + +import net.java.html.boot.BrowserBuilder; + +public final class Main { + private Main() { + } + + public static void main(String... args) throws Exception { + BrowserBuilder.newBrowser(). + loadPage("pages/index.html"). + loadClass(Main.class). + invoke("onPageLoad", args). + showAndWait(); + System.exit(0); + } + + /** + * Called when the page is ready. + */ + public static void onPageLoad() throws Exception { + ChatClient.onPageLoad(); + } + +} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/src/main/java/org/apidesign/html/chatserver/client/ChatClient.java --- a/chat/client/src/main/java/org/apidesign/html/chatserver/client/ChatClient.java Thu Aug 14 07:51:33 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,90 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (C) 2013 Jaroslav Tulach - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.apidesign.html.chatserver.client; - -import net.java.html.json.ComputedProperty; -import net.java.html.json.Function; -import net.java.html.json.Model; -import net.java.html.json.OnReceive; -import net.java.html.json.Property; -import org.apidesign.html.chatserver.model.Message; -import org.apidesign.html.chatserver.model.Query; - -/** - * - * @author Jaroslav Tulach - */ -@Model(className = "ChatModel", properties = { - @Property(name = "user", type = String.class), - @Property(name = "comment", type = String.class), - @Property(name = "msgs", type = Message.class, array = true) -}) -class ChatClient { - @ComputedProperty - static boolean sendEnabled(String user, String comment) { - boolean res = user != null && comment != null && !user.isEmpty() && !comment.isEmpty(); - return res; - } - - @Function - static void submit(ChatModel m) { - if (!sendEnabled(m.getUser(), m.getComment())) { - return; - } - Message msg = new Message(); - msg.setUser(m.getUser()); - msg.setComment(m.getComment()); - m.postComment(msg); - } - - @OnReceive(url = "/chat", method = "POST", data = Message.class) - static void postComment(ChatModel m, Message addedMessage) { - if (addedMessage.getComment().equals(m.getComment())) { - m.setComment(""); - } - } - - @OnReceive(url = "/chat?since=0") - static void initialRead(ChatModel m, Query q) { - m.getMsgs().clear(); - m.getMsgs().addAll(q.getMessages()); - moreMessages(m); - } - - @OnReceive(url = "/chat?since={since}") - static void updateMsgs(ChatModel m, Query q) { - m.getMsgs().addAll(q.getMessages()); - moreMessages(m); - } - - private static void moreMessages(ChatModel m) { - long now = 0; - for (Message msg : m.getMsgs()) { - if (now < msg.getSince()) { - now = msg.getSince(); - } - } - m.updateMsgs("" + (now + 1)); - } -} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/src/main/java/org/apidesign/html/chatserver/client/Main.java --- a/chat/client/src/main/java/org/apidesign/html/chatserver/client/Main.java Thu Aug 14 07:51:33 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (C) 2013 Jaroslav Tulach - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.apidesign.html.chatserver.client; - -import org.apidesign.html.chatserver.model.Message; - -/** - * - * @author Jaroslav Tulach - */ -public class Main { - private Main() { - } - - static { - ChatModel chm = new ChatModel(); - Message m = new Message(); - m.setComment("Waiting for messages from the server..."); - m.setUser("system"); - chm.getMsgs().add(m); - chm.applyBindings(); - chm.initialRead(); - } -} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/src/main/resources/org/apidesign/html/chatserver/client/chat.html --- a/chat/client/src/main/resources/org/apidesign/html/chatserver/client/chat.html Thu Aug 14 07:51:33 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ - - - - - Chat via Jersey Server - - - -
Username:
- -
Message:
- - - -
    -
  • - @ - : - -
  • -
- - - - - - diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/src/main/webapp/pages/index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client/src/main/webapp/pages/index.html Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,49 @@ + + + + + Chat via Jersey Server + + + +
Username:
+ +
Message:
+ + + +
    +
  • + @ + : + +
  • +
+ + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/src/test/java/org/apidesign/demo/chat/ChatClientTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/client/src/test/java/org/apidesign/demo/chat/ChatClientTest.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,50 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat; + +import static org.testng.Assert.*; +import org.testng.annotations.Test; + +/** + * + * @author Jaroslav Tulach + */ +public class ChatClientTest { + public ChatClientTest() { + } + + @Test public void hasSendEnabled() { + ChatModel m = new ChatModel(); + assertFalse(m.isSendEnabled(), "By default disabled"); + m.setComment("some msg"); + m.setUser("by me"); + assertTrue(m.isSendEnabled(), "Now it is enabled"); + m.setUser(null); + assertFalse(m.isSendEnabled(), "No user means disabled"); + m.setUser("by him"); + assertTrue(m.isSendEnabled(), "Again enabled"); + m.setComment(""); + assertFalse(m.isSendEnabled(), "Empty text means disabled"); + } +} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/client/src/test/java/org/apidesign/html/chatserver/client/ChatClientTest.java --- a/chat/client/src/test/java/org/apidesign/html/chatserver/client/ChatClientTest.java Thu Aug 14 07:51:33 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (C) 2013 Jaroslav Tulach - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.apidesign.html.chatserver.client; - -import static org.testng.Assert.*; -import org.testng.annotations.Test; - -/** - * - * @author Jaroslav Tulach - */ -public class ChatClientTest { - public ChatClientTest() { - } - - @Test public void hasSendEnabled() { - ChatModel m = new ChatModel(); - assertFalse(m.isSendEnabled(), "By default disabled"); - m.setComment("some msg"); - m.setUser("by me"); - assertTrue(m.isSendEnabled(), "Now it is enabled"); - m.setUser(null); - assertFalse(m.isSendEnabled(), "No user means disabled"); - m.setUser("by him"); - assertTrue(m.isSendEnabled(), "Again enabled"); - m.setComment(""); - assertFalse(m.isSendEnabled(), "Empty text means disabled"); - } -} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/js/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/js/pom.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,92 @@ + + + 4.0.0 + + org.apidesign.demo + chat-pom + 1.0-SNAPSHOT + + + org.apidesign.demo + chat-js + 1.0-SNAPSHOT + bundle + + chat JavaScript Libraries + + + none + + + + + org.apache.felix + maven-bundle-plugin + 2.4.0 + true + + + org.apidesign.demo.chat.js + org.apidesign.demo.chat.js + + + + + org.netbeans.html + html4j-maven-plugin + ${net.java.html.version} + + + js-classes + + process-js-annotations + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + org.apidesign.bck2brwsr + bck2brwsr-maven-plugin + 0.16 + + + + library + + + + + NONE + + + + + + + org.netbeans.html + net.java.html.boot + ${net.java.html.version} + + + org.testng + testng + test + + + org.netbeans.html + net.java.html.boot.script + ${net.java.html.version} + test + jar + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/js/src/main/java/org/apidesign/demo/chat/js/Dialogs.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/js/src/main/java/org/apidesign/demo/chat/js/Dialogs.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,45 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat.js; + +public final class Dialogs { + private Dialogs() { + } + + /** Shows confirmation dialog to the user. + * + * @param msg the message + * @param callback called back when the use accepts (can be null) + * @return true or false + */ + @net.java.html.js.JavaScriptBody( + args = { "msg", "callback" }, + javacall = true, + body = + "var ret = confirm(msg);" + + "if (ret && callback) callback.@java.lang.Runnable::run()();" + + "return ret;" + ) + public static native boolean confirm(String msg, Runnable callback); +} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/js/src/test/java/org/apidesign/demo/chat/js/JsInteractionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/js/src/test/java/org/apidesign/demo/chat/js/JsInteractionTest.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,64 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat.js; + +import java.io.Closeable; +import net.java.html.boot.script.Scripts; +import org.netbeans.html.boot.spi.Fn; +import static org.testng.Assert.assertEquals; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** Tests for behavior of @JavaScriptBody methods. Set your JavaScript + * environment up (for example define alert or use some + * emulation library like env.js), register script presenter + * and then you can call methods that deal with JavaScript in your tests. + */ +public class JsInteractionTest { + private Closeable jsEngine; + @BeforeMethod public void initializeJSEngine() throws Exception { + jsEngine = Fn.activate(Scripts.createPresenter()); + } + + @AfterMethod public void shutdownJSEngine() throws Exception { + jsEngine.close(); + } + + @Test public void testCallbackFromJavaScript() throws Exception { + class R implements Runnable { + int called; + + @Override + public void run() { + called++; + } + } + R callback = new R(); + + Dialogs.confirm("Hello", callback); + + assertEquals(callback.called, 1, "One immediate callback"); + } + } diff -r 0e2b05057c97 -r a0f15cb8c730 chat/model/pom.xml --- a/chat/model/pom.xml Thu Aug 14 07:51:33 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ - - - 4.0.0 - - org.apidesign.html - chat-demo - 1.0-SNAPSHOT - - org.apidesign.html.demo - chat-model - 1.0-SNAPSHOT - Shared Model of a Message - http://maven.apache.org - - UTF-8 - - - - org.netbeans.html - net.java.html.json - ${net.java.html.version} - jar - - - org.testng - testng - 6.5.2 - test - - - diff -r 0e2b05057c97 -r a0f15cb8c730 chat/model/src/main/java/org/apidesign/html/chatserver/model/MessageImpl.java --- a/chat/model/src/main/java/org/apidesign/html/chatserver/model/MessageImpl.java Thu Aug 14 07:51:33 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (C) 2013 Jaroslav Tulach - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.apidesign.html.chatserver.model; - -import net.java.html.json.ComputedProperty; -import net.java.html.json.Model; -import net.java.html.json.Property; - -/** Generic model of communication between browser and a chat server. - * The same code is then used on the server, on the client and even in unit - * tests. - * - * @author Jaroslav Tulach - */ -@Model(className = "Message", properties = { - @Property(name = "user", type = String.class), - @Property(name = "comment", type = String.class), - @Property(name = "since", type = long.class) -}) -class MessageImpl { - @ComputedProperty static String at(long since) { - long delta = since / 1000; - if (delta <= 0) { - return "Boot-time"; - } - if (delta < 60) { - return delta + "s"; - } - delta /= 60; - return delta + "min"; - } - - @Model(className = "Query", properties = { - @Property(name = "messages", type = Message.class, array = true) - }) - class QryMsgs { - } -} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/model/src/test/java/org/apidesign/html/chatserver/model/MessageImplTest.java --- a/chat/model/src/test/java/org/apidesign/html/chatserver/model/MessageImplTest.java Thu Aug 14 07:51:33 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (C) 2013 Jaroslav Tulach - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.apidesign.html.chatserver.model; - -import static org.testng.Assert.*; -import org.testng.annotations.Test; - -/** - * - * @author Jaroslav Tulach - */ -public class MessageImplTest { - - @Test public void properlyConvertedToSeconds() { - Message msg = new Message(); - msg.setSince(5143); - assertEquals(msg.getAt(), "5s"); - } - @Test public void properlyConvertedToMinutes() { - Message msg = new Message(); - msg.setSince(63564); - assertEquals(msg.getAt(), "1min"); - } -} \ No newline at end of file diff -r 0e2b05057c97 -r a0f15cb8c730 chat/pom.xml --- a/chat/pom.xml Thu Aug 14 07:51:33 2014 +0200 +++ b/chat/pom.xml Fri Apr 22 05:56:47 2016 +0200 @@ -1,38 +1,68 @@ - - - 4.0.0 + + + 4.0.0 + + org.apidesign.demo + chat-pom + 1.0-SNAPSHOT - demo - org.apidesign.html - 1.0-SNAPSHOT + demo + org.apidesign.html + 1.0-SNAPSHOT - org.apidesign.html - chat-demo - 1.0-SNAPSHOT pom - Chat Server with Jersey and Bck2Brwsr - - UTF-8 - MINIMAL - - - model - client - server - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.7 - 1.7 - - - - - - \ No newline at end of file + + chat + + + shared + client + client-web + client-android + client-ios + server + js + + + 1.3 + 0.16 + FULL + 2.13 + UTF-8 + + + + + org.testng + testng + test + 6.8.8 + + + + + + + + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/server/nbactions.xml --- a/chat/server/nbactions.xml Thu Aug 14 07:51:33 2014 +0200 +++ b/chat/server/nbactions.xml Fri Apr 22 05:56:47 2016 +0200 @@ -32,4 +32,14 @@ exec:java + + debug + + process-classes + exec:java + + + maven + + diff -r 0e2b05057c97 -r a0f15cb8c730 chat/server/pom.xml --- a/chat/server/pom.xml Thu Aug 14 07:51:33 2014 +0200 +++ b/chat/server/pom.xml Fri Apr 22 05:56:47 2016 +0200 @@ -1,130 +1,99 @@ - - - 4.0.0 - - org.apidesign.html - chat-demo - 1.0-SNAPSHOT - - org.apidesign.html.demo - chat-server - 1.0-SNAPSHOT - Chat Server Using @Model - http://maven.apache.org - - + + + 4.0.0 + + org.apidesign.demo + chat-pom + 1.0-SNAPSHOT + + chat-server + jar + chat Jersey based Server + + 1.7 + 1.7 + + + + org.netbeans.html + net.java.html.json + ${net.java.html.version} + jar + + + org.glassfish.jersey.media + html-json + ${jersey.version} + runtime + + + + org.netbeans.html + net.java.html.json + + + org.netbeans.html + ko-ws-tyrus + + + + + org.testng + testng + test + + + org.glassfish.jersey.connectors + jersey-grizzly-connector + ${jersey.version} + + + org.glassfish.jersey.containers + jersey-container-grizzly2-http + ${jersey.version} + jar + + + org.glassfish.jersey.core + jersey-common + ${jersey.version} + runtime + + + ko-ws-tyrus + org.netbeans.html + jar + ${net.java.html.version} + runtime + + + + org.glassfish.grizzly + grizzly-framework + + + org.glassfish.grizzly + grizzly-http-server + + + + + org.apidesign.demo + chat-shared + ${project.version} + jar + + + + org.codehaus.mojo exec-maven-plugin 1.2.1 - org.apidesign.bck2brwsr.demo.chatserver.impl.Main + org.apidesign.demo.chat.server.Main - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.7 - 1.7 - - - - org.apache.maven.plugins - maven-dependency-plugin - 2.7 - - - process-resources - unpack-client-code - - unpack - - - - - org.apidesign.html.demo - chat-client - 1.0-SNAPSHOT - zip - bck2brwsr - - - ${project.build.directory}/classes/org/apidesign/bck2brwsr/demo/chatserver/impl/ - - - - - - - - - - org.netbeans.html - net.java.html.json - ${net.java.html.version} - jar - - - org.glassfish.jersey.media - html-json - 2.6 - runtime - - - org.testng - testng - 6.5.2 - test - - - org.glassfish.jersey.connectors - jersey-grizzly-connector - 2.4.1 - - - org.glassfish.jersey.containers - jersey-container-grizzly2-http - 2.6 - jar - - - org.glassfish.grizzly - grizzly-http-server - 2.3.8 - - - org.apidesign.html.demo - chat-model - 1.0-SNAPSHOT - jar - - - javax.ws.rs-api - javax.ws.rs - jar - 2.0 - - - org.glassfish.jersey.core - jersey-common - 2.6 - runtime - - - org.glassfish.grizzly - grizzly-framework - 2.3.8 - runtime - - - ko-ws-tyrus - org.netbeans.html - jar - ${net.java.html.version} - runtime - - - + + + + \ No newline at end of file diff -r 0e2b05057c97 -r a0f15cb8c730 chat/server/src/main/java/org/apidesign/bck2brwsr/demo/chatserver/impl/ChatServerResource.java --- a/chat/server/src/main/java/org/apidesign/bck2brwsr/demo/chatserver/impl/ChatServerResource.java Thu Aug 14 07:51:33 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (C) 2013 Jaroslav Tulach - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.apidesign.bck2brwsr.demo.chatserver.impl; - -import java.util.ArrayList; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Map; -import java.util.logging.Logger; -import javax.inject.Singleton; -import javax.ws.rs.Consumes; -import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.container.AsyncResponse; -import javax.ws.rs.container.Suspended; -import javax.ws.rs.core.MediaType; -import org.apidesign.html.chatserver.model.Message; -import org.apidesign.html.chatserver.model.Query; - -/** Server side of the chat application.*/ -@Path("/chat/") @Singleton -public final class ChatServerResource { - private static final Logger LOG = Logger.getLogger(ChatServerResource.class.getName()); - private static final long started = System.currentTimeMillis() - 10; - - private List msgs = new ArrayList<>(); - { - Message welcome = new Message(); - welcome.setUser("system"); - welcome.setComment("Welcome and enjoy!"); - welcome.setSince(10); - msgs.add(welcome); - } - - private final Map awaiting = new IdentityHashMap<>(); - - @Produces(MediaType.APPLICATION_JSON) - @GET public synchronized void getResources( - @QueryParam("since") @DefaultValue("0") long since, - @Suspended AsyncResponse ar - ) { - Query q = new Query(); - for (Message m : msgs) { - if (m.getSince()>= since) { - q.getMessages().add(m); - } - } - if (!q.getMessages().isEmpty()) { - ar.resume(q); - } else { - awaiting.put(ar, since); - } - } - - private void handleAwaiting(long newest) { - assert Thread.holdsLock(this); - AGAIN: for (;;) { - for (Map.Entry entry : awaiting.entrySet()) { - AsyncResponse ar = entry.getKey(); - Long since = entry.getValue(); - if (since <= newest) { - awaiting.remove(ar); - getResources(since, ar); - continue AGAIN; - } - } - return; - } - } - - @POST @Consumes(value = MediaType.APPLICATION_JSON) - public synchronized Message publish(Message msg) { - msg.setSince(System.currentTimeMillis() - started); - msgs.add(msg); - handleAwaiting(msg.getSince()); - return msg; - } -} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/server/src/main/java/org/apidesign/bck2brwsr/demo/chatserver/impl/ClientPagesResource.java --- a/chat/server/src/main/java/org/apidesign/bck2brwsr/demo/chatserver/impl/ClientPagesResource.java Thu Aug 14 07:51:33 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (C) 2013 Jaroslav Tulach - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.apidesign.bck2brwsr.demo.chatserver.impl; - -import java.io.InputStream; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; - -/** - * - * @author Jaroslav Tulach - */ -@Path("/") -public final class ClientPagesResource { - @GET public InputStream indexHtml() { - return clientData("index.html"); - } - - @GET @Path("{resource:.*}") - public InputStream clientData(@PathParam("resource") String res) { - return ClientPagesResource.class.getResourceAsStream("client/" + res); - } -} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/server/src/main/java/org/apidesign/bck2brwsr/demo/chatserver/impl/Main.java --- a/chat/server/src/main/java/org/apidesign/bck2brwsr/demo/chatserver/impl/Main.java Thu Aug 14 07:51:33 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,56 +0,0 @@ -/** - * The MIT License (MIT) - * - * Copyright (C) 2013 Jaroslav Tulach - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package org.apidesign.bck2brwsr.demo.chatserver.impl; - -import java.awt.Desktop; -import java.io.IOException; -import java.net.URI; -import org.glassfish.grizzly.http.server.HttpServer; -import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; -import org.glassfish.jersey.server.ResourceConfig; - -/** Starts chat server based on Jersey. - * - * @author Jaroslav Tulach - */ -final class Main { - public static void main(String... args) throws Exception { - ResourceConfig rc = new ResourceConfig( - ChatServerResource.class, ClientPagesResource.class - ); - URI u = new URI("http://localhost:8080/"); - HttpServer server = GrizzlyHttpServerFactory.createHttpServer(u, rc); - System.err.println("Server running at " + u); - try { - System.err.println("Launching browser"); - Desktop.getDesktop().browse(u); - } catch (IOException ex) { - System.err.println("Launching failed: " + ex.getMessage()); - } - System.err.println("Press Enter to shutdown the server"); - System.in.read(); - server.stop(); - } - -} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/server/src/main/java/org/apidesign/demo/chat/server/ChatServerResource.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/server/src/main/java/org/apidesign/demo/chat/server/ChatServerResource.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,103 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat.server; + +import java.util.ArrayList; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; +import javax.inject.Singleton; +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.container.AsyncResponse; +import javax.ws.rs.container.Suspended; +import javax.ws.rs.core.MediaType; +import org.apidesign.demo.chat.shared.Message; +import org.apidesign.demo.chat.shared.Query; + +/** Server side of the chat application.*/ +@Path("/chat/") @Singleton +public final class ChatServerResource { + private static final Logger LOG = Logger.getLogger(ChatServerResource.class.getName()); + private static final long started = System.currentTimeMillis() - 10; + + private List msgs = new ArrayList<>(); + { + Message welcome = new Message(); + welcome.setUser("system"); + welcome.setComment("Welcome and enjoy!"); + welcome.setSince(10); + msgs.add(welcome); + } + + private final Map awaiting = new IdentityHashMap<>(); + + @Produces(MediaType.APPLICATION_JSON) + @GET public synchronized void getResources( + @QueryParam("since") @DefaultValue("0") long since, + @Suspended AsyncResponse ar + ) { + Query q = new Query(); + for (Message m : msgs) { + if (m.getSince()>= since) { + q.getMessages().add(m); + } + } + if (!q.getMessages().isEmpty()) { + ar.resume(q); + } else { + awaiting.put(ar, since); + } + } + + private void handleAwaiting(long newest) { + assert Thread.holdsLock(this); + AGAIN: for (;;) { + for (Map.Entry entry : awaiting.entrySet()) { + AsyncResponse ar = entry.getKey(); + Long since = entry.getValue(); + if (since <= newest) { + awaiting.remove(ar); + getResources(since, ar); + continue AGAIN; + } + } + return; + } + } + + @POST @Consumes(value = MediaType.APPLICATION_JSON) + public synchronized Message publish(Message msg) { + msg.setSince(System.currentTimeMillis() - started); + msgs.add(msg); + handleAwaiting(msg.getSince()); + return msg; + } +} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/server/src/main/java/org/apidesign/demo/chat/server/Main.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/server/src/main/java/org/apidesign/demo/chat/server/Main.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,79 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat.server; + +import java.io.IOException; +import java.net.Inet4Address; +import java.net.InterfaceAddress; +import java.net.NetworkInterface; +import java.net.URI; +import java.util.Enumeration; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.container.ContainerResponseContext; +import javax.ws.rs.container.ContainerResponseFilter; +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; +import org.glassfish.jersey.server.ResourceConfig; + +/** Starts REST server based on Jersey. + */ +final class Main implements ContainerResponseFilter { + public static void main(String... args) throws Exception { + ResourceConfig rc = new ResourceConfig( + ChatServerResource.class, Main.class + ); + URI u = new URI("http://0.0.0.0:8080/"); + HttpServer server = GrizzlyHttpServerFactory.createHttpServer(u, rc); + System.err.println("Server running on following IP addresses:"); + dumpIPs(); + System.err.println("Press Enter to shutdown the server"); + System.in.read(); + server.stop(); + } + + @Override + public void filter( + ContainerRequestContext requestContext, + ContainerResponseContext r + ) throws IOException { + r.getHeaders().add("Access-Control-Allow-Origin", "*"); + r.getHeaders().add("Access-Control-Allow-Credentials", "true"); + r.getHeaders().add("Access-Control-Allow-Headers", "Content-Type"); + r.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); + } + + private static void dumpIPs() throws Exception { + Enumeration en = NetworkInterface.getNetworkInterfaces(); + while (en.hasMoreElements()) { + NetworkInterface n = en.nextElement(); + if (n.isUp()) { + for (InterfaceAddress i : n.getInterfaceAddresses()) { + if (i.getAddress() instanceof Inet4Address) { + System.err.println(n.getName() + ": " + i.getAddress()); + } + } + } + } + } +} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/shared/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/shared/pom.xml Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,45 @@ + + + 4.0.0 + + org.apidesign.demo + chat-pom + 1.0-SNAPSHOT + + chat-shared + bundle + chat Shared Client Server Data Structures + + + org.netbeans.html + net.java.html.json + ${net.java.html.version} + jar + + + org.testng + testng + test + + + + 1.7 + 1.7 + + + + + org.apache.felix + maven-bundle-plugin + 2.4.0 + true + + + org.apidesign.demo.chat.shared + org.apidesign.demo.chat.shared + + + + + + \ No newline at end of file diff -r 0e2b05057c97 -r a0f15cb8c730 chat/shared/src/main/java/org/apidesign/demo/chat/shared/MessageImpl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/shared/src/main/java/org/apidesign/demo/chat/shared/MessageImpl.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,59 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat.shared; + +import net.java.html.json.ComputedProperty; +import net.java.html.json.Model; +import net.java.html.json.Property; + +/** Generic model of communication between browser and a chat server. + * The same code is then used on the server, on the client and even in unit + * tests. + * + * @author Jaroslav Tulach + */ +@Model(className = "Message", properties = { + @Property(name = "user", type = String.class), + @Property(name = "comment", type = String.class), + @Property(name = "since", type = long.class) +}) +class MessageImpl { + @ComputedProperty static String at(long since) { + long delta = since / 1000; + if (delta <= 0) { + return "Boot-time"; + } + if (delta < 60) { + return delta + "s"; + } + delta /= 60; + return delta + "min"; + } + + @Model(className = "Query", properties = { + @Property(name = "messages", type = Message.class, array = true) + }) + class QryMsgs { + } +} diff -r 0e2b05057c97 -r a0f15cb8c730 chat/shared/src/test/java/org/apidesign/demo/chat/shared/MessageImplTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/chat/shared/src/test/java/org/apidesign/demo/chat/shared/MessageImplTest.java Fri Apr 22 05:56:47 2016 +0200 @@ -0,0 +1,45 @@ +/** + * The MIT License (MIT) + * + * Copyright (C) 2013 Jaroslav Tulach + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.apidesign.demo.chat.shared; + +import static org.testng.Assert.*; +import org.testng.annotations.Test; + +/** + * + * @author Jaroslav Tulach + */ +public class MessageImplTest { + + @Test public void properlyConvertedToSeconds() { + Message msg = new Message(); + msg.setSince(5143); + assertEquals(msg.getAt(), "5s"); + } + @Test public void properlyConvertedToMinutes() { + Message msg = new Message(); + msg.setSince(63564); + assertEquals(msg.getAt(), "1min"); + } +} \ No newline at end of file diff -r 0e2b05057c97 -r a0f15cb8c730 minesweeper/Info.plist.xml --- a/minesweeper/Info.plist.xml Thu Aug 14 07:51:33 2014 +0200 +++ b/minesweeper/Info.plist.xml Fri Apr 22 05:56:47 2016 +0200 @@ -1,4 +1,29 @@ + diff -r 0e2b05057c97 -r a0f15cb8c730 pom.xml --- a/pom.xml Thu Aug 14 07:51:33 2014 +0200 +++ b/pom.xml Fri Apr 22 05:56:47 2016 +0200 @@ -83,5 +83,14 @@ + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + +