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

New application types (templates) for the CLI #1797

Merged
merged 3 commits into from
May 18, 2020
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
30 changes: 30 additions & 0 deletions archetypes/mp/basic/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2020 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.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.helidon.archetypes</groupId>
<artifactId>helidon-archetypes-mp</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>helidon-archetypes-mp-basic</artifactId>
<name>Helidon Template Application MP basic</name>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pom.xml.mustache
src/main/java/__pkg__/GreetResource.java.mustache
src/main/java/__pkg__/package-info.java.mustache
src/main/resources/META-INF/beans.xml
src/main/resources/META-INF/microprofile-config.properties
src/main/resources/logging.properties
src/main/resources/native-image/reflect-config.json
src/test/java/__pkg__/MainTest.java.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved.

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-descriptor>
<properties>
<property id="gradle" description="Gradle based project"/>
<property id="maven" description="Maven based project"/>
<property id="groupId" description="Project groupId"/>
<property id="artifactId" description="Project artifactId"/>
<property id="version" description="Project version" default="1.0-SNAPSHOT"/>
<property id="name" description="Project name"/>
<property id="package" description="Java package name"/>
<property id="helidonVersion" description="Version of Helidon to use"/>
</properties>
<transformations>
<transformation id="packaged">
<replace regex="__pkg__" replacement="${package/\./\/}"/>
</transformation>
<transformation id="mustache">
<replace regex="\.mustache$" replacement=""/>
</transformation>
</transformations>
<template-sets transformations="mustache">
<template-set transformations="packaged">
<directory>src/main/java</directory>
<includes>
<include>**/*.mustache</include>
</includes>
</template-set>
<template-set transformations="packaged">
<directory>src/test/java</directory>
<includes>
<include>**/*.mustache</include>
</includes>
</template-set>
<template-set if="gradle">
<directory>.</directory>
<includes>
<include>build.gradle.mustache</include>
</includes>
</template-set>
<template-set if="maven">
<directory>.</directory>
<includes>
<include>pom.xml.mustache</include>
</includes>
</template-set>
</template-sets>
<file-sets>
<file-set transformations="packaged">
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.mustache</exclude>
</excludes>
</file-set>
<file-set>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
</file-set>
<file-set transformations="packaged">
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.mustache</exclude>
</excludes>
</file-set>
<file-set>
<directory>src/test/resources</directory>
<excludes>
<exclude>**/*</exclude>
</excludes>
</file-set>
</file-sets>
<input-flow>
<input property="name" text="Project name" default="${name}"/>
<input property="groupId" text="Project groupId" if="maven" default="${groupId}"/>
<input property="artifactId" text="Project artifactId" default="${artifactId}"/>
<input property="version" text="Project version" default="${version}"/>
<input property="package" text="Java package name" default="${package}"/>
</input-flow>
</archetype-descriptor>
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#set( $symbol_dollar = '$' )
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -7,19 +6,12 @@
<parent>
<groupId>io.helidon.applications</groupId>
<artifactId>helidon-mp</artifactId>
<version>@project.version@</version>
<relativePath/>
<version>{{helidonVersion}}</version>
</parent>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
<name>${artifactId}</name>

<properties>
#if( $mainClass.matches("y|yes|true") )
<mainClass>${package}.Main</mainClass>
#end
</properties>
<groupId>{{groupId}}</groupId>
<artifactId>{{artifactId}}</artifactId>
<version>{{version}}</version>
<name>{{name}}</name>

<dependencies>
<dependency>
Expand All @@ -32,16 +24,18 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>
#if( $unitTest.matches("y|yes|true") )
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
#end
</dependencies>


<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@

package {{package}};

import java.util.Collections;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.json.Json;
import javax.json.JsonBuilderFactory;
import javax.json.JsonObject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.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/greet
*
* The message is returned as a JSON object.
*/
@Path("/greet")
public class GreetResource {
private static final JsonBuilderFactory JSON = Json.createBuilderFactory(Collections.emptyMap());

private final String message;

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

/**
* Return a wordly greeting message.
*
* @return {@link JsonObject}
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject getDefaultMessage() {
String msg = String.format("%s %s!", message, "World");
return JSON.createObjectBuilder()
.add("message", msg)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

package {{package}};
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Application properties. This is the default greeting
app.greeting=Hello

# Microprofile server properties
server.port=8080
server.host=0.0.0.0
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Example Logging Configuration File
# For more information see $JAVA_HOME/jre/lib/logging.properties

Expand All @@ -14,9 +15,5 @@ java.util.logging.SimpleFormatter.format=%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS %4$
#io.helidon.webserver.level=INFO
#io.helidon.config.level=INFO
#io.helidon.security.level=INFO
#io.helidon.microprofile.level=INFO
#io.helidon.common.level=INFO
#io.netty.level=INFO
#org.glassfish.jersey.level=INFO
#org.jboss.weld=INFO

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

package {{package}};

import javax.enterprise.inject.se.SeContainer;
import javax.enterprise.inject.spi.CDI;
import javax.json.JsonObject;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;

import javax.ws.rs.core.Response;

import io.helidon.microprofile.server.Server;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

class MainTest {

private static Server server;

@BeforeAll
public static void startTheServer() {
server = Server.create().start();
}

@Test
void testHelloWorld() {
Client client = ClientBuilder.newClient();

JsonObject jsonObject = client
.target(getConnectionString("/greet"))
.request()
.get(JsonObject.class);
Assertions.assertEquals("Hello World!", jsonObject.getString("message"),
"default message");

Response r = client
.target(getConnectionString("/metrics"))
.request()
.get();
Assertions.assertEquals(200, r.getStatus(), "GET metrics status code");

r = client
.target(getConnectionString("/health"))
.request()
.get();
Assertions.assertEquals(200, r.getStatus(), "GET health status code");
}

@AfterAll
static void destroyClass() {
CDI<Object> current = CDI.current();
((SeContainer) current).close();
}

private String getConnectionString(String path) {
return "http://localhost:" + server.port() + path;
}
}
24 changes: 10 additions & 14 deletions archetypes/mp/pom.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2020 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 @@ -16,24 +16,20 @@
limitations under the License.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.helidon.archetypes</groupId>
<artifactId>helidon-archetypes-project</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>helidon-mp</artifactId>
<packaging>maven-archetype</packaging>
<name>Helidon MP Archetype</name>
<description>Archetype to generate a basic Helidon MP application</description>
<artifactId>helidon-archetypes-mp</artifactId>
<name>Helidon Template Application Types for MP</name>
<packaging>pom</packaging>

<build>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
</extension>
</extensions>
</build>
<modules>
<module>basic</module>
</modules>
</project>
Loading