use of org.fakereplace.replacement.MethodReplacementTransformer 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