Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -32,7 +33,7 @@

import io.avaje.http.generator.core.openapi.DocContext;

public class ProcessingContext {
public final class ProcessingContext {

private static final ThreadLocal<Ctx> CTX = new ThreadLocal<>();

Expand Down Expand Up @@ -202,7 +203,7 @@ public static boolean instrumentAllWebMethods() {
public static boolean useJsonb() {
try {
return CTX.get().elementUtils.getTypeElement("io.avaje.jsonb.Jsonb") != null
|| Class.forName("io.avaje.jsonb.Jsonb") != null;
|| Class.forName("io.avaje.jsonb.Jsonb") != null;
} catch (final ClassNotFoundException e) {
return false;
}
Expand Down Expand Up @@ -253,33 +254,24 @@ public static void validateModule(String fqn) {
if (module != null && !CTX.get().validated && !module.isUnnamed()) {

CTX.get().validated = true;

try (var inputStream =
CTX.get()
.filer
.getResource(StandardLocation.SOURCE_PATH, "", "module-info.java")
.toUri()
.toURL()
.openStream();
CTX.get()
.filer
.getResource(StandardLocation.SOURCE_PATH, "", "module-info.java")
.toUri()
.toURL()
.openStream();
var reader = new BufferedReader(new InputStreamReader(inputStream))) {

var noProvides =
reader
.lines()
.map(
s -> {
if (s.contains("io.avaje.http.api.javalin") && !s.contains("static")) {
logWarn(
"io.avaje.http.api.javalin only contains SOURCE retention annotations. It should added as `requires static`");
}
return s;
})
.noneMatch(s -> s.contains(fqn));
if (noProvides) {
logError(
module,
"Missing `provides io.avaje.http.client.HttpClient.GeneratedComponent with %s;`",
fqn);
var noProvides = reader.lines().map(s -> {
if (s.contains("io.avaje.http.api.javalin") && !s.contains("static")) {
logWarn("io.avaje.http.api.javalin only contains SOURCE retention annotations. It should added as `requires static`");
}
return s;
})
.noneMatch(s -> s.contains(fqn));
if (noProvides && !buildPluginAvailable()) {
logError(module, "Missing `provides io.avaje.http.client.HttpClient.GeneratedComponent with %s;`", fqn);
}
} catch (Exception e) {
// can't read module
Expand All @@ -297,4 +289,24 @@ static ModuleElement getModuleElement(Element e) {
static Elements elements() {
return CTX.get().elementUtils;
}

private static boolean buildPluginAvailable() {
return resourceExists("target/avaje-plugin-exists.txt")
|| resourceExists("build/avaje-plugin-exists.txt");
}

private static boolean resourceExists(String relativeName) {
try {
final String resource =
filer()
.getResource(StandardLocation.CLASS_OUTPUT, "", relativeName)
.toUri()
.toString()
.replaceFirst("/target/classes", "")
.replaceFirst("/build/classes/java/main", "");
return Paths.get(new URI(resource)).toFile().exists();
} catch (final Exception e) {
return false;
}
}
}