use of org.springframework.asm.ClassReader in project spring-boot by spring-projects.
the class AutoConfigurationMetadata method readAutoConfiguration.
private Properties readAutoConfiguration() throws IOException {
Properties autoConfiguration = CollectionFactory.createSortedProperties(true);
Set<String> classNames = new LinkedHashSet<>();
classNames.addAll(readSpringFactories());
classNames.addAll(readAutoConfigurationsFile());
Set<String> publicClassNames = new LinkedHashSet<>();
for (String className : classNames) {
File classFile = findClassFile(className);
if (classFile == null) {
throw new IllegalStateException("Auto-configuration class '" + className + "' not found.");
}
try (InputStream in = new FileInputStream(classFile)) {
int access = new ClassReader(in).getAccess();
if ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) {
publicClassNames.add(className);
}
}
}
autoConfiguration.setProperty("autoConfigurationClassNames", String.join(",", publicClassNames));
autoConfiguration.setProperty("module", getProject().getName());
return autoConfiguration;
}
use of org.springframework.asm.ClassReader in project spring-boot by spring-projects.
the class MainClassFinder method createClassDescriptor.
private static ClassDescriptor createClassDescriptor(InputStream inputStream) {
try {
ClassReader classReader = new ClassReader(inputStream);
ClassDescriptor classDescriptor = new ClassDescriptor();
classReader.accept(classDescriptor, ClassReader.SKIP_CODE);
return classDescriptor;
} catch (IOException ex) {
return null;
}
}
use of org.springframework.asm.ClassReader in project spring-boot by spring-projects.
the class DatabaseDriverClassNameTests method getInterfaceNames.
private List<String> getInterfaceNames(String className) throws IOException {
// Use ASM to avoid unwanted side-effects of loading JDBC drivers
ClassReader classReader = new ClassReader(getClass().getResourceAsStream("/" + className + ".class"));
List<String> interfaceNames = new ArrayList<>();
for (String name : classReader.getInterfaces()) {
interfaceNames.add(name);
interfaceNames.addAll(getInterfaceNames(name));
}
String superName = classReader.getSuperName();
if (superName != null) {
interfaceNames.addAll(getInterfaceNames(superName));
}
return interfaceNames;
}
use of org.springframework.asm.ClassReader in project spring-framework by spring-projects.
the class AbstractClassGenerator method generate.
protected Class generate(ClassLoaderData data) {
Class gen;
Object save = CURRENT.get();
CURRENT.set(this);
try {
ClassLoader classLoader = data.getClassLoader();
if (classLoader == null) {
throw new IllegalStateException("ClassLoader is null while trying to define class " + getClassName() + ". It seems that the loader has been expired from a weak reference somehow. " + "Please file an issue at cglib's issue tracker.");
}
synchronized (classLoader) {
String name = generateClassName(data.getUniqueNamePredicate());
data.reserveName(name);
this.setClassName(name);
}
if (attemptLoad) {
try {
gen = classLoader.loadClass(getClassName());
return gen;
} catch (ClassNotFoundException e) {
// ignore
}
}
byte[] b = strategy.generate(this);
String className = ClassNameReader.getClassName(new ClassReader(b));
ProtectionDomain protectionDomain = getProtectionDomain();
synchronized (classLoader) {
// just in case
// SPRING PATCH BEGIN
gen = ReflectUtils.defineClass(className, b, classLoader, protectionDomain, contextClass);
// SPRING PATCH END
}
return gen;
} catch (RuntimeException | Error ex) {
throw ex;
} catch (Exception ex) {
throw new CodeGenerationException(ex);
} finally {
CURRENT.set(save);
}
}
use of org.springframework.asm.ClassReader in project spring-framework by spring-projects.
the class LocalVariableTableParameterNameDiscoverer method inspectClass.
/**
* Inspects the target class.
* <p>Exceptions will be logged, and a marker map returned to indicate the
* lack of debug information.
*/
private Map<Executable, String[]> inspectClass(Class<?> clazz) {
InputStream is = clazz.getResourceAsStream(ClassUtils.getClassFileName(clazz));
if (is == null) {
// simply means this method of discovering parameter names won't work.
if (logger.isDebugEnabled()) {
logger.debug("Cannot find '.class' file for class [" + clazz + "] - unable to determine constructor/method parameter names");
}
return NO_DEBUG_INFO_MAP;
}
// custom handling of the close() method in a finally-block.
try {
ClassReader classReader = new ClassReader(is);
Map<Executable, String[]> map = new ConcurrentHashMap<>(32);
classReader.accept(new ParameterNameDiscoveringVisitor(clazz, map), 0);
return map;
} catch (IOException ex) {
if (logger.isDebugEnabled()) {
logger.debug("Exception thrown while reading '.class' file for class [" + clazz + "] - unable to determine constructor/method parameter names", ex);
}
} catch (IllegalArgumentException ex) {
if (logger.isDebugEnabled()) {
logger.debug("ASM ClassReader failed to parse class file [" + clazz + "], probably due to a new Java class file version that isn't supported yet " + "- unable to determine constructor/method parameter names", ex);
}
} finally {
try {
is.close();
} catch (IOException ex) {
// ignore
}
}
return NO_DEBUG_INFO_MAP;
}
Aggregations