mirror of
https://github.com/alibaba/testable-mock.git
synced 2026-09-03 21:23:02 +08:00
38 lines
1.1 KiB
Java
Executable File
38 lines
1.1 KiB
Java
Executable File
package com.alibaba.testable.agent;
|
|
|
|
import com.alibaba.testable.agent.transformer.TestableClassTransformer;
|
|
import com.alibaba.testable.core.util.LogUtil;
|
|
import com.alibaba.testable.core.model.MockDiagnose;
|
|
|
|
import java.lang.instrument.Instrumentation;
|
|
|
|
/**
|
|
* Agent entry, dynamically modify the byte code of classes under testing
|
|
* @author flin
|
|
*/
|
|
public class PreMain {
|
|
|
|
private static final String AND = "&";
|
|
private static final String DEBUG = "debug";
|
|
private static final String VERBOSE = "verbose";
|
|
|
|
public static void premain(String agentArgs, Instrumentation inst) {
|
|
parseArgs(agentArgs);
|
|
inst.addTransformer(new TestableClassTransformer());
|
|
}
|
|
|
|
private static void parseArgs(String args) {
|
|
if (args == null) {
|
|
return;
|
|
}
|
|
for (String a : args.split(AND)) {
|
|
if (a.equals(DEBUG)) {
|
|
LogUtil.setDefaultLevel(LogUtil.LEVEL_DIAGNOSE);
|
|
} else if (a.equals(VERBOSE)) {
|
|
LogUtil.setDefaultLevel(LogUtil.LEVEL_VERBOSE);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|