Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dont-stop-validatio…
Browse files Browse the repository at this point in the history
…n-after-first-invalid-field-found
  • Loading branch information
yasuyuki-baba-2 committed May 18, 2017
2 parents 049cbb6 + df45b07 commit 6bf1aa3
Show file tree
Hide file tree
Showing 11 changed files with 231 additions and 169 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# http://editorconfig.org
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.yml]
indent_size = 2

[script/*]
indent_size = 4
indent_style = tab
13 changes: 13 additions & 0 deletions .maven-bintray.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">

<servers>
<server>
<id>jfrog-oss-snapshot-local</id>
<username>jirutka</username>
<password>${env.BINTRAY_API_KEY}</password>
</server>
</servers>
</settings>
37 changes: 28 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
language: java
sudo: false
language: java
jdk:
- openjdk7
- oraclejdk8
env:
- HV_VERSION=4.3.1.Final
- HV_VERSION=5.0.3.Final
- HV_VERSION=5.1.3.Final
- HV_VERSION=5.2.1.Final
script:
- "mvn verify -B -Ptest-different-hv-version -Dhibernate-validator.version.test=${HV_VERSION}"
after_success:
- mvn jacoco:report coveralls:jacoco
global:
secure: "KncKGamS99AWFQNs2L4a3s65BdNvP07yD/fulNZA+tsBNVLgxsieXkRdzrA5Efxbd5PvnBJuLkYgjPFSFh4uPNwijH5PnZMsSYlnSFIbLyGAIkWx2cJeUoDXOOrbHIeRmCDS6gZjs9sUZHrVlhF9B/19txf4XUjpd/6slqdsEng=" # BINTRAY_API_KEY
matrix:
- HV_VERSION=4.3.2.Final
- HV_VERSION=5.0.3.Final DEPLOY=yes
- HV_VERSION=5.1.3.Final
- HV_VERSION=5.2.5.Final
- HV_VERSION=5.3.5.Final
- HV_VERSION=5.4.1.Final

# Cache local Maven repository
cache:
directories:
- $HOME/.m2
before_cache:
- rm -Rf ~/.m2/repository/cz/jirutka/validator/validator-collection

install:
- mvn install -Ptest-different-hv-version -Dhv.version.test=${HV_VERSION} -DskipTests=true --batch-mode
script:
- mvn verify -Ptest-different-hv-version -Dhv.version.test=${HV_VERSION} --batch-mode
after_success:
- mvn jacoco:report coveralls:report

deploy:
provider: script
script: script/travis-deploy
skip_cleanup: true
on:
branch: master
jdk: oraclejdk8
condition: "$DEPLOY = yes"
125 changes: 125 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
= Bean Validation / Collection Validators
:source-language: java
:name: validator-collection
:version: 2.2.0
:artifact-id: {name}
:group-id: cz.jirutka.validator
:gh-name: jirutka/{name}
:gh-branch: master
:codacy-id: b77fcc2a16794c49a64ac0727ec274f7

ifdef::env-github[]
image:https://travis-ci.org/{gh-name}.svg?branch={gh-branch}[Build Status, link="https://travis-ci.org/{gh-name}"]
image:https://coveralls.io/repos/github/{gh-name}/badge.svg?branch={gh-branch}[Coverage Status, link="https://coveralls.io/github/{gh-name}"]
image:https://api.codacy.com/project/badge/grade/{codacy-id}[Code quality, link="https://www.codacy.com/app/{gh-name}"]
image:https://maven-badges.herokuapp.com/maven-central/{group-id}/{artifact-id}/badge.svg[Maven Central, link="https://maven-badges.herokuapp.com/maven-central/{group-id}/{artifact-id}"]
endif::env-github[]


Neither http://beanvalidation.org/1.1/spec/[Bean Validation 1.1] (JSR 303/349) nor http://hibernate.org/validator/[Hibernate Validator], the reference _(and the only one…)_ implementation of it, provide simple way to validate a collection of basic types like String, Integer, Date… (i.e. validate each element of the collection).

This library allows you to easily create a “pseudo constraint” (typically named as `@EachX`) for _any_ validation constraint to annotate a collection of simple types, without writing an extra validator or unnecessary wrapper classes for every collection.
`EachX` constraint is supported for all standard Bean Validation constraints and Hibernate specific constraints.
For example:

[source]
----
@EachSize(min = 5, max = 255)
Collection<String> values;
@EachFuture
List<Date> dates;
@EachEmail
Set<String> emails;
----


== How to create a custom constraint

Every `@EachX` pseudo constraint uses the same validator, link:src/main/java/cz/jirutka/validator/collection/CommonEachValidator.java[CommonEachValidator].
To create an `@EachAwesome` for your own `@Awesome` constraint, just copy & paste the annotation class (i.e. all the attributes and boilerplate meta annotations), replace `@Constraint` annotation with `@Constraint(validatedBy = CommonEachValidator.class)` and add the annotation `@EachConstraint(validateAs = Awesome.class)`.
That’s all!

[source]
----
// common boilerplate
@Documented
@Retention(RUNTIME)
@Target({METHOD, FIELD, ANNOTATION_TYPE})
// this is important!
@EachConstraint(validateAs = Awesome.class)
@Constraint(validatedBy = CommonEachValidator.class)
public @interface EachAwesome {
// copy&paste all attributes from Awesome annotation here
String message() default "";
Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {};
String someAttribute();
}
----


=== The old way

The previous versions (before 2.1.0) used a different approach to write `@EachX` annotations (see https://github.com/{gh-name}/tree/v2.0.2[here]).
It is still supported for custom constraints, but all the built-in annotations has been already updated to the new style.

If you’re upgrading from an older version of Collection Validators, then you must update all built-in annotations to the new style.
For example:

[source]
@EachSize(@Size(min = 5, max = 255)) -> @EachSize(min = 5, max = 255)

You _should_ also update custom annotations.
The old style is still supported, but may be deprecated in the future.


== Maven

Released versions are available in The Central Repository.
Just add this artifact to your project:

[source, xml, subs="verbatim, attributes"]
----
<dependency>
<groupId>{group-id}</groupId>
<artifactId>{artifact-id}</artifactId>
<version>{version}</version>
</dependency>
----

However if you want to use the last snapshot version, you have to add the JFrog OSS repository:

[source, xml]
----
<repository>
<id>jfrog-oss-snapshot-local</id>
<name>JFrog OSS repository for snapshots</name>
<url>https://oss.jfrog.org/oss-snapshot-local</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
----


== Requirements

http://hibernate.org/validator/[Hibernate Validator] 4.3.1.Final and newer is supported, but 5.× is recommended.

Please note that on older versions some Hibernate specific constraints doesn’t exist, so their `@EachX` annotations will not work (e.g. `@EachEAN`, `@EachMod10Check`, …).
It’s described in JavaDoc.


=== Version detection

In order to support multiple versions of Hibernate Validator at a time, we attempt to determine what version is being used at runtime using the package metadata for the `HibernateValidator` class.
This can sometimes fail, particularly if your project creates an “uber JAR.”
If the version cannot be detected, then it fallbacks to ≥ 5.1.0.


== License

This project is licensed under http://opensource.org/licenses/MIT[MIT license].
115 changes: 0 additions & 115 deletions README.md

This file was deleted.

Loading

0 comments on commit 6bf1aa3

Please sign in to comment.