Search in sources :

Example 1 with IClassMatchBuilder

use of com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder in project LinkAgent by shulieTech.

the class DefaultEnhanceTemplate method enhance.

@Override
public InstrumentClass enhance(ExtensionModule module, String className, EnhanceCallback callback) {
    IClassMatchBuilder iClassMatchBuilder = new EventWatchBuilder(moduleEventWatcher).onClass(className);
    final DefaultInstrumentClass instrumentClass = new DefaultInstrumentClass(iClassMatchBuilder);
    callback.doEnhance(instrumentClass);
    if (module instanceof ModuleLifecycleAdapter) {
        ((ModuleLifecycleAdapter) module).addReleaseResource(new InstrumentClassResource(instrumentClass));
    }
    instrumentClass.execute();
    return instrumentClass;
}
Also used : InstrumentClassResource(com.shulie.instrument.simulator.api.resource.InstrumentClassResource) IClassMatchBuilder(com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder) ModuleLifecycleAdapter(com.shulie.instrument.simulator.api.ModuleLifecycleAdapter) EventWatchBuilder(com.shulie.instrument.simulator.api.listener.ext.EventWatchBuilder)

Example 2 with IClassMatchBuilder

use of com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder in project LinkAgent by shulieTech.

the class DefaultEnhanceTemplate method enhanceWithInterface.

@Override
public InstrumentClass enhanceWithInterface(ExtensionModule module, String interfaceClassName, EnhanceCallback callback) {
    IClassMatchBuilder iClassMatchBuilder = new EventWatchBuilder(moduleEventWatcher).onAnyClass().hasInterfaceTypes(interfaceClassName);
    final DefaultInstrumentClass instrumentClass = new DefaultInstrumentClass(iClassMatchBuilder);
    callback.doEnhance(instrumentClass);
    if (module instanceof ModuleLifecycleAdapter) {
        ((ModuleLifecycleAdapter) module).addReleaseResource(new InstrumentClassResource(instrumentClass));
    }
    instrumentClass.execute();
    return instrumentClass;
}
Also used : InstrumentClassResource(com.shulie.instrument.simulator.api.resource.InstrumentClassResource) IClassMatchBuilder(com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder) ModuleLifecycleAdapter(com.shulie.instrument.simulator.api.ModuleLifecycleAdapter) EventWatchBuilder(com.shulie.instrument.simulator.api.listener.ext.EventWatchBuilder)

Example 3 with IClassMatchBuilder

use of com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder in project LinkAgent by shulieTech.

the class DefaultEnhanceTemplate method enhanceWithSuperClass.

@Override
public InstrumentClass enhanceWithSuperClass(ExtensionModule module, EnhanceCallback callback, String... superClassNames) {
    IClassMatchBuilder iClassMatchBuilder = new EventWatchBuilder(moduleEventWatcher).onAnyClass().withSuperClass(superClassNames);
    final DefaultInstrumentClass instrumentClass = new DefaultInstrumentClass(iClassMatchBuilder);
    callback.doEnhance(instrumentClass);
    if (module instanceof ModuleLifecycleAdapter) {
        ((ModuleLifecycleAdapter) module).addReleaseResource(new InstrumentClassResource(instrumentClass));
    }
    instrumentClass.execute();
    return instrumentClass;
}
Also used : InstrumentClassResource(com.shulie.instrument.simulator.api.resource.InstrumentClassResource) IClassMatchBuilder(com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder) ModuleLifecycleAdapter(com.shulie.instrument.simulator.api.ModuleLifecycleAdapter) EventWatchBuilder(com.shulie.instrument.simulator.api.listener.ext.EventWatchBuilder)

Example 4 with IClassMatchBuilder

use of com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder in project LinkAgent by shulieTech.

the class MockPlugin method enhanceClassMethod.

public Map<String, EventWatcher> enhanceClassMethod(Map<String, Set<MockConfig>> configs) {
    if (configs == null || configs.isEmpty()) {
        return Collections.EMPTY_MAP;
    }
    Map<String, EventWatcher> watchers = new HashMap<String, EventWatcher>();
    for (Map.Entry<String, Set<MockConfig>> entry : configs.entrySet()) {
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("pre enhance class:{} ,configs:{}", entry.getKey(), entry.getValue());
        }
        for (MockConfig mockConfig : entry.getValue()) {
            IClassMatchBuilder buildingForClass = new EventWatchBuilder(moduleEventWatcher).onClass(entry.getKey());
            IBehaviorMatchBuilder buildingForBehavior = buildingForClass.onAnyBehavior(mockConfig.getMethodName());
            if (mockConfig.getMethodArgClasses() != null && !mockConfig.getMethodArgClasses().isEmpty()) {
                buildingForBehavior.withParameterTypes(mockConfig.getMethodArgClasses().toArray(new String[mockConfig.getMethodArgClasses().size()]));
            }
            buildingForBehavior.onListener(Listeners.of(MockAdviceListener.class, new Object[] { mockConfig.getCodeScript() }));
            watchers.put(mockConfig.getKey(), buildingForClass.onWatch());
        }
    }
    return watchers;
}
Also used : IClassMatchBuilder(com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder) MockAdviceListener(com.pamirs.attach.plugin.mock.interceptor.MockAdviceListener) EventWatcher(com.shulie.instrument.simulator.api.listener.ext.EventWatcher) IBehaviorMatchBuilder(com.shulie.instrument.simulator.api.listener.ext.IBehaviorMatchBuilder) MockConfig(com.pamirs.pradar.internal.config.MockConfig) EventWatchBuilder(com.shulie.instrument.simulator.api.listener.ext.EventWatchBuilder)

Aggregations

EventWatchBuilder (com.shulie.instrument.simulator.api.listener.ext.EventWatchBuilder)4 IClassMatchBuilder (com.shulie.instrument.simulator.api.listener.ext.IClassMatchBuilder)4 ModuleLifecycleAdapter (com.shulie.instrument.simulator.api.ModuleLifecycleAdapter)3 InstrumentClassResource (com.shulie.instrument.simulator.api.resource.InstrumentClassResource)3 MockAdviceListener (com.pamirs.attach.plugin.mock.interceptor.MockAdviceListener)1 MockConfig (com.pamirs.pradar.internal.config.MockConfig)1 EventWatcher (com.shulie.instrument.simulator.api.listener.ext.EventWatcher)1 IBehaviorMatchBuilder (com.shulie.instrument.simulator.api.listener.ext.IBehaviorMatchBuilder)1