From 45be16ec21af74c099c2d3abfdcc915da465b01e Mon Sep 17 00:00:00 2001 From: Colin Alworth Date: Thu, 17 Feb 2022 14:02:07 -0600 Subject: [PATCH] Add a simple maven archetype for a multi-module project with servlets (#114) This provides a working example of a good way to build a real project, with minimal configuration. There is a shared project which runs its own test, but is also included by both client and server, and a client test that confirms the behavior of the shared code. Fixes #66 --- j2cl-archetypes/README.md | 29 +-- .../j2cl-servlet-project/README.md | 14 ++ j2cl-archetypes/j2cl-servlet-project/pom.xml | 27 +++ .../META-INF/maven/archetype-metadata.xml | 65 ++++++ .../__rootArtifactId__-client/pom.xml | 106 ++++++++++ .../src/main/java/client/__module__.java | 40 ++++ .../src/main/java/client/__module__.native.js | 12 ++ .../test/java/sharedtest/SharedTypeTest.java | 17 ++ .../__rootArtifactId__-server/pom.xml | 104 ++++++++++ .../main/java/server/SimpleJsonServlet.java | 39 ++++ .../src/main/jettyconf/context.xml | 6 + .../src/main/webapp/css/__module__.css | 27 +++ .../src/main/webapp/index.html | 14 ++ .../__rootArtifactId__-shared/pom.xml | 20 ++ .../src/main/java/shared/SharedType.java | 10 + .../src/test/java/shared/SharedTypeTest.java | 14 ++ .../resources/archetype-resources/pom.xml | 190 ++++++++++++++++++ .../projects/test-app/archetype.properties | 5 + .../test/resources/projects/test-app/goal.txt | 1 + j2cl-archetypes/pom.xml | 7 + j2cl-archetypes/simple-project/README.md | 20 ++ .../resources/archetype-resources/pom.xml | 18 -- .../src/main/java/__module__.java | 2 +- .../src/main/webapp/css/__artifactId__.css | 32 +-- .../src/main/webapp/index.html | 4 +- .../app/pom.xml | 3 - .../it/dependency-replacements/app/pom.xml | 2 - .../src/it/elemental2-project/pom.xml | 2 - .../src/it/failing-htmlunit-test/pom.xml | 1 - .../src/it/hello-world-reactor/app/pom.xml | 2 - .../src/it/hello-world-single/pom.xml | 2 - .../src/it/hello-world-web-components/pom.xml | 2 - j2cl-maven-plugin/src/it/issue-41/pom.xml | 2 - .../src/it/java-assertions/pom.xml | 3 - .../src/it/simple-htmlunit-test/pom.xml | 2 - .../src/it/top-level-source-file/pom.xml | 2 - .../it/transitive-dependencies/app/pom.xml | 2 - 37 files changed, 768 insertions(+), 80 deletions(-) create mode 100644 j2cl-archetypes/j2cl-servlet-project/README.md create mode 100644 j2cl-archetypes/j2cl-servlet-project/pom.xml create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/META-INF/maven/archetype-metadata.xml create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/pom.xml create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/client/__module__.java create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/client/__module__.native.js create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/src/test/java/sharedtest/SharedTypeTest.java create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/pom.xml create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/java/server/SimpleJsonServlet.java create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/jettyconf/context.xml create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/webapp/css/__module__.css create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/webapp/index.html create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-shared/pom.xml create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-shared/src/main/java/shared/SharedType.java create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-shared/src/test/java/shared/SharedTypeTest.java create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/pom.xml create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/test/resources/projects/test-app/archetype.properties create mode 100644 j2cl-archetypes/j2cl-servlet-project/src/test/resources/projects/test-app/goal.txt create mode 100644 j2cl-archetypes/simple-project/README.md diff --git a/j2cl-archetypes/README.md b/j2cl-archetypes/README.md index bc1d52d7..28a2f297 100644 --- a/j2cl-archetypes/README.md +++ b/j2cl-archetypes/README.md @@ -31,21 +31,14 @@ mvn org.apache.maven.plugins:maven-dependency-plugin:get \ # `simple-project` -This project is a simple html page, with a css file, and a single Java class. It is not a good example -of how to set up a client/server project, but serves only to show how to make very simple standalone -samples. - -After creating this, you'll need two consoles to start it. First, run `mvn jetty:run` in one window - -you'll know it is working when it reports "Started Jetty Server". In the other console window, run -`mvn j2cl:watch`, and wait for `Build Complete: ready for browser refresh`. With both running, open -`http://localhost:8080/` in a browser to see the app. Refresh the page in the browser after editing -any source file (and seeing the "Build Complete" message in the j2cl:watch log). - -To deploy a sample to a servlet container, use `mvn verify` to build a war, then copy it from the -`target/` directory to the webapps directory of the servlet container. Alternatively, just run -`mvn jetty:run` without also running the watch command, the j2cl output will be replaced automatically -with JS compiled for production. - -To reiterate, this is _not_ a suggested way to develop a real project, but is only intended for a quick -sample to get the basic idea of how the plugin functions, and to quickly experiment with J2CL and the -Closure Compiler in Maven. +This project is a simple html page, with a css file, and a single Java class. It is _not_ a good +example of how to set up a client/server project, but serves only to show how to make very simple +standalone samples. + +# `j2cl-servlet-project` + +Creates two Java modules, one for the server, and one for the client. The server module uses Jakarta +servlets to host some http static content and offer some services, and the client module provides a +simple J2cl-based browser application that is served from, and connects to that server for more content. +The parent pom is configured to make it easy to add either shared or client-only modules to the project, +and still get a good debugging experience from the browser. \ No newline at end of file diff --git a/j2cl-archetypes/j2cl-servlet-project/README.md b/j2cl-archetypes/j2cl-servlet-project/README.md new file mode 100644 index 00000000..32a461cc --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/README.md @@ -0,0 +1,14 @@ +# `j2cl-servlet-project` + +Creates two Java modules, one for the server, and one for the client. The server module uses Jakarta +servlets to host some http static content and offer some services, and the client module provides a +simple J2cl-based browser application that is served from, and connects to that server for more content. +The parent pom is configured to make it easy to add either shared or client-only modules to the project, +and still get a good debugging experience from the browser. + +After creating this, you'll need two consoles to start it. First, run `mvn jetty:run -pl *-server -am -Denv=dev` +in one window - you'll know it is working when it reports "Started Jetty Server". In the other +console window, run `mvn j2cl:watch`, and wait for `Build Complete: ready for browser refresh`. With +both running, open `http://localhost:8080/` in a browser to see the app. Refresh the page in the +browser after editing any source file (and seeing the "Build Complete" message in the j2cl:watch log). + diff --git a/j2cl-archetypes/j2cl-servlet-project/pom.xml b/j2cl-archetypes/j2cl-servlet-project/pom.xml new file mode 100644 index 00000000..96b1c862 --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + com.vertispan.j2cl + j2cl-maven-archetypes + 0.19-SNAPSHOT + + j2cl-servlet-project + maven-archetype + + J2CL+Servlet Project + Example reactor project with Jakarta Servlets + + + + src/main/resources + true + + **/* + + + + + diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/META-INF/maven/archetype-metadata.xml b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 00000000..33ca604c --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,65 @@ + + + + + + + + + + src/main/java + + **/*.java + **/*.native.js + + + + src/test/java + + **/*.java + + + + + + + + src/main/java + + **/*.java + + + + src/test/java + + **/*.java + + + + + + + + src/main/java + + **/*.java + + + + src/main/webapp + + **/*.xml + **/*.html + **/*.css + + + + src/main/jettyconf + + **/*.xml + + + + + + diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/pom.xml b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/pom.xml new file mode 100644 index 00000000..ac7fd8b7 --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/pom.xml @@ -0,0 +1,106 @@ + + + 4.0.0 + + \${groupId} + \${rootArtifactId} + \${version} + + + \${artifactId} + war + + + + \${project.groupId} + \${rootArtifactId}-shared + \${project.version} + + + + com.google.elemental2 + elemental2-dom + + + com.google.elemental2 + elemental2-core + + + com.google.jsinterop + jsinterop-annotations + + + + + com.vertispan.j2cl + junit-annotations + \${j2cl.version} + test + + + + com.vertispan.j2cl + gwttestcase-emul + \${j2cl.version} + test + + + + com.vertispan.j2cl + gwttestcase-emul + \${j2cl.version} + sources + test + + + com.vertispan.j2cl + junit-emul + \${j2cl.version} + test + + + com.vertispan.j2cl + junit-emul + \${j2cl.version} + sources + test + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M4 + + true + + + + + com.vertispan.j2cl + j2cl-maven-plugin + + + + build + + + + js-tests + + test + + + + ADVANCED + + + + + + + \ No newline at end of file diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/client/__module__.java b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/client/__module__.java new file mode 100644 index 00000000..fa119b34 --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/client/__module__.java @@ -0,0 +1,40 @@ +package ${package}.client; + +import ${package}.shared.SharedType; + +import elemental2.dom.DomGlobal; +import elemental2.dom.HTMLButtonElement; +import elemental2.dom.HTMLDivElement; +import elemental2.dom.Response; +import elemental2.promise.Promise; +import jsinterop.base.Js; + +public class ${module} { + + public void onModuleLoad() { + HTMLDivElement wrapper = (HTMLDivElement) DomGlobal.document.createElement("div"); + wrapper.classList.add("wrapper"); + + HTMLButtonElement btn = (HTMLButtonElement) DomGlobal.document.createElement("button"); + btn.classList.add("myButton"); + btn.textContent = SharedType.sayHello("HTML"); + + btn.addEventListener("click", evt -> { + goGetData(btn); + }); + + wrapper.appendChild(btn); + + DomGlobal.document.body.appendChild(wrapper); + } + + private void goGetData(HTMLButtonElement button) { + DomGlobal.fetch("/hello.json?name=J2cl") + .then(Response::json) + .then(json -> { + String string = Js.asPropertyMap(json).getAsAny("response").asString(); + button.textContent = string; + return Promise.resolve(json); + }); + } +} diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/client/__module__.native.js b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/client/__module__.native.js new file mode 100644 index 00000000..88d8860d --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/src/main/java/client/__module__.native.js @@ -0,0 +1,12 @@ +// Defer this command, since this will be folded into the entrypoint js impl, +// and if it runs right away, will not have its dependencies resolved yet (at least while +// running in BUNDLE or BUNDLE_JAR). +setTimeout(function(){ + // Call the java "constructor" method, `new` will only work if it is a @JsType, or maybe + // once optimized. Without this, in BUNDLE mode, `new` doesn't include the clinit, so + // static imports haven't been resolved yet. + var ep = ${module}.$create__(); + // Invoke onModuleLoad to start the app. + ep.m_onModuleLoad__() +}, 0); + diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/src/test/java/sharedtest/SharedTypeTest.java b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/src/test/java/sharedtest/SharedTypeTest.java new file mode 100644 index 00000000..fd4c08f9 --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-client/src/test/java/sharedtest/SharedTypeTest.java @@ -0,0 +1,17 @@ +package ${package}.shared; + +import org.junit.Assert; +import org.junit.Test; +import com.google.j2cl.junit.apt.J2clTestInput; + + +/** + * Represents some type that could be shared between client and server. + */ +@J2clTestInput(SharedTypeTest.class) +public class SharedTypeTest { + @Test + public void sayHello() { + Assert.assertEquals("Hello, Foo!", SharedType.sayHello("Foo")); + } +} \ No newline at end of file diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/pom.xml b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/pom.xml new file mode 100644 index 00000000..53494150 --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/pom.xml @@ -0,0 +1,104 @@ + + + 4.0.0 + + \${groupId} + \${rootArtifactId} + \${version} + + + \${artifactId} + war + + + + + \${project.groupId} + \${rootArtifactId}-shared + \${project.version} + + + + javax.servlet + javax.servlet-api + provided + + + + + + + + org.eclipse.jetty + jetty-maven-plugin + + 1 + + \${project.basedir}/../\${rootArtifactId}-shared/target/classes/ + + \${project.basedir}/src/main/jettyconf/context.xml + + + + + + + + + env-prod + + true + + + + + \${project.groupId} + ${rootArtifactId}-client + \${project.version} + war + runtime + + + + + env-dev + + + env + dev + + + + + + + org.eclipse.jetty + jetty-maven-plugin + + + + + \${project.basedir}/src/main/webapp + + \${project.basedir}/../target/j2cl-watch + + + + + + + + + + diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/java/server/SimpleJsonServlet.java b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/java/server/SimpleJsonServlet.java new file mode 100644 index 00000000..3e3a54a0 --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/java/server/SimpleJsonServlet.java @@ -0,0 +1,39 @@ +package ${package}.server; + +import ${package}.shared.SharedType; + +import java.io.IOException; +import java.util.regex.Pattern; + +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.ServletOutputStream; + +/** + * A very simple servlet, avoiding any server libraries, with an overly-simple JSON + * encoding strategy. + */ +@WebServlet(name = "SimpleJsonServlet", urlPatterns = {"/hello.json"}) +public class SimpleJsonServlet extends HttpServlet { + private static final Pattern simpleAsciiChars = Pattern.compile("^[a-zA-Z0-9]*$"); + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws IOException { + String name = request.getParameter("name"); + if (!simpleAsciiChars.matcher(name).matches()) { + response.setStatus(HttpServletResponse.SC_BAD_REQUEST); + return; + } + String reply = SharedType.sayHello(name); + + response.setContentType("application/json;charset=UTF-8"); + + try (ServletOutputStream out = response.getOutputStream()) { + out.print("{\"response\":\"" + reply + "\"}"); + } + } + +} \ No newline at end of file diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/jettyconf/context.xml b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/jettyconf/context.xml new file mode 100644 index 00000000..3c395c74 --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/jettyconf/context.xml @@ -0,0 +1,6 @@ + + + org.eclipse.jetty.servlet.Default.useFileMappedBuffer + false + + \ No newline at end of file diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/webapp/css/__module__.css b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/webapp/css/__module__.css new file mode 100644 index 00000000..9894899f --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/webapp/css/__module__.css @@ -0,0 +1,27 @@ +body { + background-color: #e6ede8; +} + +.myButton { + position: absolute; + top: 50%; + background-color:#44c767; + border-radius:28px; + border:1px solid #18ab29; + display:inline-block; + cursor:pointer; + color:#ffffff; + font-family:Arial; + font-size:17px; + padding:16px 31px; + text-decoration:none; + text-shadow:0px 1px 0px #2f6627; +} + +.myButton:hover { + background-color:#5cbf2a; +} + +.wrapper { + text-align: center; +} diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/webapp/index.html b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/webapp/index.html new file mode 100644 index 00000000..efff8b4d --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-server/src/main/webapp/index.html @@ -0,0 +1,14 @@ + + + + J2CL Sample Project '\${module}' + + + + + + + + + + diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-shared/pom.xml b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-shared/pom.xml new file mode 100644 index 00000000..4df29e9a --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-shared/pom.xml @@ -0,0 +1,20 @@ + + + 4.0.0 + + \${groupId} + \${rootArtifactId} + \${version} + + + \${artifactId} + + + + junit + junit + test + + + \ No newline at end of file diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-shared/src/main/java/shared/SharedType.java b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-shared/src/main/java/shared/SharedType.java new file mode 100644 index 00000000..cbc79d71 --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-shared/src/main/java/shared/SharedType.java @@ -0,0 +1,10 @@ +package ${package}.shared; + +/** + * Represents some type that could be shared between client and server. + */ +public class SharedType { + public static String sayHello(String name) { + return "Hello, " + name + "!"; + } +} \ No newline at end of file diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-shared/src/test/java/shared/SharedTypeTest.java b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-shared/src/test/java/shared/SharedTypeTest.java new file mode 100644 index 00000000..b3739333 --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/__rootArtifactId__-shared/src/test/java/shared/SharedTypeTest.java @@ -0,0 +1,14 @@ +package ${package}.shared; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Represents some type that could be shared between client and server. + */ +public class SharedTypeTest { + @Test + public void sayHello() { + Assert.assertEquals("Hello, Foo!", SharedType.sayHello("Foo")); + } +} \ No newline at end of file diff --git a/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/pom.xml b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 00000000..054e6b2e --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,190 @@ + + + 4.0.0 + + \${groupId} + \${artifactId} + pom + \${version} + + + ${project.version} + 1.1.0 + + 2.0.0 + 1.0.0 + ${j2cl.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + 3.8.1 + 9.4.44.v20210927 + 3.3.2 + + + + + + com.google.elemental2 + elemental2-dom + \${elemental2.version} + + + com.google.elemental2 + elemental2-core + \${elemental2.version} + + + com.google.jsinterop + jsinterop-annotations + \${jsinterop.annotations.version} + + + + javax.servlet + javax.servlet-api + 3.1.0 + + + + junit + junit + 4.13.2 + test + + + + + + + + + maven-compiler-plugin + \${maven.compiler.plugin.version} + + \${maven.compiler.source} + \${maven.compiler.target} + + + + org.apache.maven.plugins + maven-war-plugin + \${maven.war.plugin.version} + + + false + + + + + org.eclipse.jetty + jetty-maven-plugin + \${maven.jetty.plugin.version} + + + com.vertispan.j2cl + j2cl-maven-plugin + \${j2cl.maven.plugin.version} + + + + + + + com.vertispan.j2cl + j2cl-maven-plugin + false + + + \${project.build.directory}/j2cl-watch + + + + + + + + + vertispan-releases + Vertispan hosted artifacts-releases + https://repo.vertispan.com/j2cl + + true + + + true + + + + sonatype-snapshots-repo + https://oss.sonatype.org/content/repositories/snapshots + + true + daily + fail + + + + + + + google-snapshots + google-snapshots + https://oss.sonatype.org/content/repositories/google-snapshots/ + + true + + + true + + + + vertispan-releases + Vertispan hosted artifacts-releases + https://repo.vertispan.com/j2cl/ + + true + + + true + + + + vertispan-snapshots + Vertispan Snapshots + https://repo.vertispan.com/gwt-snapshot/ + + true + daily + fail + + + + sonatype-snapshots-repo + https://oss.sonatype.org/content/repositories/snapshots + + true + daily + fail + + + + diff --git a/j2cl-archetypes/j2cl-servlet-project/src/test/resources/projects/test-app/archetype.properties b/j2cl-archetypes/j2cl-servlet-project/src/test/resources/projects/test-app/archetype.properties new file mode 100644 index 00000000..dc7ab1db --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/test/resources/projects/test-app/archetype.properties @@ -0,0 +1,5 @@ +package=com.example +module=TestApp +version=0.1-SNAPSHOT +groupId=com.example +artifactId=test-app diff --git a/j2cl-archetypes/j2cl-servlet-project/src/test/resources/projects/test-app/goal.txt b/j2cl-archetypes/j2cl-servlet-project/src/test/resources/projects/test-app/goal.txt new file mode 100644 index 00000000..0b598736 --- /dev/null +++ b/j2cl-archetypes/j2cl-servlet-project/src/test/resources/projects/test-app/goal.txt @@ -0,0 +1 @@ +verify diff --git a/j2cl-archetypes/pom.xml b/j2cl-archetypes/pom.xml index 1ff8b889..23f1a93b 100644 --- a/j2cl-archetypes/pom.xml +++ b/j2cl-archetypes/pom.xml @@ -14,6 +14,12 @@ J2CL Maven Archetypes Maven project archetypes for using J2CL + + + 1.8 + 1.8 + + @@ -46,5 +52,6 @@ simple-project + j2cl-servlet-project diff --git a/j2cl-archetypes/simple-project/README.md b/j2cl-archetypes/simple-project/README.md new file mode 100644 index 00000000..229652c1 --- /dev/null +++ b/j2cl-archetypes/simple-project/README.md @@ -0,0 +1,20 @@ +# `simple-project` + +This project is a simple html page, with a css file, and a single Java class. It is _not_ a good +example of how to set up a client/server project, but serves only to show how to make very simple +standalone samples. + +After creating this, you'll need two consoles to start it. First, run `mvn jetty:run` in one window - +you'll know it is working when it reports "Started Jetty Server". In the other console window, run +`mvn j2cl:watch`, and wait for `Build Complete: ready for browser refresh`. With both running, open +`http://localhost:8080/` in a browser to see the app. Refresh the page in the browser after editing +any source file (and seeing the "Build Complete" message in the j2cl:watch log). + +To deploy a sample to a servlet container, use `mvn verify` to build a war, then copy it from the +`target/` directory to the webapps directory of the servlet container. Alternatively, just run +`mvn jetty:run` without also running the watch command, the j2cl output will be replaced automatically +with JS compiled for production. + +To reiterate, this is _not_ a suggested way to develop a real project, but is only intended for a quick +sample to get the basic idea of how the plugin functions, and to quickly experiment with J2CL and the +Closure Compiler in Maven. \ No newline at end of file diff --git a/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/pom.xml b/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/pom.xml index c7a83ae0..19935acf 100644 --- a/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/pom.xml +++ b/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/pom.xml @@ -43,21 +43,6 @@ test - - com.vertispan.j2cl - gwttestcase-emul - \${j2cl.version} - test - - - - com.vertispan.j2cl - gwttestcase-emul - \${j2cl.version} - sources - test - - com.vertispan.j2cl junit-emul @@ -95,15 +80,12 @@ \${j2cl.maven.plugin.version} - build-js - generate-sources build test-js - test test diff --git a/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/src/main/java/__module__.java b/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/src/main/java/__module__.java index 16ebc397..baa1b019 100644 --- a/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/src/main/java/__module__.java +++ b/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/src/main/java/__module__.java @@ -23,7 +23,7 @@ public void onModuleLoad() { DomGlobal.document.body.appendChild(wrapper); } - String helloWorldString() { + public String helloWorldString() { return HELLO_WORLD; } } diff --git a/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/src/main/webapp/css/__artifactId__.css b/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/src/main/webapp/css/__artifactId__.css index cb126f6c..9894899f 100644 --- a/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/src/main/webapp/css/__artifactId__.css +++ b/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/src/main/webapp/css/__artifactId__.css @@ -1,27 +1,27 @@ body { - background-color: #e6ede8; + background-color: #e6ede8; } .myButton { - position: absolute; - top: 50%; - background-color:#44c767; - border-radius:28px; - border:1px solid #18ab29; - display:inline-block; - cursor:pointer; - color:#ffffff; - font-family:Arial; - font-size:17px; - padding:16px 31px; - text-decoration:none; - text-shadow:0px 1px 0px #2f6627; + position: absolute; + top: 50%; + background-color:#44c767; + border-radius:28px; + border:1px solid #18ab29; + display:inline-block; + cursor:pointer; + color:#ffffff; + font-family:Arial; + font-size:17px; + padding:16px 31px; + text-decoration:none; + text-shadow:0px 1px 0px #2f6627; } .myButton:hover { - background-color:#5cbf2a; + background-color:#5cbf2a; } .wrapper { - text-align: center; + text-align: center; } diff --git a/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/src/main/webapp/index.html b/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/src/main/webapp/index.html index c76f2e5a..fdc8d54f 100644 --- a/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/src/main/webapp/index.html +++ b/j2cl-archetypes/simple-project/src/main/resources/archetype-resources/src/main/webapp/index.html @@ -1,13 +1,13 @@ - J2CL + J2CL Sample Project '\${module}' - + diff --git a/j2cl-maven-plugin/src/it/annotation-processor-in-reactor/app/pom.xml b/j2cl-maven-plugin/src/it/annotation-processor-in-reactor/app/pom.xml index 30d16f77..23bff811 100644 --- a/j2cl-maven-plugin/src/it/annotation-processor-in-reactor/app/pom.xml +++ b/j2cl-maven-plugin/src/it/annotation-processor-in-reactor/app/pom.xml @@ -56,15 +56,12 @@ @project.version@ - build-js - prepare-package build test-js - test test diff --git a/j2cl-maven-plugin/src/it/dependency-replacements/app/pom.xml b/j2cl-maven-plugin/src/it/dependency-replacements/app/pom.xml index 601c4a56..53626e7a 100644 --- a/j2cl-maven-plugin/src/it/dependency-replacements/app/pom.xml +++ b/j2cl-maven-plugin/src/it/dependency-replacements/app/pom.xml @@ -22,8 +22,6 @@ @project.version@ - build-js - prepare-package build diff --git a/j2cl-maven-plugin/src/it/elemental2-project/pom.xml b/j2cl-maven-plugin/src/it/elemental2-project/pom.xml index 54522c99..8f6f3acd 100644 --- a/j2cl-maven-plugin/src/it/elemental2-project/pom.xml +++ b/j2cl-maven-plugin/src/it/elemental2-project/pom.xml @@ -67,8 +67,6 @@ @project.version@ - compile - prepare-package build diff --git a/j2cl-maven-plugin/src/it/failing-htmlunit-test/pom.xml b/j2cl-maven-plugin/src/it/failing-htmlunit-test/pom.xml index 0c271ce3..f48b6f52 100644 --- a/j2cl-maven-plugin/src/it/failing-htmlunit-test/pom.xml +++ b/j2cl-maven-plugin/src/it/failing-htmlunit-test/pom.xml @@ -53,7 +53,6 @@ test-js - test test diff --git a/j2cl-maven-plugin/src/it/hello-world-reactor/app/pom.xml b/j2cl-maven-plugin/src/it/hello-world-reactor/app/pom.xml index c478a9ed..9199186e 100644 --- a/j2cl-maven-plugin/src/it/hello-world-reactor/app/pom.xml +++ b/j2cl-maven-plugin/src/it/hello-world-reactor/app/pom.xml @@ -25,8 +25,6 @@ @project.version@ - build-js - prepare-package build diff --git a/j2cl-maven-plugin/src/it/hello-world-single/pom.xml b/j2cl-maven-plugin/src/it/hello-world-single/pom.xml index 8c5d9928..18413dd1 100644 --- a/j2cl-maven-plugin/src/it/hello-world-single/pom.xml +++ b/j2cl-maven-plugin/src/it/hello-world-single/pom.xml @@ -22,8 +22,6 @@ @project.version@ - build-js - prepare-package build diff --git a/j2cl-maven-plugin/src/it/hello-world-web-components/pom.xml b/j2cl-maven-plugin/src/it/hello-world-web-components/pom.xml index ffb66546..cfbc83f1 100644 --- a/j2cl-maven-plugin/src/it/hello-world-web-components/pom.xml +++ b/j2cl-maven-plugin/src/it/hello-world-web-components/pom.xml @@ -34,8 +34,6 @@ @project.version@ - build-js - prepare-package build diff --git a/j2cl-maven-plugin/src/it/issue-41/pom.xml b/j2cl-maven-plugin/src/it/issue-41/pom.xml index 9188fcec..bb67c74c 100644 --- a/j2cl-maven-plugin/src/it/issue-41/pom.xml +++ b/j2cl-maven-plugin/src/it/issue-41/pom.xml @@ -41,8 +41,6 @@ @project.version@ - test-js - prepare-package test diff --git a/j2cl-maven-plugin/src/it/java-assertions/pom.xml b/j2cl-maven-plugin/src/it/java-assertions/pom.xml index a9acf4b6..f8758b25 100644 --- a/j2cl-maven-plugin/src/it/java-assertions/pom.xml +++ b/j2cl-maven-plugin/src/it/java-assertions/pom.xml @@ -58,7 +58,6 @@ test-js-with-assertions-default - prepare-package test @@ -73,7 +72,6 @@ test-js-with-assertions-true - prepare-package test @@ -87,7 +85,6 @@ test-js-with-assertions-false - prepare-package test diff --git a/j2cl-maven-plugin/src/it/simple-htmlunit-test/pom.xml b/j2cl-maven-plugin/src/it/simple-htmlunit-test/pom.xml index 64e15f23..526866ae 100644 --- a/j2cl-maven-plugin/src/it/simple-htmlunit-test/pom.xml +++ b/j2cl-maven-plugin/src/it/simple-htmlunit-test/pom.xml @@ -42,8 +42,6 @@ @project.version@ - test-js - prepare-package test diff --git a/j2cl-maven-plugin/src/it/top-level-source-file/pom.xml b/j2cl-maven-plugin/src/it/top-level-source-file/pom.xml index 7641d5a6..3f21306b 100644 --- a/j2cl-maven-plugin/src/it/top-level-source-file/pom.xml +++ b/j2cl-maven-plugin/src/it/top-level-source-file/pom.xml @@ -22,8 +22,6 @@ @project.version@ - build-js - prepare-package build diff --git a/j2cl-maven-plugin/src/it/transitive-dependencies/app/pom.xml b/j2cl-maven-plugin/src/it/transitive-dependencies/app/pom.xml index b0e94caa..ac0a7487 100644 --- a/j2cl-maven-plugin/src/it/transitive-dependencies/app/pom.xml +++ b/j2cl-maven-plugin/src/it/transitive-dependencies/app/pom.xml @@ -25,8 +25,6 @@ @project.version@ - build-js - prepare-package build