use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class ModuleClassLoaderTransformer method patchModulesPaths.
/**
* @param classPool the class pool
* @param ctClass the ct class
* @throws NotFoundException the not found exception
* @throws CannotCompileException the cannot compile exception
*/
@OnClassLoadEvent(classNameRegexp = "org.jboss.modules.Paths")
public static void patchModulesPaths(ClassPool classPool, CtClass ctClass) throws NotFoundException, CannotCompileException {
CtClass objectClass = classPool.get(Object.class.getName());
CtField ctField = new CtField(objectClass, "$$ha$prepend", ctClass);
ctClass.addField(ctField);
try {
CtMethod methGetAllPaths = ctClass.getDeclaredMethod("getAllPaths");
methGetAllPaths.setBody("{" + " if (this.$$ha$prepend != null) {" + " java.util.Map result = new org.hotswap.agent.plugin.jbossmodules.PrependingMap(this.allPaths, this.$$ha$prepend);" + " return result;" + " }" + " return this.allPaths;" + "}");
ctClass.addMethod(CtNewMethod.make("public void $$ha$setPrepend(java.lang.Object prepend) {" + " this.$$ha$prepend = prepend; " + "}", ctClass));
} catch (NotFoundException e) {
LOGGER.warning("Unable to find method \"getAllPaths()\" in org.jboss.modules.Paths.", e);
}
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class SignatureTest method testOne.
@Test
public void testOne() throws Exception {
CtClass makeClass = ClassPool.getDefault().get(OneMethod.class.getName());
String expected = ClassSignatureComparerHelper.getJavaClassSignature(OneMethod.class, SIGNATURE_ELEMENTS);
String actual = ClassSignatureComparerHelper.getCtClassSignature(makeClass, SIGNATURE_ELEMENTS);
assertEquals("Signatures not equal", expected, actual);
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class SignatureTest method testAbstractClassSignature.
@Test
public void testAbstractClassSignature() throws Exception {
CtClass makeClass = ClassPool.getDefault().get(B.class.getName());
String expected = ClassSignatureComparerHelper.getJavaClassSignature(B.class, SIGNATURE_ELEMENTS);
String actual = ClassSignatureComparerHelper.getCtClassSignature(makeClass, SIGNATURE_ELEMENTS);
assertEquals("Signatures not equal", expected, actual);
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class GlassFishPlugin method transformFelix.
@OnClassLoadEvent(classNameRegexp = "org.apache.felix.framework.Felix")
public static void transformFelix(ClassPool classPool, CtClass ctClass) throws NotFoundException, CannotCompileException {
CtClass[] constructorParams = new CtClass[] { classPool.get("java.util.Map") };
CtConstructor declaredConstructor = ctClass.getDeclaredConstructor(constructorParams);
declaredConstructor.insertBefore("{" + "if ($1 == null) { " + "$1 = new java.util.HashMap();" + "}" + "String __bootDeleg = (String) $1.get(\"" + FRAMEWORK_BOOTDELEGATION + "\");" + "if (__bootDeleg == null) {" + "__bootDeleg = \"\";" + "}" + "if (__bootDeleg.indexOf(\"org.hotswap.agent\") == -1) {" + "__bootDeleg = __bootDeleg.trim();" + "if (!__bootDeleg.isEmpty()) {" + "__bootDeleg = __bootDeleg + \", \";" + "}" + "__bootDeleg = __bootDeleg + \"" + BOOTDELEGATION_PACKAGES + "\";" + "$1.put(\"" + FRAMEWORK_BOOTDELEGATION + "\", __bootDeleg);" + "}" + "}");
// declaredConstructor.insertAfter(PluginManagerInvoker.buildInitializePlugin(GlassFishPlugin.class));
LOGGER.debug("Class 'org.apache.felix.framework.Felix' patched in classLoader {}.");
}
use of org.hotswap.agent.javassist.CtClass in project HotswapAgent by HotswapProjects.
the class ProxyUtil method makeProxy.
/**
* Make proxy.
*
* @param proxy
* the proxy
* @param proxied
* the proxied
* @param classPool
* the class pool
* @param classLoader
* the class loader
* @throws Exception
* the exception
*/
public static void makeProxy(CtClass proxy, CtClass proxied, ClassPool classPool, ClassLoader classLoader) throws Exception {
proxy.setSuperclass(proxied);
for (CtMethod m : proxied.getMethods()) {
int mod = m.getModifiers();
if (//
!Modifier.isFinal(mod) && //
!Modifier.isStatic(mod) && //
isVisible(mod, proxied.getPackageName(), m) && (!m.getDeclaringClass().getName().equals("java.lang.Object"))) {
String meth = toProxy(m);
CtMethod newMethod = CtNewMethod.make(meth, proxy);
proxy.addMethod(newMethod);
}
}
for (CtClass i : proxied.getInterfaces()) {
proxy.addInterface(i);
}
}
Aggregations