mirror of
https://github.com/jlengrand/quarkus.git
synced 2026-03-10 08:41:22 +00:00
Don't require EL
This commit is contained in:
@@ -21,10 +21,6 @@
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.web</groupId>
|
||||
<artifactId>el-impl</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jboss.graalvm</groupId>
|
||||
<artifactId>graal-annotations</artifactId>
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
package org.jboss.shamrock.beanvalidation.runtime;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.enterprise.context.ApplicationScoped;
|
||||
import javax.enterprise.inject.Produces;
|
||||
import javax.validation.Configuration;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.Validator;
|
||||
import javax.validation.ValidatorFactory;
|
||||
|
||||
import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator;
|
||||
|
||||
@ApplicationScoped
|
||||
public class ValidatorProvider {
|
||||
|
||||
@@ -14,7 +19,16 @@ public class ValidatorProvider {
|
||||
|
||||
@PostConstruct
|
||||
public void setup() {
|
||||
factory = Validation.buildDefaultValidatorFactory();
|
||||
Configuration<?> configure = Validation.byDefaultProvider().configure();
|
||||
try {
|
||||
Class<?> cl = Class.forName("javax.el.ELManager");
|
||||
Method method = cl.getDeclaredMethod("getExpressionFactory");
|
||||
method.invoke(null);
|
||||
} catch (Throwable t) {
|
||||
//if EL is not on the class path we use the parameter message interpolator
|
||||
configure.messageInterpolator(new ParameterMessageInterpolator());
|
||||
}
|
||||
factory = configure.buildValidatorFactory();
|
||||
}
|
||||
|
||||
@Produces
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.jboss.shamrock.beanvalidation.runtime.graal;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import javax.validation.MessageInterpolator;
|
||||
|
||||
import org.hibernate.validator.internal.engine.ConfigurationImpl;
|
||||
import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator;
|
||||
|
||||
import com.oracle.svm.core.annotate.Alias;
|
||||
import com.oracle.svm.core.annotate.Substitute;
|
||||
import com.oracle.svm.core.annotate.TargetClass;
|
||||
import com.oracle.svm.core.annotate.TargetElement;
|
||||
|
||||
@TargetClass(ConfigurationImpl.class)
|
||||
final class ConfigurationImplSubstitution {
|
||||
|
||||
@Alias
|
||||
private MessageInterpolator defaultMessageInterpolator;
|
||||
|
||||
@Substitute
|
||||
@TargetElement(onlyWith = ElPredicate.class)
|
||||
public final MessageInterpolator getDefaultMessageInterpolator() {
|
||||
if (defaultMessageInterpolator == null) {
|
||||
defaultMessageInterpolator = new ParameterMessageInterpolator();
|
||||
}
|
||||
|
||||
return defaultMessageInterpolator;
|
||||
}
|
||||
|
||||
@Substitute
|
||||
@TargetElement(onlyWith = ElPredicate.class)
|
||||
private MessageInterpolator getDefaultMessageInterpolatorConfiguredWithClassLoader() {
|
||||
return new ParameterMessageInterpolator();
|
||||
}
|
||||
|
||||
|
||||
static class ElPredicate implements Predicate<Class<?>> {
|
||||
|
||||
@Override
|
||||
public boolean test(Class<?> o) {
|
||||
try {
|
||||
Class.forName("com.sun.el.ExpressionFactoryImpl");
|
||||
return false;
|
||||
} catch (Throwable t) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
pom.xml
12
pom.xml
@@ -50,7 +50,6 @@
|
||||
<classmate.version>1.3.4</classmate.version>
|
||||
<javax.el-impl.version>3.0.1.b08-redhat-1</javax.el-impl.version>
|
||||
<hibernate-validator.version>6.0.7.Final</hibernate-validator.version>
|
||||
<el-impl.version>2.2</el-impl.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
@@ -373,17 +372,6 @@
|
||||
<artifactId>fakereplace</artifactId>
|
||||
<version>${fakereplace.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish</groupId>
|
||||
<artifactId>javax.el-impl</artifactId>
|
||||
<version>${javax.el-impl.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.glassfish</groupId>
|
||||
<artifactId>javax.el-api</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish</groupId>
|
||||
<artifactId>javax.json</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user