[springframework] fix build problems with hibernate-validator 5.x

gil gil at fedoraproject.org
Fri Dec 6 14:10:00 UTC 2013


commit ba42a545bb184b213d54c0956ebb132886864795
Author: gil <puntogil at libero.it>
Date:   Fri Dec 6 15:09:53 2013 +0100

    fix build problems with hibernate-validator 5.x

 springframework-3.1.4-hibernate-validator5.patch |  230 ++++++++++++++++++++++
 springframework.spec                             |   25 ++-
 2 files changed, 251 insertions(+), 4 deletions(-)
---
diff --git a/springframework-3.1.4-hibernate-validator5.patch b/springframework-3.1.4-hibernate-validator5.patch
new file mode 100644
index 0000000..b26bdc8
--- /dev/null
+++ b/springframework-3.1.4-hibernate-validator5.patch
@@ -0,0 +1,230 @@
+diff -Nru spring-framework-3.1.4.RELEASE/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java spring-framework-3.1.4.RELEASE-gil/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java
+--- spring-framework-3.1.4.RELEASE/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java	2013-01-23 14:58:18.000000000 +0100
++++ spring-framework-3.1.4.RELEASE-gil/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java	2013-12-06 14:05:49.853810862 +0100
+@@ -29,7 +29,7 @@
+ import javax.validation.ValidatorContext;
+ import javax.validation.ValidatorFactory;
+ 
+-import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
++//import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator;
+ 
+ import org.springframework.beans.factory.InitializingBean;
+ import org.springframework.context.ApplicationContext;
+@@ -114,7 +114,7 @@
+ 	 * @see MessageSourceResourceBundleLocator
+ 	 */
+ 	public void setValidationMessageSource(MessageSource messageSource) {
+-		this.messageInterpolator = HibernateValidatorDelegate.buildMessageInterpolator(messageSource);
++		// this.messageInterpolator = HibernateValidatorDelegate.buildMessageInterpolator(messageSource);
+ 	}
+ 
+ 	/**
+@@ -246,11 +246,11 @@
+ 	/**
+ 	 * Inner class to avoid a hard-coded Hibernate Validator 4.1 dependency.
+ 	 */
+-	private static class HibernateValidatorDelegate {
++	/*private static class HibernateValidatorDelegate {
+ 
+ 		public static MessageInterpolator buildMessageInterpolator(MessageSource messageSource) {
+ 			return new ResourceBundleMessageInterpolator(new MessageSourceResourceBundleLocator(messageSource));
+ 		}
+-	}
++	}*/
+ 
+ }
+diff -Nru spring-framework-3.1.4.RELEASE/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MessageSourceResourceBundleLocator.java spring-framework-3.1.4.RELEASE-gil/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MessageSourceResourceBundleLocator.java
+--- spring-framework-3.1.4.RELEASE/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MessageSourceResourceBundleLocator.java	2013-01-23 14:58:18.000000000 +0100
++++ spring-framework-3.1.4.RELEASE-gil/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MessageSourceResourceBundleLocator.java	1970-01-01 01:00:00.000000000 +0100
+@@ -1,55 +0,0 @@
+-/*
+- * Copyright 2002-2010 the original author or authors.
+- *
+- * Licensed under the Apache License, Version 2.0 (the "License");
+- * you may not use this file except in compliance with the License.
+- * You may obtain a copy of the License at
+- *
+- *      http://www.apache.org/licenses/LICENSE-2.0
+- *
+- * Unless required by applicable law or agreed to in writing, software
+- * distributed under the License is distributed on an "AS IS" BASIS,
+- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+- * See the License for the specific language governing permissions and
+- * limitations under the License.
+- */
+-
+-package org.springframework.validation.beanvalidation;
+-
+-import java.util.Locale;
+-import java.util.ResourceBundle;
+-
+-import org.hibernate.validator.resourceloading.ResourceBundleLocator;
+-
+-import org.springframework.context.MessageSource;
+-import org.springframework.context.support.MessageSourceResourceBundle;
+-import org.springframework.util.Assert;
+-
+-/**
+- * Implementation of Hibernate Validator 4.1's {@link ResourceBundleLocator} interface,
+- * exposing a Spring {@link MessageSource} as localized {@link MessageSourceResourceBundle}.
+- *
+- * @author Juergen Hoeller
+- * @since 3.0.4
+- * @see ResourceBundleLocator
+- * @see MessageSource
+- * @see MessageSourceResourceBundle
+- */
+-public class MessageSourceResourceBundleLocator implements ResourceBundleLocator {
+-
+-	private final MessageSource messageSource;
+-
+-	/**
+-	 * Build a MessageSourceResourceBundleLocator for the given MessageSource.
+-	 * @param messageSource the Spring MessageSource to wrap
+-	 */
+-	public MessageSourceResourceBundleLocator(MessageSource messageSource) {
+-		Assert.notNull(messageSource, "MessageSource must not be null");
+-		this.messageSource = messageSource;
+-	}
+-
+-	public ResourceBundle getResourceBundle(Locale locale) {
+-		return new MessageSourceResourceBundle(this.messageSource, locale);
+-	}
+-
+-}
+diff -Nru spring-framework-3.1.4.RELEASE/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java spring-framework-3.1.4.RELEASE-gil/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java
+--- spring-framework-3.1.4.RELEASE/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java	2013-01-23 14:58:18.000000000 +0100
++++ spring-framework-3.1.4.RELEASE-gil/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java	1970-01-01 01:00:00.000000000 +0100
+@@ -1,114 +0,0 @@
+-/*
+- * Copyright 2002-2011 the original author or authors.
+- *
+- * Licensed under the Apache License, Version 2.0 (the "License");
+- * you may not use this file except in compliance with the License.
+- * You may obtain a copy of the License at
+- *
+- *      http://www.apache.org/licenses/LICENSE-2.0
+- *
+- * Unless required by applicable law or agreed to in writing, software
+- * distributed under the License is distributed on an "AS IS" BASIS,
+- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+- * See the License for the specific language governing permissions and
+- * limitations under the License.
+- */
+-
+-package org.springframework.validation.beanvalidation;
+-
+-import java.util.Set;
+-import javax.validation.Validation;
+-import javax.validation.Validator;
+-import javax.validation.ValidatorFactory;
+-
+-import org.aopalliance.intercept.MethodInterceptor;
+-import org.aopalliance.intercept.MethodInvocation;
+-import org.hibernate.validator.HibernateValidator;
+-import org.hibernate.validator.method.MethodConstraintViolation;
+-import org.hibernate.validator.method.MethodConstraintViolationException;
+-import org.hibernate.validator.method.MethodValidator;
+-
+-import org.springframework.core.annotation.AnnotationUtils;
+-import org.springframework.validation.annotation.Validated;
+-
+-/**
+- * An AOP Alliance {@link MethodInterceptor} implementation that delegates to a
+- * JSR-303 provider for performing method-level validation on annotated methods.
+- *
+- * <p>Applicable methods have JSR-303 constraint annotations on their parameters
+- * and/or on their return value (in the latter case specified at the method level,
+- * typically as inline annotation).
+- *
+- * <p>E.g.: <code>public @NotNull Object myValidMethod(@NotNull String arg1, @Max(10) int arg2)</code>
+- *
+- * <p>Validation groups can be specified through Spring's {@link Validated} annotation
+- * at the type level of the containing target class, applying to all public service methods
+- * of that class. By default, JSR-303 will validate against its default group only.
+- *
+- * <p>As of Spring 3.1, this functionality requires Hibernate Validator 4.2 or higher.
+- * In Spring 3.1.2, this class will autodetect a Bean Validation 1.1 compliant provider
+- * and automatically use the standard method validation support there (once available).
+- *
+- * @author Juergen Hoeller
+- * @since 3.1
+- * @see MethodValidationPostProcessor
+- * @see org.hibernate.validator.method.MethodValidator
+- */
+-public class MethodValidationInterceptor implements MethodInterceptor {
+-
+-	private final MethodValidator validator;
+-
+-
+-	/**
+-	 * Create a new MethodValidationInterceptor using a default JSR-303 validator underneath.
+-	 */
+-	public MethodValidationInterceptor() {
+-		this(Validation.byProvider(HibernateValidator.class).configure().buildValidatorFactory());
+-	}
+-
+-	/**
+-	 * Create a new MethodValidationInterceptor using the given JSR-303 ValidatorFactory.
+-	 * @param validatorFactory the JSR-303 ValidatorFactory to use
+-	 */
+-	public MethodValidationInterceptor(ValidatorFactory validatorFactory) {
+-		this(validatorFactory.getValidator());
+-	}
+-
+-	/**
+-	 * Create a new MethodValidationInterceptor using the given JSR-303 Validator.
+-	 * @param validatorFactory the JSR-303 Validator to use
+-	 */
+-	public MethodValidationInterceptor(Validator validator) {
+-		this.validator = validator.unwrap(MethodValidator.class);
+-	}
+-
+-
+-	public Object invoke(MethodInvocation invocation) throws Throwable {
+-		Class[] groups = determineValidationGroups(invocation);
+-		Set<MethodConstraintViolation<Object>> result = this.validator.validateAllParameters(
+-				invocation.getThis(), invocation.getMethod(), invocation.getArguments(), groups);
+-		if (!result.isEmpty()) {
+-			throw new MethodConstraintViolationException(result);
+-		}
+-		Object returnValue = invocation.proceed();
+-		result = this.validator.validateReturnValue(
+-				invocation.getThis(), invocation.getMethod(), returnValue, groups);
+-		if (!result.isEmpty()) {
+-			throw new MethodConstraintViolationException(result);
+-		}
+-		return returnValue;
+-	}
+-
+-	/**
+-	 * Determine the validation groups to validate against for the given method invocation.
+-	 * <p>Default are the validation groups as specified in the {@link Validated} annotation
+-	 * on the containing target class of the method.
+-	 * @param invocation the current MethodInvocation
+-	 * @return the applicable validation groups as a Class array
+-	 */
+-	protected Class[] determineValidationGroups(MethodInvocation invocation) {
+-		Validated valid = AnnotationUtils.findAnnotation(invocation.getThis().getClass(), Validated.class);
+-		return (valid != null ? valid.value() : new Class[0]);
+-	}
+-
+-}
+diff -Nru spring-framework-3.1.4.RELEASE/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java spring-framework-3.1.4.RELEASE-gil/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java
+--- spring-framework-3.1.4.RELEASE/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java	2013-01-23 14:58:18.000000000 +0100
++++ spring-framework-3.1.4.RELEASE-gil/org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java	2013-12-06 14:08:01.505889028 +0100
+@@ -122,10 +122,10 @@
+ 
+ 
+ 	public void afterPropertiesSet() {
+-		Pointcut pointcut = new AnnotationMatchingPointcut(this.validatedAnnotationType, true);
+-		Advice advice = (this.validator != null ? new MethodValidationInterceptor(this.validator) :
+-				new MethodValidationInterceptor());
+-		this.advisor = new DefaultPointcutAdvisor(pointcut, advice);
++		// Pointcut pointcut = new AnnotationMatchingPointcut(this.validatedAnnotationType, true);
++		// Advice advice = (this.validator != null ? new MethodValidationInterceptor(this.validator) :
++		// 		new MethodValidationInterceptor());
++		// this.advisor = new DefaultPointcutAdvisor(pointcut, advice);
+ 	}
+ 
+ 
diff --git a/springframework.spec b/springframework.spec
index 232fbd8..89a10fb 100644
--- a/springframework.spec
+++ b/springframework.spec
@@ -2,7 +2,7 @@
 %global namedversion %{version}%{?namedreltag}
 Name:          springframework
 Version:       3.1.4
-Release:       1%{?dist}
+Release:       2%{?dist}
 Summary:       Spring Java Application Framework
 Epoch:         0
 License:       ASL 2.0
@@ -52,6 +52,8 @@ Patch12:       %{name}-3.1.4-dont-rebundle-asm.patch
 #      org.springframework.transaction use com.springsource.javax.ejb
 #      now use geronimo-ejb_3.1_spec
 Patch13:       %{name}-3.1.4-fix-javax-apis.patch
+# Remove some code which don't compile with Hibernate Validator 5.x
+Patch14:       %{name}-3.1.4-hibernate-validator5.patch
 
 BuildRequires: hibernate3
 BuildRequires: hibernate3-entitymanager
@@ -346,6 +348,7 @@ find -name "*.jar" -print -delete
 %patch11 -p1
 %patch12 -p1
 %patch13 -p1
+%patch14 -p1
 
 cp -p %{SOURCE1} pom.xml
 
@@ -383,6 +386,20 @@ sed -i "s|ResourceBundleLocator|PlatformResourceBundleLocator|" \
 # TODO Fix jruby aId
 %if %{?fedora} <= 19
 %pom_xpath_set "pom:dependencies/pom:dependency[pom:groupId = 'org.jruby']/pom:artifactId" shared org.springframework.context
+%else
+# Make sure we require version '1' of hsqldb
+while read f
+do
+
+%pom_xpath_set "pom:dependencies/pom:dependency[pom:groupId = 'hsqldb']/pom:version" 1 ${f}
+
+done << EOF
+org.springframework.context.support/pom.xml
+org.springframework.integration-tests/pom.xml
+org.springframework.jdbc/pom.xml
+org.springframework.orm/pom.xml
+org.springframework.test/pom.xml
+EOF
 %endif
 %pom_add_dep org.jruby.extras:bytelist:1.0.8:compile org.springframework.context
 
@@ -396,7 +413,7 @@ sed -i "s|ResourceBundleLocator|PlatformResourceBundleLocator|" \
 #%%pom_add_dep junit:junit:4.11:compile org.springframework.test
 # require for build test module
 %pom_xpath_remove "pom:dependencyManagement/pom:dependencies/pom:dependency[pom:artifactId = 'junit']/pom:scope" org.springframework.spring-parent
-
+# TODO
 %pom_remove_dep :jopt-simple org.springframework.core
 rm -r org.springframework.core/src/main/java/org/springframework/core/env/JOptCommandLinePropertySource.java
 
@@ -562,7 +579,7 @@ cp -p build-spring-framework/resources/* .
 * Thu Aug  2 2012 Andy Grimm <agrimm at gmail.com> 0:3.1.1-9
 - Fix broken Requires line in struts subpackage
 
-* Thu Jul 31 2012 gil cattaneo <puntogil at libero.it> 0:3.1.1-8
+* Tue Jul 31 2012 gil cattaneo <puntogil at libero.it> 0:3.1.1-8
 - Enable new modules:  
 - spring-context-support, spring-oxm, spring-web,
 - spring-jms, spring-orm, spring-webmvc,
@@ -585,5 +602,5 @@ cp -p build-spring-framework/resources/* .
 * Thu Mar 15 2012 Juan Hernandez <juan.hernandez at redhat.com> 0:3.1.1-2
 - Cleanup of the spec file
 
-* Fri Mar 1 2012 Andy Grimm <agrimm at gmail.com> 0:3.1.1-1
+* Thu Mar 1 2012 Andy Grimm <agrimm at gmail.com> 0:3.1.1-1
 - Initial build


More information about the scm-commits mailing list