Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HV-2025 Remove OSGi testing and support #1413

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Guidelines for contributing to Hibernate Validator
Contributions from the community are essential in keeping Hibernate Validator strong and successful.
This guide focuses on how to contribute back to Hibernate Validator using GitHub pull requests.
If you need help with cloning, compiling or setting the project up in an IDE please refer to
[this page](http://hibernate.org/validator/contribute/).
[this page](https://hibernate.org/validator/contribute/).

## Legal

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ the metadata through the use of XML validation descriptors.

## Documentation

The documentation for this release is included in the _docs_ directory of the distribution package or can be accessed [online](http://hibernate.org/validator/documentation/).
The documentation for this release is included in the _docs_ directory of the distribution package or can be accessed [online](https://hibernate.org/validator/documentation/).

## Release Notes

Expand Down Expand Up @@ -76,7 +76,7 @@ You will also need a JDK 17+ and Maven 3 (>= 3.9.8). With these prerequisites in

mvn clean install

There are more build options available as well. For more information refer to [Contributing to Hibernate Validator](http://hibernate.org/validator/contribute/).
There are more build options available as well. For more information refer to [Contributing to Hibernate Validator](https://hibernate.org/validator/contribute/).

## Continuous Integration

Expand All @@ -88,10 +88,10 @@ This build runs on Linux and Windows and executes the TCK both in standalone and

## Hibernate Validator URLs

* [Home Page](http://hibernate.org/validator/)
* [Jakarta Validation Home](http://beanvalidation.org/)
* [Home Page](https://hibernate.org/validator/)
* [Jakarta Validation Home](https://beanvalidation.org/)
* [Jakarta Validation Specs](https://jakarta.ee/specifications/bean-validation/)
* [Downloads](http://hibernate.org/validator/downloads/)
* [Mailing Lists](http://hibernate.org/community/)
* [Downloads](https://hibernate.org/validator/downloads/)
* [Mailing Lists](https://hibernate.org/community/)
* [Issue Tracking](https://hibernate.atlassian.net/browse/HV)
* [Continuous Integration](http://ci.hibernate.org/view/Validator/)
12 changes: 5 additions & 7 deletions documentation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
<asciidoctor.examples-source-dir>${basedir}/src/test/java</asciidoctor.examples-source-dir>
<asciidoctor.examples-resources-dir>${basedir}/src/test/resources</asciidoctor.examples-resources-dir>
<asciidoctor.engine-source-dir>${basedir}/../engine/src/main/java</asciidoctor.engine-source-dir>
<asciidoctor.osgi-integrationtest-source-dir>${basedir}/../osgi/integrationtest/src/test/java</asciidoctor.osgi-integrationtest-source-dir>

<html.meta.project-key>validator</html.meta.project-key>
<html.google-analytics.id>G-282CVRCQHZ</html.google-analytics.id>
Expand Down Expand Up @@ -59,6 +58,11 @@
<artifactId>hibernate-validator-cdi</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>hibernate-validator-test-utils</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.enterprise</groupId>
<artifactId>jakarta.enterprise.cdi-api</artifactId>
Expand All @@ -79,11 +83,6 @@
<artifactId>groovy-jsr223</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
Expand Down Expand Up @@ -285,7 +284,6 @@
<sourcedir>${asciidoctor.examples-source-dir}</sourcedir>
<resourcesdir>${asciidoctor.examples-resources-dir}</resourcesdir>
<engine-sourcedir>${asciidoctor.engine-source-dir}</engine-sourcedir>
<osgi-integrationtest-sourcedir>${asciidoctor.osgi-integrationtest-source-dir}</osgi-integrationtest-sourcedir>

<hvVersion>${project.version}</hvVersion>
<bvVersion>${version.jakarta.validation-api}</bvVersion>
Expand Down
32 changes: 5 additions & 27 deletions documentation/src/main/asciidoc/ch09.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ its `ValidationProvider` implementation. In the case of Hibernate Validator, thi

Depending on your environment and its classloading specifics, provider discovery via the Java's
service loader mechanism might not work. In this case, you can plug in a custom
`ValidationProviderResolver` implementation which performs the provider retrieval. An example is OSGi,
where you could implement a provider resolver which uses OSGi services for provider discovery.
`ValidationProviderResolver` implementation which performs the provider retrieval.

To use a custom provider resolver, pass it via `providerResolver()` as shown in
<<example-using-custom-validation-provider-resolver>>.
Expand All @@ -93,7 +92,7 @@ To use a custom provider resolver, pass it via `providerResolver()` as shown in
====
[source, JAVA, indent=0]
----
include::{sourcedir}/org/hibernate/validator/referenceguide/chapter09/OsgiServiceDiscoverer.java[tags=include]
include::{sourcedir}/org/hibernate/validator/referenceguide/chapter09/CustomValidationProviderResolver.java[tags=include]
----

[source, JAVA, indent=0]
Expand Down Expand Up @@ -436,7 +435,7 @@ For constraints like `@ScriptAssert` and `@ParameterScriptAssert`, it might be u
how the script engines are initialized and how the script evaluators are built.
This can be done by setting a custom implementation of `ScriptEvaluatorFactory`.

In particular, this is important for modular environments (e.g. OSGi), where user might face issues
In particular, this is important for modular environments, where user might face issues
with modular class loading and https://www.jcp.org/en/jsr/detail?id=223[JSR 223].
It also allows to use any custom script engine, not necessarily based on the
https://www.jcp.org/en/jsr/detail?id=223[JSR 223] (e.g. Spring Expression Language).
Expand Down Expand Up @@ -487,7 +486,7 @@ To solve this issue, the `MultiClassLoaderScriptEvaluatorFactory` class below ca
====
[source, JAVA, indent=0]
----
include::{osgi-integrationtest-sourcedir}/org/hibernate/validator/osgi/scripting/MultiClassLoaderScriptEvaluatorFactory.java[]
include::{sourcedir}/org/hibernate/validator/referenceguide/chapter09/MultiClassLoaderScriptEvaluatorFactory.java[]
----
====

Expand All @@ -496,33 +495,12 @@ and then declared with:
====
[source, JAVA, indent=0]
----
include::{osgi-integrationtest-sourcedir}/org/hibernate/validator/osgi/integrationtest/OsgiIntegrationTest.java[tags=scriptEvaluatorFactoryMultiClassLoaderScriptEvaluatorFactory]
include::{sourcedir}/org/hibernate/validator/referenceguide/chapter09/BootstrappingTest.java[tags=scriptEvaluatorFactoryMultiClassLoaderScriptEvaluatorFactory]
----
====

This way, it is possible to pass multiple `ClassLoader` instances: typically the class loaders of the wanted ``ScriptEngine``s.

An alternative approach for OSGi environments can be to use the `OsgiScriptEvaluatorFactory` defined below:

====
[source, JAVA, indent=0]
----
include::{osgi-integrationtest-sourcedir}/org/hibernate/validator/osgi/scripting/OsgiScriptEvaluatorFactory.java[]
----
====

and then declared with:

====
[source, JAVA, indent=0]
----
include::{osgi-integrationtest-sourcedir}/org/hibernate/validator/osgi/integrationtest/OsgiIntegrationTest.java[tags=scriptEvaluatorFactoryOsgiScriptEvaluatorFactory]
----
====

It is designed specifically for OSGi environments and allows you to pass the `BundleContext` which will be used to search
for `ScriptEngineFactory` as a parameter.

As already mentioned, you can also use script engines that are not based on https://www.jcp.org/en/jsr/detail?id=223[JSR 223].

For instance, to use the https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#expressions[Spring Expression Language],
Expand Down
8 changes: 8 additions & 0 deletions documentation/src/main/asciidoc/ch11.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,11 @@ dependency injection in constraint validators.
Hibernate Validator also provides support for the unwrapping of JavaFX properties. If JavaFX is present
on the classpath, ``ValueExtractor``s for JavaFX properties are automatically registered.
See <<section-valueextraction-javafx>> for examples and further discussion.


[[validator-osgi]]
=== OSGi

Starting with Hibernate Validator 9.0, the Hibernate team no longer tests nor maintains the OSGi integration.
For users who would want to experiment with Hibernate Validator in an OSGi environment,
we will keep the existing manifest entries in place as they were.
marko-bekhta marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions documentation/src/main/asciidoc/ch12.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,8 @@ There are several cases in which Hibernate Validator needs to load resources or
By default, Hibernate Validator tries to load these resources via the current thread context class loader.
If that's not successful, Hibernate Validator's own class loader will be tried as a fallback.

// Let's keep this mention of OSGi here in the docs, pointing the users,
// to what they can do, if they are in the OSGi env.
For cases where this strategy is not appropriate (e.g. modularized environments such as OSGi),
you may provide a specific class loader for loading these resources when bootstrapping the validator factory:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package org.hibernate.validator.referenceguide.chapter09;

import static org.hibernate.validator.testutil.ConstraintViolationAssert.assertThat;
import static org.hibernate.validator.testutil.ConstraintViolationAssert.pathWith;
import static org.hibernate.validator.testutil.ConstraintViolationAssert.violationOf;

import java.io.InputStream;
import java.time.Duration;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;

Expand All @@ -11,9 +16,12 @@

import org.hibernate.validator.HibernateValidator;
import org.hibernate.validator.cfg.ConstraintMapping;
import org.hibernate.validator.constraints.ScriptAssert;

import org.junit.Test;

import org.codehaus.groovy.jsr223.GroovyScriptEngineFactory;

public class BootstrappingTest {

@Test
Expand Down Expand Up @@ -54,7 +62,7 @@ public void byDefaultProvider() {
public void providerResolver() {
//tag::providerResolver[]
ValidatorFactory validatorFactory = Validation.byDefaultProvider()
.providerResolver( new OsgiServiceDiscoverer() )
.providerResolver( new CustomValidationProviderResolver() )
.configure()
.buildValidatorFactory();
Validator validator = validatorFactory.getValidator();
Expand Down Expand Up @@ -227,4 +235,41 @@ public void scriptEvaluatorFactoryProgrammatically() {
Validator validator = validatorFactory.getValidator();
//end::scriptEvaluatorFactoryProgrammatically[]
}

@Test
public void canUseScriptAssertConstraintWithMultiClassLoaderScriptEvaluatorFactory() {
//tag::scriptEvaluatorFactoryMultiClassLoaderScriptEvaluatorFactory[]
Validator validator = Validation.byProvider( HibernateValidator.class )
.configure()
.scriptEvaluatorFactory(
new MultiClassLoaderScriptEvaluatorFactory( GroovyScriptEngineFactory.class.getClassLoader() )
)
.buildValidatorFactory()
.getValidator();
//end::scriptEvaluatorFactoryMultiClassLoaderScriptEvaluatorFactory[]

canUseScriptAssertConstraint( validator );
}

private void canUseScriptAssertConstraint(Validator validator) {
assertThat(
validator.validate( new Event( LocalDate.of( 2017, 8, 8 ), LocalDate.of( 2016, 8, 8 ) ) )
).containsOnlyViolations(
violationOf( ScriptAssert.class ).withPropertyPath( pathWith().bean() )
.withMessage( "start of event cannot be after the end" )
);
}

@ScriptAssert(lang = "groovy", script = "_this.start < _this.end", message = "start of event cannot be after the end")
public class Event {

private final LocalDate start;

private final LocalDate end;

public Event(LocalDate start, LocalDate end) {
this.start = start;
this.end = end;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import jakarta.validation.spi.ValidationProvider;

//tag::include[]
public class OsgiServiceDiscoverer implements ValidationProviderResolver {
public class CustomValidationProviderResolver implements ValidationProviderResolver {

@Override
public List<ValidationProvider<?>> getValidationProviders() {
//...
return null;
//end::include[]
List<ValidationProvider<?>> providers = null;
//tag::include[]
return providers;
}
}
//end::include[]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License: Apache License, Version 2.0
* See the license.txt file in the root directory or <http://www.apache.org/licenses/LICENSE-2.0>.
*/
package org.hibernate.validator.osgi.scripting;
package org.hibernate.validator.referenceguide.chapter09;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
Expand Down
2 changes: 1 addition & 1 deletion engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<distributionManagement>
<site>
<id>site</id>
<url>http://hibernate.org/validator</url>
<url>https://hibernate.org/validator</url>
</site>
</distributionManagement>

Expand Down
Loading