Search in sources :

Example 1 with FieldReplacementTransformer

use of org.fakereplace.replacement.FieldReplacementTransformer 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);
}
Also used : FieldReplacementTransformer(org.fakereplace.replacement.FieldReplacementTransformer) MethodReplacementTransformer(org.fakereplace.replacement.MethodReplacementTransformer) AnnotationTransformer(org.fakereplace.replacement.AnnotationTransformer) UnmodifiableClassException(java.lang.instrument.UnmodifiableClassException) Extension(org.fakereplace.Extension) AnnotationTransformer(org.fakereplace.replacement.AnnotationTransformer) FieldReplacementTransformer(org.fakereplace.replacement.FieldReplacementTransformer) AddedClass(org.fakereplace.replacement.AddedClass) MethodReplacementTransformer(org.fakereplace.replacement.MethodReplacementTransformer) HashSet(java.util.HashSet)

Aggregations

UnmodifiableClassException (java.lang.instrument.UnmodifiableClassException)1 HashSet (java.util.HashSet)1 Extension (org.fakereplace.Extension)1 AddedClass (org.fakereplace.replacement.AddedClass)1 AnnotationTransformer (org.fakereplace.replacement.AnnotationTransformer)1 FieldReplacementTransformer (org.fakereplace.replacement.FieldReplacementTransformer)1 MethodReplacementTransformer (org.fakereplace.replacement.MethodReplacementTransformer)1