ReflectionTestUtils does not require spring-aop on the classpath
Issue: SPR-15757
(cherry picked from commit dd43b6a)
This commit is contained in:
67
build.gradle
67
build.gradle
@@ -62,7 +62,7 @@ configure(allprojects) { project ->
|
||||
ext.jtaVersion = "1.2"
|
||||
ext.junitVersion = "4.12"
|
||||
ext.log4jVersion = "1.2.17"
|
||||
ext.nettyVersion = "4.1.12.Final"
|
||||
ext.nettyVersion = "4.1.13.Final"
|
||||
ext.okhttpVersion = "2.7.5"
|
||||
ext.okhttp3Version = "3.7.0"
|
||||
ext.openjpaVersion = "2.4.1"
|
||||
@@ -499,6 +499,37 @@ project("spring-context") {
|
||||
}
|
||||
}
|
||||
|
||||
project("spring-oxm") {
|
||||
description = "Spring Object/XML Marshalling"
|
||||
apply from: "oxm.gradle"
|
||||
|
||||
dependencies {
|
||||
compile(project(":spring-beans"))
|
||||
compile(project(":spring-core"))
|
||||
optional("org.codehaus.castor:castor-xml:1.4.1") {
|
||||
exclude group: 'stax', module: 'stax-api'
|
||||
exclude group: "org.springframework", module: "spring-context"
|
||||
}
|
||||
optional("org.apache.xmlbeans:xmlbeans:2.6.0") {
|
||||
exclude group: 'stax', module: 'stax-api'
|
||||
}
|
||||
optional("com.thoughtworks.xstream:xstream:${xstreamVersion}") {
|
||||
exclude group: 'xpp3', module: 'xpp3_min'
|
||||
exclude group: 'xmlpull', module: 'xmlpull'
|
||||
}
|
||||
optional("org.jibx:jibx-run:1.2.6")
|
||||
testCompile(project(":spring-context"))
|
||||
testCompile("org.ogce:xpp3:1.1.6")
|
||||
testCompile("org.codehaus.jettison:jettison:1.3.8") {
|
||||
exclude group: 'stax', module: 'stax-api'
|
||||
}
|
||||
testCompile("xmlunit:xmlunit:${xmlunitVersion}")
|
||||
testCompile(files(genCastor.classesDir).builtBy(genCastor))
|
||||
testCompile(files(genJaxb.classesDir).builtBy(genJaxb))
|
||||
testCompile(files(genXmlbeans.classesDir).builtBy(genXmlbeans))
|
||||
}
|
||||
}
|
||||
|
||||
project("spring-messaging") {
|
||||
description = "Spring Messaging"
|
||||
|
||||
@@ -557,37 +588,6 @@ project("spring-tx") {
|
||||
}
|
||||
}
|
||||
|
||||
project("spring-oxm") {
|
||||
description = "Spring Object/XML Marshalling"
|
||||
apply from: "oxm.gradle"
|
||||
|
||||
dependencies {
|
||||
compile(project(":spring-beans"))
|
||||
compile(project(":spring-core"))
|
||||
optional("org.codehaus.castor:castor-xml:1.4.1") {
|
||||
exclude group: 'stax', module: 'stax-api'
|
||||
exclude group: "org.springframework", module: "spring-context"
|
||||
}
|
||||
optional("org.apache.xmlbeans:xmlbeans:2.6.0") {
|
||||
exclude group: 'stax', module: 'stax-api'
|
||||
}
|
||||
optional("com.thoughtworks.xstream:xstream:${xstreamVersion}") {
|
||||
exclude group: 'xpp3', module: 'xpp3_min'
|
||||
exclude group: 'xmlpull', module: 'xmlpull'
|
||||
}
|
||||
optional("org.jibx:jibx-run:1.2.6")
|
||||
testCompile(project(":spring-context"))
|
||||
testCompile("xmlunit:xmlunit:${xmlunitVersion}")
|
||||
testCompile("xpp3:xpp3:1.1.4c")
|
||||
testCompile("org.codehaus.jettison:jettison:1.3.8") {
|
||||
exclude group: 'stax', module: 'stax-api'
|
||||
}
|
||||
testCompile(files(genCastor.classesDir).builtBy(genCastor))
|
||||
testCompile(files(genJaxb.classesDir).builtBy(genJaxb))
|
||||
testCompile(files(genXmlbeans.classesDir).builtBy(genXmlbeans))
|
||||
}
|
||||
}
|
||||
|
||||
project("spring-jms") {
|
||||
description = "Spring JMS"
|
||||
|
||||
@@ -981,11 +981,12 @@ project("spring-test") {
|
||||
|
||||
dependencies {
|
||||
compile(project(":spring-core"))
|
||||
optional(project(":spring-aop"))
|
||||
optional(project(":spring-beans"))
|
||||
optional(project(":spring-context"))
|
||||
optional(project(":spring-jdbc"))
|
||||
optional(project(":spring-tx"))
|
||||
optional(project(":spring-orm"))
|
||||
optional(project(":spring-tx"))
|
||||
optional(project(":spring-web"))
|
||||
optional(project(":spring-webmvc"))
|
||||
optional(project(":spring-webmvc-portlet"))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2017 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.
|
||||
@@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.MethodInvoker;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -62,7 +63,7 @@ import org.springframework.util.StringUtils;
|
||||
* @see ReflectionUtils
|
||||
* @see AopTestUtils
|
||||
*/
|
||||
public class ReflectionTestUtils {
|
||||
public abstract class ReflectionTestUtils {
|
||||
|
||||
private static final String SETTER_PREFIX = "set";
|
||||
|
||||
@@ -70,6 +71,9 @@ public class ReflectionTestUtils {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(ReflectionTestUtils.class);
|
||||
|
||||
private static final boolean springAopPresent = ClassUtils.isPresent(
|
||||
"org.springframework.aop.framework.Advised", ReflectionTestUtils.class.getClassLoader());
|
||||
|
||||
|
||||
/**
|
||||
* Set the {@linkplain Field field} with the given {@code name} on the
|
||||
@@ -164,26 +168,27 @@ public class ReflectionTestUtils {
|
||||
Assert.isTrue(targetObject != null || targetClass != null,
|
||||
"Either targetObject or targetClass for the field must be specified");
|
||||
|
||||
Object ultimateTarget = (targetObject != null ? AopTestUtils.getUltimateTargetObject(targetObject) : null);
|
||||
|
||||
if (targetObject != null && springAopPresent) {
|
||||
targetObject = AopTestUtils.getUltimateTargetObject(targetObject);
|
||||
}
|
||||
if (targetClass == null) {
|
||||
targetClass = ultimateTarget.getClass();
|
||||
targetClass = targetObject.getClass();
|
||||
}
|
||||
|
||||
Field field = ReflectionUtils.findField(targetClass, name, type);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException(String.format(
|
||||
"Could not find field '%s' of type [%s] on %s or target class [%s]", name, type,
|
||||
safeToString(ultimateTarget), targetClass));
|
||||
safeToString(targetObject), targetClass));
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format(
|
||||
"Setting field '%s' of type [%s] on %s or target class [%s] to value [%s]", name, type,
|
||||
safeToString(ultimateTarget), targetClass, value));
|
||||
safeToString(targetObject), targetClass, value));
|
||||
}
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
ReflectionUtils.setField(field, ultimateTarget, value);
|
||||
ReflectionUtils.setField(field, targetObject, value);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -245,24 +250,25 @@ public class ReflectionTestUtils {
|
||||
Assert.isTrue(targetObject != null || targetClass != null,
|
||||
"Either targetObject or targetClass for the field must be specified");
|
||||
|
||||
Object ultimateTarget = (targetObject != null ? AopTestUtils.getUltimateTargetObject(targetObject) : null);
|
||||
|
||||
if (targetObject != null && springAopPresent) {
|
||||
targetObject = AopTestUtils.getUltimateTargetObject(targetObject);
|
||||
}
|
||||
if (targetClass == null) {
|
||||
targetClass = ultimateTarget.getClass();
|
||||
targetClass = targetObject.getClass();
|
||||
}
|
||||
|
||||
Field field = ReflectionUtils.findField(targetClass, name);
|
||||
if (field == null) {
|
||||
throw new IllegalArgumentException(String.format("Could not find field '%s' on %s or target class [%s]",
|
||||
name, safeToString(ultimateTarget), targetClass));
|
||||
name, safeToString(targetObject), targetClass));
|
||||
}
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Getting field '%s' from %s or target class [%s]", name,
|
||||
safeToString(ultimateTarget), targetClass));
|
||||
safeToString(targetObject), targetClass));
|
||||
}
|
||||
ReflectionUtils.makeAccessible(field);
|
||||
return ReflectionUtils.getField(field, ultimateTarget);
|
||||
return ReflectionUtils.getField(field, targetObject);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user