diff --git a/build.gradle b/build.gradle
index 2870f9cafd2..806d03fa39d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -91,11 +91,19 @@ configure(subprojects) { subproject ->
project('spring-core') {
description = 'Spring Core'
+ // As of Spring 3.2 spring-core repackages both asm 4.0 and cglib 3.0 and inlines both
+ // into the spring-core jar. cglib 3.0 itself depends on asm 4.0, and is therefore
+ // further transformed by the JarJar task to depend on org.springframework.asm; this
+ // avoids including two different copies of asm unnecessarily. If however future cglib
+ // versions drift from the version of asm used by Spring internally, this duplication
+ // will become necessary.
def asmVersion = '4.0'
+ def cglibVersion = '3.0'
configurations {
jarjar
asm
+ cglib
}
task asmRepackJar(type: Jar) { repackJar ->
@@ -116,8 +124,32 @@ project('spring-core') {
}
}
+ task cglibRepackJar(type: Jar) { repackJar ->
+ repackJar.baseName = "spring-cglib-repack"
+ repackJar.version = cglibVersion
+
+ doLast() {
+ project.ant {
+ taskdef name: "jarjar", classname: "com.tonicsystems.jarjar.JarJarTask",
+ classpath: configurations.jarjar.asPath
+ jarjar(destfile: repackJar.archivePath) {
+ configurations.cglib.each { originalJar ->
+ zipfileset(src: originalJar)
+ }
+ // repackage net.sf.cglib => org.springframework.cglib
+ rule(pattern: 'net.sf.cglib.**', result: 'org.springframework.cglib.@1')
+ // as mentioned above, transform cglib's internal asm dependencies from
+ // org.objectweb.asm => org.springframework.asm. Doing this counts on the
+ // the fact that Spring and cglib depend on the same version of asm!
+ rule(pattern: 'org.objectweb.asm.**', result: 'org.springframework.asm.@1')
+ }
+ }
+ }
+ }
+
dependencies {
asm "org.ow2.asm:asm:${asmVersion}@jar", "org.ow2.asm:asm-commons:${asmVersion}@jar"
+ cglib "cglib:cglib:${cglibVersion}@jar"
jarjar 'com.googlecode.jarjar:jarjar:1.3'
compile files(asmRepackJar)
@@ -139,10 +171,13 @@ project('spring-core') {
}
jar {
- // inline all repackaged asm classes directly into the spring-core jar
+ // inline all repackaged asm and cglib classes directly into the spring-core jar
from(asmRepackJar) {
exclude 'META-INF/**'
}
+ from(cglibRepackJar) {
+ exclude 'META-INF/**'
+ }
}
}
@@ -150,9 +185,9 @@ project('spring-beans') {
description = 'Spring Beans'
dependencies {
compile project(":spring-core")
+ compile files(project(":spring-core").cglibRepackJar)
compile("javax.el:el-api:1.0", provided)
compile("javax.inject:javax.inject:1", provided)
- compile("cglib:cglib-nodep:2.2", optional)
}
}
@@ -160,6 +195,7 @@ project('spring-aop') {
description = 'Spring AOP'
dependencies {
compile project(":spring-core")
+ compile files(project(":spring-core").cglibRepackJar)
compile project(":spring-beans")
compile("aopalliance:aopalliance:1.0")
compile("com.jamonapi:jamon:2.4", optional)
@@ -200,6 +236,7 @@ project('spring-context') {
compile project(":spring-beans")
compile project(":spring-expression")
compile project(":spring-core")
+ compile files(project(":spring-core").cglibRepackJar)
compile("backport-util-concurrent:backport-util-concurrent:3.0", optional)
compile("javax.annotation:jsr250-api:1.0", optional)
compile("javax.ejb:ejb-api:3.0", optional)
diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/Cglib2AopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java
similarity index 91%
rename from spring-aop/src/main/java/org/springframework/aop/framework/Cglib2AopProxy.java
rename to spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java
index 46ed66b9049..49bfe5fc2b4 100644
--- a/spring-aop/src/main/java/org/springframework/aop/framework/Cglib2AopProxy.java
+++ b/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2010 the original author or authors.
+ * Copyright 2002-2012 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.
@@ -25,16 +25,16 @@ import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
-import net.sf.cglib.core.CodeGenerationException;
-import net.sf.cglib.proxy.Callback;
-import net.sf.cglib.proxy.CallbackFilter;
-import net.sf.cglib.proxy.Dispatcher;
-import net.sf.cglib.proxy.Enhancer;
-import net.sf.cglib.proxy.Factory;
-import net.sf.cglib.proxy.MethodInterceptor;
-import net.sf.cglib.proxy.MethodProxy;
-import net.sf.cglib.proxy.NoOp;
-import net.sf.cglib.transform.impl.UndeclaredThrowableStrategy;
+import org.springframework.cglib.core.CodeGenerationException;
+import org.springframework.cglib.proxy.Callback;
+import org.springframework.cglib.proxy.CallbackFilter;
+import org.springframework.cglib.proxy.Dispatcher;
+import org.springframework.cglib.proxy.Enhancer;
+import org.springframework.cglib.proxy.Factory;
+import org.springframework.cglib.proxy.MethodInterceptor;
+import org.springframework.cglib.proxy.MethodProxy;
+import org.springframework.cglib.proxy.NoOp;
+import org.springframework.cglib.transform.impl.UndeclaredThrowableStrategy;
import org.aopalliance.aop.Advice;
import org.aopalliance.intercept.MethodInvocation;
@@ -51,16 +51,16 @@ import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
/**
- * CGLIB2-based {@link AopProxy} implementation for the Spring AOP framework.
+ * CGLIB-based {@link AopProxy} implementation for the Spring AOP framework.
*
- *
Requires CGLIB 2.1+ on the classpath..
- * As of Spring 2.0, earlier CGLIB versions are not supported anymore.
+ *
Formerly named {@code Cglib2AopProxy}, as of Spring 3.2, this class depends on
+ * Spring's own internally repackaged version of CGLIB 3..
*
*
Objects of this type should be obtained through proxy factories,
* configured by an {@link AdvisedSupport} object. This class is internal
* to Spring's AOP framework and need not be used directly by client code.
*
- *
{@link DefaultAopProxyFactory} will automatically create CGLIB2-based
+ *
{@link DefaultAopProxyFactory} will automatically create CGLIB-based
* proxies if necessary, for example in case of proxying a target class
* (see the {@link DefaultAopProxyFactory attendant javadoc} for details).
*
@@ -71,11 +71,13 @@ import org.springframework.util.ObjectUtils;
* @author Rob Harrop
* @author Juergen Hoeller
* @author Ramnivas Laddad
- * @see net.sf.cglib.proxy.Enhancer
+ * @author Chris Beams
+ * @see org.springframework.cglib.proxy.Enhancer
* @see AdvisedSupport#setProxyTargetClass
* @see DefaultAopProxyFactory
*/
-final class Cglib2AopProxy implements AopProxy, Serializable {
+@SuppressWarnings("serial")
+final class CglibAopProxy implements AopProxy, Serializable {
// Constants for CGLIB callback array indices
private static final int AOP_PROXY = 0;
@@ -88,10 +90,10 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
/** Logger available to subclasses; static to optimize serialization */
- protected final static Log logger = LogFactory.getLog(Cglib2AopProxy.class);
+ protected final static Log logger = LogFactory.getLog(CglibAopProxy.class);
/** Keeps track of the Classes that we have validated for final methods */
- private static final Map validatedClasses = new WeakHashMap();
+ private static final Map, Boolean> validatedClasses = new WeakHashMap, Boolean>();
/** The configuration used to configure this proxy */
@@ -99,7 +101,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
private Object[] constructorArgs;
- private Class[] constructorArgTypes;
+ private Class>[] constructorArgTypes;
/** Dispatcher used for methods on Advised */
private final transient AdvisedDispatcher advisedDispatcher;
@@ -110,12 +112,12 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
/**
- * Create a new Cglib2AopProxy for the given AOP configuration.
+ * Create a new CglibAopProxy for the given AOP configuration.
* @param config the AOP configuration as AdvisedSupport object
* @throws AopConfigException if the config is invalid. We try to throw an informative
* exception in this case, rather than let a mysterious failure happen later.
*/
- public Cglib2AopProxy(AdvisedSupport config) throws AopConfigException {
+ public CglibAopProxy(AdvisedSupport config) throws AopConfigException {
Assert.notNull(config, "AdvisedSupport must not be null");
if (config.getAdvisors().length == 0 && config.getTargetSource() == AdvisedSupport.EMPTY_TARGET_SOURCE) {
throw new AopConfigException("No advisors and no TargetSource specified");
@@ -129,7 +131,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
* @param constructorArgs the constructor argument values
* @param constructorArgTypes the constructor argument types
*/
- public void setConstructorArguments(Object[] constructorArgs, Class[] constructorArgTypes) {
+ public void setConstructorArguments(Object[] constructorArgs, Class>[] constructorArgTypes) {
if (constructorArgs == null || constructorArgTypes == null) {
throw new IllegalArgumentException("Both 'constructorArgs' and 'constructorArgTypes' need to be specified");
}
@@ -148,18 +150,18 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
public Object getProxy(ClassLoader classLoader) {
if (logger.isDebugEnabled()) {
- logger.debug("Creating CGLIB2 proxy: target source is " + this.advised.getTargetSource());
+ logger.debug("Creating CGLIB proxy: target source is " + this.advised.getTargetSource());
}
try {
- Class rootClass = this.advised.getTargetClass();
+ Class> rootClass = this.advised.getTargetClass();
Assert.state(rootClass != null, "Target class must be available for creating a CGLIB proxy");
- Class proxySuperClass = rootClass;
+ Class> proxySuperClass = rootClass;
if (ClassUtils.isCglibProxyClass(rootClass)) {
proxySuperClass = rootClass.getSuperclass();
- Class[] additionalInterfaces = rootClass.getInterfaces();
- for (Class additionalInterface : additionalInterfaces) {
+ Class>[] additionalInterfaces = rootClass.getInterfaces();
+ for (Class> additionalInterface : additionalInterfaces) {
this.advised.addInterface(additionalInterface);
}
}
@@ -186,7 +188,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
enhancer.setCallbackFilter(new ProxyCallbackFilter(
this.advised.getConfigurationOnlyCopy(), this.fixedInterceptorMap, this.fixedInterceptorOffset));
- Class[] types = new Class[callbacks.length];
+ Class>[] types = new Class[callbacks.length];
for (int x = 0; x < types.length; x++) {
types[x] = callbacks[x].getClass();
}
@@ -233,7 +235,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
* Checks to see whether the supplied Class has already been validated and
* validates it if not.
*/
- private void validateClassIfNecessary(Class proxySuperClass) {
+ private void validateClassIfNecessary(Class> proxySuperClass) {
if (logger.isWarnEnabled()) {
synchronized (validatedClasses) {
if (!validatedClasses.containsKey(proxySuperClass)) {
@@ -248,7 +250,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
* Checks for final methods on the Class and writes warnings to the log
* for each one found.
*/
- private void doValidateClass(Class proxySuperClass) {
+ private void doValidateClass(Class> proxySuperClass) {
Method[] methods = proxySuperClass.getMethods();
for (Method method : methods) {
if (!Object.class.equals(method.getDeclaringClass()) && Modifier.isFinal(method.getModifiers())) {
@@ -258,7 +260,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
}
}
- private Callback[] getCallbacks(Class rootClass) throws Exception {
+ private Callback[] getCallbacks(Class> rootClass) throws Exception {
// Parameters used for optimisation choices...
boolean exposeProxy = this.advised.isExposeProxy();
boolean isFrozen = this.advised.isFrozen();
@@ -345,13 +347,13 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
@Override
public boolean equals(Object other) {
- return (this == other || (other instanceof Cglib2AopProxy &&
- AopProxyUtils.equalsInProxy(this.advised, ((Cglib2AopProxy) other).advised)));
+ return (this == other || (other instanceof CglibAopProxy &&
+ AopProxyUtils.equalsInProxy(this.advised, ((CglibAopProxy) other).advised)));
}
@Override
public int hashCode() {
- return Cglib2AopProxy.class.hashCode() * 13 + this.advised.getTargetSource().hashCode();
+ return CglibAopProxy.class.hashCode() * 13 + this.advised.getTargetSource().hashCode();
}
@@ -544,7 +546,7 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
}
public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) {
- return Cglib2AopProxy.class.hashCode() * 13 + this.advised.getTargetSource().hashCode();
+ return CglibAopProxy.class.hashCode() * 13 + this.advised.getTargetSource().hashCode();
}
}
@@ -558,9 +560,9 @@ final class Cglib2AopProxy implements AopProxy, Serializable {
private final Object target;
- private final Class targetClass;
+ private final Class> targetClass;
- public FixedChainStaticTargetInterceptor(List