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

Initial commit for upgrading Hibernate validator to 9 #29668

Open
wants to merge 2 commits into
base: integration
Choose a base branch
from
Open
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
30 changes: 30 additions & 0 deletions dev/cnf/dependabot/check_this_in_if_it_changes/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@
<artifactId>cloudant-client</artifactId>
<version>2.16.0</version>
</dependency>
<dependency>
<groupId>com.cloudant</groupId>
<artifactId>cloudant-client</artifactId>
<version>2.20.1</version>
</dependency>
<dependency>
<groupId>com.cloudant</groupId>
<artifactId>cloudant-client</artifactId>
Expand All @@ -71,6 +76,11 @@
<artifactId>cloudant-http</artifactId>
<version>2.16.0</version>
</dependency>
<dependency>
<groupId>com.cloudant</groupId>
<artifactId>cloudant-http</artifactId>
<version>2.20.1</version>
</dependency>
<dependency>
<groupId>com.cloudant</groupId>
<artifactId>cloudant-http</artifactId>
Expand Down Expand Up @@ -3601,6 +3611,11 @@
<artifactId>hibernate-validator-cdi</artifactId>
<version>7.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
<version>9.0.0.Beta3</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
Expand All @@ -3611,6 +3626,11 @@
<artifactId>hibernate-validator</artifactId>
<version>7.0.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>9.0.0.Beta3</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
Expand Down Expand Up @@ -3701,6 +3721,11 @@
<artifactId>jboss-logging-processor</artifactId>
<version>2.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-processor</artifactId>
<version>3.0.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
Expand All @@ -3711,6 +3736,11 @@
<artifactId>jboss-logging</artifactId>
<version>3.5.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.6.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.narayana.arjunacore</groupId>
<artifactId>arjuna</artifactId>
Expand Down
8 changes: 6 additions & 2 deletions dev/cnf/oss_dependencies.maven
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ biz.aQute.bnd:biz.aQute.bnd:7.0.0
cglib:cglib:3.3.0
ch.qos.logback:logback-classic:1.2.3
com.beust:jcommander:1.72
com.cloudant:cloudant-client:2.20.1
com.cloudant:cloudant-client:2.16.0
com.cloudant:cloudant-client:2.20.1
com.cloudant:cloudant-client:2.8.0
com.cloudant:cloudant-http:2.20.1
com.cloudant:cloudant-http:2.16.0
com.cloudant:cloudant-http:2.20.1
com.cloudant:cloudant-http:2.8.0
com.fasterxml.jackson.core:jackson-annotations:2.15.2
com.fasterxml.jackson.core:jackson-core:2.15.2
Expand Down Expand Up @@ -718,8 +718,10 @@ org.hibernate.common:hibernate-commons-annotations:5.1.0.Final
org.hibernate.orm:hibernate-core:7.0.0.Alpha2
org.hibernate.validator:hibernate-validator-cdi:6.2.5.Final
org.hibernate.validator:hibernate-validator-cdi:7.0.4.Final
org.hibernate.validator:hibernate-validator-cdi:9.0.0.Beta3
org.hibernate.validator:hibernate-validator:6.2.5.Final
org.hibernate.validator:hibernate-validator:7.0.4.Final
org.hibernate.validator:hibernate-validator:9.0.0.Beta3
org.hibernate:hibernate-core:5.2.17.Final
org.hibernate:hibernate-search-engine:5.11.2.Final
org.infinispan:infinispan-client-hotrod:13.0.10.Final
Expand All @@ -738,8 +740,10 @@ org.jboss.arquillian.test:arquillian-test-spi:1.7.0.Alpha13
org.jboss.classfilewriter:jboss-classfilewriter:1.3.0.Final
org.jboss.logging:jboss-logging-annotations:2.2.1.Final
org.jboss.logging:jboss-logging-processor:2.2.1.Final
org.jboss.logging:jboss-logging-processor:3.0.0.Final
org.jboss.logging:jboss-logging:3.4.3.Final
org.jboss.logging:jboss-logging:3.5.0.Final
org.jboss.logging:jboss-logging:3.6.0.Final
org.jboss.narayana.arjunacore:arjuna:5.10.6.Final
org.jboss.narayana.rts:lra-client:5.10.6.Final
org.jboss.narayana.rts:lra-coordinator-jar:5.10.6.Final
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ visibility=private
IBM-App-ForceRestart: install, uninstall
IBM-Provision-Capability: \
osgi.identity; filter:="(&(type=osgi.subsystem.feature)(|(osgi.identity=io.openliberty.cdi-3.0)(osgi.identity=io.openliberty.cdi-4.0)(osgi.identity=io.openliberty.cdi-4.1)))", \
osgi.identity; filter:="(&(type=osgi.subsystem.feature)(|(osgi.identity=io.openliberty.beanValidation-3.0)(osgi.identity=io.openliberty.beanValidation-3.1)))"
osgi.identity; filter:="(&(type=osgi.subsystem.feature)(|(osgi.identity=io.openliberty.beanValidation-3.0)))"
IBM-Install-Policy: when-satisfied
-bundles=\
com.ibm.ws.beanvalidation.v20.cdi.jakarta,\
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-include= ~${workspace}/cnf/resources/bnd/feature.props
symbolicName=io.openliberty.beanValidationCDI-3.1
visibility=private
IBM-App-ForceRestart: install, uninstall
IBM-Provision-Capability: \
osgi.identity; filter:="(&(type=osgi.subsystem.feature)(|(osgi.identity=io.openliberty.cdi-3.0)(osgi.identity=io.openliberty.cdi-4.0)(osgi.identity=io.openliberty.cdi-4.1)))", \
osgi.identity; filter:="(&(type=osgi.subsystem.feature)(|(osgi.identity=io.openliberty.beanValidation-3.1)))"
IBM-Install-Policy: when-satisfied
-bundles=\
com.ibm.ws.beanvalidation.v20.cdi.jakarta,\
io.openliberty.org.hibernate.validator.cdi.9.0
kind=ga
edition=core
WLP-Activation-Type: parallel
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ IBM-SPI-Package: \
io.openliberty.jakarta.cdi-4.1
-bundles=\
com.ibm.ws.beanvalidation.v20.jakarta, \
com.ibm.ws.org.jboss.logging, \
io.openliberty.org.jboss.logging36, \
com.ibm.ws.com.fasterxml.classmate, \
io.openliberty.org.hibernate.validator.7.0
io.openliberty.org.hibernate.validator.9.0
kind=beta
edition=core
WLP-Activation-Type: parallel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 IBM Corporation and others.
* Copyright (c) 2017, 2018, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand All @@ -14,9 +14,13 @@

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ServiceConfigurationError;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -34,7 +38,6 @@

import org.hibernate.validator.cdi.internal.InjectingConstraintValidatorFactory;
import org.hibernate.validator.internal.engine.valueextraction.ValueExtractorDescriptor;
import org.hibernate.validator.internal.util.privilegedactions.GetInstancesFromServiceLoader;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.Activate;
Expand Down Expand Up @@ -75,6 +78,53 @@ public class BvalManagedObjectBuilderImpl implements BvalManagedObjectBuilder {
private final AtomicServiceReference<CDIService> cdiService = new AtomicServiceReference<CDIService>(REFERENCE_CDI_SERVICE);
private final AtomicServiceReference<ManagedObjectService> managedObjectServiceRef = new AtomicServiceReference<ManagedObjectService>(REFERENCE_MANAGED_OBJECT_SERVICE);

private static class GetInstancesFromServiceLoader implements PrivilegedAction<List<ValueExtractor>> {

//private static final Log LOG = LoggerFactory.make(MethodHandles.lookup());

private GetInstancesFromServiceLoader() {
}

public static <T> List<T> action(ClassLoader primaryClassLoader, Class<T> serviceClass) {
// Option #1: try the primary class loader first (either the thread context class loader or the external class
// loader that has been defined)
List<T> instances = loadInstances(primaryClassLoader, serviceClass);

// Option #2: if we cannot find any service files within the primary class loader, use the current class loader
if (instances.isEmpty() && GetInstancesFromServiceLoader.class.getClassLoader() != primaryClassLoader) {
instances = loadInstances(GetInstancesFromServiceLoader.class.getClassLoader(), serviceClass);
}

return instances;
}

private static <T> List<T> loadInstances(ClassLoader classloader, Class<T> clazz) {
ServiceLoader<T> loader = ServiceLoader.load(clazz, classloader);
Iterator<T> iterator = loader.iterator();
List<T> instances = new ArrayList<T>();
while (iterator.hasNext()) {
try {
instances.add(iterator.next());
} catch (ServiceConfigurationError e) {
// ignore, because it can happen when multiple
// services are present and some of them are not class loader
// compatible with our API.
// log an error still as it can hide a legitimate issue (see HV-1689)
//LOG.unableToLoadInstanceOfService(loader.getClass().getName(), e);
Tr.debug(tc, "unableToLoadInstanceOfService");
}
}
return instances;
}

@Override
public List<ValueExtractor> run() {

return action(Thread.currentThread().getContextClassLoader(),
ValueExtractor.class);
}
}

@Override
public ValidatorFactory injectValidatorFactoryResources(Configuration<?> config, ClassLoader appClassLoader) {
if (cdiService.getServiceWithException().isCurrentModuleCDIEnabled()) {
Expand Down Expand Up @@ -240,8 +290,7 @@ private Set<ValueExtractorDescriptor> createServiceLoaderValueExtractors() {

List<ValueExtractor> valueExtractors;

valueExtractors = AccessController.doPrivileged((PrivilegedAction<List<ValueExtractor>>) () -> GetInstancesFromServiceLoader.action(Thread.currentThread().getContextClassLoader(),
ValueExtractor.class).run());
valueExtractors = AccessController.doPrivileged((PrivilegedAction<List<ValueExtractor>>) () -> new GetInstancesFromServiceLoader().run());
for (ValueExtractor<?> valueExtractor : valueExtractors) {
valueExtractorDescriptors.add(new ValueExtractorDescriptor(createManagedObject((Class<? extends ValueExtractor<?>>) valueExtractor.getClass())));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*******************************************************************************
* Copyright (c) 2020 IBM Corporation and others.
* Copyright (c) 2020, 2024 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-2.0/
*
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
Expand Down Expand Up @@ -43,7 +43,6 @@
import org.hibernate.validator.internal.util.classhierarchy.ClassHierarchyHelper;
import org.hibernate.validator.internal.util.logging.Log;
import org.hibernate.validator.internal.util.logging.LoggerFactory;
import org.hibernate.validator.internal.util.privilegedactions.GetMethods;
import org.hibernate.validator.spi.properties.ConstrainableExecutable;
import org.hibernate.validator.spi.properties.GetterPropertySelectionStrategy;
import org.osgi.service.component.annotations.Component;
Expand Down Expand Up @@ -109,7 +108,7 @@ public static List<Method> getAllMethods(Class<?> clazz) {
List<Method> methods = newArrayList();

for (Class<?> hierarchyClass : ClassHierarchyHelper.getHierarchy(clazz)) {
Collections.addAll(methods, run(GetMethods.action(hierarchyClass)));
Collections.addAll(methods, run((PrivilegedAction<Method[]>) () -> hierarchyClass.getMethods()));
}

return methods;
Expand Down
12 changes: 12 additions & 0 deletions dev/io.openliberty.org.hibernate.validator.9.0/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin_test" path="test"/>
<classpathentry exported="true" kind="src" path="/com.ibm.ws.junit.extensions"/>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
</classpath>
23 changes: 23 additions & 0 deletions dev/io.openliberty.org.hibernate.validator.9.0/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>io.openliberty.org.hibernate.validator.9.0</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>bndtools.core.bndbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>bndtools.core.bndnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
compileErrorAction=build
eclipse.preferences.version=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#Ant properties
#Automatically generated by the ant prepare.settings.files task
eclipse.preferences.version=1
encoding/<project>=UTF-8
Loading