Skip to content

Commit

Permalink
4.x: Fix several issue in archetype and add native-image.properties
Browse files Browse the repository at this point in the history
… to generated projects (#7731)

* Uplevel Main template
* Add javadoc + native-image.properties
Signed-off-by: tvallin <thibault.vallin@oracle.com>
  • Loading branch information
tvallin authored Oct 6, 2023
1 parent 4144a72 commit 0f8a570
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 104 deletions.
8 changes: 6 additions & 2 deletions archetypes/helidon/src/main/archetype/common/common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@
<transformation id="multipart-mustache">
<replace regex="\.multipart.mustache$" replacement=""/>
</transformation>
<templates engine="mustache" transformations="mustache">
<transformation id="native-image">
<replace regex="groupid" replacement="${groupId/\./\/}"/>
<replace regex="artifactid" replacement="${artifactId/\./\/}"/>
</transformation>
<templates engine="mustache" transformations="mustache,packaged">
<directory>files</directory>
<includes>
<include>.helidon.mustache</include>
<include>README.md.mustache</include>
<include>src/main/java/module-info.java.mustache</include>
<include>src/main/java/**/*.java.mustache</include>
</includes>
</templates>
<model>
Expand Down
11 changes: 10 additions & 1 deletion archetypes/helidon/src/main/archetype/common/docker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@
name="GraalVM Native Image Support"
description="Add a native-image capable Dockerfile to your project"
default="false"
optional="true"/>
optional="true">
<output>
<templates engine="mustache" transformations="mustache,native-image">
<directory>files</directory>
<includes>
<include>src/*/resources/META-INF/**/*.mustache</include>
</includes>
</templates>
</output>
</boolean>
<boolean id="jlink-image" name="JLink Support"
description="Add a JLink capable Dockerfile to your project"
default="false"
Expand Down
5 changes: 1 addition & 4 deletions archetypes/helidon/src/main/archetype/common/extra.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ java -cp "target/classes:target/libs/*" {{package}}.WebClientMain PORT
<list key="modules">
<value if="${flavor} == 'mp'">io.helidon.microprofile.faulttolerance</value>
</list>
<list key="Main-other-imports" if="${flavor} == 'mp'">
<value>java.util.concurrent.TimeoutException</value>
</list>
<list key="maven-plugins" if="${flavor} == 'mp'">
<value><![CDATA[
<plugin>
Expand Down Expand Up @@ -284,7 +281,7 @@ restrictive-cors:
<value><![CDATA[ .register("/cors-greet", corsSupportForGreeting(config), new GreetService())
]]></value>
</list>
<list key="Main-content" if="${flavor} == 'se'">
<list key="main-class-content" if="${flavor} == 'se'">
<value><![CDATA[
private static CorsSupport corsSupportForGreeting(Config config) {
Config restrictiveConfig = config.get("restrictive-cors");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

package {{package}};

{{#Main-java-imports}}
import {{.}};
{{/Main-java-imports}}

{{#Main-helidon-imports}}
import {{.}};
{{/Main-helidon-imports}}

{{#Main-other-imports}}
import {{.}};
{{/Main-other-imports}}

{{#Main-static-imports}}
import {{.}};
{{/Main-static-imports}}

{{main-class-javadoc}}
public class Main {
{{#main-class-fields}}
{{.}}
{{/main-class-fields}}

{{main-method-javadoc}}
public static void main(String[] args) {
{{#main-method-content}}
{{.}}
{{/main-method-content}}
}

{{#main-class-content}}
{{.}}
{{/main-class-content}}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Args=--initialize-at-build-time={{package}}
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,13 @@ curl -s -X GET http://localhost:8080/health
<list key="Main-java-imports" if="${flavor} == 'se'">
<value>java.time.Duration</value>
</list>
<list key="Main-fields" if="${flavor} == 'se'">
<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-content" if="${flavor} == 'se'">
<list key="main-class-content" if="${flavor} == 'se'">
<value><![CDATA[
private static boolean isStarted() {
return Duration.ofMillis(System.currentTimeMillis() - serverStartTime).getSeconds() >= 8;
Expand Down
27 changes: 27 additions & 0 deletions archetypes/helidon/src/main/archetype/mp/common/common-mp.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,33 @@
<value>static org.hamcrest.MatcherAssert.assertThat</value>
<value>static org.hamcrest.Matchers.is</value>
</list>
<value key="main-class-javadoc"><![CDATA[
/**
* Main entry point of the application.
* <p>
* Note that this class is required when using modules as the module main class must be in a package that is either exported
* or opened by the module, see {@link java.lang.module.ModuleDescriptor#read(java.io.InputStream, java.util.function.Supplier)}.
* <p>
* This class provides a proper module main class and calls the {@link io.helidon.Main#main(String[]) built-in main class}.
*/]]></value>
<value key="main-method-javadoc"><![CDATA[
/**
* Main method. Starts CDI (and the application).
*
* @param args ignored
*/]]></value>
<list key="main-class-fields">
<value><![CDATA[
/**
* Cannot be instantiated.
*/
private Main() {
}
]]></value>
</list>
<list key="main-method-content">
<value><![CDATA[ io.helidon.Main.main(args);]]></value>
</list>
</model>
</output>
</archetype-script>

This file was deleted.

56 changes: 56 additions & 0 deletions archetypes/helidon/src/main/archetype/se/common/common-se.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,62 @@ app:
app:
greeting: "Hello"]]></value>
</list>
<value key="main-class-javadoc"><![CDATA[
/**
* The application main class.
*/]]></value>
<value key="main-method-javadoc"><![CDATA[/**
* Application main entry point.
* @param args command line arguments.
*/]]></value>
<list key="main-class-fields">
<value order="0"><![CDATA[
/**
* Cannot be instantiated.
*/
private Main() {
}
]]></value>
</list>
<list key="main-method-content">
<value template="mustache"><![CDATA[
// load logging configuration
LogConfig.configureRuntime();
{{#Main-main}}
{{.}}
{{/Main-main}}
// initialize global config from default configuration
Config config = Config.create();
Config.global(config);
WebServer server = WebServer.builder()
.config(Config.global().get("server"))
.routing(Main::routing)
.build()
.start();
System.out.println("WEB server is up! http://localhost:" + server.port() + "/simple-greet");
]]></value>
</list>
<list key="main-class-content">
<value template="mustache"><![CDATA[
/**
* Updates HTTP Routing.
*/
static void routing(HttpRouting.Builder routing) {
Config config = Config.global();
{{#Main-routing}}
{{.}}
{{/Main-routing}}
routing
{{#Main-routing-builder}}
{{.}}{{#last}}; {{/last}}
{{/Main-routing-builder}}
}]]></value>
</list>
</model>
</output>
</archetype-script>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<value><![CDATA[Tracer tracer = TracerBuilder.create("server").build();
]]></value>
</list>
<list key="Main-content" if="${tracing}">
<list key="main-class-content" if="${tracing}">
<value><![CDATA[
private static class TracedHandler implements Handler {
private final Tracer tracer;
Expand Down

0 comments on commit 0f8a570

Please sign in to comment.