Polishing
This commit is contained in:
@@ -197,6 +197,20 @@ class ConfigurationClassParser {
|
||||
processConfigurationClass(new ConfigurationClass(metadata, beanName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate each {@link ConfigurationClass} object.
|
||||
* @see ConfigurationClass#validate
|
||||
*/
|
||||
public void validate() {
|
||||
for (ConfigurationClass configClass : this.configurationClasses.keySet()) {
|
||||
configClass.validate(this.problemReporter);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<ConfigurationClass> getConfigurationClasses() {
|
||||
return this.configurationClasses.keySet();
|
||||
}
|
||||
|
||||
|
||||
protected void processConfigurationClass(ConfigurationClass configClass) throws IOException {
|
||||
if (this.conditionEvaluator.shouldSkip(configClass.getMetadata(), ConfigurationPhase.PARSE_CONFIGURATION)) {
|
||||
@@ -390,6 +404,7 @@ class ConfigurationClassParser {
|
||||
return beanMethods;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Process the given <code>@PropertySource</code> annotation metadata.
|
||||
* @param propertySource metadata for the <code>@PropertySource</code> annotation found
|
||||
@@ -608,30 +623,15 @@ class ConfigurationClassParser {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validate each {@link ConfigurationClass} object.
|
||||
* @see ConfigurationClass#validate
|
||||
*/
|
||||
public void validate() {
|
||||
for (ConfigurationClass configClass : this.configurationClasses.keySet()) {
|
||||
configClass.validate(this.problemReporter);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<ConfigurationClass> getConfigurationClasses() {
|
||||
return this.configurationClasses.keySet();
|
||||
}
|
||||
|
||||
|
||||
ImportRegistry getImportRegistry() {
|
||||
return this.importStack;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Factory method to obtain a {@link SourceClass} from a {@link ConfigurationClass}.
|
||||
*/
|
||||
public SourceClass asSourceClass(ConfigurationClass configurationClass) throws IOException {
|
||||
private SourceClass asSourceClass(ConfigurationClass configurationClass) throws IOException {
|
||||
AnnotationMetadata metadata = configurationClass.getMetadata();
|
||||
if (metadata instanceof StandardAnnotationMetadata) {
|
||||
return asSourceClass(((StandardAnnotationMetadata) metadata).getIntrospectedClass());
|
||||
@@ -642,7 +642,7 @@ class ConfigurationClassParser {
|
||||
/**
|
||||
* Factory method to obtain a {@link SourceClass} from a {@link Class}.
|
||||
*/
|
||||
public SourceClass asSourceClass(Class<?> classType) throws IOException {
|
||||
SourceClass asSourceClass(Class<?> classType) throws IOException {
|
||||
try {
|
||||
// Sanity test that we can read annotations, if not fall back to ASM
|
||||
classType.getAnnotations();
|
||||
@@ -657,8 +657,8 @@ class ConfigurationClassParser {
|
||||
/**
|
||||
* Factory method to obtain {@link SourceClass}s from class names.
|
||||
*/
|
||||
public Collection<SourceClass> asSourceClasses(String[] classNames) throws IOException {
|
||||
List<SourceClass> annotatedClasses = new ArrayList<SourceClass>();
|
||||
private Collection<SourceClass> asSourceClasses(String[] classNames) throws IOException {
|
||||
List<SourceClass> annotatedClasses = new ArrayList<SourceClass>(classNames.length);
|
||||
for (String className : classNames) {
|
||||
annotatedClasses.add(asSourceClass(className));
|
||||
}
|
||||
@@ -668,7 +668,7 @@ class ConfigurationClassParser {
|
||||
/**
|
||||
* Factory method to obtain a {@link SourceClass} from a class name.
|
||||
*/
|
||||
public SourceClass asSourceClass(String className) throws IOException {
|
||||
SourceClass asSourceClass(String className) throws IOException {
|
||||
if (className.startsWith("java")) {
|
||||
// Never use ASM for core java types
|
||||
try {
|
||||
|
||||
@@ -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.
|
||||
@@ -37,7 +37,8 @@ import org.springframework.util.ClassUtils;
|
||||
*/
|
||||
public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
|
||||
|
||||
private static final String INSTRUMENTABLE_LOADER_CLASS_NAME = "org.glassfish.api.deployment.InstrumentableClassLoader";
|
||||
private static final String INSTRUMENTABLE_LOADER_CLASS_NAME =
|
||||
"org.glassfish.api.deployment.InstrumentableClassLoader";
|
||||
|
||||
|
||||
private final ClassLoader classLoader;
|
||||
@@ -57,16 +58,10 @@ public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
|
||||
Class<?> instrumentableLoaderClass;
|
||||
try {
|
||||
instrumentableLoaderClass = classLoader.loadClass(INSTRUMENTABLE_LOADER_CLASS_NAME);
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
throw new IllegalStateException(
|
||||
"Could not initialize GlassFishLoadTimeWeaver because GlassFish API classes are not available", ex);
|
||||
}
|
||||
try {
|
||||
this.addTransformerMethod = instrumentableLoaderClass.getMethod("addTransformer", ClassFileTransformer.class);
|
||||
this.copyMethod = instrumentableLoaderClass.getMethod("copy");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(
|
||||
"Could not initialize GlassFishLoadTimeWeaver because GlassFish API classes are not available", ex);
|
||||
}
|
||||
@@ -97,7 +92,7 @@ public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
|
||||
catch (InvocationTargetException ex) {
|
||||
throw new IllegalStateException("GlassFish addTransformer method threw exception", ex.getCause());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Could not invoke GlassFish addTransformer method", ex);
|
||||
}
|
||||
}
|
||||
@@ -115,7 +110,7 @@ public class GlassFishLoadTimeWeaver implements LoadTimeWeaver {
|
||||
catch (InvocationTargetException ex) {
|
||||
throw new IllegalStateException("GlassFish copy method threw exception", ex.getCause());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Could not invoke GlassFish copy method", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ class JBossMCAdapter implements JBossClassLoaderAdapter {
|
||||
this.translatorClass = classLoader.loadClass(TRANSLATOR_NAME);
|
||||
this.addTranslator = this.target.getClass().getMethod("addTranslator", this.translatorClass);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(
|
||||
"Could not initialize JBoss LoadTimeWeaver because the JBoss 6 API classes are not available", ex);
|
||||
}
|
||||
@@ -92,7 +92,7 @@ class JBossMCAdapter implements JBossClassLoaderAdapter {
|
||||
try {
|
||||
this.addTranslator.invoke(this.target, adapterInstance);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Could not add transformer on JBoss 6 ClassLoader " + this.classLoader, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -78,10 +78,7 @@ class JBossMCTranslatorAdapter implements InvocationHandler {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(getClass().getName());
|
||||
builder.append(" for transformer: ");
|
||||
builder.append(this.transformer);
|
||||
return builder.toString();
|
||||
return getClass().getName() + " for transformer: " + this.transformer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -43,22 +43,32 @@ class JBossModulesAdapter implements JBossClassLoaderAdapter {
|
||||
private final Object delegatingTransformer;
|
||||
|
||||
|
||||
public JBossModulesAdapter(ClassLoader loader) {
|
||||
this.classLoader = loader;
|
||||
public JBossModulesAdapter(ClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
try {
|
||||
Field transformer = ReflectionUtils.findField(loader.getClass(), "transformer");
|
||||
Field transformer = ReflectionUtils.findField(classLoader.getClass(), "transformer");
|
||||
if (transformer == null) {
|
||||
throw new IllegalArgumentException("Could not find 'transformer' field on JBoss ClassLoader: " +
|
||||
classLoader.getClass().getName());
|
||||
}
|
||||
transformer.setAccessible(true);
|
||||
this.delegatingTransformer = transformer.get(loader);
|
||||
this.delegatingTransformer = transformer.get(classLoader);
|
||||
if (!this.delegatingTransformer.getClass().getName().equals(DELEGATING_TRANSFORMER_CLASS_NAME)) {
|
||||
throw new IllegalStateException("Transformer not of the expected type DelegatingClassFileTransformer: " +
|
||||
throw new IllegalStateException(
|
||||
"Transformer not of the expected type DelegatingClassFileTransformer: " +
|
||||
this.delegatingTransformer.getClass().getName());
|
||||
}
|
||||
this.addTransformer = ReflectionUtils.findMethod(this.delegatingTransformer.getClass(),
|
||||
"addTransformer", ClassFileTransformer.class);
|
||||
if (this.addTransformer == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"Could not find 'addTransformer' method on JBoss DelegatingClassFileTransformer: " +
|
||||
this.delegatingTransformer.getClass().getName());
|
||||
}
|
||||
this.addTransformer.setAccessible(true);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException("Could not initialize JBoss 7 LoadTimeWeaver", ex);
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Could not initialize JBoss LoadTimeWeaver", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +77,7 @@ class JBossModulesAdapter implements JBossClassLoaderAdapter {
|
||||
try {
|
||||
this.addTransformer.invoke(this.delegatingTransformer, transformer);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Could not add transformer on JBoss 7 ClassLoader " + this.classLoader, ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -76,7 +76,7 @@ public class TomcatLoadTimeWeaver implements LoadTimeWeaver {
|
||||
}
|
||||
this.copyMethod = copyMethod;
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(
|
||||
"Could not initialize TomcatLoadTimeWeaver because Tomcat API classes are not available", ex);
|
||||
}
|
||||
@@ -91,7 +91,7 @@ public class TomcatLoadTimeWeaver implements LoadTimeWeaver {
|
||||
catch (InvocationTargetException ex) {
|
||||
throw new IllegalStateException("Tomcat addTransformer method threw exception", ex.getCause());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Could not invoke Tomcat addTransformer method", ex);
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class TomcatLoadTimeWeaver implements LoadTimeWeaver {
|
||||
catch (InvocationTargetException ex) {
|
||||
throw new IllegalStateException("Tomcat copy method threw exception", ex.getCause());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Could not invoke Tomcat copy method", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
@@ -28,7 +28,6 @@ import java.util.List;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
*
|
||||
* Reflective wrapper around a WebSphere 7+ class loader. Used to
|
||||
* encapsulate the classloader-specific methods (discovered and
|
||||
* called through reflection) from the load-time weaver.
|
||||
@@ -45,6 +44,7 @@ class WebSphereClassLoaderAdapter {
|
||||
|
||||
private static final String PLUGINS_FIELD = "preDefinePlugins";
|
||||
|
||||
|
||||
private ClassLoader classLoader;
|
||||
|
||||
private Class<?> wsPreProcessorClass;
|
||||
@@ -68,13 +68,13 @@ class WebSphereClassLoaderAdapter {
|
||||
this.transformerList = wsCompoundClassLoaderClass.getDeclaredField(PLUGINS_FIELD);
|
||||
this.transformerList.setAccessible(true);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(
|
||||
"Could not initialize WebSphere LoadTimeWeaver because WebSphere API classes are not available", ex);
|
||||
}
|
||||
|
||||
if (!wsCompoundClassLoaderClass.isInstance(classLoader)) {
|
||||
throw new IllegalArgumentException("ClassLoader must be instance of [" + COMPOUND_CLASS_LOADER_NAME + "]");
|
||||
throw new IllegalArgumentException("ClassLoader must be instance of " + COMPOUND_CLASS_LOADER_NAME);
|
||||
}
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class WebSphereClassLoaderAdapter {
|
||||
catch (InvocationTargetException ex) {
|
||||
throw new IllegalStateException("WebSphere addPreDefinePlugin method threw exception", ex.getCause());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Could not invoke WebSphere addPreDefinePlugin method", ex);
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ class WebSphereClassLoaderAdapter {
|
||||
catch (InvocationTargetException ex) {
|
||||
throw new IllegalStateException("WebSphere CompoundClassLoader constructor failed", ex.getCause());
|
||||
}
|
||||
catch (Exception ex) {
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException("Could not construct WebSphere CompoundClassLoader", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.instrument.classloading.websphere;
|
||||
|
||||
import java.lang.instrument.ClassFileTransformer;
|
||||
@@ -46,7 +47,7 @@ class WebSphereClassPreDefinePlugin implements InvocationHandler {
|
||||
this.transformer = transformer;
|
||||
ClassLoader classLoader = transformer.getClass().getClassLoader();
|
||||
|
||||
// first force the full class loading of the weaver by invoking transformation on a dummy class
|
||||
// First force the full class loading of the weaver by invoking transformation on a dummy class
|
||||
try {
|
||||
String dummyClass = Dummy.class.getName().replace('.', '/');
|
||||
byte[] bytes = FileCopyUtils.copyToByteArray(classLoader.getResourceAsStream(dummyClass + ".class"));
|
||||
@@ -81,17 +82,14 @@ class WebSphereClassPreDefinePlugin implements InvocationHandler {
|
||||
protected byte[] transform(String className, byte[] classfileBuffer, CodeSource codeSource, ClassLoader classLoader)
|
||||
throws Exception {
|
||||
|
||||
// NB: WebSphere passes className as "." without class while the transformer expects a VM, "/" format
|
||||
// NB: WebSphere passes className as "." without class while the transformer expects a VM "/" format
|
||||
byte[] result = transformer.transform(classLoader, className.replace('.', '/'), null, null, classfileBuffer);
|
||||
return (result != null ? result : classfileBuffer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder(getClass().getName());
|
||||
builder.append(" for transformer: ");
|
||||
builder.append(this.transformer);
|
||||
return builder.toString();
|
||||
return getClass().getName() + " for transformer: " + this.transformer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user