@Override
public boolean initMethod(final PluginAnnotation<OnClassLoadEvent> pluginAnnotation) {
LOGGER.debug("Init for method " + pluginAnnotation.getMethod());
final OnClassLoadEvent annot = pluginAnnotation.getAnnotation();
if (hotswapTransformer == null) {
LOGGER.error("Error in init for method " + pluginAnnotation.getMethod() + ". Hotswap transformer is missing.");
return false;
}
if (annot == null) {
LOGGER.error("Error in init for method " + pluginAnnotation.getMethod() + ". Annotation missing.");
return false;
}
ClassLoader appClassLoader = null;
if (pluginAnnotation.getPlugin() != null)
appClassLoader = pluginManager.getPluginRegistry().getAppClassLoader(pluginAnnotation.getPlugin());
hotswapTransformer.registerTransformer(appClassLoader, annot.classNameRegexp(), new ClassFileTransformer() {
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
List<LoadEvent> events = Arrays.asList(annot.events());
if ((classBeingRedefined == null) ? !events.contains(LoadEvent.DEFINE) : !events.contains(LoadEvent.REDEFINE)) {
// Hotswap reload which is the client not interested of
return classfileBuffer;
}