Skip to content
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

Detect Inject Plugins via Module Path #182

Merged
merged 1 commit into from
Jan 10, 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
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,19 @@ static void validateModule(String fqn) {
var warnHttp = CTX.get().warnHttp;

try (var reader = getModuleInfoReader()) {
AtomicBoolean noInjectPlugin = new AtomicBoolean(injectPresent);
AtomicBoolean noHttpPlugin = new AtomicBoolean(warnHttp);

var moduleInfo = new ModuleInfoReader(module, reader);
boolean noHttpPlugin =
injectPresent && warnHttp && !moduleInfo.containsOnModulePath("io.avaje.validation.http");

boolean noInjectPlugin =
noHttpPlugin
&& injectPresent
&& !moduleInfo.containsOnModulePath("io.avaje.validation.plugin");

var noProvides =
reader
.lines()
.map(
s -> {
if (injectPresent && s.contains("io.avaje.validation.plugin")) {
noInjectPlugin.set(false);
}

if (injectPresent && warnHttp && s.contains("io.avaje.validation.http")) {
noInjectPlugin.set(false);
noHttpPlugin.set(false);
}

return s;
})
moduleInfo.provides().stream()
.flatMap(s -> s.implementations().stream())
.noneMatch(s -> s.contains(fqn));

if (noProvides) {
Expand All @@ -92,12 +87,12 @@ static void validateModule(String fqn) {
fqn);
}

if (noHttpPlugin.get()) {
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);
} else if (noInjectPlugin.get()) {
} 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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@
import javax.lang.model.util.ElementFilter;

import io.avaje.prism.GenerateAPContext;
import io.avaje.prism.GenerateModuleInfoReader;
import io.avaje.prism.GenerateUtils;

import static io.avaje.validation.generator.APContext.*;

@GenerateAPContext
@GenerateUtils
@GenerateAPContext
@GenerateModuleInfoReader
@SupportedAnnotationTypes({
AvajeValidPrism.PRISM_TYPE,
ImportValidPojoPrism.PRISM_TYPE,
Expand Down