use of org.fakereplace.Extension in project fakereplace by fakereplace.
the class IntegrationActivationTransformer method transform.
@Override
public boolean transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, ClassFile file, Set<Class<?>> classesToRetransform, ChangedClassImpl changedClass, Set<MethodInfo> modifiedMethods) throws IllegalClassFormatException, BadBytecode, DuplicateMemberException {
boolean modified = false;
for (FakereplaceTransformer i : integrationTransformers) {
if (i.transform(loader, className, classBeingRedefined, protectionDomain, file, classesToRetransform, changedClass, modifiedMethods)) {
modified = true;
}
}
if (trackedInstances.contains(file.getName())) {
makeTrackedInstance(file);
modified = true;
}
if (integrationClassTriggers.containsKey(className)) {
modified = true;
integrationClassloader.add(loader);
// we need to load the class in another thread
// otherwise it will not go through the javaagent
final Extension extension = integrationClassTriggers.get(className);
if (!loadedClassChangeAwares.contains(extension.getClassChangeAwareName())) {
loadedClassChangeAwares.add(extension.getClassChangeAwareName());
try {
Class<?> clazz = Class.forName(extension.getClassChangeAwareName(), true, loader);
final Object intance = clazz.newInstance();
if (intance instanceof ClassChangeAware) {
ClassChangeNotifier.instance().add((ClassChangeAware) intance);
}
final String replaceableClassSelectorName = extension.getReplaceableClassSelectorName();
if (replaceableClassSelectorName != null) {
final Class<?> envClass = Class.forName(replaceableClassSelectorName, true, loader);
final ReplaceableClassSelector selector = (ReplaceableClassSelector) envClass.newInstance();
Fakereplace.addReplaceableClassSelector(selector);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
return modified;
}
use of org.fakereplace.Extension in project fakereplace by fakereplace.
the class IntegrationActivationTransformer method transform.
@Override
public boolean transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, ClassFile file, Set<Class<?>> classesToRetransform, ChangedClassImpl changedClass, Set<MethodInfo> modifiedMethods, boolean replaceable) throws IllegalClassFormatException, BadBytecode, DuplicateMemberException {
boolean modified = false;
for (FakereplaceTransformer i : integrationTransformers) {
if (i.transform(loader, className, classBeingRedefined, protectionDomain, file, classesToRetransform, changedClass, modifiedMethods, replaceable)) {
modified = true;
}
}
if (replaceable) {
for (Extension i : extensions) {
i.replaceableClassFileLoaded(className, loader);
}
}
if (trackedInstances.contains(file.getName())) {
makeTrackedInstance(file);
modified = true;
}
if (integrationClassTriggers.containsKey(className)) {
modified = true;
integrationClassloader.add(loader);
// we need to load the class in another thread
// otherwise it will not go through the javaagent
final Extension extension = integrationClassTriggers.get(className);
if (!loadedClassChangeAwares.contains(extension.getClassChangeAwareName())) {
loadedClassChangeAwares.add(extension.getClassChangeAwareName());
try {
Class<?> clazz = Class.forName(extension.getClassChangeAwareName(), true, loader);
final Object intance = clazz.newInstance();
if (intance instanceof ClassChangeAware) {
ClassChangeNotifier.instance().add((ClassChangeAware) intance);
}
final String replaceableClassSelectorName = extension.getReplaceableClassSelectorName();
if (replaceableClassSelectorName != null) {
final Class<?> envClass = Class.forName(replaceableClassSelectorName, true, loader);
final ReplaceableClassSelector selector = (ReplaceableClassSelector) envClass.newInstance();
Fakereplace.addReplaceableClassSelector(selector);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
}
return modified;
}
use of org.fakereplace.Extension in project fakereplace by fakereplace.
the class Fakereplace method getIntegrationInfo.
private static Set<Extension> getIntegrationInfo(ClassLoader clr) {
final ServiceLoader<Extension> loader = ServiceLoader.load(Extension.class, clr);
final Set<Extension> integrations = new HashSet<>();
for (Extension aLoader : loader) {
integrations.add(aLoader);
}
return integrations;
}
use of org.fakereplace.Extension in project fakereplace by fakereplace.
the class Fakereplace method premain.
public static void premain(java.lang.String s, java.lang.instrument.Instrumentation i) {
AgentOptions.setup(s);
inst = i;
final Set<Extension> extension = getIntegrationInfo(ClassLoader.getSystemClassLoader());
replaceableClassSelectors.add(DefaultReplaceableClassSelector.INSTANCE);
// first we need to instrument the class loaders
final Set<Class> cls = new HashSet<>();
for (Class c : inst.getAllLoadedClasses()) {
if (ClassLoader.class.isAssignableFrom(c)) {
cls.add(c);
}
}
final ClassLoaderTransformer classLoaderTransformer = new ClassLoaderTransformer();
final MainTransformer mainTransformer = new MainTransformer();
Fakereplace.mainTransformer = mainTransformer;
inst.addTransformer(mainTransformer, true);
mainTransformer.addTransformer(classLoaderTransformer);
try {
inst.retransformClasses(cls.toArray(EMPTY_CL_ARRAY));
} catch (UnmodifiableClassException e) {
e.printStackTrace();
}
mainTransformer.addTransformer(new IntegrationActivationTransformer(extension));
mainTransformer.addTransformer(new AnnotationTransformer());
mainTransformer.addTransformer(new FieldReplacementTransformer());
mainTransformer.addTransformer(new MethodReplacementTransformer());
mainTransformer.addTransformer(new Transformer());
mainTransformer.addTransformer(new ClassInfoTransformer());
mainTransformer.setRetransformationStarted(false);
mainTransformer.setLogClassRetransformation(true);
}
Aggregations