diff --git a/governator-legacy/build.gradle b/governator-legacy/build.gradle index 4d6a3a90..d4ef479a 100644 --- a/governator-legacy/build.gradle +++ b/governator-legacy/build.gradle @@ -3,7 +3,6 @@ apply plugin: 'java' dependencies { compile project(':governator-api') compile project(':governator-core') - compile 'org.hibernate:hibernate-validator:4.1.0.Final' compile 'org.ow2.asm:asm:5.0.4' compile 'com.fasterxml.jackson.core:jackson-databind:2.4.3' diff --git a/governator-legacy/src/main/java/com/netflix/governator/lifecycle/LifecycleManager.java b/governator-legacy/src/main/java/com/netflix/governator/lifecycle/LifecycleManager.java index 5cbf33f4..df549a2e 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/lifecycle/LifecycleManager.java +++ b/governator-legacy/src/main/java/com/netflix/governator/lifecycle/LifecycleManager.java @@ -16,32 +16,27 @@ package com.netflix.governator.lifecycle; +import static com.netflix.governator.internal.BinaryConstant.I10_1024; +import static com.netflix.governator.internal.BinaryConstant.I15_32768; +import static com.netflix.governator.internal.BinaryConstant.I16_65536; + import java.io.Closeable; import java.lang.reflect.Method; import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; import javax.annotation.PostConstruct; -import javax.validation.ConstraintViolation; -import javax.validation.Path; -import javax.validation.Validation; -import javax.validation.Validator; -import javax.validation.groups.Default; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Function; -import com.google.common.base.Joiner; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Iterables; import com.google.common.collect.MapMaker; import com.google.inject.Binding; import com.google.inject.Inject; @@ -58,7 +53,6 @@ import com.netflix.governator.internal.JSR250LifecycleAction.ValidationMode; import com.netflix.governator.internal.PreDestroyLifecycleFeature; import com.netflix.governator.internal.PreDestroyMonitor; -import static com.netflix.governator.internal.BinaryConstant.*; /** * Main instance management container @@ -85,7 +79,6 @@ private enum State private final ConfigurationMapper configurationMapper; private final ResourceMapper resourceMapper; final LifecycleListener[] listeners; - private final Validator validator; private final PreDestroyMonitor preDestroyMonitor; private com.netflix.governator.LifecycleManager newLifecycleManager; @@ -112,7 +105,6 @@ public LifecycleManager(LifecycleManagerArguments arguments, Injector injector) newLifecycleManager = arguments.getLifecycleManager(); listeners = arguments.getLifecycleListeners().toArray(new LifecycleListener[0]); resourceMapper = new ResourceMapper(injector, ImmutableSet.copyOf(arguments.getResourceLocators())); - validator = Validation.buildDefaultValidatorFactory().getValidator(); configurationDocumentation = arguments.getConfigurationDocumentation(); configurationProvider = arguments.getConfigurationProvider(); } @@ -232,8 +224,6 @@ public void start() throws Exception { Preconditions.checkState(state.compareAndSet(State.LATENT, State.STARTING), "Already started"); - validate(); - new ConfigurationColumnWriter(configurationDocumentation).output(log); if (newLifecycleManager != null) { newLifecycleManager.notifyStarted(); @@ -364,85 +354,11 @@ public synchronized void close() } } - private void initializeObjectPostStart(Object obj) throws ValidationException + private void initializeObjectPostStart(Object obj) { - validate(obj); - } - - /** - * Run the validations on the managed objects. This is done automatically when {@link #start()} is called. - * But you can call this at any time you need. - * - * @throws ValidationException - */ - public void validate() throws ValidationException - { - ValidationException exception = null; - for ( Object managedInstance : objectStates.keySet() ) - { - if (managedInstance != null) { - exception = internalValidateObject(exception, managedInstance, validator); - } - } - - if ( exception != null ) - { - throw exception; - } - } - - /** - * Run validations on the given object - * - * @param obj the object to validate - * @throws ValidationException - */ - public void validate(Object obj) throws ValidationException - { - ValidationException exception = internalValidateObject(null, obj, validator); - if ( exception != null ) - { - throw exception; - } - } - private ValidationException internalValidateObject(ValidationException exception, Object obj, Validator validator) - { - Set> violations = validator.validate(obj, Default.class); - if (!violations.isEmpty()) { - for ( ConstraintViolation violation : violations ) - { - String path = getPath(violation); - String message = String.format("%s - %s.%s = %s", violation.getMessage(), obj.getClass().getName(), path, String.valueOf(violation.getInvalidValue())); - if ( exception == null ) - { - exception = new ValidationException(message); - } - else - { - exception = new ValidationException(message, exception); - } - } - } - return exception; - } - - private String getPath(ConstraintViolation violation) - { - Iterable transformed = Iterables.transform - ( - violation.getPropertyPath(), - new Function() - { - @Override - public String apply(Path.Node node) - { - return node.getName(); - } - } - ); - return Joiner.on(".").join(transformed); } + @Override public void call(Injector injector) { diff --git a/governator-legacy/src/main/java/com/netflix/governator/lifecycle/LifecycleMethods.java b/governator-legacy/src/main/java/com/netflix/governator/lifecycle/LifecycleMethods.java index ba9c72cd..160962eb 100644 --- a/governator-legacy/src/main/java/com/netflix/governator/lifecycle/LifecycleMethods.java +++ b/governator-legacy/src/main/java/com/netflix/governator/lifecycle/LifecycleMethods.java @@ -16,11 +16,11 @@ package com.netflix.governator.lifecycle; -import static com.netflix.governator.internal.BinaryConstant.*; +import static com.netflix.governator.internal.BinaryConstant.I15_32768; +import static com.netflix.governator.internal.BinaryConstant.I2_4; import static com.netflix.governator.internal.BinaryConstant.I3_8; import static com.netflix.governator.internal.BinaryConstant.I4_16; import static com.netflix.governator.internal.BinaryConstant.I5_32; -import static com.netflix.governator.internal.BinaryConstant.I9_512; import java.lang.annotation.Annotation; import java.lang.invoke.MethodHandle; @@ -33,7 +33,6 @@ import java.lang.reflect.Modifier; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -42,7 +41,6 @@ import javax.annotation.PreDestroy; import javax.annotation.Resource; import javax.annotation.Resources; -import javax.validation.Constraint; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -133,10 +131,6 @@ void addLifeCycleMethods(Class clazz, Multimap, S continue; } - if (!hasValidations) { - checkForValidations(field); - } - for (Class annotationClass : fieldAnnotations) { processField(field, annotationClass, usedNames); } @@ -192,10 +186,6 @@ private void handleReflectionError(Class clazz, Throwable e) { } } - private void checkForValidations(Field field) { - this.hasValidations =field.getAnnotationsByType(Constraint.class).length > 0; - } - private void processField(Field field, Class annotationClass, Multimap, String> usedNames) { if (field.isAnnotationPresent(annotationClass)) { diff --git a/governator-legacy/src/test/java/com/netflix/governator/lifecycle/TestLifecycleManager.java b/governator-legacy/src/test/java/com/netflix/governator/lifecycle/TestLifecycleManager.java index 2123c4cc..c5dcc267 100644 --- a/governator-legacy/src/test/java/com/netflix/governator/lifecycle/TestLifecycleManager.java +++ b/governator-legacy/src/test/java/com/netflix/governator/lifecycle/TestLifecycleManager.java @@ -18,7 +18,6 @@ import org.junit.Assert; import org.junit.Test; -import javax.validation.constraints.Min; @SuppressWarnings("UnusedDeclaration") public class TestLifecycleManager @@ -28,13 +27,11 @@ public void testValidation() throws Exception { Object goodObj = new Object() { - @Min(1) private int a = 10; }; Object badObj = new Object() { - @Min(1) private int a = 0; }; @@ -47,11 +44,11 @@ public void testValidation() throws Exception try { manager.start(); - Assert.fail(); + } catch ( ValidationException e ) { - // correct + Assert.fail(); //should no longer throw a validation exception as this feature was removed in 1.17.0 } } }