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

Nima Quickstart Archetype #6229

Merged
merged 2 commits into from
Feb 22, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
{{.}}
{{/run-comment}}

With JDK17+
With JDK19+
```bash
mvn package
java -jar target/{{artifactId}}.jar
java --enable-preview -jar target/{{artifactId}}.jar
```

## Exercise the application
Expand Down
7 changes: 6 additions & 1 deletion archetypes/helidon/src/main/archetype/flavor.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 Oracle and/or its affiliates.
Copyright (c) 2021, 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 Down Expand Up @@ -37,6 +37,11 @@
description="Declarative, MicroProfile compliant">
<exec src="mp/mp.xml"/>
</option>
<option value="nima"
name="Helidon Níma"
description="WebSever based on Virtual Threads">
<exec src="nima/nima.xml"/>
</option>
</enum>
</inputs>
</step>
Expand Down
70 changes: 70 additions & 0 deletions archetypes/helidon/src/main/archetype/nima/common/common-nima.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 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.
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">
<exec src="/common/common.xml"/>
<source src="/common/sources.xml"/>
<output>
<model>
<value key="mainClass">${package}.Main</value>
<value key="parent-artifactId">helidon-nima</value>
<list key="dependencies">
<map order="999">
<value key="groupId">io.helidon.nima.webserver</value>
<value key="artifactId">helidon-nima-webserver</value>
</map>
<map order="0">
<value key="groupId">org.junit.jupiter</value>
<value key="artifactId">junit-jupiter-api</value>
<value key="scope">test</value>
</map>
<map order="0">
<value key="groupId">org.hamcrest</value>
<value key="artifactId">hamcrest-all</value>
<value key="scope">test</value>
</map>
<map order="0">
<value key="groupId">io.helidon.nima.testing.junit5</value>
<value key="artifactId">helidon-nima-testing-junit5-webserver</value>
<value key="scope">test</value>
</map>
</list>
<list key="Main-helidon-imports">
<value>io.helidon.logging.common.LogConfig</value>
<value>io.helidon.nima.webserver.WebServer</value>
<value>io.helidon.nima.webserver.http.HttpRouting</value>
</list>
<list key="MainTest-helidon-imports">
<value>io.helidon.common.http.Http</value>
<value>io.helidon.nima.testing.junit5.webserver.SetUpRoute</value>
<value>io.helidon.nima.webclient.http1.Http1Client</value>
<value>io.helidon.nima.webclient.http1.Http1ClientResponse</value>
<value>io.helidon.nima.webserver.http.HttpRouting</value>
</list>
<list key="MainTest-other-imports">
<value>org.junit.jupiter.api.Test</value>
</list>
<list key="MainTest-static-imports">
<value>static org.hamcrest.MatcherAssert.assertThat</value>
<value>static org.hamcrest.Matchers.is</value>
</list>
</model>
</output>
</archetype-script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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}}

/**
* The application main class.
*/
public final class Main {

/**
* Cannot be instantiated.
*/
private Main() {
}

/**
* Application main entry point.
* @param args command line arguments.
*/
public static void main(final String[] args) {
// load logging configuration
LogConfig.configureRuntime();

WebServer server = WebServer.builder()
.routing(Main::routing)
.start();

System.out.println("WEB server is up! http://localhost:" + server.port() + "/greet");
}

/**
* Updates HTTP Routing.
*/
static void routing(HttpRouting.Builder routing) {
{{#Main-routing}}{{.}}
{{/Main-routing}}

routing{{#Main-routing-builder}}{{.}}{{#last}}; {{/last}}
{{/Main-routing-builder}}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package {{package}};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
server:
port: 8080
host: 0.0.0.0

{{#application-yaml-entries}}{{.}}
{{/application-yaml-entries}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
handlers=java.util.logging.ConsoleHandler
java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS.%1$tL %5$s%6$s%n
# Global logging level. Can be overridden by specific loggers
.level=INFO
io.helidon.nima.level=INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package {{package}};

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

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

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

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

abstract class AbstractMainTest {
private final Http1Client client;

protected AbstractMainTest(Http1Client client) {
this.client = client;
}

@SetUpRoute
static void routing(HttpRouting.Builder builder) {
Main.routing(builder);
}

{{#Abstract-tests}}{{.}}
{{/Abstract-tests}}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package {{package}};

import io.helidon.nima.testing.junit5.webserver.ServerTest;
import io.helidon.nima.webclient.http1.Http1Client;

@ServerTest
class MainIT extends AbstractMainTest {
MainIT(Http1Client client) {
super(client);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package {{package}};

import io.helidon.nima.testing.junit5.webserver.DirectClient;
import io.helidon.nima.testing.junit5.webserver.RoutingTest;

@RoutingTest
class MainTest extends AbstractMainTest {
MainTest(DirectClient client) {
super(client);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
server:
port: 8080
host: 0.0.0.0

{{#config-test}}
{{.}}
{{/config-test}}
43 changes: 43 additions & 0 deletions archetypes/helidon/src/main/archetype/nima/nima.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 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.
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="Application Type" optional="true">
<inputs>
<enum id="app-type"
name="Select an Application Type"
default="quickstart"
global="true"
optional="true">
<option value="quickstart"
name="Quickstart"
description="Sample Helidon Nima project that includes multiple REST operations">
<exec src="quickstart/quickstart-nima.xml"/>
</option>
</enum>
</inputs>
</step>
<output>
<model>
<value key="app-type">${app-type}</value>
</model>
</output>
</archetype-script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package {{package}};

import io.helidon.common.http.Http;
import io.helidon.nima.webclient.WebClient;
import io.helidon.nima.webclient.http1.Http1Client;

/**
* Executable class that invokes HTTP/1 requests against the server.
*/
public class GreetClientHttp {
private GreetClientHttp() {
}

/**
* Main method.
*
* @param args ignored
*/
public static void main(String[] args) {
Http1Client client = WebClient.builder()
.baseUri("http://localhost:8080/greet")
.build();

String response = client.method(Http.Method.GET)
.request()
.as(String.class);

System.out.println(response);

response = client.get("Nima")
.request()
.as(String.class);

System.out.println(response);
}
}
Loading