use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.
the class framedump method main.
/**
* Main method.
*
* @param args <code>args[0]</code> is the class file name.
*/
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.err.println("Usage: java javassist.tools.framedump <fully-qualified class name>");
return;
}
ClassPool pool = ClassPool.getDefault();
CtClass clazz = pool.get(args[0]);
System.out.println("Frame Dump of " + clazz.getName() + ":");
FramePrinter.print(clazz, System.out);
}
use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.
the class Compiler method processClasses.
private static void processClasses(CompiledClass[] entries, int n) throws Exception {
Reflection implementor = new Reflection();
ClassPool pool = ClassPool.getDefault();
implementor.start(pool);
for (int i = 0; i < n; ++i) {
CtClass c = pool.get(entries[i].classname);
if (entries[i].metaobject != null || entries[i].classobject != null) {
String metaobj, classobj;
if (entries[i].metaobject == null)
metaobj = "javassist.tools.reflect.Metaobject";
else
metaobj = entries[i].metaobject;
if (entries[i].classobject == null)
classobj = "javassist.tools.reflect.ClassMetaobject";
else
classobj = entries[i].classobject;
if (!implementor.makeReflective(c, pool.get(metaobj), pool.get(classobj)))
System.err.println("Warning: " + c.getName() + " is reflective. It was not changed.");
System.err.println(c.getName() + ": " + metaobj + ", " + classobj);
} else
System.err.println(c.getName() + ": not reflective");
}
for (int i = 0; i < n; ++i) {
implementor.onLoad(pool, entries[i].classname);
pool.get(entries[i].classname).writeFile();
}
}
use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.
the class EnhancerProxyCreater method getProxyCreationMethod.
private Method getProxyCreationMethod(Object bean) throws CannotCompileException, NotFoundException {
if (getCp(loader).find("org.springframework.cglib.proxy.MethodInterceptor") != null) {
if (createSpringProxy == null) {
synchronized (springLock) {
if (createSpringProxy == null) {
ClassPool cp = getCp(loader);
springCallback = buildProxyCallbackClass(SPRING_PACKAGE, cp);
springNamingPolicy = buildNamingPolicyClass(SPRING_PACKAGE, cp);
springProxy = buildProxyCreaterClass(SPRING_PACKAGE, springCallback, springNamingPolicy, cp);
createSpringProxy = springProxy.getDeclaredMethods()[0];
}
}
}
return createSpringProxy;
} else if (getCp(loader).find("net.sf.cglib.proxy.MethodInterceptor") != null) {
if (createCglibProxy == null) {
synchronized (cglibLock) {
if (createCglibProxy == null) {
ClassPool cp = getCp(loader);
cglibCallback = buildProxyCallbackClass(CGLIB_PACKAGE, cp);
cglibNamingPolicy = buildNamingPolicyClass(CGLIB_PACKAGE, cp);
cglibProxy = buildProxyCreaterClass(CGLIB_PACKAGE, cglibCallback, cglibNamingPolicy, cp);
createCglibProxy = cglibProxy.getDeclaredMethods()[0];
}
}
}
return createCglibProxy;
} else {
LOGGER.error("Unable to determine the location of the Cglib package");
return null;
}
}
use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.
the class ComponentScanWithWildcardsTest method copyClassFile.
public static File copyClassFile(Class<?> clazz, String newName) throws Exception {
String directoryName = clazz.getClassLoader().getResource("").getPath();
ClassPool classPool = new ClassPool();
classPool.appendClassPath(new LoaderClassPath(clazz.getClassLoader()));
CtClass ctClass = classPool.getAndRename(clazz.getName(), newName);
ctClass.writeFile(directoryName);
File file = new File(directoryName + File.separatorChar + newName.replace('.', File.separatorChar) + ".class");
assertTrue(file.exists());
return file;
}
use of org.hotswap.agent.javassist.ClassPool in project HotswapAgent by HotswapProjects.
the class HotswapWebObjectsPlugin method init.
// We use reflection to get the methods from WebObjects because the jar is not distribuable publicly
// and we want to build witout it.
@Init
@SuppressWarnings({ "rawtypes", "unchecked" })
public void init(PluginConfiguration pluginConfiguration, ClassLoader appClassLoader) {
try {
Class kvcDefaultImplementationClass = Class.forName("com.webobjects.foundation.NSKeyValueCoding$DefaultImplementation", false, appClassLoader);
kvcDefaultImplementation_flushCaches = kvcDefaultImplementationClass.getMethod("_flushCaches");
Class kvcReflectionKeyBindingCreationClass = Class.forName("com.webobjects.foundation.NSKeyValueCoding$_ReflectionKeyBindingCreation", false, appClassLoader);
kvcReflectionKeyBindingCreation_flushCaches = kvcReflectionKeyBindingCreationClass.getMethod("_flushCaches");
Class kvcValueAccessorClass = Class.forName("com.webobjects.foundation.NSKeyValueCoding$ValueAccessor", false, appClassLoader);
kvcValueAccessor_flushCaches = kvcValueAccessorClass.getMethod("_flushCaches");
Class nsValidationDefaultImplementationClass = Class.forName("com.webobjects.foundation.NSValidation$DefaultImplementation", false, appClassLoader);
nsValidationDefaultImplementation_flushCaches = nsValidationDefaultImplementationClass.getMethod("_flushCaches");
Class woApplicationClass = Class.forName("com.webobjects.appserver.WOApplication", false, appClassLoader);
woApplication_removeComponentDefinitionCacheContents = woApplicationClass.getMethod("_removeComponentDefinitionCacheContents");
woApplicationObject = woApplicationClass.getMethod("application").invoke(null);
ClassPool classPool = ClassPool.getDefault();
woComponentCtClass = classPool.makeClass("com.webobjects.appserver.WOComponent");
nsValidationCtClass = classPool.makeClass("com.webobjects.foundation.NSValidation");
woActionCtClass = classPool.makeClass("com.webobjects.appserver.WOAction");
Class woActionClass = Class.forName("com.webobjects.appserver.WOAction", false, appClassLoader);
Field actionClassesField = woActionClass.getDeclaredField("_actionClasses");
actionClassesField.setAccessible(true);
actionClassesCacheDictionnary = actionClassesField.get(null);
Class nsThreadsafeMutableDictionaryClass = Class.forName("com.webobjects.foundation._NSThreadsafeMutableDictionary", false, appClassLoader);
woApplication_removeComponentDefinitionCacheContents = woApplicationClass.getMethod("_removeComponentDefinitionCacheContents");
nsThreadsafeMutableDictionary_removeAllObjects = nsThreadsafeMutableDictionaryClass.getMethod("removeAllObjects");
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations