Skip to content

Commit 13cdedd

Browse files
committed
Add maven archetype
1 parent 4671acd commit 13cdedd

File tree

11 files changed

+307
-7
lines changed

11 files changed

+307
-7
lines changed

docs/asciidoc/getting-started.adoc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,31 @@ listening on:
7373

7474
Ready {love}!
7575

76-
=== Code snippets
76+
=== Maven Archetype
77+
78+
The Maven archetype creates a minimal Jooby application.
79+
80+
.Interactive type
81+
[source, bash, subs="verbatim,attributes"]
82+
----
83+
mvn archetype:generate -B -DarchetypeArtifactId=jooby-archetype -DarchetypeGroupId=io.jooby -DarchetypeVersion={joobyVersion}
84+
----
85+
86+
You'll be ask for:
87+
88+
- `groupId`: used for application package name
89+
- `artifactId`: used for application name
90+
- `version`: application version
91+
92+
Alternative you can specify all these parameters inline:
93+
94+
.Inline
95+
[source, bash, subs="verbatim,attributes"]
96+
----
97+
mvn archetype:generate -B -DgroupId=mypackage -DartifactId=my-app -Dversion=1.0.0 -DarchetypeArtifactId=jooby-archetype -DarchetypeGroupId=io.jooby -DarchetypeVersion={joobyVersion}
98+
----
99+
100+
=== Code Snippets
77101

78102
For simplicity and brevity we are going to skip the `runApp` function and extending `Jooby`.
79103
A code example will looks like:

docs/src/main/java/io/jooby/adoc/DocGenerator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,8 @@ private static void processModule(Asciidoctor asciidoctor, Path basedir, Path mo
168168
private static Options createOptions(Path basedir, Path outdir, String version, String title)
169169
throws IOException {
170170
Attributes attributes = new Attributes();
171-
attributes.setAttribute("joobyVersion", version);
172-
attributes.setAttribute("love", "♡");
173171

172+
attributes.setAttribute("love", "♡");
174173
attributes.setAttribute("docinfo", "shared");
175174
attributes.setTitle(title == null ? "jooby: do more! more easily!!" : "jooby: " + title);
176175
attributes.setTableOfContents(Placement.LEFT);
@@ -199,6 +198,8 @@ private static Options createOptions(Path basedir, Path outdir, String version,
199198
pom.select("properties > *").stream()
200199
.forEach(tag -> attributes.setAttribute(toJavaName(tag.tagName()), tag.text().trim()));
201200

201+
attributes.setAttribute("joobyVersion", version);
202+
202203
Options options = new Options();
203204
options.setBackend("html");
204205

@@ -350,10 +351,9 @@ public static Path basedir() {
350351

351352
public static String version() {
352353
try {
353-
return Jsoup.parse(basedir().getParent().resolve("pom.xml").toFile(), "utf-8")
354-
.selectFirst("version")
355-
.text()
356-
.trim();
354+
Document doc = Jsoup.parse(basedir().getParent().resolve("pom.xml").toFile(), "utf-8");
355+
String version = doc.selectFirst("version").text().trim();
356+
return version;
357357
} catch (IOException x) {
358358
throw new IllegalStateException(x);
359359
}

modules/jooby-archetype/pom.xml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4+
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>io.jooby</groupId>
9+
<artifactId>modules</artifactId>
10+
<version>2.0.6-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>jooby-archetype</artifactId>
14+
<packaging>maven-archetype</packaging>
15+
16+
<build>
17+
<resources>
18+
<resource>
19+
<directory>src/main/resources</directory>
20+
<filtering>true</filtering>
21+
<includes>
22+
<include>**/archetype-metadata.xml</include>
23+
</includes>
24+
</resource>
25+
<resource>
26+
<directory>src/main/resources</directory>
27+
</resource>
28+
</resources>
29+
30+
<extensions>
31+
<extension>
32+
<groupId>org.apache.maven.archetype</groupId>
33+
<artifactId>archetype-packaging</artifactId>
34+
<version>${archetype-packaging.version}</version>
35+
</extension>
36+
</extensions>
37+
38+
<pluginManagement>
39+
<plugins>
40+
<plugin>
41+
<artifactId>maven-archetype-plugin</artifactId>
42+
<version>${maven-archetype-plugin.version}</version>
43+
</plugin>
44+
</plugins>
45+
</pluginManagement>
46+
</build>
47+
48+
</project>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<archetype-descriptor
3+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
4+
name="jooby" xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
6+
<requiredProperties>
7+
<requiredProperty key="jooby-version">
8+
<defaultValue>${project.version}</defaultValue>
9+
</requiredProperty>
10+
</requiredProperties>
11+
12+
<fileSets>
13+
<fileSet filtered="true" packaged="true" encoding="UTF-8">
14+
<directory>src/main/java</directory>
15+
<includes>
16+
<include>**/*.java</include>
17+
</includes>
18+
</fileSet>
19+
<fileSet filtered="true" packaged="true" encoding="UTF-8">
20+
<directory>src/test/java</directory>
21+
<includes>
22+
<include>**/*.java</include>
23+
</includes>
24+
</fileSet>
25+
<fileSet filtered="true" encoding="UTF-8">
26+
<directory>conf</directory>
27+
</fileSet>
28+
</fileSets>
29+
</archetype-descriptor>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Application configuration file. See https://github.com/typesafehub/config/blob/master/HOCON.md for more details
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration scan="true" scanPeriod="15 seconds" debug="false">
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>[%d{ISO8601}]-[%thread] %-5level %logger - %msg%n</pattern>
6+
</encoder>
7+
</appender>
8+
9+
<root level="INFO">
10+
<appender-ref ref="STDOUT" />
11+
</root>
12+
</configuration>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
5+
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<artifactId>${artifactId}</artifactId>
9+
<groupId>${groupId}</groupId>
10+
<version>${version}</version>
11+
12+
<name>${artifactId}</name>
13+
14+
<properties>
15+
<!-- Startup class -->
16+
<application.class>${package}.App</application.class>
17+
18+
<jooby.version>${jooby-version}</jooby.version>
19+
20+
<maven.compiler.source>1.8</maven.compiler.source>
21+
<maven.compiler.target>1.8</maven.compiler.target>
22+
<maven.compiler.parameters>true</maven.compiler.parameters>
23+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
24+
</properties>
25+
26+
<dependencies>
27+
<!-- Server -->
28+
<dependency>
29+
<groupId>io.jooby</groupId>
30+
<artifactId>jooby-netty</artifactId>
31+
</dependency>
32+
33+
<!-- logging -->
34+
<dependency>
35+
<groupId>ch.qos.logback</groupId>
36+
<artifactId>logback-classic</artifactId>
37+
</dependency>
38+
39+
<!-- Tests -->
40+
<dependency>
41+
<groupId>org.junit.jupiter</groupId>
42+
<artifactId>junit-jupiter-api</artifactId>
43+
<scope>test</scope>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>org.junit.jupiter</groupId>
48+
<artifactId>junit-jupiter-engine</artifactId>
49+
<scope>test</scope>
50+
</dependency>
51+
52+
<dependency>
53+
<groupId>io.jooby</groupId>
54+
<artifactId>jooby-test</artifactId>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>com.squareup.okhttp3</groupId>
59+
<artifactId>okhttp</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
</dependencies>
63+
64+
<build>
65+
<plugins>
66+
<plugin>
67+
<artifactId>maven-compiler-plugin</artifactId>
68+
<version>3.6.2</version>
69+
</plugin>
70+
<plugin>
71+
<artifactId>maven-surefire-plugin</artifactId>
72+
<version>2.22.2</version>
73+
</plugin>
74+
<!-- jooby:run -->
75+
<plugin>
76+
<groupId>io.jooby</groupId>
77+
<artifactId>jooby-maven-plugin</artifactId>
78+
<version>${jooby.version}</version>
79+
</plugin>
80+
<!-- Build uber jar -->
81+
<plugin>
82+
<artifactId>maven-shade-plugin</artifactId>
83+
<version>3.2.1</version>
84+
<executions>
85+
<execution>
86+
<id>uber-jar</id>
87+
<phase>package</phase>
88+
<goals>
89+
<goal>shade</goal>
90+
</goals>
91+
<configuration>
92+
<minimizeJar>true</minimizeJar>
93+
<createDependencyReducedPom>false</createDependencyReducedPom>
94+
<transformers>
95+
<transformer
96+
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
97+
<transformer
98+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
99+
<mainClass>${application.class}</mainClass>
100+
</transformer>
101+
</transformers>
102+
</configuration>
103+
</execution>
104+
</executions>
105+
</plugin>
106+
</plugins>
107+
</build>
108+
109+
<dependencyManagement>
110+
<dependencies>
111+
<dependency>
112+
<groupId>io.jooby</groupId>
113+
<artifactId>jooby-bom</artifactId>
114+
<version>${jooby.version}</version>
115+
<type>pom</type>
116+
<scope>import</scope>
117+
</dependency>
118+
</dependencies>
119+
</dependencyManagement>
120+
</project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package ${package};
2+
3+
import io.jooby.Jooby;
4+
5+
public class App extends Jooby {
6+
7+
{
8+
get("/", ctx -> "Welcome to Jooby!");
9+
}
10+
11+
public static void main(final String[] args) {
12+
runApp(args, App::new);
13+
}
14+
15+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package ${package};
2+
3+
import io.jooby.JoobyTest;
4+
import io.jooby.StatusCode;
5+
import okhttp3.OkHttpClient;
6+
import okhttp3.Request;
7+
import okhttp3.Response;
8+
import org.junit.jupiter.api.Test;
9+
10+
import java.io.IOException;
11+
12+
import static org.junit.jupiter.api.Assertions.assertEquals;
13+
14+
@JoobyTest(App.class)
15+
public class IntegrationTest {
16+
17+
static OkHttpClient client = new OkHttpClient();
18+
19+
@Test
20+
public void welcome(int serverPort) throws IOException {
21+
Request req = new Request.Builder()
22+
.url("http://localhost:" + serverPort)
23+
.build();
24+
25+
try (Response rsp = client.newCall(req).execute()) {
26+
assertEquals("Welcome to Jooby!", rsp.body().string());
27+
assertEquals(StatusCode.OK.value(), rsp.code());
28+
}
29+
}
30+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ${package};
2+
3+
import io.jooby.MockRouter;
4+
import io.jooby.StatusCode;
5+
import org.junit.jupiter.api.Test;
6+
7+
import static org.junit.jupiter.api.Assertions.assertEquals;
8+
9+
public class UnitTest {
10+
@Test
11+
public void welcome() {
12+
MockRouter router = new MockRouter(new App());
13+
router.get("/", rsp -> {
14+
assertEquals("Welcome to Jooby!", rsp.value());
15+
assertEquals(StatusCode.OK, rsp.getStatusCode());
16+
});
17+
18+
}
19+
}

0 commit comments

Comments
 (0)