Skip to content

Commit 605fdaf

Browse files
committed
support the build plugin
1 parent 6e2d39c commit 605fdaf

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

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

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import static io.avaje.jsonb.generator.APContext.logWarn;
99

1010
import java.io.IOException;
11+
import java.net.URI;
1112
import java.util.HashMap;
1213
import java.util.List;
1314
import java.util.Map;
1415
import java.util.Optional;
15-
1616
import javax.annotation.processing.ProcessingEnvironment;
1717
import javax.lang.model.element.Element;
1818
import javax.lang.model.element.TypeElement;
@@ -76,6 +76,23 @@ static List<SubTypePrism> importedSubtypes(TypeElement type) {
7676
return CTX.get().importedSubtypeMap.getOrDefault(type.asType().toString(), List.of());
7777
}
7878

79+
private static boolean buildPluginAvailable() {
80+
try {
81+
final String resource =
82+
filer()
83+
.getResource(StandardLocation.CLASS_OUTPUT, "", "target/avaje-plugin-exists.txt")
84+
.toUri()
85+
.toString()
86+
.replace("/target/classes", "");
87+
try (var inputStream = new URI(resource).toURL().openStream()) {
88+
89+
return inputStream.available() > 0;
90+
}
91+
} catch (final Exception e) {
92+
return false;
93+
}
94+
}
95+
7996
static void validateModule(String fqn) {
8097
var module = getProjectModuleElement();
8198
if (module != null && !CTX.get().validated && !module.isUnnamed()) {
@@ -94,13 +111,17 @@ static void validateModule(String fqn) {
94111
moduleInfo.provides().stream()
95112
.flatMap(s -> s.implementations().stream())
96113
.noneMatch(s -> s.contains(fqn));
97-
98-
if (noProvides) {
114+
var buildPluginAvailable = buildPluginAvailable();
115+
if (noProvides && !buildPluginAvailable) {
99116
logError(
100117
module, "Missing `provides io.avaje.jsonb.Jsonb.GeneratedComponent with %s;`", fqn);
101118
}
102119

103-
if (noInjectPlugin) {
120+
final var noDirectJsonb =
121+
moduleInfo.requires().stream()
122+
.noneMatch(
123+
r -> r.getDependency().getQualifiedName().contentEquals("io.avaje.jsonb"));
124+
if (noInjectPlugin && (!buildPluginAvailable || noDirectJsonb)) {
104125
logWarn(
105126
module,
106127
"`requires io.avaje.jsonb.plugin` must be explicity added or else avaje-inject may fail to detect and wire the default Jsonb instance",

0 commit comments

Comments
 (0)