mirror of
https://github.com/alibaba/testable-mock.git
synced 2025-01-06 10:20:43 +08:00
change package path to avoid conflict between core and agent
This commit is contained in:
parent
264d3d95b6
commit
53d9495838
@ -34,7 +34,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifestEntries>
|
<manifestEntries>
|
||||||
<Premain-Class>com.alibaba.testable.PreMain</Premain-Class>
|
<Premain-Class>com.alibaba.testable.agent.PreMain</Premain-Class>
|
||||||
<Can-Retransform-Classes>true</Can-Retransform-Classes>
|
<Can-Retransform-Classes>true</Can-Retransform-Classes>
|
||||||
</manifestEntries>
|
</manifestEntries>
|
||||||
</archive>
|
</archive>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.alibaba.testable;
|
package com.alibaba.testable.agent;
|
||||||
|
|
||||||
import com.alibaba.testable.transformer.TestableClassTransformer;
|
import com.alibaba.testable.agent.transformer.TestableClassTransformer;
|
||||||
|
|
||||||
import java.lang.instrument.Instrumentation;
|
import java.lang.instrument.Instrumentation;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.alibaba.testable.constant;
|
package com.alibaba.testable.agent.constant;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,6 +1,8 @@
|
|||||||
package com.alibaba.testable.handler;
|
package com.alibaba.testable.agent.handler;
|
||||||
|
|
||||||
import com.alibaba.testable.util.ClassUtil;
|
import com.alibaba.testable.agent.constant.Const;
|
||||||
|
import com.alibaba.testable.agent.util.ClassUtil;
|
||||||
|
import com.alibaba.testable.agent.util.StringUtil;
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.ClassWriter;
|
import org.objectweb.asm.ClassWriter;
|
||||||
import org.objectweb.asm.Opcodes;
|
import org.objectweb.asm.Opcodes;
|
||||||
@ -11,8 +13,6 @@ import java.io.IOException;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static com.alibaba.testable.constant.Const.SYS_CLASSES;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author flin
|
* @author flin
|
||||||
*/
|
*/
|
||||||
@ -61,7 +61,7 @@ public class TestableClassHandler implements Opcodes {
|
|||||||
instructions = replaceMemberCallOps(mn, instructions, rangeStart, i);
|
instructions = replaceMemberCallOps(mn, instructions, rangeStart, i);
|
||||||
i = rangeStart;
|
i = rangeStart;
|
||||||
}
|
}
|
||||||
} else if (CONSTRUCTOR.equals(node.name) && !SYS_CLASSES.contains(node.owner)) {
|
} else if (CONSTRUCTOR.equals(node.name) && !Const.SYS_CLASSES.contains(node.owner)) {
|
||||||
int rangeStart = getConstructorStart(instructions, node.owner, i);
|
int rangeStart = getConstructorStart(instructions, node.owner, i);
|
||||||
if (rangeStart >= 0) {
|
if (rangeStart >= 0) {
|
||||||
instructions = replaceNewOps(mn, instructions, rangeStart, i);
|
instructions = replaceNewOps(mn, instructions, rangeStart, i);
|
||||||
@ -109,7 +109,7 @@ public class TestableClassHandler implements Opcodes {
|
|||||||
|
|
||||||
private String getConstructorSubstitutionDesc(String constructorDesc) {
|
private String getConstructorSubstitutionDesc(String constructorDesc) {
|
||||||
int paramCount = ClassUtil.getParameterCount(constructorDesc);
|
int paramCount = ClassUtil.getParameterCount(constructorDesc);
|
||||||
return CONSTRUCTOR_DESC_PREFIX + ClassUtil.repeat(OBJECT_DESC, paramCount) + METHOD_DESC_POSTFIX;
|
return CONSTRUCTOR_DESC_PREFIX + StringUtil.repeat(OBJECT_DESC, paramCount) + METHOD_DESC_POSTFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AbstractInsnNode[] replaceMemberCallOps(MethodNode mn, AbstractInsnNode[] instructions, int start, int end) {
|
private AbstractInsnNode[] replaceMemberCallOps(MethodNode mn, AbstractInsnNode[] instructions, int start, int end) {
|
||||||
@ -129,7 +129,7 @@ public class TestableClassHandler implements Opcodes {
|
|||||||
|
|
||||||
private String getMethodSubstitutionDesc(String methodDesc) {
|
private String getMethodSubstitutionDesc(String methodDesc) {
|
||||||
int paramCount = ClassUtil.getParameterCount(methodDesc);
|
int paramCount = ClassUtil.getParameterCount(methodDesc);
|
||||||
return METHOD_DESC_PREFIX + ClassUtil.repeat(OBJECT_DESC, paramCount) + METHOD_DESC_POSTFIX;
|
return METHOD_DESC_PREFIX + StringUtil.repeat(OBJECT_DESC, paramCount) + METHOD_DESC_POSTFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.alibaba.testable.model;
|
package com.alibaba.testable.agent.model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author flin
|
* @author flin
|
@ -1,7 +1,7 @@
|
|||||||
package com.alibaba.testable.transformer;
|
package com.alibaba.testable.agent.transformer;
|
||||||
|
|
||||||
import com.alibaba.testable.handler.TestableClassHandler;
|
import com.alibaba.testable.agent.handler.TestableClassHandler;
|
||||||
import com.alibaba.testable.util.ClassUtil;
|
import com.alibaba.testable.agent.util.ClassUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.instrument.ClassFileTransformer;
|
import java.lang.instrument.ClassFileTransformer;
|
@ -1,5 +1,6 @@
|
|||||||
package com.alibaba.testable.util;
|
package com.alibaba.testable.agent.util;
|
||||||
|
|
||||||
|
import com.alibaba.testable.agent.constant.Const;
|
||||||
import org.objectweb.asm.ClassReader;
|
import org.objectweb.asm.ClassReader;
|
||||||
import org.objectweb.asm.tree.AnnotationNode;
|
import org.objectweb.asm.tree.AnnotationNode;
|
||||||
import org.objectweb.asm.tree.ClassNode;
|
import org.objectweb.asm.tree.ClassNode;
|
||||||
@ -8,8 +9,6 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.alibaba.testable.constant.Const.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author flin
|
* @author flin
|
||||||
*/
|
*/
|
||||||
@ -28,13 +27,17 @@ public class ClassUtil {
|
|||||||
private static final char CLASS_END = ';';
|
private static final char CLASS_END = ';';
|
||||||
private static final char TYPE_ARRAY = '[';
|
private static final char TYPE_ARRAY = '[';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get annotation on class definition
|
||||||
|
* @param className class that need to explore
|
||||||
|
*/
|
||||||
public static List<String> getAnnotations(String className) {
|
public static List<String> getAnnotations(String className) {
|
||||||
try {
|
try {
|
||||||
List<String> annotations = new ArrayList<String>();
|
List<String> annotations = new ArrayList<String>();
|
||||||
ClassNode cn = new ClassNode();
|
ClassNode cn = new ClassNode();
|
||||||
new ClassReader(className).accept(cn, 0);
|
new ClassReader(className).accept(cn, 0);
|
||||||
for (AnnotationNode an : cn.visibleAnnotations) {
|
for (AnnotationNode an : cn.visibleAnnotations) {
|
||||||
String annotationName = an.desc.replace(SLASH, DOT).substring(1, an.desc.length() - 1);
|
String annotationName = an.desc.replace(Const.SLASH, Const.DOT).substring(1, an.desc.length() - 1);
|
||||||
annotations.add(annotationName);
|
annotations.add(annotationName);
|
||||||
}
|
}
|
||||||
return annotations;
|
return annotations;
|
||||||
@ -95,12 +98,4 @@ public class ClassUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String repeat(String text, int times) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (int i = 0; i < times; i++) {
|
|
||||||
sb.append(text);
|
|
||||||
}
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.alibaba.testable.agent.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author flin
|
||||||
|
*/
|
||||||
|
public class StringUtil {
|
||||||
|
|
||||||
|
public static String repeat(String text, int times) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int i = 0; i < times; i++) {
|
||||||
|
sb.append(text);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.alibaba.testable.util;
|
package com.alibaba.testable.agent.util;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
package com.alibaba.testable.accessor;
|
package com.alibaba.testable.core.accessor;
|
||||||
|
|
||||||
import com.alibaba.testable.util.TypeUtil;
|
import com.alibaba.testable.core.util.TypeUtil;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
@ -1,4 +1,4 @@
|
|||||||
package com.alibaba.testable.annotation;
|
package com.alibaba.testable.core.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.alibaba.testable.annotation;
|
package com.alibaba.testable.core.annotation;
|
||||||
|
|
||||||
import java.lang.annotation.*;
|
import java.lang.annotation.*;
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
package com.alibaba.testable.generator;
|
package com.alibaba.testable.core.generator;
|
||||||
|
|
||||||
import com.alibaba.testable.model.TestableContext;
|
import com.alibaba.testable.core.model.TestableContext;
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
|
|
||||||
/**
|
/**
|
@ -1,7 +1,7 @@
|
|||||||
package com.alibaba.testable.generator;
|
package com.alibaba.testable.core.generator;
|
||||||
|
|
||||||
import com.alibaba.testable.model.TestableContext;
|
import com.alibaba.testable.core.model.TestableContext;
|
||||||
import com.alibaba.testable.util.ConstPool;
|
import com.alibaba.testable.core.util.ConstPool;
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
import com.sun.tools.javac.util.List;
|
import com.sun.tools.javac.util.List;
|
||||||
import com.sun.tools.javac.util.ListBuffer;
|
import com.sun.tools.javac.util.ListBuffer;
|
@ -1,8 +1,7 @@
|
|||||||
package com.alibaba.testable.generator;
|
package com.alibaba.testable.core.generator;
|
||||||
|
|
||||||
import com.alibaba.testable.model.TestLibType;
|
import com.alibaba.testable.core.model.TestableContext;
|
||||||
import com.alibaba.testable.model.TestableContext;
|
import com.alibaba.testable.core.util.ConstPool;
|
||||||
import com.alibaba.testable.util.ConstPool;
|
|
||||||
import com.sun.tools.javac.code.Type;
|
import com.sun.tools.javac.code.Type;
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
import com.sun.tools.javac.util.List;
|
import com.sun.tools.javac.util.List;
|
@ -1,6 +1,6 @@
|
|||||||
package com.alibaba.testable.model;
|
package com.alibaba.testable.core.model;
|
||||||
|
|
||||||
import com.alibaba.testable.util.TestableLogger;
|
import com.alibaba.testable.core.util.TestableLogger;
|
||||||
import com.sun.tools.javac.api.JavacTrees;
|
import com.sun.tools.javac.api.JavacTrees;
|
||||||
import com.sun.tools.javac.tree.TreeMaker;
|
import com.sun.tools.javac.tree.TreeMaker;
|
||||||
import com.sun.tools.javac.util.Names;
|
import com.sun.tools.javac.util.Names;
|
@ -1,7 +1,7 @@
|
|||||||
package com.alibaba.testable.processor;
|
package com.alibaba.testable.core.processor;
|
||||||
|
|
||||||
import com.alibaba.testable.model.TestableContext;
|
import com.alibaba.testable.core.model.TestableContext;
|
||||||
import com.alibaba.testable.util.TestableLogger;
|
import com.alibaba.testable.core.util.TestableLogger;
|
||||||
import com.sun.tools.javac.api.JavacTrees;
|
import com.sun.tools.javac.api.JavacTrees;
|
||||||
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
|
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
|
||||||
import com.sun.tools.javac.tree.TreeMaker;
|
import com.sun.tools.javac.tree.TreeMaker;
|
@ -1,8 +1,8 @@
|
|||||||
package com.alibaba.testable.processor;
|
package com.alibaba.testable.core.processor;
|
||||||
|
|
||||||
import com.alibaba.testable.annotation.EnableTestable;
|
import com.alibaba.testable.core.annotation.EnableTestable;
|
||||||
import com.alibaba.testable.translator.EnableTestableTranslator;
|
import com.alibaba.testable.core.translator.EnableTestableTranslator;
|
||||||
import com.alibaba.testable.util.ResourceUtil;
|
import com.alibaba.testable.core.util.ResourceUtil;
|
||||||
import com.sun.tools.javac.code.Symbol;
|
import com.sun.tools.javac.code.Symbol;
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.alibaba.testable.translator;
|
package com.alibaba.testable.core.translator;
|
||||||
|
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
import com.sun.tools.javac.tree.TreeTranslator;
|
import com.sun.tools.javac.tree.TreeTranslator;
|
@ -1,10 +1,9 @@
|
|||||||
package com.alibaba.testable.translator;
|
package com.alibaba.testable.core.translator;
|
||||||
|
|
||||||
import com.alibaba.testable.generator.PrivateAccessStatementGenerator;
|
import com.alibaba.testable.core.generator.PrivateAccessStatementGenerator;
|
||||||
import com.alibaba.testable.generator.TestSetupMethodGenerator;
|
import com.alibaba.testable.core.generator.TestSetupMethodGenerator;
|
||||||
import com.alibaba.testable.model.TestLibType;
|
import com.alibaba.testable.core.model.TestableContext;
|
||||||
import com.alibaba.testable.model.TestableContext;
|
import com.alibaba.testable.core.util.ConstPool;
|
||||||
import com.alibaba.testable.util.ConstPool;
|
|
||||||
import com.sun.tools.javac.tree.JCTree;
|
import com.sun.tools.javac.tree.JCTree;
|
||||||
import com.sun.tools.javac.tree.JCTree.*;
|
import com.sun.tools.javac.tree.JCTree.*;
|
||||||
import com.sun.tools.javac.util.List;
|
import com.sun.tools.javac.util.List;
|
@ -1,14 +1,10 @@
|
|||||||
package com.alibaba.testable.util;
|
package com.alibaba.testable.core.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author flin
|
* @author flin
|
||||||
*/
|
*/
|
||||||
public final class ConstPool {
|
public final class ConstPool {
|
||||||
|
|
||||||
public static final String NE_PKG = "n";
|
|
||||||
public static final String NE_CLS = "e";
|
|
||||||
public static final String NE_NEW = "w";
|
|
||||||
public static final String NE_FUN = "f";
|
|
||||||
public static final String TYPE_UTIL = "com.alibaba.testable.util.TypeUtil";
|
public static final String TYPE_UTIL = "com.alibaba.testable.util.TypeUtil";
|
||||||
public static final String CLASS_SUBSTITUTION = TYPE_UTIL + ".TestableSubstitution";
|
public static final String CLASS_SUBSTITUTION = TYPE_UTIL + ".TestableSubstitution";
|
||||||
public static final String METHOD_ADD_TO_CON_POLL = TYPE_UTIL + ".addToConstructorPool";
|
public static final String METHOD_ADD_TO_CON_POLL = TYPE_UTIL + ".addToConstructorPool";
|
@ -1,4 +1,4 @@
|
|||||||
package com.alibaba.testable.util;
|
package com.alibaba.testable.core.util;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.alibaba.testable.util;
|
package com.alibaba.testable.core.util;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package com.alibaba.testable.util;
|
package com.alibaba.testable.core.util;
|
||||||
|
|
||||||
import javax.annotation.processing.Messager;
|
import javax.annotation.processing.Messager;
|
||||||
import javax.tools.Diagnostic;
|
import javax.tools.Diagnostic;
|
@ -1,4 +1,4 @@
|
|||||||
package com.alibaba.testable.util;
|
package com.alibaba.testable.core.util;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
@ -1,10 +0,0 @@
|
|||||||
package com.alibaba.testable.model;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author flin
|
|
||||||
*/
|
|
||||||
|
|
||||||
public enum TestLibType {
|
|
||||||
JUnit4,
|
|
||||||
JUnit5
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
package n;
|
package n;
|
||||||
|
|
||||||
import static com.alibaba.testable.util.TypeUtil.wrapCall;
|
import static com.alibaba.testable.core.util.TypeUtil.wrapCall;
|
||||||
import static com.alibaba.testable.util.TypeUtil.wrapNew;
|
import static com.alibaba.testable.core.util.TypeUtil.wrapNew;
|
||||||
|
|
||||||
public final class e {
|
public final class e {
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
com.alibaba.testable.processor.EnableTestableProcessor
|
com.alibaba.testable.core.processor.EnableTestableProcessor
|
||||||
|
Loading…
Reference in New Issue
Block a user