提交 c16f18a5 编写于 作者: C Chris Beams

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
上级 69a39298
#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;
#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;
......@@ -88,30 +88,27 @@ 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')
}
......@@ -119,24 +116,11 @@ project("spring-asm") {
}
}
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') {
......
rootProject.name = 'spring'
include 'spring-aop'
include 'spring-asm'
include 'spring-aspects'
include 'spring-beans'
include 'spring-context'
......
......@@ -17,10 +17,9 @@
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}.
*
......@@ -28,4 +27,12 @@ package org.springframework.asm;
* @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;
}
/*
* 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 {@code org.objectweb.asm.*} (for internal use only).
* 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/asm223/javadoc/user">ASM 2.2.3 Javadoc</a>
* <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;
/*
* 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.Log;
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 @@ import org.springframework.util.ClassUtils;
* @author Adrian Colyer
* @author Costin Leau
* @author Juergen Hoeller
* @author Chris Beams
* @since 2.0
*/
public class LocalVariableTableParameterNameDiscoverer implements ParameterNameDiscoverer {
......@@ -77,7 +79,7 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD
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 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD
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,7 +137,7 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD
* 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>";
......@@ -143,6 +145,7 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD
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 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD
}
private static class LocalVariableTableVisitor extends EmptyVisitor {
private static class LocalVariableTableVisitor extends MethodVisitor {
private static final String CONSTRUCTOR = "<init>";
......@@ -187,6 +190,7 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD
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;
......
/*
* 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 @@ public interface ParameterNameDiscoverer {
* @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 java.util.Set;
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 @@ import org.springframework.util.ReflectionUtils;
* @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 @@ abstract class AbstractRecursiveAnnotationVisitor implements AnnotationVisitor {
public AbstractRecursiveAnnotationVisitor(ClassLoader classLoader, AnnotationAttributes attributes) {
super(SpringAsmInfo.ASM_VERSION);
this.classLoader = classLoader;
this.attributes = attributes;
}
......
/*
* Copyright 2002-2009 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,7 +25,7 @@ import org.springframework.asm.ClassVisitor;
import org.springframework.asm.FieldVisitor;
import org.springframework.asm.MethodVisitor;
import org.springframework.asm.Opcodes;
import org.springframework.asm.commons.EmptyVisitor;
import org.springframework.asm.SpringAsmInfo;
import org.springframework.core.type.ClassMetadata;
import org.springframework.util.ClassUtils;
......@@ -38,9 +38,10 @@ import org.springframework.util.ClassUtils;
* @author Costin Leau
* @author Mark Fisher
* @author Ramnivas Laddad
* @author Chris Beams
* @since 2.5
*/
class ClassMetadataReadingVisitor implements ClassVisitor, ClassMetadata {
class ClassMetadataReadingVisitor extends ClassVisitor implements ClassMetadata {
private String className;
......@@ -61,6 +62,11 @@ class ClassMetadataReadingVisitor implements ClassVisitor, ClassMetadata {
private Set<String> memberClassNames = new LinkedHashSet<String>();
public ClassMetadataReadingVisitor() {
super(SpringAsmInfo.ASM_VERSION);
}
public void visit(int version, int access, String name, String signature, String supername, String[] interfaces) {
this.className = ClassUtils.convertResourcePathToClassName(name);
this.isInterface = ((access & Opcodes.ACC_INTERFACE) != 0);
......@@ -99,7 +105,7 @@ class ClassMetadataReadingVisitor implements ClassVisitor, ClassMetadata {
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
// no-op
return new EmptyVisitor();
return new EmptyAnnotationVisitor();
}
public void visitAttribute(Attribute attr) {
......@@ -108,12 +114,12 @@ class ClassMetadataReadingVisitor implements ClassVisitor, ClassMetadata {
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
// no-op
return new EmptyVisitor();
return new EmptyFieldVisitor();
}
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
// no-op
return new EmptyVisitor();
return new EmptyMethodVisitor();
}
public void visitEnd() {
......@@ -170,3 +176,38 @@ class ClassMetadataReadingVisitor implements ClassVisitor, ClassMetadata {
}
}
class EmptyAnnotationVisitor extends AnnotationVisitor {
public EmptyAnnotationVisitor() {
super(SpringAsmInfo.ASM_VERSION);
}
@Override
public AnnotationVisitor visitAnnotation(String name, String desc) {
return this;
}
@Override
public AnnotationVisitor visitArray(String name) {
return this;
}
}
class EmptyMethodVisitor extends MethodVisitor {
public EmptyMethodVisitor() {
super(SpringAsmInfo.ASM_VERSION);
}
}
class EmptyFieldVisitor extends FieldVisitor {
public EmptyFieldVisitor() {
super(SpringAsmInfo.ASM_VERSION);
}
}
\ No newline at end of file
......@@ -20,10 +20,10 @@ import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.asm.AnnotationVisitor;
import org.springframework.asm.MethodAdapter;
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.core.annotation.AnnotationAttributes;
import org.springframework.core.type.MethodMetadata;
import org.springframework.util.MultiValueMap;
......@@ -39,7 +39,7 @@ import org.springframework.util.MultiValueMap;
* @author Chris Beams
* @since 3.0
*/
final class MethodMetadataReadingVisitor extends MethodAdapter implements MethodMetadata {
final class MethodMetadataReadingVisitor extends MethodVisitor implements MethodMetadata {
private final String name;
......@@ -55,7 +55,7 @@ final class MethodMetadataReadingVisitor extends MethodAdapter implements Method
public MethodMetadataReadingVisitor(String name, int access, String declaringClassName, ClassLoader classLoader,
MultiValueMap<String, MethodMetadata> methodMetadataMap) {
super(new EmptyVisitor());
super(SpringAsmInfo.ASM_VERSION);
this.name = name;
this.access = access;
this.declaringClassName = declaringClassName;
......
......@@ -56,7 +56,7 @@ final class SimpleMetadataReader implements MetadataReader {
}
AnnotationMetadataReadingVisitor visitor = new AnnotationMetadataReadingVisitor(classLoader);
classReader.accept(visitor, true);
classReader.accept(visitor, ClassReader.SKIP_DEBUG);
this.annotationMetadata = visitor;
// (since AnnotationMetadataReader extends ClassMetadataReadingVisitor)
......
......@@ -36,6 +36,7 @@ Changes in version 3.2 M2 (2012-08-xx)
* introduced countRowsInTableWhere() and dropTables() in JdbcTestUtils (SPR-9235)
* introduced JdbcTemplate in tx base classes in the TestContext framework (SPR-8990)
* introduced countRowsInTableWhere() and dropTables() in tx base test classes (SPR-9665)
* inlined ASM 4.0 into spring-core, removed spring-asm subproject and jar (SPR-9669)
Changes in version 3.2 M1 (2012-05-28)
......
......@@ -202,18 +202,18 @@
=======================================================================
SPRING FRAMEWORK 3.1 SUBCOMPONENTS:
SPRING FRAMEWORK 3.2 SUBCOMPONENTS:
Spring Framework 3.1 includes a number of subcomponents with
Spring Framework 3.2 includes a number of subcomponents with
separate copyright notices and license terms. The product that
includes this file does not necessarily use all the open source
subcomponents referred to below. Your use of the source
code for these subcomponents is subject to the terms and
conditions of the following licenses.
>>> asm-2.2.3:
>>> asm-4.0:
Copyright (c) 2000-2005 INRIA, France Telecom
Copyright (c) 2000-2011 INRIA, France Telecom
All rights reserved.
Redistribution and use in source and binary forms, with or without
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册