From 8db32e3acc63c4f6d324f04e927900ad7a9cd4a2 Mon Sep 17 00:00:00 2001 From: Josiah Noel <32279667+SentryMan@users.noreply.github.com> Date: Sun, 26 May 2024 14:38:48 -0400 Subject: [PATCH] remove hard dependency on http-api --- .../validation/http/HttpValidatorProvider.java | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/validator-http-plugin/src/main/java/io/avaje/validation/http/HttpValidatorProvider.java b/validator-http-plugin/src/main/java/io/avaje/validation/http/HttpValidatorProvider.java index 5bb5ca45..a922001d 100644 --- a/validator-http-plugin/src/main/java/io/avaje/validation/http/HttpValidatorProvider.java +++ b/validator-http-plugin/src/main/java/io/avaje/validation/http/HttpValidatorProvider.java @@ -4,23 +4,35 @@ import java.util.Arrays; import java.util.Locale; -import io.avaje.http.api.Validator; import io.avaje.inject.BeanScopeBuilder; /** Plugin for avaje inject that provides a default Http Validator instance. */ public final class HttpValidatorProvider implements io.avaje.inject.spi.Plugin { + private static final Class VALIDATOR_HTTP_CLASS = httpOnCp(); + + private static Class httpOnCp() { + try { + return Class.forName("io.avaje.http.api.Validator"); + } catch (ClassNotFoundException e) { + return null; + } + } + @Override public Class[] provides() { - return new Class[] {Validator.class}; + return VALIDATOR_HTTP_CLASS == null ? new Class[] {} : new Class[] {VALIDATOR_HTTP_CLASS}; } @Override public void apply(BeanScopeBuilder builder) { + if (VALIDATOR_HTTP_CLASS == null) { + return; + } builder.provideDefault( null, - Validator.class, + VALIDATOR_HTTP_CLASS, () -> { final var props = builder.propertyPlugin();