Skip to content

Commit 97c98a1

Browse files
committed
apt: update cli with apt support + some docs
1 parent e826cea commit 97c98a1

File tree

10 files changed

+127
-19
lines changed

10 files changed

+127
-19
lines changed

docs/asciidoc/mvc-api.adoc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
MVC API is an alternative way to define routes in Jooby. It uses annotations and byte code generation
44
to define and execute routes.
55

6-
The package `io.jooby.annotations` contains the annotations available for MVC routes.
6+
The package `io.jooby.annotations` contains all the annotations available for MVC routes.
7+
8+
Since 2.1.0, Jooby uses an annotation processing tool to convert MVC routes to script/lambda routes
9+
at compilation time. The tool reduces application startup time and eliminates the use of dynamic
10+
class loading.
711

812
.MVC API:
913
[source,java,role="primary"]
@@ -22,7 +26,7 @@ public class MyController {
2226
public class App extends Jooby {
2327
2428
{
25-
use(new MyController()); // <3>
29+
mvc(new MyController()); // <3>
2630
}
2731
2832
public static void main(String[] args) {
@@ -49,7 +53,7 @@ class MyController {
4953
5054
fun main(args: Array<String>) {
5155
runApp(args) {
52-
use(MyController()) // <3>
56+
mvc(MyController()) // <3>
5357
}
5458
}
5559
@@ -59,6 +63,13 @@ fun main(args: Array<String>) {
5963
<2> Add a HTTP method
6064
<3> Register/install the controller in the main application
6165

66+
The next section describes how to configure the annotation processing tool, but keep in mind all these
67+
can be done using the <<getting-started-cli, jooby console>>.
68+
69+
=== APT
70+
71+
==== Maven
72+
6273
=== Parameters
6374

6475
HTTP parameter provision is available via `*Param` annotations.

docs/asciidoc/usage/usage.adoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
= Help/Usage section
2+
3+
This section describes usage error and how to fix them.
4+
5+
== Annotation Processing Tool
6+
7+
=== MVC route missing
8+
9+
----
10+
Mvc route not found: `examples.PlainText`. Make sure Jooby annotation processor is configured properly.
11+
----
12+
13+
The cause of this error is generated when you try to use a MVC route and (usually) the annotation
14+
processing tool is not configured properly.
15+
16+
*Solution*
17+
18+
Configure the `jooby-apt` as part of your build.

docs/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
<artifactId>asm-util</artifactId>
3131
</dependency>
3232

33+
<dependency>
34+
<groupId>org.unbescape</groupId>
35+
<artifactId>unbescape</artifactId>
36+
</dependency>
37+
3338
<dependency>
3439
<groupId>org.asciidoctor</groupId>
3540
<artifactId>asciidoctorj</artifactId>

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Set;
3838
import java.util.UUID;
3939
import java.util.stream.Collectors;
40+
import java.util.stream.Stream;
4041

4142
public class DocGenerator {
4243
public static void main(String[] args) throws Exception {
@@ -69,11 +70,13 @@ public static void generate(Path basedir, boolean publish, boolean v1) throws Ex
6970

7071
asciidoctor.convertFile(asciidoc.resolve("index.adoc").toFile(),
7172
createOptions(asciidoc, outdir, version, null));
72-
Path modules = outdir.resolve("modules");
73-
Files.createDirectories(modules);
74-
Files.walk(asciidoc.resolve("modules")).filter(Files::isRegularFile).forEach(module -> {
75-
processModule(asciidoctor, asciidoc, module, outdir, version);
76-
});
73+
Stream.of("usage", "modules").forEach(SneakyThrows.throwingConsumer(name -> {
74+
Path modules = outdir.resolve(name);
75+
Files.createDirectories(modules);
76+
Files.walk(asciidoc.resolve(name)).filter(Files::isRegularFile).forEach(module -> {
77+
processModule(asciidoctor, asciidoc, module, outdir, name, version);
78+
});
79+
}));
7780

7881
// post process
7982
Files.walk(outdir).filter(it -> it.getFileName().toString().endsWith("index.html"))
@@ -142,18 +145,24 @@ private static void v1doc(Path basedir, Path output) throws Exception {
142145
}
143146

144147
private static void processModule(Asciidoctor asciidoctor, Path basedir, Path module, Path outdir,
145-
String version) {
148+
String name, String version) {
146149
try {
147150
String moduleName = module.getFileName().toString().replace(".adoc", "");
148151

149-
Options options = createOptions(basedir, outdir, version,
150-
moduleName.replace("-", " ") + " module");
152+
String title = moduleName.replace("-", " ");
153+
if (name.equals("modules")) {
154+
title += " module";
155+
}
156+
Options options = createOptions(basedir, outdir, version, title);
151157

152158
asciidoctor.convertFile(module.toFile(), options);
153159

154160
Path output = outdir.resolve(moduleName + ".html").toAbsolutePath();
155-
Path indexlike = output.getParent().resolve("modules").resolve(moduleName)
156-
.resolve("index.html");
161+
Path indexlike = output.getParent().resolve(name);
162+
if (name.equals("modules")) {
163+
indexlike = indexlike.resolve(moduleName);
164+
}
165+
indexlike = indexlike.resolve("index.html");
157166
Files.createDirectories(indexlike.getParent());
158167
Files.move(output, indexlike);
159168
String content = new String(Files.readAllBytes(indexlike), StandardCharsets.UTF_8)

jooby/src/main/java/io/jooby/Usage.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public Usage(@Nonnull String message, @Nonnull String id) {
3030
* @return Usage exception.
3131
*/
3232
public static @Nonnull Usage mvcRouteMissing(@Nonnull Class mvcRoute) {
33-
return new Usage("Mvc route not found: `" + mvcRoute.getName()
34-
+ "`. Make sure Jooby annotation processor is configured properly.", "mvc-route-apt");
33+
return apt("Mvc route not found: `" + mvcRoute.getName()
34+
+ "`. Make sure Jooby annotation processor is configured properly.", "mvc-route-missing");
35+
}
36+
37+
private static Usage apt(String message, String id) {
38+
return new Usage(message, "annotation-processing-tool-" + id);
3539
}
3640
}

modules/jooby-bom/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<!-- THIS FILE IS AUTO GENERATED. DON'T EDIT -->
1717

1818
<properties>
19-
<jooby.version>2.0.6</jooby.version>
19+
<jooby.version>2.0.7-SNAPSHOT</jooby.version>
2020
<HikariCP.version>3.3.1</HikariCP.version>
2121
<apt-maven-plugin.version>1.1.3</apt-maven-plugin.version>
2222
<archetype-packaging.version>2.2</archetype-packaging.version>
@@ -55,8 +55,8 @@
5555
<jdbi.version>3.9.1</jdbi.version>
5656
<jetty.version>9.4.20.v20190813</jetty.version>
5757
<jfiglet.version>0.0.8</jfiglet.version>
58-
<jooby-maven-plugin.version>2.0.6</jooby-maven-plugin.version>
59-
<jooby.version>2.0.6</jooby.version>
58+
<jooby-maven-plugin.version>2.0.7-SNAPSHOT</jooby-maven-plugin.version>
59+
<jooby.version>2.0.7-SNAPSHOT</jooby.version>
6060
<jsr305.version>3.0.2</jsr305.version>
6161
<junit.version>5.5.1</junit.version>
6262
<kotlin.version>1.3.50</kotlin.version>

modules/jooby-cli/src/main/java/io/jooby/cli/CreateCmd.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ public class CreateCmd extends Cmd {
171171
model.put("maven", !gradle);
172172
model.put("docker", docker);
173173
model.put("mvc", mvc);
174+
model.put("kapt", mvc && kotlin);
175+
model.put("apt", mvc && !kotlin);
174176
model.put("finalArtifactId", finalArtifactId);
175177

176178
ctx.writeTemplate(templateName, model, projectDir.resolve(buildFileName));

modules/jooby-cli/src/main/resources/cli/build.gradle.hbs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@ buildscript {
1111
}
1212

1313
dependencies {
14+
{{#kapt}}
15+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
16+
{{/kapt}}
1417
classpath "com.google.gradle:osdetector-gradle-plugin:1.4.0"
1518
classpath "io.spring.gradle:dependency-management-plugin:1.0.8.RELEASE"
1619
{{#if kotlin}}classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"{{/if}}
1720
classpath "io.jooby:jooby-gradle-plugin:$joobyVersion"
1821
classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
1922
}
2023
}
21-
2224
apply plugin: "io.spring.dependency-management"
2325
apply plugin: "com.google.osdetector"
2426
apply plugin: "com.github.johnrengelman.shadow"
2527
apply plugin: "application"
28+
{{#kapt}}
29+
apply plugin: "org.jetbrains.kotlin.kapt"
30+
{{/kapt}}
2631
{{#if kotlin}}apply plugin: "kotlin"{{/if}}
2732
apply plugin: "jooby"
2833

@@ -44,6 +49,11 @@ dependencyManagement {
4449
}
4550

4651
dependencies {
52+
{{#if kapt}}
53+
kapt "io.jooby:jooby-apt"
54+
{{else if apt}}
55+
annotationProcessor "io.jooby:jooby-apt"
56+
{{/if}}
4757
{{#each dependencies}}
4858
compile "{{this}}"
4959
{{/each}}

modules/jooby-cli/src/main/resources/cli/pom.xml.hbs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@
6464
<jvmTarget>${maven.compiler.target}</jvmTarget>
6565
</configuration>
6666
<executions>
67+
{{#if kapt}}
68+
<execution>
69+
<id>kapt</id>
70+
<goals>
71+
<goal>kapt</goal>
72+
</goals>
73+
<configuration>
74+
<sourceDirs>
75+
<sourceDir>src/main/kotlin</sourceDir>
76+
</sourceDirs>
77+
<annotationProcessorPaths>
78+
<annotationProcessorPath>
79+
<groupId>io.jooby</groupId>
80+
<artifactId>jooby-apt</artifactId>
81+
<version>${jooby.version}</version>
82+
</annotationProcessorPath>
83+
</annotationProcessorPaths>
84+
</configuration>
85+
</execution>
86+
{{/if}}
6787
<execution>
6888
<id>compile</id>
6989
<goals>
@@ -82,6 +102,17 @@
82102
<plugin>
83103
<artifactId>maven-compiler-plugin</artifactId>
84104
<version>3.6.2</version>
105+
{{#if apt}}
106+
<configuration>
107+
<annotationProcessorPaths>
108+
<path>
109+
<groupId>io.jooby</groupId>
110+
<artifactId>jooby-apt</artifactId>
111+
<version>${jooby.version}</version>
112+
</path>
113+
</annotationProcessorPaths>
114+
</configuration>
115+
{{/if}}
85116
</plugin>
86117
{{/if}}
87118
<plugin>

pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,24 @@
310310
<version>${jooby.version}</version>
311311
</dependency>
312312

313+
<dependency>
314+
<groupId>io.jooby</groupId>
315+
<artifactId>jooby-cli</artifactId>
316+
<version>${jooby.version}</version>
317+
</dependency>
318+
319+
<dependency>
320+
<groupId>io.jooby</groupId>
321+
<artifactId>jooby-apt</artifactId>
322+
<version>${jooby.version}</version>
323+
</dependency>
324+
325+
<dependency>
326+
<groupId>io.jooby</groupId>
327+
<artifactId>jooby-maven-plugin</artifactId>
328+
<version>${jooby.version}</version>
329+
</dependency>
330+
313331
<dependency>
314332
<groupId>io.jooby</groupId>
315333
<artifactId>jooby-gradle-plugin</artifactId>

0 commit comments

Comments
 (0)