change package path to avoid conflict between core and agent

This commit is contained in:
金戟 2020-07-25 22:04:13 +08:00
parent 264d3d95b6
commit 53d9495838
28 changed files with 74 additions and 79 deletions

View File

@ -34,7 +34,7 @@
<configuration>
<archive>
<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>
</manifestEntries>
</archive>

View File

@ -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;

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.constant;
package com.alibaba.testable.agent.constant;
import java.util.ArrayList;
import java.util.List;

View File

@ -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.ClassWriter;
import org.objectweb.asm.Opcodes;
@ -11,8 +13,6 @@ import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import static com.alibaba.testable.constant.Const.SYS_CLASSES;
/**
* @author flin
*/
@ -61,7 +61,7 @@ public class TestableClassHandler implements Opcodes {
instructions = replaceMemberCallOps(mn, instructions, rangeStart, i);
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);
if (rangeStart >= 0) {
instructions = replaceNewOps(mn, instructions, rangeStart, i);
@ -109,7 +109,7 @@ public class TestableClassHandler implements Opcodes {
private String getConstructorSubstitutionDesc(String 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) {
@ -129,7 +129,7 @@ public class TestableClassHandler implements Opcodes {
private String getMethodSubstitutionDesc(String 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;
}
}

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.model;
package com.alibaba.testable.agent.model;
/**
* @author flin

View File

@ -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.util.ClassUtil;
import com.alibaba.testable.agent.handler.TestableClassHandler;
import com.alibaba.testable.agent.util.ClassUtil;
import java.io.IOException;
import java.lang.instrument.ClassFileTransformer;

View File

@ -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.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
@ -8,8 +9,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static com.alibaba.testable.constant.Const.*;
/**
* @author flin
*/
@ -28,13 +27,17 @@ public class ClassUtil {
private static final char CLASS_END = ';';
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) {
try {
List<String> annotations = new ArrayList<String>();
ClassNode cn = new ClassNode();
new ClassReader(className).accept(cn, 0);
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);
}
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();
}
}

View File

@ -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();
}
}

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.util;
package com.alibaba.testable.agent.util;
import org.junit.jupiter.api.Test;

View File

@ -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.Method;

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.annotation;
package com.alibaba.testable.core.annotation;
import java.lang.annotation.*;

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.annotation;
package com.alibaba.testable.core.annotation;
import java.lang.annotation.*;

View File

@ -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.*;
/**

View File

@ -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.util.ConstPool;
import com.alibaba.testable.core.model.TestableContext;
import com.alibaba.testable.core.util.ConstPool;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;

View File

@ -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.model.TestableContext;
import com.alibaba.testable.util.ConstPool;
import com.alibaba.testable.core.model.TestableContext;
import com.alibaba.testable.core.util.ConstPool;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.util.List;

View File

@ -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.tree.TreeMaker;
import com.sun.tools.javac.util.Names;

View File

@ -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.util.TestableLogger;
import com.alibaba.testable.core.model.TestableContext;
import com.alibaba.testable.core.util.TestableLogger;
import com.sun.tools.javac.api.JavacTrees;
import com.sun.tools.javac.processing.JavacProcessingEnvironment;
import com.sun.tools.javac.tree.TreeMaker;

View File

@ -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.translator.EnableTestableTranslator;
import com.alibaba.testable.util.ResourceUtil;
import com.alibaba.testable.core.annotation.EnableTestable;
import com.alibaba.testable.core.translator.EnableTestableTranslator;
import com.alibaba.testable.core.util.ResourceUtil;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.tree.JCTree;

View File

@ -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.TreeTranslator;

View File

@ -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.generator.TestSetupMethodGenerator;
import com.alibaba.testable.model.TestLibType;
import com.alibaba.testable.model.TestableContext;
import com.alibaba.testable.util.ConstPool;
import com.alibaba.testable.core.generator.PrivateAccessStatementGenerator;
import com.alibaba.testable.core.generator.TestSetupMethodGenerator;
import com.alibaba.testable.core.model.TestableContext;
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;

View File

@ -1,14 +1,10 @@
package com.alibaba.testable.util;
package com.alibaba.testable.core.util;
/**
* @author flin
*/
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 CLASS_SUBSTITUTION = TYPE_UTIL + ".TestableSubstitution";
public static final String METHOD_ADD_TO_CON_POLL = TYPE_UTIL + ".addToConstructorPool";

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.util;
package com.alibaba.testable.core.util;
import java.io.*;

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.util;
package com.alibaba.testable.core.util;
import java.util.List;

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.util;
package com.alibaba.testable.core.util;
import javax.annotation.processing.Messager;
import javax.tools.Diagnostic;

View File

@ -1,4 +1,4 @@
package com.alibaba.testable.util;
package com.alibaba.testable.core.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

View File

@ -1,10 +0,0 @@
package com.alibaba.testable.model;
/**
* @author flin
*/
public enum TestLibType {
JUnit4,
JUnit5
}

View File

@ -1,7 +1,7 @@
package n;
import static com.alibaba.testable.util.TypeUtil.wrapCall;
import static com.alibaba.testable.util.TypeUtil.wrapNew;
import static com.alibaba.testable.core.util.TypeUtil.wrapCall;
import static com.alibaba.testable.core.util.TypeUtil.wrapNew;
public final class e {

View File

@ -1 +1 @@
com.alibaba.testable.processor.EnableTestableProcessor
com.alibaba.testable.core.processor.EnableTestableProcessor