5
5
import static io .avaje .validation .generator .APContext .getProjectModuleElement ;
6
6
import static io .avaje .validation .generator .APContext .logError ;
7
7
import static io .avaje .validation .generator .APContext .logWarn ;
8
+ import static java .util .stream .Collectors .toSet ;
8
9
9
10
import java .io .IOException ;
10
- import java .util . concurrent . atomic . AtomicBoolean ;
11
-
11
+ import java .net . URI ;
12
+ import java . net . URISyntaxException ;
12
13
import javax .annotation .processing .ProcessingEnvironment ;
13
- import javax .lang .model .element .Element ;
14
- import javax .lang .model .element .ModuleElement ;
15
14
import javax .tools .FileObject ;
16
15
import javax .tools .StandardLocation ;
17
16
17
+ import io .avaje .validation .generator .ModuleInfoReader .Requires ;
18
+
18
19
final class ProcessingContext {
19
20
20
21
private static final ThreadLocal <Ctx > CTX = new ThreadLocal <>();
@@ -65,22 +66,32 @@ static void validateModule(String fqn) {
65
66
var warnHttp = CTX .get ().warnHttp ;
66
67
67
68
try (var reader = getModuleInfoReader ()) {
68
-
69
69
var moduleInfo = new ModuleInfoReader (module , reader );
70
+ var buildPluginAvailable = buildPluginAvailable ();
71
+ var requireSet =
72
+ moduleInfo .requires ().stream ()
73
+ .map (Requires ::getDependency )
74
+ .map (m -> m .getQualifiedName ().toString ())
75
+ .collect (toSet ());
76
+
70
77
boolean noHttpPlugin =
71
- injectPresent && warnHttp && !moduleInfo .containsOnModulePath ("io.avaje.validation.http" );
78
+ injectPresent
79
+ && (!buildPluginAvailable || !requireSet .contains ("io.avaje.http.api" ))
80
+ && warnHttp
81
+ && !moduleInfo .containsOnModulePath ("io.avaje.validation.http" );
72
82
73
83
boolean noInjectPlugin =
74
84
noHttpPlugin
75
85
&& injectPresent
86
+ && (!buildPluginAvailable || !requireSet .contains ("io.avaje.validation" ))
76
87
&& !moduleInfo .containsOnModulePath ("io.avaje.validation.plugin" );
77
88
78
89
var noProvides =
79
90
moduleInfo .provides ().stream ()
80
91
.flatMap (s -> s .implementations ().stream ())
81
92
.noneMatch (s -> s .contains (fqn ));
82
93
83
- if (noProvides ) {
94
+ if (! buildPluginAvailable && noProvides ) {
84
95
logError (
85
96
module ,
86
97
"Missing `provides io.avaje.validation.Validator.GeneratedComponent with %s;`" ,
@@ -105,11 +116,27 @@ static void validateModule(String fqn) {
105
116
}
106
117
}
107
118
108
- static ModuleElement getModuleElement (Element e ) {
109
- if (e == null || e instanceof ModuleElement ) {
110
- return (ModuleElement ) e ;
119
+ private static boolean buildPluginAvailable () {
120
+
121
+ return resource ("target/avaje-plugin-exists.txt" , "/target/classes" )
122
+ || resource ("build/avaje-plugin-exists.txt" , "/build/classes/java/main" );
123
+ }
124
+
125
+ private static boolean resource (String relativeName , String replace ) {
126
+ try (var inputStream =
127
+ new URI (
128
+ filer ()
129
+ .getResource (StandardLocation .CLASS_OUTPUT , "" , relativeName )
130
+ .toUri ()
131
+ .toString ()
132
+ .replace (replace , "" ))
133
+ .toURL ()
134
+ .openStream ()) {
135
+
136
+ return inputStream .available () > 0 ;
137
+ } catch (IOException | URISyntaxException e ) {
138
+ return false ;
111
139
}
112
- return getModuleElement (e .getEnclosingElement ());
113
140
}
114
141
115
142
static void clear () {
0 commit comments