Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x: Update archetypes and dbclient examples #7873

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion applications/se/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
<name>Helidon SE applications parent pom</name>
<description>Parent pom for Helidon SE applications</description>

<properties>
<helidon.test.config.profile>test</helidon.test.config.profile>
</properties>

<build>
<pluginManagement>
<plugins>
Expand All @@ -40,7 +44,7 @@
<version>${version.plugin.surefire}</version>
<configuration>
<systemPropertyVariables>
<helidon.config.profile>test</helidon.config.profile>
<helidon.config.profile>${helidon.test.config.profile}</helidon.config.profile>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down
3 changes: 0 additions & 3 deletions archetypes/helidon/src/main/archetype/common/common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
<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
4 changes: 2 additions & 2 deletions archetypes/helidon/src/main/archetype/common/docker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
<list key="src-dirs" if="!${multi-module}">
<value>src</value>
</list>
<list key="native-sections" if="${db} &amp;&amp; ${flavor} == 'mp'">
<value file="files/README.native.md.mustache" if="${docker.native-image}" template="mustache"/>
<list key="native-sections" if="${docker.native-image}">
<value file="files/README.native.md"/>
</list>
<list key="readme-sections">
<value order="50" template="mustache">
Expand Down
8 changes: 4 additions & 4 deletions archetypes/helidon/src/main/archetype/common/extra.xml
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,21 @@ restrictive-cors:
]]></value>
</list>
<list key="Main-routing-builder" if="${flavor} == 'se'">
<value><![CDATA[ .register("/cors-greet", corsSupportForGreeting(config), new GreetService())
<value><![CDATA[ .register("/cors-greet", corsSupportForGreeting(), new GreetService())
]]></value>
</list>
<list key="main-class-content" if="${flavor} == 'se'">
<value><![CDATA[
private static CorsSupport corsSupportForGreeting(Config config) {
Config restrictiveConfig = config.get("restrictive-cors");
private static CorsSupport corsSupportForGreeting() {
Config restrictiveConfig = Config.global().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")
Config.global().get("cors")
.ifExists(c -> {
Logger.getLogger(Main.class.getName()).info("Using the override configuration");
corsBuilder.mappedConfig(c);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
The generation of native binaries requires an installation of GraalVM 22.1.0+.

You can build a native binary using Maven as follows:

```
mvn -Pnative-image install -DskipTests
```

The generation of the executable binary may take a few minutes to complete depending on
your hardware and operating system. When completed, the executable file will be available
under the `target` directory and be named after the artifact ID you have chosen during the
project generation phase.

This file was deleted.

43 changes: 27 additions & 16 deletions archetypes/helidon/src/main/archetype/common/media.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,10 @@
<list key="Abstract-tests">
<value><![CDATA[
@Test
void testRootRoute() {
try (Http1ClientResponse response = client.get("/greet")
.request()) {

assertThat(response.status(), is(Status.OK_200));
JsonObject json = response.as(JsonObject.class);
assertThat(json.getString("message"), is("Hello World!"));
}
void testGreeting() {
ClientResponseTyped<JsonObject> response = client.get("/greet").request(JsonObject.class);
assertThat(response.status(), is(Status.OK_200));
assertThat(response.entity().getString("message"), is("Hello World!"));
}
]]></value>
</list>
Expand Down Expand Up @@ -119,18 +115,16 @@
<value><![CDATA[
@Test
void testGreet() {
try (Http1ClientResponse response = client.get("/greet").request()) {
assertThat(response.status(), is(Status.OK_200));
assertThat(response.as(Message.class).getMessage(), is("Hello World!"));
}
ClientResponseTyped<Message> response = client.get("/greet").request(Message.class);
assertThat(response.status(), is(Status.OK_200));
assertThat(response.entity().getMessage(), is("Hello World!"));
}

@Test
void testGreetJoe() {
try (Http1ClientResponse response = client.get("/greet/Joe").request()) {
assertThat(response.status(), is(Status.OK_200));
assertThat(response.as(Message.class).getMessage(), is("Hello Joe!"));
}
ClientResponseTyped<Message> response = client.get("/greet/Joe").request(Message.class);
assertThat(response.status(), is(Status.OK_200));
assertThat(response.entity().getMessage(), is("Hello Joe!"));
}
]]></value>
</list>
Expand Down Expand Up @@ -225,6 +219,23 @@
<value key="media-json-jackson" if="!(${media} contains 'json' &amp;&amp; ${media.json-lib} == 'jackson')">false</value>
<value key="json-lib" if="${media} contains 'json'">${media.json-lib}</value>
<value key="multipart" if="${media} contains 'multipart'">true</value>
<list key="readme-exercise-the-application">
<value order="900" if="${media} contains 'json'"><![CDATA[
JSON:
```
curl -X GET http://localhost:8080/greet
{"message":"Hello World!"}

curl -X GET http://localhost:8080/greet/Joe
{"message":"Hello Joe!"}

curl -X PUT -H "Content-Type: application/json" -d '{"greeting" : "Hola"}' http://localhost:8080/greet/greeting

curl -X GET http://localhost:8080/greet/Jose
{"message":"Hola Jose!"}
```
]]></value>
</list>
</model>
</output>
</step>
Expand Down
39 changes: 2 additions & 37 deletions archetypes/helidon/src/main/archetype/common/observability.xml
Original file line number Diff line number Diff line change
Expand Up @@ -350,44 +350,9 @@ curl -s -X GET http://localhost:8080/health
<value key="artifactId">helidon-health-checks</value>
</map>
</list>
<list key="Observe-feature-builder" if="${flavor} == 'se'">
<value><![CDATA[.addObserver(HealthObserver.builder()
.details(true)
.useSystemServices(false)
.addCheck(() -> HealthCheckResponse.builder()
.status(HealthCheckResponse.Status.UP)
.detail("time", System.currentTimeMillis())
.build(), HealthCheckType.READINESS)
.addCheck(() -> HealthCheckResponse.builder()
.status(isStarted())
.detail("time", System.currentTimeMillis())
.build(), HealthCheckType.STARTUP)
.build())]]></value>
</list>
<list key="Main-helidon-imports" if="${flavor} == 'se'">
<value>io.helidon.health.HealthCheckResponse</value>
<value>io.helidon.health.HealthCheckType</value>
<value>io.helidon.webserver.observe.health.HealthObserver</value>
</list>
<list key="MainTest-static-imports" if="${flavor} == 'se'">
<value>org.hamcrest.CoreMatchers.containsString</value>
</list>
<list key="Main-java-imports" if="${flavor} == 'se'">
<value>java.time.Duration</value>
</list>
<list key="main-class-fields" if="${flavor} == 'se'">
<value><![CDATA[ private static long serverStartTime;]]></value>
</list>
<list key="Main-main" if="${flavor} == 'se'">
<value><![CDATA[serverStartTime = System.currentTimeMillis();]]></value>
</list>
<list key="main-class-content" if="${flavor} == 'se'">
<value><![CDATA[
private static boolean isStarted() {
return Duration.ofMillis(System.currentTimeMillis() - serverStartTime).getSeconds() >= 8;
}
]]></value>
</list>
<list key="Abstract-test" if="${flavor} == 'se'">
<value><![CDATA[
@Test
Expand All @@ -412,8 +377,8 @@ Note the port number reported by the application.
Probe the health endpoints:

```bash
curl -X GET http://localhost:8080/observe/observe/health/
curl -X GET http://localhost:8080/observe/observe/health/ready
curl -X GET http://localhost:8080/observe/health
curl -X GET http://localhost:8080/observe/health/ready
```

]]></value>
Expand Down
7 changes: 3 additions & 4 deletions archetypes/helidon/src/main/archetype/common/security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@
</list>
<list key="Main-routing" if="${flavor} == 'se'">
<value><![CDATA[
if (config.get("security.enabled").asBoolean().orElse(true)) {
if (Config.global().get("security.enabled").asBoolean().orElse(true)) {
// IDCS requires a web resource for redirects
routing.addFeature(OidcFeature.create(config));
routing.addFeature(OidcFeature.create(Config.global()));
}
]]></value>
</list>
Expand Down Expand Up @@ -168,7 +168,6 @@
<value if="${flavor} == 'se'">io.helidon.webclient.security</value>
<value>io.helidon.security.providers.jwt</value>
<value>io.helidon.webserver.context</value>
<value>io.helidon.webclient.http1</value>
</list>
</model>
</output>
Expand Down Expand Up @@ -316,7 +315,7 @@
methods: ["get"]
authenticate: true]]></value>
</list>
<list key="config-test" if="${flavor} == 'se'">
<list key="application-test-yaml-entries" if="${flavor} == 'se'">
<value><![CDATA[
security:
enabled: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
<source src="/common/sources.xml"/>
<output>
<model>
<value key="mainClass">${package}.Main</value>
<value key="parent-artifactId">helidon-mp</value>
<list key="dependencies">
<map>
Expand Down
24 changes: 13 additions & 11 deletions archetypes/helidon/src/main/archetype/mp/custom/custom-mp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,16 @@
<exec src="/common/media.xml"/>
<source src="/common/media-sources.xml"/>
<exec src="/common/security.xml"/>
<exec src="/mp/custom/database.xml"/>
<exec src="database-input.xml"/>
<source src="/common/extra.xml"/>
<source src="/common/observability.xml"/>
<exec src="/common/packaging.xml"/>
<source src="/mp/custom/observability.xml"/>
<source src="observability.xml"/>
<exec src="database-outputs.xml" if="${db}"/>
<output>
<model>
<value key="helidon-test">true</value>
<value key="readme-description">Minimal Helidon MP project suitable to start from scratch.</value>
<list key="readme-exercise-the-application">
<value file="files/README.md"/>
</list>
<list key="native-sections" if="${docker}">
<value file="files/README.native.md.mustache"
if="${docker.native-image} &amp;&amp; !(${db})"
template="mustache"/>
</list>
<value key="mainClass" if="${jpms}">${package}.Main</value>
<list key="microprofile-config-entries">
<value file="files/microprofile-config.properties"/>
</list>
Expand Down Expand Up @@ -78,6 +71,15 @@
<value key="artifactId">helidon-microprofile-core</value>
</map>
</list>
<list key="readme-exercise-the-application">
<value order="999"><![CDATA[
Basic:
```
curl -X GET http://localhost:8080/simple-greet
Hello World!
```
]]></value>
</list>
<list key="module-requires">
<value>jakarta.cdi</value>
<value>jakarta.inject</value>
Expand Down
51 changes: 51 additions & 0 deletions archetypes/helidon/src/main/archetype/mp/custom/database-input.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2022 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.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<archetype-script xmlns="https://helidon.io/archetype/2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://helidon.io/archetype/2.0 https://helidon.io/xsd/archetype-2.0.xsd">

<step name="Database" optional="true">
<inputs>
<boolean id="db"
name="Database Support"
description="Manage data in your application"
default="false"
optional="true">
<inputs>
<enum id="jpa-impl" name="Select a JPA Implementation" default="hibernate" optional="true">
<option value="hibernate" name="Hibernate" description="Hibernate Object Relational Mapping" />
<option value="eclipselink" name="EclipseLink" description="Eclipse Persistence Services" />
</enum>
<enum id="cp" name="Select a Connection Pool" default="hikaricp" optional="true">
<option value="hikaricp" name="HikariCP" description="&quot;zero overhead&quot; JDBC connection pool" />
<option value="ucp" name="UCP" description="Universal Connection Pool" />
</enum>
<enum id="server" name="Select a Database Server" default="h2" optional="true">
<option value="h2" name="H2" description="In-memory relational database" />
<option value="mysql" name="MySQL" description="Relational database" />
<option value="oracledb" name="Oracle DB" description="Multi-model database" />
</enum>
<boolean id="auto-ddl" name="Auto DDL" description="Automatic schema initialization" optional="true" />
<text id="pu-name" name="Persistence Unit Name" default="pu1" optional="true"/>
<text id="ds-name" name="Datasource Name" default="ds1" optional="true"/>
</inputs>
</boolean>
</inputs>
</step>
</archetype-script>
Loading