Skip to content

Commit

Permalink
Provide kiwi validation constraints via service loader mechanism (#1113)
Browse files Browse the repository at this point in the history
* Rename ValidationMessages.properties to
  ContributorValidationMessages.properties
* Add jakarta.validation.ConstraintValidator in META-INF/services
  which defines the services that will be loaded via service loader
* Remove the value in the validatedBy attribute of Constraint
  annotations on all kiwi custom constraints to avoid duplicate
  definitions of them.

Closes #1112
  • Loading branch information
sleberknight authored Mar 10, 2024
1 parent 5a01db1 commit 434719f
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* location such as a configuration service, so users should understand the usage risks and mitigate when possible.
*/
@Documented
@Constraint(validatedBy = {DirectoryPathValidator.class})
@Constraint(validatedBy = {})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
public @interface DirectoryPath {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/validation/FieldRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
* single day (again because there is no date component to indicate otherwise), 12:15 AM always comes before 23:56 PM.
*/
@Documented
@Constraint(validatedBy = {FieldRangeValidator.class})
@Constraint(validatedBy = {})
@Target({TYPE})
@Retention(RUNTIME)
@Repeatable(FieldRanges.class)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/validation/FilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* location such as a configuration service, so users should understand the usage risks and mitigate when possible.
*/
@Documented
@Constraint(validatedBy = {FilePathValidator.class})
@Constraint(validatedBy = {})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
public @interface FilePath {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/validation/InEnum.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* </pre>
*/
@Documented
@Constraint(validatedBy = {InEnumValidator.class})
@Constraint(validatedBy = {})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
public @interface InEnum {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/validation/IntValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* The annotated element must have a value that can be converted to a Java int or {@link Integer}.
*/
@Documented
@Constraint(validatedBy = IntValueValidator.class)
@Constraint(validatedBy = {})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
public @interface IntValue {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/validation/Ipv4Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* See <a href="https://en.wikipedia.org/wiki/IPv4">IPv4</a> on Wikipedia.
*/
@Documented
@Constraint(validatedBy = {Ipv4AddressValidator.class})
@Constraint(validatedBy = {})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
public @interface Ipv4Address {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/validation/Ipv4AndPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* range).
*/
@Documented
@Constraint(validatedBy = {Ipv4AndPortValidator.class})
@Constraint(validatedBy = {})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
public @interface Ipv4AndPort {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/validation/LongValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* The annotated element must have a value that can be converted to a Java long or {@link java.lang.Long}.
*/
@Documented
@Constraint(validatedBy = LongValueValidator.class)
@Constraint(validatedBy = {})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
public @interface LongValue {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/validation/Range.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
* therefore when the {@link RangeValidator} is instantiated.
*/
@Documented
@Constraint(validatedBy = {RangeValidator.class})
@Constraint(validatedBy = {})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
public @interface Range {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/kiwiproject/validation/Required.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* that method reflectively and use its return value to determine whether the object is empty or not.
*/
@Documented
@Constraint(validatedBy = {RequiredValidator.class})
@Constraint(validatedBy = {})
@Target({METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER, TYPE_USE})
@Retention(RUNTIME)
public @interface Required {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
org.kiwiproject.validation.DirectoryPathValidator
org.kiwiproject.validation.FieldRangeValidator
org.kiwiproject.validation.FilePathValidator
org.kiwiproject.validation.InEnumValidator
org.kiwiproject.validation.IntValueValidator
org.kiwiproject.validation.Ipv4AddressValidator
org.kiwiproject.validation.Ipv4AndPortValidator
org.kiwiproject.validation.LongValueValidator
org.kiwiproject.validation.RequiredValidator
org.kiwiproject.validation.RangeValidator

0 comments on commit 434719f

Please sign in to comment.