Skip to content

Write to different services path #212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ build/
.DS_Store
*.factorypath
validator-generator/.factorypath
validator-generator/io.avaje.validation.spi.ValidationExtension
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<maven.compiler.release>17</maven.compiler.release>
<inject.version>10.0-RC7</inject.version>
<http.version>2.0-RC2</http.version>
<spi.version>1.9</spi.version>
<spi.version>1.10</spi.version>
</properties>

<modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ private static final class Ctx {
private final String diAnnotation;
private final boolean warnHttp;
private final boolean injectPresent;
private final boolean spiPresent;
private boolean validated;

Ctx(ProcessingEnvironment env) {
var elements = env.getElementUtils();

this.injectPresent = elements.getTypeElement(Constants.COMPONENT) != null;
this.warnHttp = elements.getTypeElement("io.avaje.http.api.Controller") != null;
this.spiPresent = elements.getTypeElement("io.avaje.spi.internal.ServiceProcessor") != null;

final var jakarta = elements.getTypeElement(Constants.SINGLETON_JAKARTA) != null;

diAnnotation =
(injectPresent
? Constants.COMPONENT
Expand All @@ -48,9 +48,13 @@ static void init(ProcessingEnvironment processingEnv) {
}

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

return filer().createResource(StandardLocation.CLASS_OUTPUT, "", serviceFile);
}

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

if (noHttpPlugin) {
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);
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);
} else if (noInjectPlugin) {
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);
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);
}

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

private static boolean buildPluginAvailable() {

return resource("target/avaje-plugin-exists.txt", "/target/classes")
|| resource("build/avaje-plugin-exists.txt", "/build/classes/java/main");
}

private static boolean resource(String relativeName, String replace) {
try (var inputStream =
new URI(
filer()
.getResource(StandardLocation.CLASS_OUTPUT, "", relativeName)
.toUri()
.toString()
.replace(replace, ""))
.toURL()
.openStream()) {
new URI(filer().getResource(StandardLocation.CLASS_OUTPUT, "", relativeName)
.toUri()
.toString()
.replace(replace, ""))
.toURL()
.openStream()) {

return inputStream.available() > 0;
} catch (IOException | URISyntaxException e) {
Expand Down
Loading