Skip to content

Commit

Permalink
Archetype: Feature parity with 3.x + renaming from nima to se (he…
Browse files Browse the repository at this point in the history
  • Loading branch information
tvallin authored and dalexandrov committed Aug 26, 2023
1 parent ea27712 commit f9f0191
Show file tree
Hide file tree
Showing 67 changed files with 2,986 additions and 118 deletions.
2 changes: 1 addition & 1 deletion archetypes/helidon/filters.properties
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ tracing=!${tracing} || (${tracing} && ${metrics.provider} == 'microprofile')

# group extra options
extra=${extra} == [] || ${extra} == ['cors', 'fault-tolerance'] || \
((${extra} && ${flavor} == 'nima') && ${extra} == ['fault-tolerance'])
(${flavor} == 'se' && ${extra} == ['webclient', 'cors', 'fault-tolerance'])

# group docker, k8s and v8o
packaging=!(${docker} || ${k8s} || ${v8o}) || (${docker} && ${k8s} && ${v8o})
Expand Down
3 changes: 3 additions & 0 deletions archetypes/helidon/src/main/archetype/common/common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<transformation id="packaged">
<replace regex="__pkg__" replacement="${package/\./\/}"/>
</transformation>
<transformation id="package-name">
<replace regex="package" replacement="${package}"/>
</transformation>
<transformation id="json-mustache">
<replace regex="\.json.mustache$" replacement=""/>
</transformation>
Expand Down
206 changes: 194 additions & 12 deletions archetypes/helidon/src/main/archetype/common/extra.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,72 @@
<step name="Extra" optional="true">
<inputs>
<list id="extra" name="Select Additional Components" optional="true">
<option value="webclient" name="WebClient" description="Nima HTTP client" if="${flavor} == 'se'">
<output>
<templates engine="mustache" transformations="mustache,packaged">
<directory>files</directory>
<includes>
<include>src/*/java/**/WebClientMain.java.mustache</include>
</includes>
</templates>
<model>
<list key="dependencies">
<map>
<value key="groupId">io.helidon.webclient</value>
<value key="artifactId">helidon-webclient</value>
</map>
</list>
<list key="modules">
<value>io.helidon.webclient</value>
</list>
<list key="Abstract-tests">
<value><![CDATA[
@Test
public void testPerformGetMethod() {
String greeting = WebClientMain.performGetMethod(client);
assertThat(greeting, containsString("Hello World!"));
}
]]></value>
</list>
<list key="MainTest-static-imports">
<value if="${flavor} == 'se'">org.hamcrest.CoreMatchers.containsString</value>
</list>
<list key="readme-sections" if="${flavor} == 'se'">
<value template="mustache"><![CDATA[
## Exercise Webclient
First, start the server:
```
java -jar target/{{artifactId}}.jar
```
Note the port number that it displays. For example:
```
WEB server is up! http://localhost:PORT/simple-greet
```
Then run the client, passing the port number. It will connect
to the server:
```
java -cp "target/classes:target/libs/*" {{package}}.WebClientMain PORT
```
]]></value>
</list>
</model>
</output>
</option>
<option value="fault-tolerance" name="Fault Tolerance" description="System for building resilient applications">
<output>
<templates engine="mustache" transformations="mustache,packaged">
<directory>files</directory>
<includes>
<include>src/*/java/**/FtResource.java.mustache</include>
<include>src/*/java/**/FtResourceTest.java.mustache</include>
<include>src/*/java/**/FtService.java.mustache</include>
<include if="${flavor} == 'mp'">src/*/java/**/FtResource.java.mustache</include>
<include if="${flavor} == 'mp'">src/*/java/**/FtResourceTest.java.mustache</include>
<include if="${flavor} == 'se'">src/*/java/**/FtService.java.mustache</include>
</includes>
</templates>
<model>
Expand All @@ -45,15 +103,15 @@
</map>
</list>
<list key="modules">
<value>io.helidon.microprofile.faulttolerance</value>
<value if="${flavor} == 'mp'">io.helidon.microprofile.faulttolerance</value>
</list>
<list key="Main-helidon-imports">
<list key="Main-helidon-imports" if="${flavor} == 'mp'">
<value>io.helidon.http.Http</value>
</list>
<list key="Main-other-imports" if="${flavor} != 'nima'">
<list key="Main-other-imports" if="${flavor} == 'mp'">
<value>java.util.concurrent.TimeoutException</value>
</list>
<list key="maven-plugins">
<list key="maven-plugins" if="${flavor} == 'mp'">
<value><![CDATA[
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand All @@ -69,7 +127,7 @@
</model>
</output>
</option>
<option value="cors" name="CORS" description="Cross-Origin Resource Sharing utilities" if="${flavor} != 'nima'">
<option value="cors" name="CORS" description="Cross-Origin Resource Sharing utilities">
<output>
<templates engine="mustache" transformations="mustache,packaged">
<directory>files</directory>
Expand All @@ -83,6 +141,14 @@
<value key="groupId">io.helidon.microprofile</value>
<value key="artifactId">helidon-microprofile-cors</value>
</map>
<map if="${flavor} == 'se'">
<value key="groupId">io.helidon.webserver</value>
<value key="artifactId">helidon-webserver-cors</value>
</map>
<map if="${flavor} == 'se'">
<value key="groupId">io.helidon.cors</value>
<value key="artifactId">helidon-cors</value>
</map>
</list>
<list key="SimpleGreetService-imports" if="${flavor} == 'mp'">
<value>io.helidon.microprofile.cors.CrossOrigin</value>
Expand All @@ -92,13 +158,16 @@
<value>jakarta.ws.rs.HttpMethod</value>
</list>
<list key="modules">
<value>io.helidon.microprofile.cors</value>
<value if="${flavor} == 'mp'">io.helidon.microprofile.cors</value>
<value if="${flavor} == 'se'">io.helidon.webserver.cors</value>
<value if="${flavor} == 'se'">io.helidon.cors</value>
<value if="${flavor} == 'se'">java.logging</value>
</list>
<list key="FileServiceTest-annotations" if="${media} contains 'multipart'">
<value>@AddExtension(CorsCdiExtension.class)</value>
<value if="${flavor} == 'mp'">@AddExtension(CorsCdiExtension.class)</value>
</list>
<list key="FileServiceTest-helidon-imports" if="${media} contains 'multipart'">
<value>io.helidon.microprofile.cors.CorsCdiExtension</value>
<value if="${flavor} == 'mp'">io.helidon.microprofile.cors.CorsCdiExtension</value>
</list>
<list key="SimpleGreetService-methods" if="${flavor} == 'mp'">
<value><![CDATA[
Expand All @@ -117,7 +186,7 @@
public void optionsForGetCustomMessage() {
}]]></value>
</list>
<list key="readme-sections">
<list key="readme-sections" if="${flavor} == 'mp'">
<value><![CDATA[
## Using CORS
Expand Down Expand Up @@ -191,6 +260,119 @@ Hola World!
```
Note that the tests in the example `MainTest` class follow these same steps.
]]></value>
</list>
<list key="Main-helidon-imports" if="${flavor} == 'se'">
<value>io.helidon.cors.CrossOriginConfig</value>
<value>io.helidon.webserver.cors.CorsSupport</value>
</list>
<list key="Main-java-imports" if="${flavor} == 'se'">
<value>java.util.logging.Logger</value>
</list>
<list key="application-yaml-entries" if="${flavor} == 'se'">
<value><![CDATA[
restrictive-cors:
allow-origins: ["http://foo.com", "http://there.com"]
allow-methods: ["PUT", "DELETE"]
# The example app uses the following for overriding other settings.
#cors:
# paths:
# - path-pattern: /greeting
# allow-origins: ["http://foo.com", "http://there.com", "http://other.com"]
# allow-methods: ["PUT", "DELETE"]
]]></value>
</list>
<list key="Main-routing-builder" if="${flavor} == 'se'">
<value><![CDATA[ .register("/cors-greet", corsSupportForGreeting(config), new GreetService())
]]></value>
</list>
<list key="Main-content" if="${flavor} == 'se'">
<value><![CDATA[
private static CorsSupport corsSupportForGreeting(Config config) {
Config restrictiveConfig = config.get("restrictive-cors");
if (!restrictiveConfig.exists()) {
Logger.getLogger(Main.class.getName())
.warning("Missing restrictive config; continuing with default CORS support");
}
CorsSupport.Builder corsBuilder = CorsSupport.builder();
config.get("cors")
.ifExists(c -> {
Logger.getLogger(Main.class.getName()).info("Using the override configuration");
corsBuilder.mappedConfig(c);
});
corsBuilder
.config(restrictiveConfig) // restricted sharing for PUT, DELETE
.addCrossOrigin(CrossOriginConfig.create()) // open sharing for other methods
.build();
return corsBuilder.build();
}
]]></value>
</list>
<list key="MainTest-java-imports" if="${flavor} == 'se'">
<value>java.util.Optional</value>
</list>
<list key="MainTest-helidon-imports" if="${flavor} == 'se'">
<value>io.helidon.http.Headers</value>
<value>io.helidon.cors.CrossOriginConfig</value>
</list>
<list key="MainTest-static-imports" if="${flavor} == 'se'">
<value>io.helidon.http.Http.HeaderNames.ACCESS_CONTROL_ALLOW_ORIGIN</value>
<value>io.helidon.http.Http.HeaderNames.HOST</value>
<value>io.helidon.http.Http.HeaderNames.ORIGIN</value>
</list>
<list key="MainTest-static-imports">
<value if="${flavor} == 'se'">org.hamcrest.CoreMatchers.containsString</value>
</list>
<list key="Abstract-tests" if="${flavor} == 'se'">
<value><![CDATA[
@Test
void testAnonymousGreetWithCors() {
try (Http1ClientResponse response = client.get()
.path("/cors-greet")
.headers(it -> it
.set(ORIGIN, "http://foo.com")
.set(HOST, "here.com"))
.request()) {
assertThat(response.status().code(), is(200));
String payload = response.entity().as(String.class);
assertThat(payload, containsString("Hello World"));
Headers responseHeaders = response.headers();
Optional<String> allowOrigin = responseHeaders.value(ACCESS_CONTROL_ALLOW_ORIGIN);
assertThat("Expected CORS header " + CrossOriginConfig.ACCESS_CONTROL_ALLOW_ORIGIN + " is absent",
allowOrigin.isPresent(), is(true));
assertThat(allowOrigin.get(), is("*"));
}
}
]]></value>
</list>
<list key="readme-sections" if="${flavor} == 'se'">
<value><![CDATA[
## Using CORS
The following requests illustrate the CORS protocol with the example app.
By setting `Origin` and `Host` headers that do not indicate the same system we trigger CORS processing in the
server:
```bash
# Follow the CORS protocol for GET
curl -i -X GET -H "Origin: http://foo.com" -H "Host: here.com" http://localhost:8080/cors-greet
HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Thu, 30 Apr 2020 17:25:51 -0500
Vary: Origin
connection: keep-alive
content-length: 27
Hello World
```
]]></value>
</list>
</model>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@

# 1st stage, build the app
FROM maven:3.8.4-openjdk-17-slim as build
FROM container-registry.oracle.com/java/openjdk:21 as build

# Install maven
WORKDIR /usr/share
RUN set -x && \
curl -O https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz && \
tar -xvf apache-maven-*-bin.tar.gz && \
rm apache-maven-*-bin.tar.gz && \
mv apache-maven-* maven && \
ln -s /usr/share/maven/bin/mvn /bin/

WORKDIR /helidon

Expand All @@ -10,7 +19,7 @@ WORKDIR /helidon
{{#poms}}
ADD {{.}} {{.}}
{{/poms}}
RUN mvn package -Dmaven.test.skip {{#docker-phase1-options}}{{.}}{{^last}} {{/last}}{{/docker-phase1-options}}
RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip {{#docker-phase1-options}}{{.}}{{^last}} {{/last}}{{/docker-phase1-options}}

# Do the Maven build!
# Incremental docker builds will resume here when you change sources
Expand All @@ -22,7 +31,7 @@ RUN mvn package -DskipTests
RUN echo "done!"

# 2nd stage, build the runtime image
FROM openjdk:17-jdk-slim
FROM container-registry.oracle.com/java/openjdk:21
WORKDIR /helidon

# Copy the binary built in the 1st stage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{{.}}
{{/readme-run-commands}}
{{^readme-run-commands}}
With JDK20
With JDK21
```bash
mvn package
java -jar target/{{artifactId}}.jar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
{{#type}}
<type>{{.}}</type>
{{/type}}
{{#optional}}
<optional>{{.}}</optional>
{{/optional}}
</dependency>
{{/dependencies}}
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022 Oracle and/or its affiliates.
Copyright (c) 2022, 2023 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -27,6 +27,7 @@
<includes>
<include>src/*/java/**/SimpleGreetService.java.mustache</include>
<include>src/*/java/**/SimpleGreetResource.java.mustache</include>
<include>src/*/java/**/GreetService.java.mustache</include>
</includes>
</templates>
<templates engine="mustache" transformations="jsonp-mustache,packaged" if="${media.json-lib} == 'jsonp'">
Expand Down
Loading

0 comments on commit f9f0191

Please sign in to comment.