44import java .io .IOException ;
55import java .io .InputStreamReader ;
66import java .net .URI ;
7+ import java .nio .file .Paths ;
78import java .util .Collection ;
89import java .util .List ;
910import java .util .Objects ;
3233
3334import io .avaje .http .generator .core .openapi .DocContext ;
3435
35- public class ProcessingContext {
36+ public final class ProcessingContext {
3637
3738 private static final ThreadLocal <Ctx > CTX = new ThreadLocal <>();
3839
@@ -202,7 +203,7 @@ public static boolean instrumentAllWebMethods() {
202203 public static boolean useJsonb () {
203204 try {
204205 return CTX .get ().elementUtils .getTypeElement ("io.avaje.jsonb.Jsonb" ) != null
205- || Class .forName ("io.avaje.jsonb.Jsonb" ) != null ;
206+ || Class .forName ("io.avaje.jsonb.Jsonb" ) != null ;
206207 } catch (final ClassNotFoundException e ) {
207208 return false ;
208209 }
@@ -253,33 +254,24 @@ public static void validateModule(String fqn) {
253254 if (module != null && !CTX .get ().validated && !module .isUnnamed ()) {
254255
255256 CTX .get ().validated = true ;
256-
257257 try (var inputStream =
258- CTX .get ()
259- .filer
260- .getResource (StandardLocation .SOURCE_PATH , "" , "module-info.java" )
261- .toUri ()
262- .toURL ()
263- .openStream ();
258+ CTX .get ()
259+ .filer
260+ .getResource (StandardLocation .SOURCE_PATH , "" , "module-info.java" )
261+ .toUri ()
262+ .toURL ()
263+ .openStream ();
264264 var reader = new BufferedReader (new InputStreamReader (inputStream ))) {
265265
266- var noProvides =
267- reader
268- .lines ()
269- .map (
270- s -> {
271- if (s .contains ("io.avaje.http.api.javalin" ) && !s .contains ("static" )) {
272- logWarn (
273- "io.avaje.http.api.javalin only contains SOURCE retention annotations. It should added as `requires static`" );
274- }
275- return s ;
276- })
277- .noneMatch (s -> s .contains (fqn ));
278- if (noProvides ) {
279- logError (
280- module ,
281- "Missing `provides io.avaje.http.client.HttpClient.GeneratedComponent with %s;`" ,
282- fqn );
266+ var noProvides = reader .lines ().map (s -> {
267+ if (s .contains ("io.avaje.http.api.javalin" ) && !s .contains ("static" )) {
268+ logWarn ("io.avaje.http.api.javalin only contains SOURCE retention annotations. It should added as `requires static`" );
269+ }
270+ return s ;
271+ })
272+ .noneMatch (s -> s .contains (fqn ));
273+ if (noProvides && !buildPluginAvailable ()) {
274+ logError (module , "Missing `provides io.avaje.http.client.HttpClient.GeneratedComponent with %s;`" , fqn );
283275 }
284276 } catch (Exception e ) {
285277 // can't read module
@@ -297,4 +289,24 @@ static ModuleElement getModuleElement(Element e) {
297289 static Elements elements () {
298290 return CTX .get ().elementUtils ;
299291 }
292+
293+ private static boolean buildPluginAvailable () {
294+ return resourceExists ("target/avaje-plugin-exists.txt" )
295+ || resourceExists ("build/avaje-plugin-exists.txt" );
296+ }
297+
298+ private static boolean resourceExists (String relativeName ) {
299+ try {
300+ final String resource =
301+ filer ()
302+ .getResource (StandardLocation .CLASS_OUTPUT , "" , relativeName )
303+ .toUri ()
304+ .toString ()
305+ .replaceFirst ("/target/classes" , "" )
306+ .replaceFirst ("/build/classes/java/main" , "" );
307+ return Paths .get (new URI (resource )).toFile ().exists ();
308+ } catch (final Exception e ) {
309+ return false ;
310+ }
311+ }
300312}
0 commit comments