From a1f928ac5dcd74f3eeae0ca2849ad8ce4924bd78 Mon Sep 17 00:00:00 2001 From: oldmanpushcart Date: Sun, 28 Oct 2018 01:45:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E9=97=AE=E9=A2=98=EF=BC=9A#1?= =?UTF-8?q?07?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 4 +- sandbox-agent/pom.xml | 2 +- sandbox-api/pom.xml | 2 +- sandbox-common-api/pom.xml | 2 +- sandbox-core/pom.xml | 2 +- .../structure/ClassStructureImplByAsm.java | 118 +++++++- .../structure/ClassStructureImplByJDK.java | 16 +- sandbox-debug-module/pom.xml | 2 +- sandbox-mgr-module/pom.xml | 2 +- sandbox-mgr-provider/pom.xml | 2 +- sandbox-module-starter/pom.xml | 2 +- sandbox-provider-api/pom.xml | 2 +- sandbox-qatest/pom.xml | 2 +- .../core/enhance/CoreEnhanceBaseTestCase.java | 56 ++-- .../util/matcher/ClassStructureTestCase.java | 146 ++++++++++ .../qatest/core/util/matcher/PublicUser.java | 264 ++++++++++++++++++ .../jvm/sandbox/qatest/util/QaClassUtils.java | 32 +++ sandbox-spy/pom.xml | 2 +- 18 files changed, 603 insertions(+), 55 deletions(-) create mode 100644 sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/core/util/matcher/ClassStructureTestCase.java create mode 100644 sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/core/util/matcher/PublicUser.java create mode 100644 sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/util/QaClassUtils.java diff --git a/pom.xml b/pom.xml index 459f02e9..bbaddbe5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,14 +4,14 @@ com.alibaba.jvm.sandbox sandbox - 1.1.0 + 1.1.1-SNAPSHOT pom sandbox ${sandbox.version} UTF-8 - 1.1.0 + 1.1.1-SNAPSHOT diff --git a/sandbox-agent/pom.xml b/sandbox-agent/pom.xml index 5b1519db..c40e5b6e 100755 --- a/sandbox-agent/pom.xml +++ b/sandbox-agent/pom.xml @@ -6,7 +6,7 @@ com.alibaba.jvm.sandbox sandbox - 1.1.0 + 1.1.1-SNAPSHOT sandbox-agent sandbox-agent ${sandbox.version} diff --git a/sandbox-api/pom.xml b/sandbox-api/pom.xml index 63f7abc7..d5b869fc 100755 --- a/sandbox-api/pom.xml +++ b/sandbox-api/pom.xml @@ -6,7 +6,7 @@ com.alibaba.jvm.sandbox sandbox - 1.1.0 + 1.1.1-SNAPSHOT sandbox-api sandbox-api ${sandbox.version} diff --git a/sandbox-common-api/pom.xml b/sandbox-common-api/pom.xml index 8e476bd4..13b7e8ac 100644 --- a/sandbox-common-api/pom.xml +++ b/sandbox-common-api/pom.xml @@ -6,7 +6,7 @@ sandbox com.alibaba.jvm.sandbox - 1.1.0 + 1.1.1-SNAPSHOT sandbox-common-api sandbox-common-api ${sandbox.version} diff --git a/sandbox-core/pom.xml b/sandbox-core/pom.xml index 550b3b1e..ff109a7e 100755 --- a/sandbox-core/pom.xml +++ b/sandbox-core/pom.xml @@ -6,7 +6,7 @@ com.alibaba.jvm.sandbox sandbox - 1.1.0 + 1.1.1-SNAPSHOT sandbox-core sandbox-core ${sandbox.version} diff --git a/sandbox-core/src/main/java/com/alibaba/jvm/sandbox/core/util/matcher/structure/ClassStructureImplByAsm.java b/sandbox-core/src/main/java/com/alibaba/jvm/sandbox/core/util/matcher/structure/ClassStructureImplByAsm.java index 8ca59287..f5e3af98 100644 --- a/sandbox-core/src/main/java/com/alibaba/jvm/sandbox/core/util/matcher/structure/ClassStructureImplByAsm.java +++ b/sandbox-core/src/main/java/com/alibaba/jvm/sandbox/core/util/matcher/structure/ClassStructureImplByAsm.java @@ -6,12 +6,14 @@ import com.alibaba.jvm.sandbox.core.util.collection.Pair; import com.alibaba.jvm.sandbox.core.util.matcher.structure.PrimitiveClassStructure.Primitive; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.objectweb.asm.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; +import java.io.Serializable; import java.util.*; import static com.alibaba.jvm.sandbox.core.util.SandboxStringUtils.toInternalClassName; @@ -198,7 +200,7 @@ static Primitive mappingPrimitiveByJavaClassName(final String javaClassName) { } -class ArrayClassStructure extends EmptyClassStructure { +class ArrayClassStructure extends FamilyClassStructure { private final ClassStructure elementClassStructure; @@ -206,6 +208,92 @@ class ArrayClassStructure extends EmptyClassStructure { this.elementClassStructure = elementClassStructure; } + @Override + public Access getAccess() { + final Access access = elementClassStructure.getAccess(); + return new Access() { + @Override + public boolean isPublic() { + return access.isPublic(); + } + + @Override + public boolean isPrivate() { + return access.isPrivate(); + } + + @Override + public boolean isProtected() { + return access.isProtected(); + } + + @Override + public boolean isStatic() { + return false; + } + + @Override + public boolean isFinal() { + return true; + } + + @Override + public boolean isInterface() { + return false; + } + + @Override + public boolean isNative() { + return false; + } + + @Override + public boolean isAbstract() { + return true; + } + + @Override + public boolean isEnum() { + return false; + } + + @Override + public boolean isAnnotation() { + return false; + } + }; + } + + @Override + public ClassLoader getClassLoader() { + return elementClassStructure.getClassLoader(); + } + + @Override + public ClassStructure getSuperClassStructure() { + return new ClassStructureImplByJDK(Object.class); + } + + @Override + public List getInterfaceClassStructures() { + return new ArrayList( + Arrays.asList( + new ClassStructureImplByJDK(Cloneable.class), + new ClassStructureImplByJDK(Serializable.class) + ) + ); + } + + @Override + public List getAnnotationTypeClassStructures() { + return new LinkedList(); + } + + @Override + public List getBehaviorStructures() { + return new LinkedList(); + } + @Override public String getJavaClassName() { return new StringBuilder() @@ -236,7 +324,15 @@ public ClassStructureImplByAsm(final byte[] classByteArray, final ClassLoader loader) { this.classReader = new ClassReader(classByteArray); this.loader = loader; - this.access = new AccessImplByAsm(this.classReader.getAccess()); + this.access = new AccessImplByAsm(this.classReader.getAccess()){ + @Override + public boolean isStatic() { + // 修复ASM的BUG,如果是Enum类型,必定是static的 + // 但ASM(至少在6.0版本)会判断错误 + return isEnum() + || super.isStatic(); + } + }; } private boolean isBootstrapClassLoader() { @@ -283,6 +379,17 @@ private ClassStructure newInstance(final String javaClassName) { if (classStructureCache.containsKey(pair)) { return classStructureCache.get(pair); } else { + + // 修复ASM获取Class时,遇到已加载的类会导致ClassLoader被重新定义的BUG + try { + final Class tryToFoundClass = loader.loadClass(javaClassName); + final ClassStructure classStructure = new ClassStructureImplByJDK(tryToFoundClass); + classStructureCache.put(pair, classStructure); + return classStructure; + } catch (ClassNotFoundException e) { + // ignore... + } + final InputStream is = getResourceAsStream(internalClassNameToResourceName(toInternalClassName(javaClassName))); if (null != is) { try { @@ -415,6 +522,13 @@ public MethodVisitor visitMethod(final int access, final String desc, final String signature, final String[] exceptions) { + + // 修复ASM会把列入正常方法中的问题 + // 实际上这个方法并不会参与到任何的逻辑判断 + if(StringUtils.equals("", name)) { + return super.visitMethod(access, name, desc, signature, exceptions); + } + return new MethodVisitor(ASM6, super.visitMethod(access, name, desc, signature, exceptions)) { private final Type methodType = Type.getMethodType(desc); diff --git a/sandbox-core/src/main/java/com/alibaba/jvm/sandbox/core/util/matcher/structure/ClassStructureImplByJDK.java b/sandbox-core/src/main/java/com/alibaba/jvm/sandbox/core/util/matcher/structure/ClassStructureImplByJDK.java index 7cded9d4..4b9d37ad 100644 --- a/sandbox-core/src/main/java/com/alibaba/jvm/sandbox/core/util/matcher/structure/ClassStructureImplByJDK.java +++ b/sandbox-core/src/main/java/com/alibaba/jvm/sandbox/core/util/matcher/structure/ClassStructureImplByJDK.java @@ -140,9 +140,11 @@ public String getJavaClassName() { return javaClassName; } - return javaClassName = clazz.isArray() - ? clazz.getCanonicalName() - : clazz.getName(); + return getJavaClassName(clazz); + +// return javaClassName = clazz.isArray() +// ? clazz.getCanonicalName() +// : clazz.getName(); // final String canonicalName = clazz.getCanonicalName(); // return javaClassName = StringUtils.isEmpty(canonicalName) @@ -150,6 +152,14 @@ public String getJavaClassName() { // : canonicalName; } + private String getJavaClassName(Class clazz) { + if(clazz.isArray()) { + return getJavaClassName(clazz.getComponentType())+"[]"; + } + return clazz.getName(); + } + + @Override public ClassLoader getClassLoader() { return clazz.getClassLoader(); diff --git a/sandbox-debug-module/pom.xml b/sandbox-debug-module/pom.xml index 6400d12f..50ab0631 100755 --- a/sandbox-debug-module/pom.xml +++ b/sandbox-debug-module/pom.xml @@ -6,7 +6,7 @@ com.alibaba.jvm.sandbox sandbox-module-starter - 1.1.0 + 1.1.1-SNAPSHOT ../sandbox-module-starter/pom.xml sandbox-debug-module diff --git a/sandbox-mgr-module/pom.xml b/sandbox-mgr-module/pom.xml index 0b90c283..5242785d 100755 --- a/sandbox-mgr-module/pom.xml +++ b/sandbox-mgr-module/pom.xml @@ -6,7 +6,7 @@ com.alibaba.jvm.sandbox sandbox-module-starter - 1.1.0 + 1.1.1-SNAPSHOT ../sandbox-module-starter/pom.xml sandbox-mgr-module diff --git a/sandbox-mgr-provider/pom.xml b/sandbox-mgr-provider/pom.xml index 0532825e..4f0160d7 100644 --- a/sandbox-mgr-provider/pom.xml +++ b/sandbox-mgr-provider/pom.xml @@ -6,7 +6,7 @@ sandbox com.alibaba.jvm.sandbox - 1.1.0 + 1.1.1-SNAPSHOT sandbox-mgr-provider sandbox-mgr-provider ${sandbox.version} diff --git a/sandbox-module-starter/pom.xml b/sandbox-module-starter/pom.xml index 4b163eb4..d9495278 100644 --- a/sandbox-module-starter/pom.xml +++ b/sandbox-module-starter/pom.xml @@ -6,7 +6,7 @@ com.alibaba.jvm.sandbox sandbox - 1.1.0 + 1.1.1-SNAPSHOT sandbox-module-starter sandbox-module-starter ${sandbox.version} diff --git a/sandbox-provider-api/pom.xml b/sandbox-provider-api/pom.xml index f71ad633..ab9d1162 100644 --- a/sandbox-provider-api/pom.xml +++ b/sandbox-provider-api/pom.xml @@ -6,7 +6,7 @@ sandbox com.alibaba.jvm.sandbox - 1.1.0 + 1.1.1-SNAPSHOT sandbox-provider-api sandbox-provider-api ${sandbox.version} diff --git a/sandbox-qatest/pom.xml b/sandbox-qatest/pom.xml index 02ed5073..a4cb5a8d 100644 --- a/sandbox-qatest/pom.xml +++ b/sandbox-qatest/pom.xml @@ -6,7 +6,7 @@ com.alibaba.jvm.sandbox sandbox - 1.1.0 + 1.1.1-SNAPSHOT com.alibaba.jvm.sandbox sandbox-qatest diff --git a/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/core/enhance/CoreEnhanceBaseTestCase.java b/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/core/enhance/CoreEnhanceBaseTestCase.java index 824e1927..c70a8a5a 100644 --- a/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/core/enhance/CoreEnhanceBaseTestCase.java +++ b/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/core/enhance/CoreEnhanceBaseTestCase.java @@ -22,53 +22,35 @@ import java.util.concurrent.atomic.AtomicInteger; import static com.alibaba.jvm.sandbox.core.util.SandboxStringUtils.toInternalClassName; +import static com.alibaba.jvm.sandbox.qatest.util.QaClassUtils.toByteArray; +import static com.alibaba.jvm.sandbox.qatest.util.QaClassUtils.toResourceName; public class CoreEnhanceBaseTestCase { private static final AtomicInteger LISTENER_ID_SEQ = new AtomicInteger(1000); - /** - * 目标Class文件转换为字节码数组 - * - * @param targetClass 目标Class文件 - * @return 目标Class文件字节码数组 - * @throws IOException 转换出错 - */ - protected byte[] toByteArray(final Class targetClass) throws IOException { - final InputStream is = targetClass.getClassLoader().getResourceAsStream(toResourceName(targetClass.getName())); - try { - return IOUtils.toByteArray(is); - } finally { - IOUtils.closeQuietly(is); - } - } - - private String toResourceName(String javaClassName) { - return toInternalClassName(javaClassName).concat(".class"); - } - private class TestClassLoader extends ClassLoader { private final Map javaClassByteArrayMap = new HashMap(); -// @Override -// protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { -// final Class loadedClass = findLoadedClass(name); -// if (loadedClass == null) { -// try { -// final Class aClass = findClass(name); -// if (resolve) { -// resolveClass(aClass); -// } -// return aClass; -// } catch (Exception e) { -// return super.loadClass(name, resolve); -// } -// } else { -// return loadedClass; -// } -// } + @Override + protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + final Class loadedClass = findLoadedClass(name); + if (loadedClass == null) { + try { + final Class aClass = findClass(name); + if (resolve) { + resolveClass(aClass); + } + return aClass; + } catch (Exception e) { + return super.loadClass(name, resolve); + } + } else { + return loadedClass; + } + } public Class defineClass(final String javaClassName, final byte[] classByteArray) throws InvocationTargetException, IllegalAccessException { diff --git a/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/core/util/matcher/ClassStructureTestCase.java b/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/core/util/matcher/ClassStructureTestCase.java new file mode 100644 index 00000000..76b2a5b1 --- /dev/null +++ b/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/core/util/matcher/ClassStructureTestCase.java @@ -0,0 +1,146 @@ +package com.alibaba.jvm.sandbox.qatest.core.util.matcher; + +import com.alibaba.jvm.sandbox.core.util.matcher.structure.Access; +import com.alibaba.jvm.sandbox.core.util.matcher.structure.BehaviorStructure; +import com.alibaba.jvm.sandbox.core.util.matcher.structure.ClassStructure; +import com.alibaba.jvm.sandbox.qatest.core.enhance.target.Calculator; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.*; + +import static com.alibaba.jvm.sandbox.core.util.matcher.structure.ClassStructureFactory.createClassStructure; +import static com.alibaba.jvm.sandbox.qatest.util.QaClassUtils.toByteArray; +import static java.util.Arrays.asList; +import static org.junit.Assert.assertEquals; + +/** + * 类结构测试用例 + */ +@RunWith(Parameterized.class) +public class ClassStructureTestCase { + + private final Logger logger = LoggerFactory.getLogger(getClass()); + + @Parameterized.Parameters + public static Collection getData() { + return asList(new Object[][]{ + new Object[]{PublicUser.class}, + new Object[]{Calculator.class} + }); + } + + private final Class clazz; + + public ClassStructureTestCase(Class clazz) { + this.clazz = clazz; + } + + + private ClassStructure genByAsm() throws IOException { + return createClassStructure(toByteArray(clazz), clazz.getClassLoader()); + } + + private ClassStructure genByJdk() { + return createClassStructure(clazz); + } + + private void assertAccessEquals(Access acAsm, Access acJdk) { + assertEquals("isPublic", acAsm.isPublic(), acJdk.isPublic()); + assertEquals("isPrivate", acAsm.isPrivate(), acJdk.isPrivate()); + assertEquals("isProtected",acAsm.isProtected(), acJdk.isProtected()); + assertEquals("isStatic", acAsm.isStatic(), acJdk.isStatic()); + assertEquals("isFinal", acAsm.isFinal(), acJdk.isFinal()); + assertEquals("isInterface", acAsm.isInterface(), acJdk.isInterface()); + assertEquals("isNative", acAsm.isNative(), acJdk.isNative()); + assertEquals("isAbstract", acAsm.isAbstract(), acJdk.isAbstract()); + assertEquals("isEnum", acAsm.isEnum(), acJdk.isEnum()); + assertEquals("isAnnotation", acAsm.isAnnotation(), acJdk.isAnnotation()); + } + + private void assertClassStructureListEquals(Collection csAsmCollection, Collection csJdkCollection) { + assertEquals(csAsmCollection.size(), csJdkCollection.size()); + final List csAsmList = new ArrayList(csAsmCollection); + final List csJdkList = new ArrayList(csJdkCollection); + for (int index = 0; index < csAsmCollection.size(); index++) { + assertClassStructureEquals(csAsmList.get(index), csJdkList.get(index)); + } + } + + private void assertBehaviorStructureListEquals(List bsAsmList, List bsJdkList) { + assertEquals(String.format("asm:[%s];jdk:[%s]", bsAsmList, bsJdkList), bsAsmList.size(), bsJdkList.size()); + for (int index = 0; index < bsAsmList.size(); index++) { + assertBehaviorStructureEquals(bsAsmList.get(index), bsJdkList.get(index)); + } + } + + private void assertBehaviorStructureEquals(BehaviorStructure bsAsm, BehaviorStructure bsJdk) { + assertEquals(bsAsm.getName(), bsJdk.getName()); + logger.info("assert {}#{}", bsAsm.getDeclaringClassStructure().getJavaClassName(), bsAsm.getName()); + + assertClassStructureEquals(bsAsm.getDeclaringClassStructure(), bsJdk.getDeclaringClassStructure()); + assertAccessEquals(bsAsm.getAccess(), bsJdk.getAccess()); + assertClassStructureEquals(bsAsm.getReturnTypeClassStructure(), bsJdk.getReturnTypeClassStructure()); + + assertClassStructureListEquals(bsAsm.getParameterTypeClassStructures(), bsJdk.getParameterTypeClassStructures()); + } + + private Set uniqueClassStructureCheck = new HashSet(); + + private void assertClassStructureEquals(ClassStructure csAsm, ClassStructure csJdk) { + if (csAsm == null + || csJdk == null) { + assertEquals(csAsm, csJdk); + return; + } + + assertEquals(csAsm.getJavaClassName(), csJdk.getJavaClassName()); + + if (uniqueClassStructureCheck.contains(csAsm.getJavaClassName())) { + return; + } else { + uniqueClassStructureCheck.add(csAsm.getJavaClassName()); + } + + logger.info("assert CS:{}", csAsm.getJavaClassName()); + + assertAccessEquals(csAsm.getAccess(), csJdk.getAccess()); + assertEquals(csAsm.getClassLoader(), csJdk.getClassLoader()); + assertClassStructureEquals(csAsm.getSuperClassStructure(), csJdk.getSuperClassStructure()); + assertClassStructureListEquals(csAsm.getInterfaceClassStructures(), csJdk.getInterfaceClassStructures()); + assertClassStructureListEquals(csAsm.getFamilySuperClassStructures(), csJdk.getFamilySuperClassStructures()); + assertClassStructureListEquals(csAsm.getFamilyInterfaceClassStructures(), csJdk.getFamilyInterfaceClassStructures()); + assertClassStructureListEquals(csAsm.getFamilyTypeClassStructures(), csJdk.getFamilyTypeClassStructures()); + assertClassStructureListEquals(csAsm.getAnnotationTypeClassStructures(), csJdk.getAnnotationTypeClassStructures()); + assertClassStructureListEquals(csAsm.getFamilyAnnotationTypeClassStructures(), csJdk.getFamilyAnnotationTypeClassStructures()); + assertBehaviorStructureListEquals(sortBehaviorStructureCollectionByName(csAsm.getBehaviorStructures()), sortBehaviorStructureCollectionByName(csJdk.getBehaviorStructures())); + + } + + private List sortBehaviorStructureCollectionByName(Collection bsCollection) { + final List sortedBsList; + Collections.sort(sortedBsList = new ArrayList(bsCollection), new Comparator() { + @Override + public int compare(BehaviorStructure o1, BehaviorStructure o2) { + return o1.getName().compareTo(o2.getName()); + } + }); + return sortedBsList; + } + + + @Test + public void assertTheSame_Asm_Jdk() throws IOException { + + final ClassStructure csByAsm = genByAsm(); + final ClassStructure csByJdk = genByJdk(); + + assertClassStructureEquals(csByAsm, csByJdk); + + } + +} diff --git a/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/core/util/matcher/PublicUser.java b/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/core/util/matcher/PublicUser.java new file mode 100644 index 00000000..5a9a27e0 --- /dev/null +++ b/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/core/util/matcher/PublicUser.java @@ -0,0 +1,264 @@ +package com.alibaba.jvm.sandbox.qatest.core.util.matcher; + +import java.util.Collection; +import java.util.List; +import java.util.Set; + +enum Sex { + MAN, WOMAN +} + +public class PublicUser { + + enum Occupation { + STUDENT, + TEACHER, + ENGINEER + } + + class Address { + + } + + static class StaticAddress { + + } + + interface Face { + + } + + public PublicUser(String username, int age, Sex sex, Occupation occupation, Address address, StaticAddress staticAddress, PublicUser friend, Face face) { + this.username = username; + this.age = age; + this.sex = sex; + this.occupation = occupation; + this.address = address; + this.staticAddress = staticAddress; + this.friend = friend; + this.face = face; + } + + private String username; + private int age; + private Sex sex; + private Occupation occupation; + private Address address; + private StaticAddress staticAddress; + private PublicUser friend; + private Face face; + + private Collection usernames; + private Collection ages; + private Collection sexes; + private Collection occupations; + private Collection
addresses; + private Collection staticAddresses; + private Collection publicUsers; + private Collection faces; + + private String[] usernameArray; + private int[] ageArray; + private Sex[] sexArray; + private Occupation[] occupationArray; + private Address[] addressArray; + private StaticAddress[] staticAddressArray; + private PublicUser[] friendArray; + private Face[] faceArray; + + + // --- GETTER & SETTER + + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public Sex getSex() { + return sex; + } + + public void setSex(Sex sex) { + this.sex = sex; + } + + public Occupation getOccupation() { + return occupation; + } + + public void setOccupation(Occupation occupation) { + this.occupation = occupation; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } + + public StaticAddress getStaticAddress() { + return staticAddress; + } + + public void setStaticAddress(StaticAddress staticAddress) { + this.staticAddress = staticAddress; + } + + public PublicUser getFriend() { + return friend; + } + + public void setFriend(PublicUser friend) { + this.friend = friend; + } + + public Face getFace() { + return face; + } + + public void setFace(Face face) { + this.face = face; + } + + public Collection getUsernames() { + return usernames; + } + + public void setUsernames(Collection usernames) { + this.usernames = usernames; + } + + public Collection getAges() { + return ages; + } + + public void setAges(Collection ages) { + this.ages = ages; + } + + public Collection getSexes() { + return sexes; + } + + public void setSexes(Collection sexes) { + this.sexes = sexes; + } + + public Collection getOccupations() { + return occupations; + } + + public void setOccupations(Collection occupations) { + this.occupations = occupations; + } + + public Collection
getAddresses() { + return addresses; + } + + public void setAddresses(Collection
addresses) { + this.addresses = addresses; + } + + public Collection getStaticAddresses() { + return staticAddresses; + } + + public void setStaticAddresses(Collection staticAddresses) { + this.staticAddresses = staticAddresses; + } + + public Collection getPublicUsers() { + return publicUsers; + } + + public void setPublicUsers(Collection publicUsers) { + this.publicUsers = publicUsers; + } + + public Collection getFaces() { + return faces; + } + + public void setFaces(Collection faces) { + this.faces = faces; + } + + public String[] getUsernameArray() { + return usernameArray; + } + + public void setUsernameArray(String[] usernameArray) { + this.usernameArray = usernameArray; + } + + public int[] getAgeArray() { + return ageArray; + } + + public void setAgeArray(int[] ageArray) { + this.ageArray = ageArray; + } + + public Sex[] getSexArray() { + return sexArray; + } + + public void setSexArray(Sex[] sexArray) { + this.sexArray = sexArray; + } + + public Occupation[] getOccupationArray() { + return occupationArray; + } + + public void setOccupationArray(Occupation[] occupationArray) { + this.occupationArray = occupationArray; + } + + public Address[] getAddressArray() { + return addressArray; + } + + public void setAddressArray(Address[] addressArray) { + this.addressArray = addressArray; + } + + public StaticAddress[] getStaticAddressArray() { + return staticAddressArray; + } + + public void setStaticAddressArray(StaticAddress[] staticAddressArray) { + this.staticAddressArray = staticAddressArray; + } + + public PublicUser[] getFriendArray() { + return friendArray; + } + + public void setFriendArray(PublicUser[] friendArray) { + this.friendArray = friendArray; + } + + public Face[] getFaceArray() { + return faceArray; + } + + public void setFaceArray(Face[] faceArray) { + this.faceArray = faceArray; + } +} diff --git a/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/util/QaClassUtils.java b/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/util/QaClassUtils.java new file mode 100644 index 00000000..236f4f2d --- /dev/null +++ b/sandbox-qatest/src/test/java/com/alibaba/jvm/sandbox/qatest/util/QaClassUtils.java @@ -0,0 +1,32 @@ +package com.alibaba.jvm.sandbox.qatest.util; + +import org.apache.commons.io.IOUtils; + +import java.io.IOException; +import java.io.InputStream; + +import static com.alibaba.jvm.sandbox.core.util.SandboxStringUtils.toInternalClassName; + +public class QaClassUtils { + + /** + * 目标Class文件转换为字节码数组 + * + * @param targetClass 目标Class文件 + * @return 目标Class文件字节码数组 + * @throws IOException 转换出错 + */ + public static byte[] toByteArray(final Class targetClass) throws IOException { + final InputStream is = targetClass.getClassLoader().getResourceAsStream(toResourceName(targetClass.getName())); + try { + return IOUtils.toByteArray(is); + } finally { + IOUtils.closeQuietly(is); + } + } + + public static String toResourceName(String javaClassName) { + return toInternalClassName(javaClassName).concat(".class"); + } + +} diff --git a/sandbox-spy/pom.xml b/sandbox-spy/pom.xml index b5055bb7..e250a452 100755 --- a/sandbox-spy/pom.xml +++ b/sandbox-spy/pom.xml @@ -6,7 +6,7 @@ com.alibaba.jvm.sandbox sandbox - 1.1.0 + 1.1.1-SNAPSHOT sandbox-spy sandbox-spy ${sandbox.version}