Skip to content

Commit fac8cad

Browse files
committed
Changing to aggregating type and enable by default.
1 parent d20625e commit fac8cad

File tree

3 files changed

+12
-29
lines changed

3 files changed

+12
-29
lines changed

docs/asciidoc/mvc-api.adoc

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,6 @@ To create a new MVC project open the `jooby` console and type:
6666
The <<getting-started, jooby console>> takes care of all configuration steps required by the
6767
annotation processing tool.
6868

69-
Using Gradle? You may enable incremental annotation processing support:
70-
71-
.build.gradle
72-
[source, groovy, role = "secondary", subs="verbatim,attributes"]
73-
----
74-
tasks.withType(JavaCompile) {
75-
options.compilerArgs += [
76-
'-parameters',
77-
'-Ajooby.incremental=true'
78-
]
79-
}
80-
----
81-
82-
This will cause however – due to technical a limitation – that generated classes will be loaded with reflection instead of the `ServiceLoader`.
83-
8469
=== Registration
8570

8671
Mvc routes need to be registered (no classpath scanning). Registration is done from your application

modules/jooby-apt/src/main/java/io/jooby/apt/JoobyProcessor.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class JoobyProcessor extends AbstractProcessor {
7474

7575
if (incremental) {
7676
// enables incremental annotation processing support in Gradle
77-
options.add("org.gradle.annotation.processing.isolating");
77+
options.add("org.gradle.annotation.processing.aggregating");
7878
}
7979

8080
return options;
@@ -93,7 +93,7 @@ public class JoobyProcessor extends AbstractProcessor {
9393
this.processingEnv = processingEnvironment;
9494

9595
debug = boolOpt(processingEnv, OPT_DEBUG, false);
96-
incremental = boolOpt(processingEnv, OPT_INCREMENTAL, false);
96+
incremental = boolOpt(processingEnv, OPT_INCREMENTAL, true);
9797

9898
debug("Incremental annotation processing is turned %s.", incremental ? "ON" : "OFF");
9999
}
@@ -193,7 +193,7 @@ private void build(Filer filer) throws Exception {
193193
}
194194
}
195195

196-
List<String> moduleList = new ArrayList<>();
196+
Map<TypeElement, String> modules = new LinkedHashMap<>();
197197
for (Map.Entry<TypeElement, List<HandlerCompiler>> entry : classes.entrySet()) {
198198
TypeElement type = entry.getKey();
199199
String typeName = typeUtils.erasure(type.asType()).toString();
@@ -204,14 +204,10 @@ private void build(Filer filer) throws Exception {
204204
onClass(moduleClass, moduleBin);
205205
writeClass(filer.createClassFile(moduleClass, type), moduleBin);
206206

207-
moduleList.add(moduleClass);
207+
modules.put(type, moduleClass);
208208
}
209209

210-
if (!incremental) {
211-
// writing resource files would prevent incremental annotation processing in Gradle:
212-
// https://docs.gradle.org/5.0/userguide/java_plugin.html#sec:incremental_annotation_processing
213-
doServices(filer, moduleList);
214-
}
210+
doServices(filer, modules);
215211
}
216212

217213
private String signature(ExecutableElement method) {
@@ -244,12 +240,14 @@ private void debug(String format, Object... args) {
244240
}
245241
}
246242

247-
private void doServices(Filer filer, List<String> moduleList) throws IOException {
243+
private void doServices(Filer filer, Map<TypeElement, String> modules) throws IOException {
248244
String location = "META-INF/services/" + MvcFactory.class.getName();
245+
Element[] originatingElements = modules.keySet().toArray(new Element[0]);
249246
debug("%s", location);
250-
FileObject resource = filer.createResource(StandardLocation.CLASS_OUTPUT, "", location);
247+
FileObject resource = filer.createResource(StandardLocation.CLASS_OUTPUT, "", location, originatingElements);
251248
StringBuilder content = new StringBuilder();
252-
for (String classname : moduleList) {
249+
for (Map.Entry<TypeElement, String> e : modules.entrySet()) {
250+
String classname = e.getValue();
253251
debug(" %s", classname);
254252
content.append(classname).append(System.getProperty("line.separator"));
255253
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ tasks.withType(JavaCompile) {
6969
options.compilerArgs += [
7070
'-parameters',
7171
{{#if apt}}
72-
'-Ajooby.incremental=false',
72+
'-Ajooby.incremental=true',
7373
'-Ajooby.debug=false'
7474
{{/if}}
7575
]
@@ -80,7 +80,7 @@ tasks.withType(JavaCompile) {
8080
{{#if kapt}}
8181
kapt {
8282
arguments {
83-
arg('jooby.incremental', false)
83+
arg('jooby.incremental', true)
8484
arg('jooby.debug', false)
8585
}
8686
}

0 commit comments

Comments
 (0)