Skip to content

Commit

Permalink
3.0 archetypes minor issues : Multiple fix to templates (helidon-io#4556
Browse files Browse the repository at this point in the history
)

* Multiple fix to templates

Signed-off-by: tvallin <[email protected]>

* readme sections for native image and jlink + enable tests

Signed-off-by: tvallin <[email protected]>

* readme sections for native image and jlink left over for bare

Signed-off-by: tvallin <[email protected]>

* readme sections for metrics left over

Signed-off-by: tvallin <[email protected]>

* remove db mp filter and corresponding unit tests

Signed-off-by: tvallin <[email protected]>

* fix docker.native-image unresolved properties

Signed-off-by: tvallin <[email protected]>
  • Loading branch information
tvallin authored and romain-grecourt committed Jul 21, 2022
1 parent 0a73810 commit 7b8e895
Show file tree
Hide file tree
Showing 32 changed files with 555 additions and 256 deletions.
3 changes: 0 additions & 3 deletions archetypes/helidon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
<artifactId>helidon-archetype-maven-plugin</artifactId>
<configuration>
<mavenArchetypeCompatible>false</mavenArchetypeCompatible>
<properties>
<skipTests>true</skipTests>
</properties>
<entrypoint>
<variables>
<text path="helidon-version" transient="true">${project.version}</text>
Expand Down
56 changes: 51 additions & 5 deletions archetypes/helidon/src/main/archetype/common/docker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,59 @@
</includes>
</templates>
<model>
<list key="readme-section">
<list key="readme-sections">
<value order="50" template="mustache">
<![CDATA[
## Build the Docker Image
```
docker build -t {{artifactId}} .
```
## Build the Docker Image
```
docker build -t {{artifactId}} .
```
]]>
</value>
<value template="mustache" if="${native-image}">
<![CDATA[
## Building a Native Image
{{#native-sections}}
{{.}}
{{/native-sections}}
]]>
</value>
<value order="40" template="mustache" if="${jlink-image}">
<![CDATA[
## Building a Custom Runtime Image
Build the custom runtime image using the jlink image profile:
```
mvn package -Pjlink-image
```
This uses the helidon-maven-plugin to perform the custom image generation.
After the build completes it will report some statistics about the build including the reduction in image size.
The target/{{artifactId}}-jri directory is a self contained custom image of your application. It contains your application,
its runtime dependencies and the JDK modules it depends on. You can start your application using the provide start script:
```
./target/{{artifactId}}-jri/bin/start
```
Class Data Sharing (CDS) Archive
Also included in the custom image is a Class Data Sharing (CDS) archive that improves your application’s startup
performance and in-memory footprint. You can learn more about Class Data Sharing in the JDK documentation.
The CDS archive increases your image size to get these performance optimizations. It can be of significant size (tens of MB).
The size of the CDS archive is reported at the end of the build output.
If you’d rather have a smaller image size (with a slightly increased startup time) you can skip the creation of the CDS
archive by executing your build like this:
```
mvn package -Pjlink-image -Djlink.image.addClassDataSharingArchive=false
```
For more information on available configuration options see the helidon-maven-plugin documentation.
]]>
</value>
</list>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@

## Build and run

{{#run-comment}}
{{.}}
{{/run-comment}}

With JDK11+
```bash
mvn package
java -jar target/{{artifactId}}.jar
```

## Exercise the application
{{#readme-exercise-the-application}}
{{.}}
{{/readme-exercise-the-application}}

{{#readme-sections}}
{{.}}
{{/readme-sections}}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

<exec src="/common/common.xml"/>
<output>
<templates engine="mustache" transformations="mustache,packaged" if="!(${media} contains 'json')">
<directory>files</directory>
<includes>
<include>src/*/java/**/SimpleGreetService.java.mustache</include>
<include>src/*/java/**/SimpleGreetResource.java.mustache</include>
</includes>
</templates>
<templates engine="mustache" transformations="jsonp-mustache,packaged" if="${media.json-lib} == 'jsonp'">
<directory>files</directory>
<includes>
Expand Down
36 changes: 33 additions & 3 deletions archetypes/helidon/src/main/archetype/common/observability.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@
description="Expose metrics using the MicroProfile API">
<output>
<model>
<list key="readme-sections">
<value><![CDATA[
## Try metrics
```
# Prometheus Format
curl -s -X GET http://localhost:8080/metrics
# TYPE base:gc_g1_young_generation_count gauge
. . .
# JSON Format
curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
{"base":...
. . .
```
]]></value>
</list>
<list key="dependencies">
<map if="${flavor} == 'mp'">
<value key="groupId">org.eclipse.microprofile.metrics</value>
Expand All @@ -51,6 +69,12 @@
<value key="artifactId">helidon-metrics</value>
</map>
</list>
<list key="Main-helidon-imports">
<value>io.helidon.metrics.MetricsSupport</value>
</list>
<list key="Main-routingBuilder">
<value><![CDATA[ .register(MetricsSupport.create()) // Metrics at "/metrics"]]></value>
</list>
<list key="SimpleGreetService-imports">
<value if="${flavor} == 'mp'">org.eclipse.microprofile.metrics.MetricUnits</value>
<value if="${flavor} == 'mp'">org.eclipse.microprofile.metrics.annotation.Counted</value>
Expand Down Expand Up @@ -303,10 +327,16 @@ allRequests_total 0.0
optional="true">
<output>
<model>
<list key="Main-helidon-imports">
<list key="dependencies">
<map if="${flavor} == 'se' &amp;&amp; !(${metrics.provider} == 'microprofile')">
<value key="groupId">io.helidon.metrics</value>
<value key="artifactId">helidon-metrics</value>
</map>
</list>
<list key="Main-helidon-imports" if="!(${metrics.provider} == 'microprofile')">
<value>io.helidon.metrics.MetricsSupport</value>
</list>
<list key="Main-routingBuilder">
<list key="Main-routingBuilder" if="!(${metrics.provider} == 'microprofile')">
<value><![CDATA[ .register(MetricsSupport.create()) // Metrics at "/metrics"]]></value>
</list>
<list key="MainTest-methods">
Expand All @@ -329,7 +359,7 @@ allRequests_total 0.0
assertThat(response.status().code(), is(200));
}]]></value>
</list>
<list key="readme-sections">
<list key="readme-sections" if="!(${metrics.provider} == 'microprofile')">
<value><![CDATA[
## Try metrics
Expand Down
7 changes: 7 additions & 0 deletions archetypes/helidon/src/main/archetype/common/sources.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,18 @@
<includes>
<include>src/*/java/**/*.java.mustache</include>
</includes>
<excludes>
<exclude if="${flavor} == 'mp' &amp;&amp; ${db}">src/test/**/*.mustache</exclude>
</excludes>
</templates>
<templates engine="mustache" transformations="mustache">
<directory>files</directory>
<includes>
<include>src/*/resources/**/*.mustache</include>
</includes>
<excludes>
<exclude if="${flavor} == 'mp' &amp;&amp; ${db}">src/test/resources/**/*.mustache</exclude>
</excludes>
</templates>
<files>
<directory>files</directory>
Expand All @@ -41,6 +47,7 @@
</includes>
<excludes>
<exclude>**/*.mustache</exclude>
<exclude if="${flavor} == 'mp' &amp;&amp; ${db}">src/test/resources/**</exclude>
</excludes>
</files>
<model>
Expand Down
12 changes: 8 additions & 4 deletions archetypes/helidon/src/main/archetype/mp/custom/custom-mp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
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">

<exec src="/mp/common/common-mp.xml"/>
<!--source src="/common/sources.xml"/-->
<exec src="/common/media.xml"/>
<source src="/common/media-sources.xml"/>
<source src="/common/observability.xml"/>
<exec src="/mp/custom/database.xml"/>
<exec src="/common/security.xml"/>
<source src="/common/extra.xml"/>
<exec src="/common/packaging.xml"/>
<exec src="/mp/custom/database.xml"/>
<exec src="/mp/common/common-mp.xml"/>
<output>
<files if="${security}">
<directory>files</directory>
Expand All @@ -39,9 +38,14 @@
</files>
<model>
<value key="readme-description">Minimal Helidon MP project suitable to start from scratch.</value>
<list key="readme-sections">
<list key="readme-exercise-the-application">
<value file="files/README.md"/>
</list>
<list key="native-sections" if="${docker}">
<value file="files/README.native.md"
if="${docker.native-image} &amp;&amp; !(${db})"
template="mustache"/>
</list>
<list key="config-entries">
<value file="files/microprofile-config.properties"/>
</list>
Expand Down
42 changes: 42 additions & 0 deletions archetypes/helidon/src/main/archetype/mp/custom/database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@
<option value="h2" name="H2" description="In-memory relational database">
<output>
<model>
<value key="readme-description">Helidon MP application that uses the dbclient API with an in-memory H2 database.</value>
<value key="readme-native-docker">docker run -d -p 1521:1521 -p 81:81 -e H2_OPTIONS='-ifNotExists' --name=h2 oscarfonts/h2</value>
<value key="readme-native-url">javax.sql.DataSource.test.dataSource.url=jdbc:h2:tcp://localhost:1521/test</value>
<value key="integration-artifactId">h2</value>
<value key="db">H2</value>
<list key="run-comment">
<value><![CDATA[
This example requires a database.
Instructions for H2 can be found here: https://www.h2database.com/html/cheatSheet.html
]]></value>
</list>
<list key="main-persistence-properties">
<map if="${..jpa-impl} == 'hibernate'">
<value key="name">hibernate.dialect</value>
Expand All @@ -188,6 +199,20 @@
<option value="mysql" name="MySQL" description="Relational database">
<output>
<model>
<value key="readme-description">Helidon MP application that uses the dbclient API with MySQL database.</value>
<value key="readme-native-docker">docker run --rm --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=pokemon -e MYSQL_USER=user -e MYSQL_PASSWORD=password mysql:5.7</value>
<value key="readme-native-url">url: jdbc:mysql:tcp://127.0.0.1:3306/pokemon?useSSL=false</value>
<value key="integration-artifactId">helidon-integrations-db-mysql</value>
<value key="db">MySQL</value>
<list key="run-comment">
<value><![CDATA[
This example requires a MySQL database, start it using docker:
```
docker run --rm --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=pokemon -e MYSQL_USER=user -e MYSQL_PASSWORD=password mysql:5.7
```
]]></value>
</list>
<list key="main-persistence-properties">
<map if="${..jpa-impl} == 'hibernate'">
<value key="name">hibernate.dialect</value>
Expand All @@ -212,6 +237,20 @@
<option value="oracledb" name="Oracle DB" description="Multi-model database">
<output>
<model>
<value key="readme-description">Helidon MP application that uses the dbclient API with OracleDB database.</value>
<value key="readme-native-docker">docker run --rm --name xe -p 1521:1521 -p 8888:8080 -e ORACLE_PWD=oracle wnameless/oracle-xe-11g-r2</value>
<value key="readme-native-url">url: jdbc:oracle:thin:@localhost:1521/XE</value>
<value key="integration-artifactId">ojdbc</value>
<value key="db">OracleDB</value>
<list key="run-comment">
<value><![CDATA[
This example requires a oracleDB database, start it using docker:
```
docker run --rm --name xe -p 1521:1521 -p 8888:8080 -e ORACLE_PWD=oracle wnameless/oracle-xe-11g-r2
```
]]></value>
</list>
<list key="main-persistence-properties">
<map if="${..jpa-impl} == 'hibernate'">
<value key="name">hibernate.dialect</value>
Expand Down Expand Up @@ -270,6 +309,9 @@
</includes>
</templates>
<model>
<list key="native-sections" if="${docker}">
<value file="../database/files/README.native.md" if="${docker.native-image}" template="mustache"/>
</list>
<value key="database">true</value>
<value key="pu-name">${pu-name}</value>
<value key="ds-name">${ds-name}</value>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
## Exercise the application

```
curl -X GET http://localhost:8080/greet
curl -X GET http://localhost:8080/simple-greet
{"message":"Hello World!"}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Make sure you have GraalVM locally installed:

```
$GRAALVM_HOME/bin/native-image --version
```

Build the native image using the native image profile:

```
mvn package -Pnative-image
```

This uses the helidon-maven-plugin to perform the native compilation using your installed copy of GraalVM. It might take a while to complete.
Once it completes start the application using the native executable (no JVM!):

```
./target/{{artifactId}}
```

Yep, it starts fast. You can exercise the application’s endpoints as before.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

package {{package}};

import java.util.Collections;

{{#SimpleGreetService-imports}}
import {{.}};
{{/SimpleGreetService-imports}}

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import org.eclipse.microprofile.config.inject.ConfigProperty;

/**
* A simple JAX-RS resource to greet you. Examples:
*
* Get default greeting message:
* curl -X GET http://localhost:8080/simple-greet
*
* The message is returned as a JSON object.
*/
@Path("/simple-greet")
public class SimpleGreetResource {
{{#SimpleGreetResource-static-fields}}
{{.}}
{{/SimpleGreetResource-static-fields}}

private final String message;

@Inject
public SimpleGreetResource(@ConfigProperty(name = "app.greeting") String message) {
this.message = message;
}

/**
* Return a worldly greeting message.
*
* @return {@link JsonObject}
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getDefaultMessage() {
return String.format("%s %s!", message, "World");
}

{{#SimpleGreetService-methods}}
{{.}}
{{/SimpleGreetService-methods}}

}
Loading

0 comments on commit 7b8e895

Please sign in to comment.