From 95dad1457fa7fea10756cf65f6d87f8979b4d7e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Guill=C3=A9n?= Date: Tue, 10 Apr 2018 17:59:28 +0200 Subject: [PATCH 1/6] Added support for Hibernate Validator 6.0.0 --- pom.xml | 4 +- .../collection/constraints/EachSafeHtml.java | 7 +++ .../collection/internal/AnnotationUtils.java | 47 +++++++++++++++++-- .../internal/ConstraintDescriptorFactory.java | 18 ++++++- .../validator/collection/TestUtils.groovy | 6 +-- .../internal/AnnotationUtilsTest.groovy | 4 +- 6 files changed, 72 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index 98cf647..109e1e7 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,7 @@ org.hibernate hibernate-validator - 5.4.1.Final + 6.0.4.Final @@ -86,7 +86,7 @@ javax.el javax.el-api - 2.2.4 + 3.0.0 provided diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachSafeHtml.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachSafeHtml.java index 3617a84..10d75ba 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachSafeHtml.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachSafeHtml.java @@ -71,4 +71,11 @@ * @since Hibernate Validator 5.1.0 */ Tag[] additionalTagsWithAttributes() default { }; + + /** + * @return Base URI used to resolve relative URIs to absolute ones. If not set, validation + * of HTML containing relative URIs will fail. + * @since Hibernate Validator 6.0.0 + */ + String baseURI() default ""; } diff --git a/src/main/java/cz/jirutka/validator/collection/internal/AnnotationUtils.java b/src/main/java/cz/jirutka/validator/collection/internal/AnnotationUtils.java index 8dce3d5..e46b10d 100644 --- a/src/main/java/cz/jirutka/validator/collection/internal/AnnotationUtils.java +++ b/src/main/java/cz/jirutka/validator/collection/internal/AnnotationUtils.java @@ -24,8 +24,6 @@ package cz.jirutka.validator.collection.internal; import org.apache.commons.lang3.Validate; -import org.hibernate.validator.internal.util.annotationfactory.AnnotationDescriptor; -import org.hibernate.validator.internal.util.annotationfactory.AnnotationFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -140,11 +138,50 @@ public static T createAnnotation(Class annotationType, "Missing required attribute: %s", m.getName()); } - AnnotationDescriptor descriptor = AnnotationDescriptor.getInstance(annotationType, attributes); - - return AnnotationFactory.create(descriptor); + return createAnnotationInternal(annotationType, attributes); } + public static T createAnnotationInternal(Class annotationType, Map attributes) { + try { + final Object descriptor; + final Class annotationDescriptorClass; + final Class annotationFactoryClass; + + int version = HibernateValidatorInfo.getVersion(); + if (version >= 6_0_0) { + annotationDescriptorClass = + Class.forName("org.hibernate.validator.internal.util.annotation.AnnotationDescriptor"); + annotationFactoryClass = + Class.forName("org.hibernate.validator.internal.util.annotation.AnnotationFactory"); + + Class annotationDescriptorBuilderClass = + Class.forName("org.hibernate.validator.internal.util.annotation.AnnotationDescriptor$Builder"); + + final Object descriptorBuilder = annotationDescriptorBuilderClass + .getConstructor(Class.class, Map.class) + .newInstance(annotationType, attributes); + + descriptor = annotationDescriptorBuilderClass + .getMethod("build") + .invoke(descriptorBuilder); + } else { + annotationDescriptorClass = + Class.forName("org.hibernate.validator.internal.util.annotationfactory.AnnotationDescriptor"); + annotationFactoryClass = + Class.forName("org.hibernate.validator.internal.util.annotationfactory.AnnotationFactory"); + + descriptor = annotationDescriptorClass + .getMethod("getInstance", Class.class, Map.class) + .invoke(null, annotationType, attributes); + } + + return (T) annotationFactoryClass + .getMethod("create", annotationDescriptorClass) + .invoke(null, descriptor); + } catch (ReflectiveOperationException ex) { + throw new IllegalStateException(ex); + } + } private static Object invokeNonArgMethod(Object object, String methodName) { Class clazz = object.getClass(); diff --git a/src/main/java/cz/jirutka/validator/collection/internal/ConstraintDescriptorFactory.java b/src/main/java/cz/jirutka/validator/collection/internal/ConstraintDescriptorFactory.java index c7e2933..a17bfe9 100644 --- a/src/main/java/cz/jirutka/validator/collection/internal/ConstraintDescriptorFactory.java +++ b/src/main/java/cz/jirutka/validator/collection/internal/ConstraintDescriptorFactory.java @@ -67,7 +67,23 @@ public static ConstraintDescriptorFactory newInstance() { int version = HibernateValidatorInfo.getVersion(); - if (version >= 5_1_0) { + if (version >= 6_0_0) { + try { + final Class descriptorClass + = Class.forName("org.hibernate.validator.internal.util.annotation.AnnotationDescriptor"); + return new ConstraintDescriptorFactory() { + Class[] getConstructorArguments() { + return new Class[]{ConstraintHelper.class, Member.class, descriptorClass, ElementType.class}; + } + ConstraintDescriptorImpl newInstance(Annotation annotation) throws ReflectiveOperationException { + final Object descriptor = descriptorClass.getConstructor(Annotation.class).newInstance(annotation); + return constructor.newInstance(CONSTRAINT_HELPER, null, descriptor, ElementType.LOCAL_VARIABLE); + } + }; + } catch (ClassNotFoundException ex) { + throw new IllegalStateException(ex); + } + } else if (version >= 5_1_0) { return new ConstraintDescriptorFactory() { Class[] getConstructorArguments() { return new Class[]{ ConstraintHelper.class, Member.class, Annotation.class, ElementType.class }; diff --git a/src/test/groovy/cz/jirutka/validator/collection/TestUtils.groovy b/src/test/groovy/cz/jirutka/validator/collection/TestUtils.groovy index 331652f..e7dce5f 100644 --- a/src/test/groovy/cz/jirutka/validator/collection/TestUtils.groovy +++ b/src/test/groovy/cz/jirutka/validator/collection/TestUtils.groovy @@ -23,8 +23,7 @@ */ package cz.jirutka.validator.collection -import org.hibernate.validator.internal.util.annotationfactory.AnnotationDescriptor -import org.hibernate.validator.internal.util.annotationfactory.AnnotationFactory +import cz.jirutka.validator.collection.internal.AnnotationUtils import javax.validation.Validation @@ -68,8 +67,7 @@ class TestUtils { } static createAnnotation(Map attributes=[:], Class annotationType) { - def desc = AnnotationDescriptor.getInstance(annotationType, attributes) - AnnotationFactory.create(desc) + AnnotationUtils.createAnnotationInternal(annotationType, attributes) } static createAnnotationString(Class annotationType, Map attributes) { diff --git a/src/test/groovy/cz/jirutka/validator/collection/internal/AnnotationUtilsTest.groovy b/src/test/groovy/cz/jirutka/validator/collection/internal/AnnotationUtilsTest.groovy index 58c1dd6..4cba5df 100644 --- a/src/test/groovy/cz/jirutka/validator/collection/internal/AnnotationUtilsTest.groovy +++ b/src/test/groovy/cz/jirutka/validator/collection/internal/AnnotationUtilsTest.groovy @@ -41,7 +41,7 @@ class AnnotationUtilsTest extends Specification { def "readAttribute: return attribute's value"() { given: def attrs = value != null ? [(name): value] : [:] - def annotation = TestUtils.createAnnotation(Size, attrs) + def annotation = createAnnotationInternal(Size, attrs) expect: readAttribute(annotation, name, reqType) == expected where: @@ -86,7 +86,7 @@ class AnnotationUtilsTest extends Specification { def 'readAllAttributes: return attributes as map'() { given: def attrs = [message: 'allons-y!', max: 10] - def annotation = TestUtils.createAnnotation(Size, attrs) + def annotation = createAnnotationInternal(Size, attrs) def expected = [groups: [], payload: [], min: 0] + attrs expect: readAllAttributes(annotation) == expected From d6a407982d5d22b32e91b90b524f75dcbdcf2d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Guill=C3=A9n?= Date: Wed, 11 Apr 2018 15:40:33 +0200 Subject: [PATCH 2/6] Added missing @Each* JSR annotations --- .../constraints/EachCodePointLength.java | 62 +++++++++++++++++++ .../collection/constraints/EachEmail.java | 4 +- .../constraints/EachFutureOrPresent.java | 54 ++++++++++++++++ .../constraints/EachMod11Check.java | 10 +-- .../collection/constraints/EachNegative.java | 54 ++++++++++++++++ .../constraints/EachNegativeOrZero.java | 54 ++++++++++++++++ .../collection/constraints/EachNotEmpty.java | 19 +++--- .../collection/constraints/EachNull.java | 54 ++++++++++++++++ .../constraints/EachPastOrPresent.java | 54 ++++++++++++++++ .../collection/constraints/EachPositive.java | 54 ++++++++++++++++ .../constraints/EachPositiveOrZero.java | 54 ++++++++++++++++ 11 files changed, 458 insertions(+), 15 deletions(-) create mode 100644 src/main/java/cz/jirutka/validator/collection/constraints/EachCodePointLength.java create mode 100644 src/main/java/cz/jirutka/validator/collection/constraints/EachFutureOrPresent.java create mode 100644 src/main/java/cz/jirutka/validator/collection/constraints/EachNegative.java create mode 100644 src/main/java/cz/jirutka/validator/collection/constraints/EachNegativeOrZero.java create mode 100644 src/main/java/cz/jirutka/validator/collection/constraints/EachNull.java create mode 100644 src/main/java/cz/jirutka/validator/collection/constraints/EachPastOrPresent.java create mode 100644 src/main/java/cz/jirutka/validator/collection/constraints/EachPositive.java create mode 100644 src/main/java/cz/jirutka/validator/collection/constraints/EachPositiveOrZero.java diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachCodePointLength.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachCodePointLength.java new file mode 100644 index 0000000..ae50d39 --- /dev/null +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachCodePointLength.java @@ -0,0 +1,62 @@ +/* + * The MIT License + * + * Copyright 2013-2014 Jakub Jirutka . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package cz.jirutka.validator.collection.constraints; + +import cz.jirutka.validator.collection.CommonEachValidator; +import org.hibernate.validator.constraints.CodePointLength; +import org.hibernate.validator.constraints.CodePointLength.NormalizationStrategy; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @since Hibernate Validator 6.0.3 + * @see CodePointLength + * @see CommonEachValidator + */ +@Documented +@Retention(RUNTIME) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) +@EachConstraint(validateAs = CodePointLength.class) +@Constraint(validatedBy = CommonEachValidator.class) +public @interface EachCodePointLength { + + String message() default ""; + + Class[] groups() default { }; + + Class[] payload() default { }; + + int min() default 0; + + int max() default Integer.MAX_VALUE; + + NormalizationStrategy normalizationStrategy() default NormalizationStrategy.NONE; +} diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachEmail.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachEmail.java index ff33ace..8c793ac 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachEmail.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachEmail.java @@ -24,10 +24,10 @@ package cz.jirutka.validator.collection.constraints; import cz.jirutka.validator.collection.CommonEachValidator; -import org.hibernate.validator.constraints.Email; import javax.validation.Constraint; import javax.validation.Payload; +import javax.validation.constraints.Email; import javax.validation.constraints.Pattern; import java.lang.annotation.Documented; import java.lang.annotation.Retention; @@ -42,7 +42,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) @EachConstraint(validateAs = Email.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachEmail { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachFutureOrPresent.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachFutureOrPresent.java new file mode 100644 index 0000000..f8479be --- /dev/null +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachFutureOrPresent.java @@ -0,0 +1,54 @@ +/* + * The MIT License + * + * Copyright 2013-2014 Jakub Jirutka . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package cz.jirutka.validator.collection.constraints; + +import cz.jirutka.validator.collection.CommonEachValidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.FutureOrPresent; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @see FutureOrPresent + * @see CommonEachValidator + */ +@Documented +@Retention(RUNTIME) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@EachConstraint(validateAs = FutureOrPresent.class) +@Constraint(validatedBy = CommonEachValidator.class) +public @interface EachFutureOrPresent { + + String message() default ""; + + Class[] groups() default { }; + + Class[] payload() default { }; +} diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachMod11Check.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachMod11Check.java index e4e1d15..6220015 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachMod11Check.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachMod11Check.java @@ -55,7 +55,8 @@ Class[] payload() default { }; /** - * @return The threshold for the Mod11 algorithm multiplier growth, if no value is specified the multiplier will grow indefinitely + * @return The threshold for the Mod11 algorithm multiplier growth, if no value is specified the multiplier will + * grow indefinitely */ int threshold() default Integer.MAX_VALUE; @@ -71,8 +72,8 @@ /** * @return The index of the check digit in the input. Per default it is assumed that the check digit is the last - * digit of the specified range. If set, the digit at the specified index is used. If set - * the following must hold true:
+ * digit of the specified range. If set, the digit at the specified index is used. If set the following must hold + * true:
* {@code checkDigitIndex > 0 && (checkDigitIndex < startIndex || checkDigitIndex >= endIndex}. */ int checkDigitIndex() default -1; @@ -96,7 +97,8 @@ char treatCheck11As() default '0'; /** - * @return Returns {@code RIGHT_TO_LEFT} if the Mod11 checksum must be done from the rightmost to the leftmost digit. + * @return Returns {@code RIGHT_TO_LEFT} if the Mod11 checksum must be done from the rightmost to the leftmost + * digit. * e.g. Code 12345-?: *
    *
  • {@code RIGHT_TO_LEFT} the sum (5*2 + 4*3 + 3*4 + 2*5 + 1*6) with check digit 5
  • diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachNegative.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachNegative.java new file mode 100644 index 0000000..f388796 --- /dev/null +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachNegative.java @@ -0,0 +1,54 @@ +/* + * The MIT License + * + * Copyright 2013-2014 Jakub Jirutka . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package cz.jirutka.validator.collection.constraints; + +import cz.jirutka.validator.collection.CommonEachValidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.Negative; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @see Negative + * @see CommonEachValidator + */ +@Documented +@Retention(RUNTIME) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@EachConstraint(validateAs = Negative.class) +@Constraint(validatedBy = CommonEachValidator.class) +public @interface EachNegative { + + String message() default ""; + + Class[] groups() default { }; + + Class[] payload() default { }; +} diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachNegativeOrZero.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachNegativeOrZero.java new file mode 100644 index 0000000..1f8e992 --- /dev/null +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachNegativeOrZero.java @@ -0,0 +1,54 @@ +/* + * The MIT License + * + * Copyright 2013-2014 Jakub Jirutka . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package cz.jirutka.validator.collection.constraints; + +import cz.jirutka.validator.collection.CommonEachValidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.NegativeOrZero; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @see NegativeOrZero + * @see CommonEachValidator + */ +@Documented +@Retention(RUNTIME) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@EachConstraint(validateAs = NegativeOrZero.class) +@Constraint(validatedBy = CommonEachValidator.class) +public @interface EachNegativeOrZero { + + String message() default ""; + + Class[] groups() default { }; + + Class[] payload() default { }; +} diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachNotEmpty.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachNotEmpty.java index e70dfde..d853b3e 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachNotEmpty.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachNotEmpty.java @@ -23,9 +23,11 @@ */ package cz.jirutka.validator.collection.constraints; +import cz.jirutka.validator.collection.CommonEachValidator; + import javax.validation.Constraint; import javax.validation.Payload; -import javax.validation.ReportAsSingleViolation; +import javax.validation.constraints.NotEmpty; import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -34,20 +36,19 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; /** - * @see org.hibernate.validator.constraints.NotEmpty + * @see NotEmpty + * @see CommonEachValidator */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE}) -@EachNotNull -@EachSize(min = 1) -@ReportAsSingleViolation -@Constraint(validatedBy = { }) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@EachConstraint(validateAs = NotEmpty.class) +@Constraint(validatedBy = CommonEachValidator.class) public @interface EachNotEmpty { String message() default "{org.hibernate.validator.constraints.NotEmpty.message}"; - Class[] groups() default { }; + Class[] groups() default {}; - Class[] payload() default { }; + Class[] payload() default {}; } diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachNull.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachNull.java new file mode 100644 index 0000000..c228849 --- /dev/null +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachNull.java @@ -0,0 +1,54 @@ +/* + * The MIT License + * + * Copyright 2013-2014 Jakub Jirutka . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package cz.jirutka.validator.collection.constraints; + +import cz.jirutka.validator.collection.CommonEachValidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.Null; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @see Null + * @see CommonEachValidator + */ +@Documented +@Retention(RUNTIME) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@EachConstraint(validateAs = Null.class) +@Constraint(validatedBy = CommonEachValidator.class) +public @interface EachNull { + + String message() default ""; + + Class[] groups() default { }; + + Class[] payload() default { }; +} diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachPastOrPresent.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachPastOrPresent.java new file mode 100644 index 0000000..ba3582b --- /dev/null +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachPastOrPresent.java @@ -0,0 +1,54 @@ +/* + * The MIT License + * + * Copyright 2013-2014 Jakub Jirutka . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package cz.jirutka.validator.collection.constraints; + +import cz.jirutka.validator.collection.CommonEachValidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.PastOrPresent; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @see PastOrPresent + * @see CommonEachValidator + */ +@Documented +@Retention(RUNTIME) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@EachConstraint(validateAs = PastOrPresent.class) +@Constraint(validatedBy = CommonEachValidator.class) +public @interface EachPastOrPresent { + + String message() default ""; + + Class[] groups() default { }; + + Class[] payload() default { }; +} diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachPositive.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachPositive.java new file mode 100644 index 0000000..0d6383f --- /dev/null +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachPositive.java @@ -0,0 +1,54 @@ +/* + * The MIT License + * + * Copyright 2013-2014 Jakub Jirutka . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package cz.jirutka.validator.collection.constraints; + +import cz.jirutka.validator.collection.CommonEachValidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.Positive; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @see Positive + * @see CommonEachValidator + */ +@Documented +@Retention(RUNTIME) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@EachConstraint(validateAs = Positive.class) +@Constraint(validatedBy = CommonEachValidator.class) +public @interface EachPositive { + + String message() default ""; + + Class[] groups() default { }; + + Class[] payload() default { }; +} diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachPositiveOrZero.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachPositiveOrZero.java new file mode 100644 index 0000000..26de97d --- /dev/null +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachPositiveOrZero.java @@ -0,0 +1,54 @@ +/* + * The MIT License + * + * Copyright 2013-2014 Jakub Jirutka . + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package cz.jirutka.validator.collection.constraints; + +import cz.jirutka.validator.collection.CommonEachValidator; + +import javax.validation.Constraint; +import javax.validation.Payload; +import javax.validation.constraints.PositiveOrZero; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * @see PositiveOrZero + * @see CommonEachValidator + */ +@Documented +@Retention(RUNTIME) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@EachConstraint(validateAs = PositiveOrZero.class) +@Constraint(validatedBy = CommonEachValidator.class) +public @interface EachPositiveOrZero { + + String message() default ""; + + Class[] groups() default { }; + + Class[] payload() default { }; +} From d36dc2a34195be2d5a380793cce82dc9df8540d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Guill=C3=A9n?= Date: Wed, 11 Apr 2018 15:47:36 +0200 Subject: [PATCH 3/6] Added tests, fixed code quality validations --- .travis.yml | 1 + pom.xml | 7 ++++ .../collection/internal/AnnotationUtils.java | 14 ++++++- .../internal/ConstraintDescriptorFactory.java | 4 +- .../collection/CommonEachValidatorIT.groovy | 8 +++- .../constraints/EachAnnotationIT.groovy | 40 ++++++++++++++----- 6 files changed, 61 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9dc31a8..f30a194 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ env: - HV_VERSION=5.2.5.Final - HV_VERSION=5.3.5.Final - HV_VERSION=5.4.1.Final + - HV_VERSION=6.0.4.Final # Cache local Maven repository cache: diff --git a/pom.xml b/pom.xml index 109e1e7..9c1c59c 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,13 @@ + + + + 2.4.15 + + + diff --git a/src/main/java/cz/jirutka/validator/collection/internal/AnnotationUtils.java b/src/main/java/cz/jirutka/validator/collection/internal/AnnotationUtils.java index e46b10d..4e9fa52 100644 --- a/src/main/java/cz/jirutka/validator/collection/internal/AnnotationUtils.java +++ b/src/main/java/cz/jirutka/validator/collection/internal/AnnotationUtils.java @@ -141,7 +141,19 @@ public static T createAnnotation(Class annotationType, return createAnnotationInternal(annotationType, attributes); } - public static T createAnnotationInternal(Class annotationType, Map attributes) { + /** + * Creates an annotation instance using the respective constructor for each HV version. + * This is required to support both version 4.3-5.X and 6.0.0 + * + * @param annotationType The annotation's class. + * @param attributes A map with attribute values for the annotation to be created. + * @param The type of the annotation. + * + * @return An instance of the annotation. + * @throws IllegalStateException if the required constructor classes or methods are not found. + */ + public static T createAnnotationInternal(Class annotationType, + Map attributes) { try { final Object descriptor; final Class annotationDescriptorClass; diff --git a/src/main/java/cz/jirutka/validator/collection/internal/ConstraintDescriptorFactory.java b/src/main/java/cz/jirutka/validator/collection/internal/ConstraintDescriptorFactory.java index a17bfe9..34192ff 100644 --- a/src/main/java/cz/jirutka/validator/collection/internal/ConstraintDescriptorFactory.java +++ b/src/main/java/cz/jirutka/validator/collection/internal/ConstraintDescriptorFactory.java @@ -76,7 +76,9 @@ Class[] getConstructorArguments() { return new Class[]{ConstraintHelper.class, Member.class, descriptorClass, ElementType.class}; } ConstraintDescriptorImpl newInstance(Annotation annotation) throws ReflectiveOperationException { - final Object descriptor = descriptorClass.getConstructor(Annotation.class).newInstance(annotation); + final Object descriptor = descriptorClass + .getConstructor(Annotation.class) + .newInstance(annotation); return constructor.newInstance(CONSTRAINT_HELPER, null, descriptor, ElementType.LOCAL_VARIABLE); } }; diff --git a/src/test/groovy/cz/jirutka/validator/collection/CommonEachValidatorIT.groovy b/src/test/groovy/cz/jirutka/validator/collection/CommonEachValidatorIT.groovy index 3c49925..bd283b2 100644 --- a/src/test/groovy/cz/jirutka/validator/collection/CommonEachValidatorIT.groovy +++ b/src/test/groovy/cz/jirutka/validator/collection/CommonEachValidatorIT.groovy @@ -35,6 +35,10 @@ import static cz.jirutka.validator.collection.TestUtils.validate @Unroll class CommonEachValidatorIT extends Specification { + static { + Locale.setDefault(new Locale("en", "US")) + } + static HV_VERSION = HibernateValidatorInfo.getVersion() def constraint = null @@ -72,7 +76,7 @@ class CommonEachValidatorIT extends Specification { given: constraint = '@EachNotNull' expect: - assertViolations values, isValid, 1, 'may not be null' + assertViolations values, isValid, 1, 'must not be null' where: values | desc || isValid ['a', null] | 'a null value' || false @@ -96,7 +100,7 @@ class CommonEachValidatorIT extends Specification { given: constraint = '@EachNotBlank' expect: - assertViolations values, isValid, invalidIndex, 'may not be empty' + assertViolations values, isValid, invalidIndex, 'must not be empty' where: values | desc || isValid | invalidIndex [''] | 'value invalid by top validator' || false | 0 diff --git a/src/test/groovy/cz/jirutka/validator/collection/constraints/EachAnnotationIT.groovy b/src/test/groovy/cz/jirutka/validator/collection/constraints/EachAnnotationIT.groovy index 1c15654..2a96197 100644 --- a/src/test/groovy/cz/jirutka/validator/collection/constraints/EachAnnotationIT.groovy +++ b/src/test/groovy/cz/jirutka/validator/collection/constraints/EachAnnotationIT.groovy @@ -26,11 +26,12 @@ package cz.jirutka.validator.collection.constraints import cz.jirutka.validator.collection.internal.HibernateValidatorInfo import org.apache.commons.lang3.ClassUtils import org.hibernate.validator.constraints.CreditCardNumber -import org.hibernate.validator.constraints.NotEmpty import org.hibernate.validator.constraints.Range import spock.lang.Specification import spock.lang.Unroll +import javax.validation.constraints.NotEmpty + import static cz.jirutka.validator.collection.TestUtils.evalClassWithConstraint import static cz.jirutka.validator.collection.TestUtils.validate @@ -41,15 +42,16 @@ class EachAnnotationIT extends Specification { // List of @Each* annotations for constraints defined in JSR 303/349. static final CONSTRAINTS_JSR = [ - EachAssertFalse, EachAssertTrue, EachDecimalMax, EachDecimalMin, - EachDigits, EachFuture, EachMax, EachMin, EachNotNull, EachPast, - EachPattern, EachSize + EachAssertFalse, EachAssertTrue, EachDecimalMax, EachDecimalMin, EachDigits, + EachEmail, EachFuture, EachFutureOrPresent, EachMax, EachMin, EachNegative, + EachNegativeOrZero, EachNotBlank, EachNotNull, EachNull, EachPast, + EachPastOrPresent, EachPattern, EachPositive, EachPositiveOrZero, EachSize ] // List of @Each* annotations for Hibernate constraints in HV 4.3.0. static final CONSTRAINTS_HV = [ - EachEmail, EachLength, EachNotBlank, EachNotEmpty, EachRange, - EachScriptAssert, EachURL + EachLength, EachNotBlank, EachNotEmpty, EachRange, EachScriptAssert, + EachURL ] // List of @Each* annotations for Hibernate constraints in HV 5.1.0 and newer. @@ -58,6 +60,11 @@ class EachAnnotationIT extends Specification { EachMod11Check, EachSafeHtml ] + // List of @Each* annotations for Hibernate constraints in HV 6.0.3 and newer. + static final CONSTRAINTS_6_0_3 = [ + EachCodePointLength + ] + // List of @Each* annotations which are only a composition of other @Each* annotations. static final COMPOSITE_CONSTRAINTS = [ EachCreditCardNumber, EachNotEmpty, EachRange @@ -112,6 +119,7 @@ class EachAnnotationIT extends Specification { constraint | attributes | validValue | invalidValue EachAssertFalse | [:] | [false, false] | [false, true] EachAssertTrue | [:] | [true, true] | [true, false] + EachCodePointLength | [min: 1, max: 2] | ['a', 'ab', 'a𝔊'] | ['abc', 'ab𝔊', 'क्तु'] EachCreditCardNumber | [:] | ['79927398713'] | ['79927398714'] EachDecimalMax | [value: '3'] | [1, 2, 3] | [2, 3, 4] EachDecimalMax | [value: '3'] | ['1', '2', '3'] | ['2', '3', '4'] @@ -121,7 +129,8 @@ class EachAnnotationIT extends Specification { EachDigits | [integer: 2, fraction: 1] | ['42.1', '13.2'] | ['42.1', '3.14'] EachEAN | [:] | ['1234567890128'] | ['1234567890128', '66'] EachEmail | [:] | ['x@y.z', 'a@b.c'] | ['x@y.z', 'ab.c'] - EachFuture | [:] | [futureDate()] | [pastDate()] + EachFuture | [:] | [futureDate()] | [pastDate(), currentDate()] + EachFutureOrPresent | [:] | [futureDate()] | [pastDate()] // currentDate() is too late for present EachLength | [min: 1, max: 3] | ['a', 'foo'] | ['a', 'allons-y!'] EachLuhnCheck | [:] | ['79927398713'] | ['79927398714'] EachMax | [value: 3L] | [1, 2, 3] | [2, 3, 4] @@ -130,13 +139,19 @@ class EachAnnotationIT extends Specification { EachMin | [value: 3L] | ['3', '4', '5'] | ['1', '2', '3'] EachMod10Check | [:] | ['123'] | ['123', '124'] EachMod11Check | [:] | ['124'] | ['124', '125'] + EachNegative | [:] | [-1, -2, -3] | [0, 1, 2] + EachNegativeOrZero | [:] | [0, -1, -2] | [1, 2, 3] EachNotBlank | [:] | ['foo', 'bar'] | ['foo', ''] EachNotEmpty | [:] | ['x', 'yz'] | ['x', ''] EachNotEmpty | [:] | [[1], [2, 3]] | [[1], []] EachNotEmpty | [:] | [[a: 1], [b: 2]] | [[a: 1], [:]] EachNotNull | [:] | ['foo', 'bar'] | ['foo', null] - EachPast | [:] | [pastDate()] | [futureDate()] + EachNull | [:] | [null, null] | ['foo', null] + EachPast | [:] | [pastDate(), currentDate()] | [futureDate()] + EachPastOrPresent | [:] | [pastDate(), currentDate()] | [futureDate()] EachPattern | [regexp: '[A-Z]+'] | ['FOO', 'BAR'] | ['FOO', '123'] + EachPositive | [:] | [1, 2, 3] | [0, -1, -2] + EachPositiveOrZero | [:] | [0, 1, 2] | [-1, -2, -3] EachRange | [min: 3L, max: 6L] | [3, 4, 5] | [6, 7, 8] EachRange | [min: 3L, max: 6L] | ['3', '4', '5'] | ['6', '7', '8'] EachSafeHtml | [:] | ['foo'] | ['WAT?'] @@ -153,7 +168,10 @@ class EachAnnotationIT extends Specification { //////// Helpers //////// static getEachConstraints() { - (CONSTRAINTS_JSR + CONSTRAINTS_HV + (HV_VERSION >= 5_1_0 ? CONSTRAINTS_5_1_0 : [])).toSet() + (CONSTRAINTS_JSR + CONSTRAINTS_HV + ( + HV_VERSION >= 6_0_3 ? CONSTRAINTS_5_1_0 + CONSTRAINTS_6_0_3 + : HV_VERSION >= 5_1_0 ? CONSTRAINTS_5_1_0 + : [])).toSet() } def attributesTypesSet(Class annotation) { @@ -166,6 +184,10 @@ class EachAnnotationIT extends Specification { new Date().plus(1) } + def currentDate() { + new Date() + } + def pastDate() { new Date().minus(1) } From 6a5d0b5d7bc07f1b0e1c75d759e88ce1ca4e51da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Guill=C3=A9n?= Date: Wed, 11 Apr 2018 16:08:14 +0200 Subject: [PATCH 4/6] Removed annotation target TYPE_USE to support Java7 --- pom.xml | 7 ------- .../validator/collection/constraints/EachEmail.java | 2 +- .../collection/constraints/EachFutureOrPresent.java | 2 +- .../validator/collection/constraints/EachNegative.java | 2 +- .../collection/constraints/EachNegativeOrZero.java | 2 +- .../validator/collection/constraints/EachNotEmpty.java | 2 +- .../jirutka/validator/collection/constraints/EachNull.java | 2 +- .../collection/constraints/EachPastOrPresent.java | 2 +- .../validator/collection/constraints/EachPositive.java | 2 +- .../collection/constraints/EachPositiveOrZero.java | 2 +- 10 files changed, 9 insertions(+), 16 deletions(-) diff --git a/pom.xml b/pom.xml index 9c1c59c..109e1e7 100644 --- a/pom.xml +++ b/pom.xml @@ -58,13 +58,6 @@ - - - - 2.4.15 - - - diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachEmail.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachEmail.java index 8c793ac..7677c97 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachEmail.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachEmail.java @@ -42,7 +42,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) @EachConstraint(validateAs = Email.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachEmail { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachFutureOrPresent.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachFutureOrPresent.java index f8479be..a99dca0 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachFutureOrPresent.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachFutureOrPresent.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) @EachConstraint(validateAs = FutureOrPresent.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachFutureOrPresent { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachNegative.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachNegative.java index f388796..d8057e4 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachNegative.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachNegative.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) @EachConstraint(validateAs = Negative.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachNegative { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachNegativeOrZero.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachNegativeOrZero.java index 1f8e992..bf00dff 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachNegativeOrZero.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachNegativeOrZero.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) @EachConstraint(validateAs = NegativeOrZero.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachNegativeOrZero { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachNotEmpty.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachNotEmpty.java index d853b3e..bfc41ba 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachNotEmpty.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachNotEmpty.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) @EachConstraint(validateAs = NotEmpty.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachNotEmpty { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachNull.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachNull.java index c228849..f13ebc6 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachNull.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachNull.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) @EachConstraint(validateAs = Null.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachNull { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachPastOrPresent.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachPastOrPresent.java index ba3582b..92c32da 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachPastOrPresent.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachPastOrPresent.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) @EachConstraint(validateAs = PastOrPresent.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachPastOrPresent { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachPositive.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachPositive.java index 0d6383f..c018c44 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachPositive.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachPositive.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) @EachConstraint(validateAs = Positive.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachPositive { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachPositiveOrZero.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachPositiveOrZero.java index 26de97d..0863e68 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachPositiveOrZero.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachPositiveOrZero.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) @EachConstraint(validateAs = PositiveOrZero.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachPositiveOrZero { From 81355c8048d6e5da4fc58db1e1f27ba8712cff53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Guill=C3=A9n?= Date: Wed, 11 Apr 2018 16:17:44 +0200 Subject: [PATCH 5/6] Revert "Removed annotation target TYPE_USE to support Java7" This reverts commit 6a5d0b5 --- pom.xml | 7 +++++++ .../validator/collection/constraints/EachEmail.java | 2 +- .../collection/constraints/EachFutureOrPresent.java | 2 +- .../validator/collection/constraints/EachNegative.java | 2 +- .../collection/constraints/EachNegativeOrZero.java | 2 +- .../validator/collection/constraints/EachNotEmpty.java | 2 +- .../jirutka/validator/collection/constraints/EachNull.java | 2 +- .../collection/constraints/EachPastOrPresent.java | 2 +- .../validator/collection/constraints/EachPositive.java | 2 +- .../collection/constraints/EachPositiveOrZero.java | 2 +- 10 files changed, 16 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 109e1e7..9c1c59c 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,13 @@ + + + + 2.4.15 + + + diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachEmail.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachEmail.java index 7677c97..8c793ac 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachEmail.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachEmail.java @@ -42,7 +42,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) @EachConstraint(validateAs = Email.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachEmail { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachFutureOrPresent.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachFutureOrPresent.java index a99dca0..f8479be 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachFutureOrPresent.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachFutureOrPresent.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) @EachConstraint(validateAs = FutureOrPresent.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachFutureOrPresent { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachNegative.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachNegative.java index d8057e4..f388796 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachNegative.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachNegative.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) @EachConstraint(validateAs = Negative.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachNegative { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachNegativeOrZero.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachNegativeOrZero.java index bf00dff..1f8e992 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachNegativeOrZero.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachNegativeOrZero.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) @EachConstraint(validateAs = NegativeOrZero.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachNegativeOrZero { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachNotEmpty.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachNotEmpty.java index bfc41ba..d853b3e 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachNotEmpty.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachNotEmpty.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) @EachConstraint(validateAs = NotEmpty.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachNotEmpty { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachNull.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachNull.java index f13ebc6..c228849 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachNull.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachNull.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) @EachConstraint(validateAs = Null.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachNull { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachPastOrPresent.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachPastOrPresent.java index 92c32da..ba3582b 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachPastOrPresent.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachPastOrPresent.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) @EachConstraint(validateAs = PastOrPresent.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachPastOrPresent { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachPositive.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachPositive.java index c018c44..0d6383f 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachPositive.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachPositive.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) @EachConstraint(validateAs = Positive.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachPositive { diff --git a/src/main/java/cz/jirutka/validator/collection/constraints/EachPositiveOrZero.java b/src/main/java/cz/jirutka/validator/collection/constraints/EachPositiveOrZero.java index 0863e68..26de97d 100644 --- a/src/main/java/cz/jirutka/validator/collection/constraints/EachPositiveOrZero.java +++ b/src/main/java/cz/jirutka/validator/collection/constraints/EachPositiveOrZero.java @@ -41,7 +41,7 @@ */ @Documented @Retention(RUNTIME) -@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER}) +@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE}) @EachConstraint(validateAs = PositiveOrZero.class) @Constraint(validatedBy = CommonEachValidator.class) public @interface EachPositiveOrZero { From 4aa1ce55fa23fb2f2c21c30f67d83c93ff2f116c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Guill=C3=A9n?= Date: Wed, 11 Apr 2018 16:19:36 +0200 Subject: [PATCH 6/6] Revert "Removed annotation target TYPE_USE to support Java7" Hibernate 6.0 requires javax.el-api 3.0 which requires Java8 This reverts commit 6a5d0b5 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f30a194..3b85ce7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ sudo: false language: java jdk: - - openjdk7 - oraclejdk8 env: global: