Skip to content

Commit 339bf46

Browse files
SentryManrbygrave
andauthored
Write to different services path (#212)
* write to different services path * remove hard spi dependency * Format only change --------- Co-authored-by: Rob Bygrave <[email protected]>
1 parent 5a41aaa commit 339bf46

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ build/
1010
.DS_Store
1111
*.factorypath
1212
validator-generator/.factorypath
13+
validator-generator/io.avaje.validation.spi.ValidationExtension

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<maven.compiler.release>17</maven.compiler.release>
3030
<inject.version>10.0-RC7</inject.version>
3131
<http.version>2.0-RC2</http.version>
32-
<spi.version>1.9</spi.version>
32+
<spi.version>1.10</spi.version>
3333
</properties>
3434

3535
<modules>

validator-generator/src/main/java/io/avaje/validation/generator/ProcessingContext.java

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ private static final class Ctx {
2323
private final String diAnnotation;
2424
private final boolean warnHttp;
2525
private final boolean injectPresent;
26+
private final boolean spiPresent;
2627
private boolean validated;
2728

2829
Ctx(ProcessingEnvironment env) {
2930
var elements = env.getElementUtils();
30-
3131
this.injectPresent = elements.getTypeElement(Constants.COMPONENT) != null;
3232
this.warnHttp = elements.getTypeElement("io.avaje.http.api.Controller") != null;
33+
this.spiPresent = elements.getTypeElement("io.avaje.spi.internal.ServiceProcessor") != null;
3334

3435
final var jakarta = elements.getTypeElement(Constants.SINGLETON_JAKARTA) != null;
35-
3636
diAnnotation =
3737
(injectPresent
3838
? Constants.COMPONENT
@@ -48,9 +48,13 @@ static void init(ProcessingEnvironment processingEnv) {
4848
}
4949

5050
static FileObject createMetaInfWriterFor(String interfaceType) throws IOException {
51-
return filer().createResource(StandardLocation.CLASS_OUTPUT, "", interfaceType);
52-
}
51+
var serviceFile =
52+
CTX.get().spiPresent
53+
? interfaceType.replace("META-INF/services/", "META-INF/generated-services/")
54+
: interfaceType;
5355

56+
return filer().createResource(StandardLocation.CLASS_OUTPUT, "", serviceFile);
57+
}
5458

5559
static String diAnnotation() {
5660
return CTX.get().diAnnotation;
@@ -86,15 +90,9 @@ static void validateModule(String fqn) {
8690
&& !moduleInfo.containsOnModulePath("io.avaje.validation.plugin");
8791

8892
if (noHttpPlugin) {
89-
logWarn(
90-
module,
91-
"`requires io.avaje.validation.http` must be explicity added or else avaje-inject may fail to detect the default http validator, validator, and method AOP validator",
92-
fqn);
93+
logWarn(module, "`requires io.avaje.validation.http` must be explicity added or else avaje-inject may fail to detect the default http validator, validator, and method AOP validator", fqn);
9394
} else if (noInjectPlugin) {
94-
logWarn(
95-
module,
96-
"`requires io.avaje.validation.plugin` must be explicity added or else avaje-inject may fail to detect the default validator and method AOP validator",
97-
fqn);
95+
logWarn(module, "`requires io.avaje.validation.plugin` must be explicity added or else avaje-inject may fail to detect the default validator and method AOP validator", fqn);
9896
}
9997

10098
} catch (Exception e) {
@@ -104,21 +102,18 @@ static void validateModule(String fqn) {
104102
}
105103

106104
private static boolean buildPluginAvailable() {
107-
108105
return resource("target/avaje-plugin-exists.txt", "/target/classes")
109106
|| resource("build/avaje-plugin-exists.txt", "/build/classes/java/main");
110107
}
111108

112109
private static boolean resource(String relativeName, String replace) {
113110
try (var inputStream =
114-
new URI(
115-
filer()
116-
.getResource(StandardLocation.CLASS_OUTPUT, "", relativeName)
117-
.toUri()
118-
.toString()
119-
.replace(replace, ""))
120-
.toURL()
121-
.openStream()) {
111+
new URI(filer().getResource(StandardLocation.CLASS_OUTPUT, "", relativeName)
112+
.toUri()
113+
.toString()
114+
.replace(replace, ""))
115+
.toURL()
116+
.openStream()) {
122117

123118
return inputStream.available() > 0;
124119
} catch (IOException | URISyntaxException e) {

0 commit comments

Comments
 (0)