8
8
import static io .avaje .jsonb .generator .APContext .logWarn ;
9
9
10
10
import java .io .IOException ;
11
+ import java .net .URI ;
11
12
import java .util .HashMap ;
12
13
import java .util .List ;
13
14
import java .util .Map ;
14
15
import java .util .Optional ;
15
-
16
16
import javax .annotation .processing .ProcessingEnvironment ;
17
17
import javax .lang .model .element .Element ;
18
18
import javax .lang .model .element .TypeElement ;
@@ -76,6 +76,23 @@ static List<SubTypePrism> importedSubtypes(TypeElement type) {
76
76
return CTX .get ().importedSubtypeMap .getOrDefault (type .asType ().toString (), List .of ());
77
77
}
78
78
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
+
79
96
static void validateModule (String fqn ) {
80
97
var module = getProjectModuleElement ();
81
98
if (module != null && !CTX .get ().validated && !module .isUnnamed ()) {
@@ -94,13 +111,17 @@ static void validateModule(String fqn) {
94
111
moduleInfo .provides ().stream ()
95
112
.flatMap (s -> s .implementations ().stream ())
96
113
.noneMatch (s -> s .contains (fqn ));
97
-
98
- if (noProvides ) {
114
+ var buildPluginAvailable = buildPluginAvailable ();
115
+ if (noProvides && ! buildPluginAvailable ) {
99
116
logError (
100
117
module , "Missing `provides io.avaje.jsonb.Jsonb.GeneratedComponent with %s;`" , fqn );
101
118
}
102
119
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 )) {
104
125
logWarn (
105
126
module ,
106
127
"`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