Permalink
Browse files

Remove spring-asm and inline ASM 4 into spring-core

ASM 4.0 is generally compatibile with Java 7 classfiles, particularly
including 'invokedynamic' instructions. This is important when
considering that Spring's component-scanning support is internally
ASM-based and it is increasingly likely that component classes having
invokedynamic instructions may be encountered and read by ASM.
This upgrade, then, is primarily preventive in nature.

Changes include:

 - upgrade from ASM 2.2.3 to ASM 4.0

 - adapt to ASM API changes as necessary throughout spring-core,
   resulting in no impact to the public Spring API.

 - remove dedicated spring-asm module

 - use new :spring-core:asmRepackJar task to repackage
   org.objectweb.asm => org.springframework.asm as per usual and write
   repackaged classes directly into spring-core jar

The choice to eliminate the spring-asm module altogether and instead
inline the repackaged classes directly into spring-core is first to
eliminate an otherwise unnecessary second jar. spring-core has a
non-optional dependency on spring-asm meaning it is always on the
application classpath. This change simplifies that situation by
consoliding two jars into one. The second reason for this choice is in
anticipation of upgrading CGLIB to version 3 and inlining it into
spring-core as well. See subsequent commit for details.

Issue: SPR-9669
  • Loading branch information...
1 parent 69a3929 commit c16f18a5fd659f34d6290b5f2cffe54534b7592a @cbeams cbeams committed Aug 7, 2012
@@ -1,9 +1,9 @@
#com.springsource.sts.gradle.core.preferences.GradleImportPreferences
-#Thu Feb 23 14:10:34 CET 2012
+#Thu Aug 9 11:34:43 CEST 2012
enableAfterTasks=true
afterTasks=afterEclipseImport;
enableDependendencyManagement=false
enableBeforeTasks=true
-projects=;spring-aop;spring-asm;spring-aspects;spring-beans;spring-context;spring-context-support;spring-core;spring-expression;spring-instrument;spring-instrument-tomcat;spring-jdbc;spring-jms;spring-orm;spring-oxm;spring-struts;spring-test;spring-tx;spring-web;spring-webmvc;spring-webmvc-portlet;
+projects=;spring-aop;spring-aspects;spring-beans;spring-context;spring-context-support;spring-core;spring-expression;spring-instrument;spring-instrument-tomcat;spring-jdbc;spring-jms;spring-orm;spring-oxm;spring-struts;spring-test;spring-tx;spring-web;spring-webmvc;spring-webmvc-portlet;
enableDSLD=false
-beforeTasks=cleanEclipse;eclipse;\:spring-asm\:jar;\:spring-oxm\:compileTestJava;
+beforeTasks=cleanEclipse;eclipse;\:spring-oxm\:compileTestJava;
@@ -1,9 +1,9 @@
#com.springsource.sts.gradle.core.actions.GradleRefreshPreferences
-#Thu Feb 23 14:12:55 CET 2012
+#Thu Aug 9 11:34:43 CEST 2012
enableAfterTasks=true
afterTasks=afterEclipseImport;
useHierarchicalNames=false
enableBeforeTasks=true
addResourceFilters=false
enableDSLD=false
-beforeTasks=cleanEclipse;eclipse;\:spring-asm\:jar;\:spring-oxm\:compileTestJava;
+beforeTasks=cleanEclipse;eclipse;\:spring-oxm\:compileTestJava;
View
@@ -88,55 +88,39 @@ configure(subprojects) { subproject ->
}
-project("spring-asm") {
- description = 'Spring ASM'
- ext.asmVersion = '2.2.3'
+project('spring-core') {
+ description = 'Spring Core'
+
+ def asmVersion = '4.0'
configurations {
- asm
jarjar
- }
- dependencies {
- asm "asm:asm:${asmVersion}@jar", "asm:asm-commons:${asmVersion}@jar"
- jarjar 'com.googlecode.jarjar:jarjar:1.3'
+ asm
}
- task repackageAsm(type: Jar) { jar ->
- jar.baseName = "asm-repack"
- jar.version = asmVersion
+ task asmRepackJar(type: Jar) { repackJar ->
+ repackJar.baseName = "spring-asm-repack"
+ repackJar.version = asmVersion
doLast() {
project.ant {
taskdef name: "jarjar", classname: "com.tonicsystems.jarjar.JarJarTask",
classpath: configurations.jarjar.asPath
- jarjar(destfile: archivePath, index: "true", filesetmanifest: "merge") {
- configurations.asm.each { jarfile ->
- zipfileset(src: jarfile)
+ jarjar(destfile: repackJar.archivePath) {
+ configurations.asm.each { originalJar ->
+ zipfileset(src: originalJar)
}
rule(pattern: 'org.objectweb.asm.**', result: 'org.springframework.asm.@1')
}
}
}
}
- jar {
- dependsOn repackageAsm
- from(zipTree(repackageAsm.archivePath)) {
- exclude 'META-INF/INDEX.LIST'
- }
- }
-}
-
-project('spring-core') {
- description = 'Spring Core'
dependencies {
- // depend on spring-asm project in order to have it show up as a
- // <dependency> in the generated pom
- compile project(":spring-asm")
- // depend directly on the spring-asm jar to avoid errors in Eclipse/STS
- compile files(project(":spring-asm").jar.archivePath) {
- builtBy project(":spring-asm").jar
- }
+ asm "org.ow2.asm:asm:${asmVersion}@jar", "org.ow2.asm:asm-commons:${asmVersion}@jar"
+ jarjar 'com.googlecode.jarjar:jarjar:1.3'
+
+ compile files(asmRepackJar)
compile "commons-logging:commons-logging:1.1.1"
compile("org.aspectj:aspectjweaver:${aspectjVersion}", optional)
compile("net.sf.jopt-simple:jopt-simple:3.0") { dep ->
@@ -153,6 +137,13 @@ project('spring-core') {
testCompile "xmlunit:xmlunit:1.2"
testCompile "org.codehaus.woodstox:wstx-asl:3.2.7"
}
+
+ jar {
+ // inline all repackaged asm classes directly into the spring-core jar
+ from(asmRepackJar) {
+ exclude 'META-INF/**'
+ }
+ }
}
project('spring-beans') {
View
@@ -1,7 +1,6 @@
rootProject.name = 'spring'
include 'spring-aop'
-include 'spring-asm'
include 'spring-aspects'
include 'spring-beans'
include 'spring-context'
@@ -1,11 +0,0 @@
-/**
- * Spring's repackaging of {@code org.objectweb.asm.*} (for internal use only).
- * <p>This repackaging technique avoids any potential conflicts with
- * dependencies on ASM at the application level or from other third-party
- * libraries and frameworks.
- * <p>As this repackaging happens at the classfile level, sources and Javadoc
- * are not available here. See the original ObjectWeb
- * <a href="http://asm.ow2.org/asm223/javadoc/user">ASM 2.2.3 Javadoc</a>
- * for details when working with these classes.
- */
-package org.springframework.asm;
@@ -17,15 +17,22 @@
package org.springframework.asm;
/**
- * Placeholder to allow Javadoc generation. Required because
- * <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4492654">this bug</a>
- * does not allow the generation of Javadoc for packages having only a
- * {@code package-info.java} file.
+ * Utility class exposing constants related to Spring's internal repackaging of the ASM
+ * bytecode manipulation library.
+ *
* <p>See <a href="package-summary.html">package-level Javadoc</a> for more
* information on {@code org.springframework.asm}.
*
* @author Chris Beams
* @since 3.2
*/
public final class SpringAsmInfo {
+
+ /**
+ * The ASM version used internally throughout the framework.
+ *
+ * @see Opcodes#ASM4
+ */
+ public static final int ASM_VERSION = Opcodes.ASM4;
+
}
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ * 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.
+ */
+
+/**
+ * Spring's repackaging of <a href="http://asm.ow2.org">org.objectweb.asm 4</a> (for
+ * internal use only).
+ * <p>This repackaging technique avoids any potential conflicts with
+ * dependencies on ASM at the application level or from other third-party
+ * libraries and frameworks.
+ * <p>As this repackaging happens at the classfile level, sources and Javadoc
+ * are not available here. See the original ObjectWeb
+ * <a href="http://asm.ow2.org/asm40/javadoc/user">ASM 4 Javadoc</a>
+ * for details when working with these classes.
+ *
+ * @since 3.2
+ */
+package org.springframework.asm;
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ * 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.
+ */
+
+/**
+ * Dummy implementations of asm-util classes (for internal use only).
+ *
+ * @since 3.2
+ */
+package org.springframework.asm.util;
@@ -29,11 +29,12 @@
import org.apache.commons.logging.LogFactory;
import org.springframework.asm.ClassReader;
+import org.springframework.asm.ClassVisitor;
import org.springframework.asm.Label;
import org.springframework.asm.MethodVisitor;
import org.springframework.asm.Opcodes;
+import org.springframework.asm.SpringAsmInfo;
import org.springframework.asm.Type;
-import org.springframework.asm.commons.EmptyVisitor;
import org.springframework.util.ClassUtils;
/**
@@ -49,6 +50,7 @@
* @author Adrian Colyer
* @author Costin Leau
* @author Juergen Hoeller
+ * @author Chris Beams
* @since 2.0
*/
public class LocalVariableTableParameterNameDiscoverer implements ParameterNameDiscoverer {
@@ -77,7 +79,7 @@
return null;
}
- public String[] getParameterNames(Constructor ctor) {
+ public String[] getParameterNames(Constructor<?> ctor) {
Class<?> declaringClass = ctor.getDeclaringClass();
Map<Member, String[]> map = this.parameterNamesCache.get(declaringClass);
if (map == null) {
@@ -110,7 +112,7 @@
try {
ClassReader classReader = new ClassReader(is);
Map<Member, String[]> map = new ConcurrentHashMap<Member, String[]>();
- classReader.accept(new ParameterNameDiscoveringVisitor(clazz, map), false);
+ classReader.accept(new ParameterNameDiscoveringVisitor(clazz, map), 0);
return map;
}
catch (IOException ex) {
@@ -135,14 +137,15 @@
* Helper class that inspects all methods (constructor included) and then
* attempts to find the parameter names for that member.
*/
- private static class ParameterNameDiscoveringVisitor extends EmptyVisitor {
+ private static class ParameterNameDiscoveringVisitor extends ClassVisitor {
private static final String STATIC_CLASS_INIT = "<clinit>";
private final Class<?> clazz;
private final Map<Member, String[]> memberMap;
public ParameterNameDiscoveringVisitor(Class<?> clazz, Map<Member, String[]> memberMap) {
+ super(SpringAsmInfo.ASM_VERSION);
this.clazz = clazz;
this.memberMap = memberMap;
}
@@ -166,7 +169,7 @@ private static boolean isStatic(int access) {
}
- private static class LocalVariableTableVisitor extends EmptyVisitor {
+ private static class LocalVariableTableVisitor extends MethodVisitor {
private static final String CONSTRUCTOR = "<init>";
@@ -187,6 +190,7 @@ private static boolean isStatic(int access) {
public LocalVariableTableVisitor(Class<?> clazz, Map<Member, String[]> map, String name, String desc,
boolean isStatic) {
+ super(SpringAsmInfo.ASM_VERSION);
this.clazz = clazz;
this.memberMap = map;
this.name = name;
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2006 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.
@@ -49,6 +49,6 @@
* @return an array of parameter names if the names can be resolved,
* or <code>null</code> if they cannot
*/
- String[] getParameterNames(Constructor ctor);
+ String[] getParameterNames(Constructor<?> ctor);
}
@@ -29,6 +29,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.asm.AnnotationVisitor;
+import org.springframework.asm.SpringAsmInfo;
import org.springframework.asm.Type;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.AnnotationUtils;
@@ -41,7 +42,7 @@
* @author Juergen Hoeller
* @since 3.1.1
*/
-abstract class AbstractRecursiveAnnotationVisitor implements AnnotationVisitor {
+abstract class AbstractRecursiveAnnotationVisitor extends AnnotationVisitor {
protected final Log logger = LogFactory.getLog(this.getClass());
@@ -51,6 +52,7 @@
public AbstractRecursiveAnnotationVisitor(ClassLoader classLoader, AnnotationAttributes attributes) {
+ super(SpringAsmInfo.ASM_VERSION);
this.classLoader = classLoader;
this.attributes = attributes;
}
Oops, something went wrong.

0 comments on commit c16f18a

Please sign in to comment.