Skip to content

Commit 8779547

Browse files
authored
Prisms 2.0 Module Validation (#468)
1 parent 7ae548d commit 8779547

File tree

3 files changed

+24
-27
lines changed

3 files changed

+24
-27
lines changed

jsonb-generator/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<name>avaje jsonb generator</name>
1212
<description>annotation processor generating source code json adapters for avaje-jsonb</description>
1313
<properties>
14-
<avaje.prisms.version>1.44</avaje.prisms.version>
14+
<avaje.prisms.version>2.0-RC1</avaje.prisms.version>
1515
</properties>
1616

1717
<licenses>

jsonb-generator/src/main/java/io/avaje/jsonb/generator/JsonbProcessor.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@
4343
import javax.tools.FileObject;
4444

4545
import io.avaje.prism.GenerateAPContext;
46-
import io.avaje.prism.GenerateModuleInfoReader;
4746
import io.avaje.prism.GenerateUtils;
4847

4948
@GenerateUtils
5049
@GenerateAPContext
51-
@GenerateModuleInfoReader
5250
@SupportedAnnotationTypes({
5351
CustomAdapterPrism.PRISM_TYPE,
5452
JSON,
@@ -115,6 +113,10 @@ private void readModule() {
115113
@Override
116114
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment round) {
117115
if (generateComponent || round.errorRaised()) {
116+
if (round.processingOver()) {
117+
ProcessingContext.validateModule();
118+
ProcessingContext.clear();
119+
}
118120
return false;
119121
}
120122
generateComponent = rounds++ > 0;
@@ -338,11 +340,8 @@ private void writeComponent(boolean processingOver) {
338340
writer.write();
339341
}
340342
writeMetaInf();
341-
ProcessingContext.validateModule();
342343
} catch (final IOException e) {
343344
logError("Error writing component", e);
344-
} finally {
345-
ProcessingContext.clear();
346345
}
347346
}
348347
}

jsonb-generator/src/main/java/io/avaje/jsonb/generator/ProcessingContext.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package io.avaje.jsonb.generator;
22

33
import static io.avaje.jsonb.generator.APContext.filer;
4-
import static io.avaje.jsonb.generator.APContext.getModuleInfoReader;
54
import static io.avaje.jsonb.generator.APContext.getProjectModuleElement;
65
import static io.avaje.jsonb.generator.APContext.jdkVersion;
76
import static io.avaje.jsonb.generator.APContext.logError;
87
import static io.avaje.jsonb.generator.APContext.logWarn;
9-
108
import java.io.BufferedReader;
119
import java.io.IOException;
1210
import java.io.InputStreamReader;
@@ -86,31 +84,31 @@ private static boolean buildPluginAvailable() {
8684

8785
static void validateModule() {
8886
var module = getProjectModuleElement();
89-
if (module != null && !module.isUnnamed()) {
90-
var injectPresent = CTX.get().injectPresent;
91-
92-
try (var reader = getModuleInfoReader()) {
93-
var moduleInfo = new ModuleInfoReader(module, reader);
9487

95-
moduleInfo.validateServices("io.avaje.jsonb.spi.JsonbExtension", CTX.get().services);
88+
var injectPresent = CTX.get().injectPresent;
9689

97-
boolean noInjectPlugin =
98-
injectPresent && !moduleInfo.containsOnModulePath("io.avaje.jsonb.plugin");
90+
APContext.moduleInfoReader()
91+
.ifPresent(
92+
moduleInfo -> {
93+
moduleInfo.validateServices("io.avaje.jsonb.spi.JsonbExtension", CTX.get().services);
9994

100-
var buildPluginAvailable = buildPluginAvailable();
95+
boolean noInjectPlugin =
96+
injectPresent && !moduleInfo.containsOnModulePath("io.avaje.jsonb.plugin");
10197

102-
final var noDirectJsonb =
103-
moduleInfo.requires().stream()
104-
.noneMatch(r -> r.getDependency().getQualifiedName().contentEquals("io.avaje.jsonb"));
98+
var buildPluginAvailable = buildPluginAvailable();
10599

106-
if (noInjectPlugin && (!buildPluginAvailable || noDirectJsonb)) {
107-
logWarn(module, "`requires io.avaje.jsonb.plugin` must be explicitly added or else avaje-inject may fail to detect and wire the default Jsonb instance");
108-
}
100+
final var noDirectJsonb =
101+
moduleInfo.requires().stream()
102+
.noneMatch(
103+
r ->
104+
r.getDependency().getQualifiedName().contentEquals("io.avaje.jsonb"));
109105

110-
} catch (Exception e) {
111-
// can't read module
112-
}
113-
}
106+
if (noInjectPlugin && (!buildPluginAvailable || noDirectJsonb)) {
107+
logWarn(
108+
module,
109+
"`requires io.avaje.jsonb.plugin` must be explicitly added or else avaje-inject may fail to detect and wire the default Jsonb instance");
110+
}
111+
});
114112
}
115113

116114
static void addJsonSpi(String spi) {

0 commit comments

Comments
 (0)