Skip to content

Commit

Permalink
add main class from helidon MP with JPMS
Browse files Browse the repository at this point in the history
Signed-off-by: tvallin <thibault.vallin@oracle.com>
  • Loading branch information
tvallin committed Jan 31, 2024
1 parent ca711ba commit 09fce31
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 108 deletions.
6 changes: 3 additions & 3 deletions archetypes/helidon/src/main/archetype/common/extra.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022, 2023 Oracle and/or its affiliates.
Copyright (c) 2022, 2024 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 Down Expand Up @@ -72,12 +72,12 @@
<value if="${flavor} == 'mp'">io.helidon.common.reactive</value>
<value if="${flavor} == 'se'">io.helidon.faulttolerance</value>
</list>
<list key="Main-helidon-imports">
<list key="Main-helidon-imports" if="${flavor} == 'se'">
<value>io.helidon.common.http.Http</value>
<value>io.helidon.faulttolerance.BulkheadException</value>
<value>io.helidon.faulttolerance.CircuitBreakerOpenException</value>
</list>
<list key="Main-other-imports">
<list key="Main-other-imports" if="${flavor} == 'se'">
<value>java.util.concurrent.TimeoutException</value>
</list>
<list key="Main-routingBuilder">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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}}
}
10 changes: 2 additions & 8 deletions archetypes/helidon/src/main/archetype/common/observability.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2022, 2023 Oracle and/or its affiliates.
Copyright (c) 2022, 2024 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 Down Expand Up @@ -66,12 +66,6 @@ curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
<value key="artifactId">helidon-microprofile-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>org.eclipse.microprofile.metrics.MetricUnits</value>
<value>org.eclipse.microprofile.metrics.annotation.Counted</value>
Expand Down Expand Up @@ -355,7 +349,7 @@ curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
<value>io.helidon.health</value>
<value if="${flavor} == 'se'">io.helidon.health.checks</value>
</list>
<list key="Main-helidon-imports">
<list key="Main-helidon-imports" if="${flavor} == 'se'">
<value>io.helidon.health.HealthSupport</value>
<value>io.helidon.health.checks.HealthChecks</value>
</list>
Expand Down
39 changes: 38 additions & 1 deletion archetypes/helidon/src/main/archetype/common/packaging.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,46 @@ kubectl delete -f app.yaml
<templates engine="mustache" transformations="mustache,packaged">
<directory>files</directory>
<includes>
<include>src/main/java/**/module-info.java.mustache</include>
<include>src/main/java/module-info.java.mustache</include>
<include if="${flavor} == 'mp'">src/**/Main.java.mustache</include>
</includes>
</templates>
<model if="${flavor} == 'mp'">
<value key="mainClass">${package}.Main</value>
<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.microprofile.cdi.Main.main(args);]]></value>
</list>
<list key="modules">
<value>io.helidon.microprofile.cdi</value>
</list>
</model>
</output>
</boolean>
</inputs>
Expand Down
93 changes: 92 additions & 1 deletion archetypes/helidon/src/main/archetype/se/common/common-se.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2021, 2022 Oracle and/or its affiliates.
Copyright (c) 2021, 2024 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 @@ -23,6 +23,12 @@
<exec src="/common/common.xml"/>
<source src="/common/sources.xml"/>
<output>
<templates engine="mustache" transformations="mustache,packaged">
<directory>/common/files</directory>
<includes>
<include>src/**/Main.java.mustache</include>
</includes>
</templates>
<model>
<value key="mainClass">${package}.Main</value>
<value key="parent-artifactId">helidon-se</value>
Expand Down Expand Up @@ -88,6 +94,91 @@
<value>io.helidon.common.http</value>
<value>io.helidon.config</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><![CDATA[ startServer();]]>
</value>
</list>
<list key="Main-class-content">
<value template="mustache"><![CDATA[
/**
* Start the server.
* @return the created {@link WebServer} instance
*/
static Single<WebServer> startServer() {
// load logging configuration
LogConfig.configureRuntime();
// By default this will pick up application.yaml from the classpath
Config config = Config.create();
WebServer server = WebServer.builder(createRouting(config))
.config(config.get("server"))
{{#Main-serverBuilder}}
{{.}}
{{/Main-serverBuilder}}
.build();
Single<WebServer> webserver = server.start();
// Try to start the server. If successful, print some info and arrange to
// print a message at shutdown. If unsuccessful, print the exception.
webserver.forSingle(ws -> {
{{Main-readyMessage}}
ws.whenShutdown().thenRun(() -> System.out.println("WEB server is DOWN. Good bye!"));
})
.exceptionallyAccept(t -> {
System.err.println("Startup failed: " + t.getMessage());
t.printStackTrace(System.err);
});
return webserver;
}
/**
* Creates new {@link Routing}.
*
* @return routing configured with JSON support, a health check, and a service
* @param config configuration of this server
*/
private static Routing createRouting(Config config) {
{{#Main-createRouting}}
{{.}}
{{/Main-createRouting}}
Routing.Builder builder = Routing.builder()
{{#Main-routingBuilder}}
{{.}}{{#last}}; {{/last}}
{{/Main-routingBuilder}}
{{#Main-security-routing-section}}
{{.}}
{{/Main-security-routing-section}}
return builder.build();
}]]>
</value>
</list>
</model>
</output>
</archetype-script>

This file was deleted.

0 comments on commit 09fce31

Please sign in to comment.