You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by li...@apache.org on 2020/04/22 00:21:03 UTC
[servicecomb-java-chassis] branch master updated: [SCB-1871]
dependency update: remove javassist dependency and remove common-javassist
module
This is an automated email from the ASF dual-hosted git repository.
liubao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 7d5b006 [SCB-1871] dependency update: remove javassist dependency and remove common-javassist module
7d5b006 is described below
commit 7d5b006287aa9ea233bcc20f42045b81d4ceb285
Author: liubao <bi...@qq.com>
AuthorDate: Tue Apr 21 11:45:43 2020 +0800
[SCB-1871] dependency update: remove javassist dependency and remove common-javassist module
---
common/common-javassist/pom.xml | 49 ---
.../servicecomb/common/javassist/ClassConfig.java | 108 ------
.../servicecomb/common/javassist/CtType.java | 98 ------
.../common/javassist/CtTypeJavaType.java | 70 ----
.../servicecomb/common/javassist/FieldConfig.java | 66 ----
.../common/javassist/JavassistUtils.java | 362 ---------------------
.../servicecomb/common/javassist/MethodConfig.java | 129 --------
.../servicecomb/common/javassist/MultiWrapper.java | 24 --
.../common/javassist/ParameterConfig.java | 39 ---
.../common/javassist/SingleWrapper.java | 24 --
.../common/javassist/StdScopedClassPool.java | 40 ---
.../javassist/StdScopedClassPoolFactory.java | 40 ---
.../servicecomb/common/javassist/TestCtType.java | 124 -------
.../common/javassist/TestCtTypeJavaType.java | 89 -----
.../common/javassist/TestJavassistUtils.java | 268 ---------------
.../src/test/resources/log4j.properties | 30 --
common/common-protobuf/pom.xml | 5 -
common/pom.xml | 2 +-
coverage-reports/pom.xml | 4 -
dependencies/bom/pom.xml | 5 -
dependencies/default/pom.xml | 7 -
distribution/pom.xml | 4 -
22 files changed, 1 insertion(+), 1586 deletions(-)
diff --git a/common/common-javassist/pom.xml b/common/common-javassist/pom.xml
deleted file mode 100644
index 75ede6f..0000000
--- a/common/common-javassist/pom.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<!--
- ~ Licensed to the Apache Software Foundation (ASF) under one or more
- ~ contributor license agreements. See the NOTICE file distributed with
- ~ this work for additional information regarding copyright ownership.
- ~ The ASF licenses this file to You under the Apache License, Version 2.0
- ~ (the "License"); you may not use this file except in compliance with
- ~ the License. You may obtain a copy of the License at
- ~
- ~ http://www.apache.org/licenses/LICENSE-2.0
- ~
- ~ Unless required by applicable law or agreed to in writing, software
- ~ distributed under the License is distributed on an "AS IS" BASIS,
- ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- ~ See the License for the specific language governing permissions and
- ~ limitations under the License.
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>common</artifactId>
- <version>2.0.2-SNAPSHOT</version>
- </parent>
- <artifactId>common-javassist</artifactId>
- <name>Java Chassis::Common::Javassist</name>
-
- <dependencies>
- <dependency>
- <groupId>org.javassist</groupId>
- <artifactId>javassist</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
- <artifactId>foundation-common</artifactId>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/ClassConfig.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/ClassConfig.java
deleted file mode 100644
index bc070ba..0000000
--- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/ClassConfig.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.common.javassist;
-
-import java.lang.reflect.Type;
-import java.util.ArrayList;
-import java.util.List;
-
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.type.TypeFactory;
-
-public class ClassConfig {
-
- private String className;
-
- private boolean intf;
-
- private List<String> intfList = new ArrayList<>();
-
- private List<FieldConfig> fieldList = new ArrayList<>();
-
- private List<MethodConfig> methodList = new ArrayList<>();
-
- public boolean isIntf() {
- return intf;
- }
-
- public void setIntf(boolean intf) {
- this.intf = intf;
- }
-
- public String getClassName() {
- return className;
- }
-
- public void setClassName(String className) {
- this.className = className;
- }
-
- public void addInterface(Class<?> intf) {
- addInterface(intf.getName());
- }
-
- public void addInterface(String intf) {
- intfList.add(intf);
- }
-
- public List<String> getIntfList() {
- return intfList;
- }
-
- public List<FieldConfig> getFieldList() {
- return fieldList;
- }
-
- public FieldConfig addField(String name, Type genericType) {
- return addField(name, TypeFactory.defaultInstance().constructType(genericType));
- }
-
- public FieldConfig addField(String name, JavaType javaType) {
- return addField(name, new CtType(javaType));
- }
-
- public FieldConfig addField(String name, CtType ctType) {
- FieldConfig field = new FieldConfig();
- field.setName(name);
- field.setType(ctType);
-
- fieldList.add(field);
-
- return field;
- }
-
- public void addMethod(MethodConfig methodConfig) {
- methodConfig.init();
- methodList.add(methodConfig);
- }
-
- public void addMethod(String source) {
- addMethod(source, null);
- }
-
- public void addMethod(String source, String genericSignature) {
- MethodConfig methodConfig = new MethodConfig();
- methodConfig.setSource(source);
- methodConfig.setGenericSignature(genericSignature);
- addMethod(methodConfig);
- }
-
- public List<MethodConfig> getMethodList() {
- return methodList;
- }
-}
diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtType.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtType.java
deleted file mode 100644
index cb4653d..0000000
--- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtType.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.common.javassist;
-
-import com.fasterxml.jackson.databind.JavaType;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtPrimitiveType;
-import javassist.NotFoundException;
-import javassist.bytecode.SignatureAttribute.ClassType;
-
-public class CtType {
- private static final ClassPool PRIMITIVE_CLASSPOOL = JavassistUtils.getOrCreateClassPool(int.class.getClassLoader());
-
- private CtClass ctClass;
-
- private boolean hasGenericTypes;
-
- private String genericSignature;
-
- public CtType(CtClass ctClass) {
- ClassType classType = new ClassType(ctClass.getName(), null);
- init(ctClass, false, classType.encode());
- }
-
- public CtType(CtClass ctClass, boolean hasGenericTypes, String genericSignature) {
- init(ctClass, hasGenericTypes, genericSignature);
- }
-
- public CtType(JavaType javaType) {
- if (CtTypeJavaType.class.isInstance(javaType)) {
- CtType ctType = ((CtTypeJavaType) javaType).getType();
- init(ctType.ctClass, ctType.hasGenericTypes, ctType.genericSignature);
- return;
- }
-
- ClassLoader classLoader = javaType.getRawClass().getClassLoader();
- try {
- ClassPool classPool = JavassistUtils.getOrCreateClassPool(classLoader);
- init(classPool.get(javaType.getRawClass().getCanonicalName()), javaType.hasGenericTypes(),
- javaType.getGenericSignature()
- );
- } catch (NotFoundException e) {
- throw new IllegalStateException(
- String.format("Failed to get CtClass for %s in classloader %s.",
- javaType.getRawClass().getName(),
- classLoader),
- e);
- }
- }
-
- private void init(CtClass ctClass, boolean hasGenericTypes, String genericSignature) {
- if (ctClass.isPrimitive() && !void.class.getName().equals(ctClass.getName())) {
- try {
- ctClass = PRIMITIVE_CLASSPOOL.get(((CtPrimitiveType) ctClass).getWrapperName());
- } catch (NotFoundException e) {
- throw new IllegalStateException("Impossible exception.", e);
- }
- }
-
- this.ctClass = ctClass;
- // no problem:
- // Ljava/util/List<Ljava/lang/String;>;
- // cause problem:
- // Ljava/util/List<[B;>;
- // it should be Ljava/util/List<[B>;
- // jackson generate genericSignature to be "Ljava/util/List<[B;>;" of List<byte[]>, we should convert it
- this.genericSignature = genericSignature.replace("[B;>", "[B>");
- this.hasGenericTypes = hasGenericTypes;
- }
-
- public CtClass getCtClass() {
- return ctClass;
- }
-
- public boolean hasGenericTypes() {
- return this.hasGenericTypes;
- }
-
- public String getGenericSignature() {
- return genericSignature;
- }
-}
diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtTypeJavaType.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtTypeJavaType.java
deleted file mode 100644
index 74c083c..0000000
--- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtTypeJavaType.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.common.javassist;
-
-import java.util.Objects;
-
-import com.fasterxml.jackson.databind.type.SimpleType;
-import com.fasterxml.jackson.databind.type.TypeBindings;
-
-/**
- * just a wrapper for CtType
- * pending create class from CtClass to support recursive dependency class
- */
-public class CtTypeJavaType extends SimpleType {
- private static final long serialVersionUID = 301147079248607138L;
-
- private CtType type;
-
- public CtTypeJavaType(CtType type) {
- super(CtTypeJavaType.class, TypeBindings.emptyBindings(), null, null,
- type == null ? 0 : type.getGenericSignature().hashCode(),
- null, null, false);
- this.type = type;
- }
-
- public CtType getType() {
- return type;
- }
-
- @Override
- protected String buildCanonicalName() {
- return type.getCtClass().getName();
- }
-
- @Override
- public String getGenericSignature() {
- return type.getGenericSignature();
- }
-
- @Override
- public StringBuilder getGenericSignature(StringBuilder sb) {
- return sb.append(type.getGenericSignature());
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || !this.getClass().isAssignableFrom(o.getClass())) {
- return false;
- }
- CtTypeJavaType that = (CtTypeJavaType) o;
- return Objects.equals(this.getGenericSignature(), that.getGenericSignature());
- }
-}
diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/FieldConfig.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/FieldConfig.java
deleted file mode 100644
index 8975690..0000000
--- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/FieldConfig.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.common.javassist;
-
-import com.fasterxml.jackson.databind.JavaType;
-
-public class FieldConfig {
- private String name;
-
- private CtType type;
-
- private boolean genGetter;
-
- private boolean genSetter;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public CtType getType() {
- return type;
- }
-
- public void setType(JavaType javaType) {
- this.type = new CtType(javaType);
- }
-
- public void setType(CtType ctType) {
- this.type = ctType;
- }
-
- public boolean isGenGetter() {
- return genGetter;
- }
-
- public void setGenGetter(boolean genGetter) {
- this.genGetter = genGetter;
- }
-
- public boolean isGenSetter() {
- return genSetter;
- }
-
- public void setGenSetter(boolean genSetter) {
- this.genSetter = genSetter;
- }
-}
diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/JavassistUtils.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/JavassistUtils.java
deleted file mode 100644
index 0be5b83..0000000
--- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/JavassistUtils.java
+++ /dev/null
@@ -1,362 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.common.javassist;
-
-import static java.util.Locale.ENGLISH;
-
-import java.lang.reflect.Modifier;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.servicecomb.foundation.common.utils.JvmUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.hash.Hashing;
-
-import javassist.CannotCompileException;
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.CtConstructor;
-import javassist.CtField;
-import javassist.CtMethod;
-import javassist.scopedpool.ScopedClassPoolRepositoryImpl;
-
-public final class JavassistUtils {
- private static final Logger LOGGER = LoggerFactory.getLogger(JavassistUtils.class);
-
- static {
- ScopedClassPoolRepositoryImpl.getInstance().setClassPoolFactory(new StdScopedClassPoolFactory());
- }
-
- public static ClassPool getOrCreateClassPool(ClassLoader classLoader) {
- return ScopedClassPoolRepositoryImpl.getInstance().registerClassLoader(classLoader);
- }
-
- public static void clearByClassLoader(ClassLoader classLoader) {
- ScopedClassPoolRepositoryImpl.getInstance().unregisterClassLoader(classLoader);
- }
-
- private JavassistUtils() {
- }
-
- @SuppressWarnings("rawtypes")
- public static Class<? extends Enum> createEnum(String clsName, String... values) {
- return createEnum(null, clsName, Arrays.asList(values));
- }
-
- @SuppressWarnings("rawtypes")
- public static Class<? extends Enum> createEnum(String clsName, List<String> values) {
- return createEnum(null, clsName, values);
- }
-
- @SuppressWarnings("rawtypes")
- public static Class<? extends Enum> getOrCreateEnumWithPackageName(ClassLoader classLoader, String packageName,
- List<String> enums) {
- String strEnums = enums.toString();
- String enumClsName =
- packageName + ".Enum_" + Hashing.sha256().hashString(strEnums, StandardCharsets.UTF_8).toString();
- return JavassistUtils.getOrCreateEnumWithClassName(classLoader, enumClsName, enums);
- }
-
- @SuppressWarnings({"rawtypes", "unchecked"})
- public static synchronized Class<? extends Enum> getOrCreateEnumWithClassName(ClassLoader classLoader, String clsName,
- List<String> values) {
- try {
- return (Class<? extends Enum>) classLoader.loadClass(clsName);
- } catch (ClassNotFoundException e) {
- return createEnum(classLoader, clsName, values);
- }
- }
-
- @SuppressWarnings({"rawtypes", "unchecked"})
- public static Class<? extends Enum> createEnum(ClassLoader classLoader, String clsName, List<String> values) {
- if (values == null || values.isEmpty()) {
- throw new Error("values is not allowed empty.");
- }
-
- classLoader = JvmUtils.correctClassLoader(classLoader);
-
- ClassPool classPool = getOrCreateClassPool(classLoader);
- CtClass ctClass = classPool.makeClass(clsName);
- ctClass.setModifiers(ctClass.getModifiers() | javassist.Modifier.ENUM);
-
- try {
- ctClass.setSuperclass(classPool.get(Enum.class.getName()));
-
- addEnumConstructor(classPool, ctClass);
- addEnumValuesMethod(ctClass, values);
-
- return (Class<? extends Enum>) ctClass.toClass(classLoader, null);
- } catch (Throwable e) {
- throw new Error(e);
- }
- }
-
- private static void addEnumConstructor(ClassPool classPool, CtClass ctClass) throws Exception {
- String src = "super($1, $2);";
- CtConstructor ctConstructor = new CtConstructor(
- classPool.get(new String[] {String.class.getName(), int.class.getName()}), ctClass);
- ctConstructor.setBody(src);
-
- ctClass.addConstructor(ctConstructor);
- }
-
- private static void addEnumValuesMethod(CtClass ctClass, List<String> values) throws CannotCompileException {
- StringBuilder sb = new StringBuilder();
- sb.append("public static Enum[] values(){return new Enum[]{");
- for (int idx = 0; idx < values.size(); idx++) {
- String value = values.get(idx);
-
- String line = String.format("new %s(\"%s\", %d),", ctClass.getName(), value, idx);
- sb.append(line);
- }
- sb.setLength(sb.length() - 1);
- sb.append("};}");
-
- CtMethod valuesMethod = CtMethod.make(sb.toString(), ctClass);
- ctClass.addMethod(valuesMethod);
- }
-
- public static Class<?> createClass(ClassConfig config) {
- return createClass(null, config);
- }
-
- public static CtClass createCtClass(ClassLoader classLoader, ClassConfig config) {
- classLoader = JvmUtils.correctClassLoader(classLoader);
-
- ClassPool classPool = getOrCreateClassPool(classLoader);
- CtClass ctClass = classPool.getOrNull(config.getClassName());
- if (ctClass == null) {
- if (config.isIntf()) {
- ctClass = classPool.makeInterface(config.getClassName());
- } else {
- ctClass = classPool.makeClass(config.getClassName());
- }
- }
-
- try {
- for (String intfName : config.getIntfList()) {
- ctClass.addInterface(classPool.get(intfName));
- }
-
- for (FieldConfig fieldConfig : config.getFieldList()) {
- CtField field = createCtField(ctClass, fieldConfig);
- ctClass.addField(field);
-
- if (fieldConfig.isGenGetter()) {
- addFieldGetter(config, fieldConfig);
- }
-
- if (fieldConfig.isGenSetter()) {
- addFieldSetter(config, fieldConfig);
- }
- }
-
- for (MethodConfig methodConfig : config.getMethodList()) {
- try {
- CtMethod ctMethod = CtMethod.make(methodConfig.getSource(), ctClass);
- if (methodConfig.getGenericSignature() != null) {
- ctMethod.setGenericSignature(methodConfig.getGenericSignature());
- }
- ctClass.addMethod(ctMethod);
- } catch (CannotCompileException e) {
- LOGGER.error("Failed to create method, source:\n{}.", methodConfig.getSource());
- throw e;
- }
- }
-
- LOGGER.info("create CtClass {} in classLoader {}.", config.getClassName(), classLoader);
- return ctClass;
- } catch (Throwable e) {
- throw new IllegalStateException(
- String.format("Failed to create CtClass %s in classLoader %s.", config.getClassName(),
- classLoader), e);
- }
- }
-
- public static Class<?> createClass(ClassLoader classLoader, ClassConfig config) {
- classLoader = JvmUtils.correctClassLoader(classLoader);
-
- CtClass ctClass = createCtClass(classLoader, config);
- return createClass(classLoader, ctClass);
- }
-
- public static Class<?> createClass(ClassLoader classLoader, CtClass ctClass) {
- classLoader = JvmUtils.correctClassLoader(classLoader);
-
- String clsName = ctClass.getName();
- try {
- // must try load from classloader first
- // because class A depend on class B
- // when load class A, will load class B
- // after this, if CtClass B invoke toClass again, will cause problem.
- return classLoader.loadClass(clsName);
- } catch (ClassNotFoundException e) {
- // ignore it
- }
-
- try {
- Class<?> cls = ctClass.toClass(classLoader, null);
- LOGGER.info("create class {} in classLoader {}.", clsName, classLoader);
- return cls;
- } catch (Throwable e) {
- throw new IllegalStateException(
- String.format("Failed to create %s in classLoader %s.", clsName, classLoader), e);
- }
- }
-
- public static String capitalize(String name) {
- if (name == null || name.length() == 0) {
- return name;
- }
- return name.substring(0, 1).toUpperCase(ENGLISH) + name.substring(1);
- }
-
- private static void addFieldGetter(ClassConfig config, FieldConfig fieldConfig) {
- MethodConfig methodConfig = new MethodConfig();
-
- String prefix = "get";
- if (boolean.class.getName().equals(fieldConfig.getType().getCtClass().getName())
- || Boolean.class.getName().equals(fieldConfig.getType().getCtClass().getName())) {
- prefix = "is";
- }
- methodConfig.setName(prefix + capitalize(fieldConfig.getName()));
- methodConfig.setResult(fieldConfig.getType());
- methodConfig.setBodySource("return " + fieldConfig.getName() + ";");
-
- config.addMethod(methodConfig);
- }
-
- private static void addFieldSetter(ClassConfig config, FieldConfig fieldConfig) {
- MethodConfig methodConfig = new MethodConfig();
- methodConfig.setName("set" + capitalize(fieldConfig.getName()));
- methodConfig.addParameter(fieldConfig.getName(), fieldConfig.getType());
- methodConfig.setBodySource(" this." + fieldConfig.getName() + " = " + fieldConfig.getName() + ";");
-
- config.addMethod(methodConfig);
- }
-
- public static void genMultiWrapperInterface(ClassConfig config) {
- try {
- config.addInterface(MultiWrapper.class);
-
- config.addMethod(genReadFieldsMethodSource(config.getFieldList()));
- config.addMethod(genWriteFieldsMethodSource(config.getFieldList()));
- } catch (Exception e) {
- String msg = String.format("failed to genMultiWrapperInterface, name=%s", config.getClassName());
- LOGGER.error(msg, e);
-
- throw new Error(msg, e);
- }
- }
-
- public static void genSingleWrapperInterface(ClassConfig config) {
- try {
- config.addInterface(SingleWrapper.class);
-
- config.addMethod(genReadFieldMethodSource(config.getFieldList()));
- config.addMethod(genWriteFieldMethodSource(config.getFieldList()));
- } catch (Exception e) {
- String msg = String.format("failed to genSingleWrapperMethod, name=%s", config.getClassName());
- LOGGER.error(msg, e);
-
- throw new Error(msg, e);
- }
- }
-
- private static String genReadFieldsMethodSource(List<FieldConfig> fieldList) {
- StringBuilder sb = new StringBuilder();
- sb.append("public Object[] readFields(){");
- sb.append(String.format("Object values[] = new Object[%d];", fieldList.size()));
-
- for (int idx = 0; idx < fieldList.size(); idx++) {
- String fieldName = fieldList.get(idx).getName();
- String code = String.format(" values[%d] = %s;",
- idx,
- fieldName);
-
- sb.append(code);
- }
- sb.append("return values;");
- sb.append("}");
-
- return sb.toString();
- }
-
- private static String genWriteFieldsMethodSource(List<FieldConfig> fieldList) {
- StringBuilder sb = new StringBuilder();
- sb.append("public void writeFields(Object[] values){");
- for (int idx = 0; idx < fieldList.size(); idx++) {
- FieldConfig fieldConfig = fieldList.get(idx);
-
- String fieldName = fieldConfig.getName();
- String code = String.format(" %s = (%s)values[%d];",
- fieldName,
- fieldConfig.getType().getCtClass().getName(),
- idx);
-
- sb.append(code);
- }
- sb.append("}");
-
- return sb.toString();
- }
-
- private static String genReadFieldMethodSource(List<FieldConfig> fieldList) {
- StringBuilder sb = new StringBuilder();
- sb.append("public Object readField(){");
-
- String fieldName = "null";
- if (!fieldList.isEmpty()) {
- fieldName = fieldList.get(0).getName();
- }
-
- sb.append(String.format(" return %s;", fieldName));
- sb.append("}");
-
- return sb.toString();
- }
-
- private static String genWriteFieldMethodSource(List<FieldConfig> fieldList) {
- StringBuilder sb = new StringBuilder();
- sb.append("public void writeField(Object value){");
-
- if (!fieldList.isEmpty()) {
- FieldConfig fieldConfig = fieldList.get(0);
- sb.append(
- String.format(" %s=(%s)value;",
- fieldConfig.getName(),
- fieldConfig.getType().getCtClass().getName()));
- }
-
- sb.append("}");
-
- return sb.toString();
- }
-
- private static CtField createCtField(CtClass ctClass, FieldConfig field) throws CannotCompileException {
- CtField ctField = new CtField(field.getType().getCtClass(), field.getName(), ctClass);
- if (field.getType().hasGenericTypes()) {
- ctField.setGenericSignature(field.getType().getGenericSignature());
- }
- ctField.setModifiers(Modifier.PUBLIC);
- return ctField;
- }
-}
diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/MethodConfig.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/MethodConfig.java
deleted file mode 100644
index 437c308..0000000
--- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/MethodConfig.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.common.javassist;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.fasterxml.jackson.databind.JavaType;
-
-public class MethodConfig {
- private String name;
-
- private CtType result;
-
- private List<ParameterConfig> parameterList = new ArrayList<>();
-
- // 不包括前后的{}
- private String bodySource;
-
- // 根据上面的信息,生成下面两个字段
- // 包括method声明和body
- // 如果是接口,则只是method声明
- private String source;
-
- // 泛型声明,如果method参数及应答中没有泛型类型,则此字段应该为null
- private String genericSignature;
-
- public String getSource() {
- return source;
- }
-
- public void setSource(String source) {
- this.source = source;
- }
-
- public String getGenericSignature() {
- return genericSignature;
- }
-
- public void setGenericSignature(String genericSignature) {
- this.genericSignature = genericSignature;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public void setResult(JavaType javaType) {
- this.result = new CtType(javaType);
- }
-
- public void setResult(CtType result) {
- this.result = result;
- }
-
- public void addParameter(String name, JavaType javaType) {
- addParameter(name, new CtType(javaType));
- }
-
- public void addParameter(String name, CtType ctType) {
- ParameterConfig parameterConfig = new ParameterConfig();
- parameterConfig.setName(name);
- parameterConfig.setType(ctType);
- parameterList.add(parameterConfig);
- }
-
- public void setBodySource(String bodySource) {
- this.bodySource = bodySource;
- }
-
- void init() {
- if (source != null) {
- return;
- }
-
- StringBuilder sbMethod = new StringBuilder();
- StringBuilder sbMethodGenericSignature = new StringBuilder();
-
- sbMethod.append("public ");
- sbMethod.append(result == null ? "void" : result.getCtClass().getName());
- sbMethod.append(" ")
- .append(name)
- .append("(");
- sbMethodGenericSignature.append("(");
-
- boolean hasGenericSignature = result != null && result.hasGenericTypes();
- for (ParameterConfig parameter : parameterList) {
- hasGenericSignature = hasGenericSignature || parameter.getType().hasGenericTypes();
-
- String paramTypeName = parameter.getType().getCtClass().getName();
- String code = String.format("%s %s,", paramTypeName, parameter.getName());
- sbMethod.append(code);
- sbMethodGenericSignature.append(parameter.getType().getGenericSignature());
- }
-
- if (!parameterList.isEmpty()) {
- sbMethod.setLength(sbMethod.length() - 1);
- }
- sbMethod.append(")");
- sbMethodGenericSignature.append(")");
- sbMethodGenericSignature.append(result == null ? "V" : result.getGenericSignature());
-
- if (bodySource != null) {
- sbMethod.append("{").append(bodySource).append("}");
- } else {
- sbMethod.append(";");
- }
-
- source = sbMethod.toString();
- if (hasGenericSignature) {
- genericSignature = sbMethodGenericSignature.toString();
- }
- }
-}
diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/MultiWrapper.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/MultiWrapper.java
deleted file mode 100644
index 4449e04..0000000
--- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/MultiWrapper.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.common.javassist;
-
-public interface MultiWrapper {
- void writeFields(Object[] values);
-
- Object[] readFields();
-}
diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/ParameterConfig.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/ParameterConfig.java
deleted file mode 100644
index 3234ccb..0000000
--- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/ParameterConfig.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.common.javassist;
-
-public class ParameterConfig {
- private String name;
-
- private CtType type;
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public CtType getType() {
- return type;
- }
-
- public void setType(CtType type) {
- this.type = type;
- }
-}
diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/SingleWrapper.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/SingleWrapper.java
deleted file mode 100644
index 26590b0..0000000
--- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/SingleWrapper.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.common.javassist;
-
-public interface SingleWrapper {
- void writeField(Object value);
-
- Object readField();
-}
diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/StdScopedClassPool.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/StdScopedClassPool.java
deleted file mode 100644
index 6f54754..0000000
--- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/StdScopedClassPool.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.common.javassist;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.scopedpool.ScopedClassPool;
-import javassist.scopedpool.ScopedClassPoolRepository;
-
-/**
- * getCached of ScopedClassPool, not only search self and parent
- * but also search other ScopedClassPool in repository
- *
- * this is not what we want, so change getCached behavior
- */
-public class StdScopedClassPool extends ScopedClassPool {
- protected StdScopedClassPool(ClassLoader cl, ClassPool src,
- ScopedClassPoolRepository repository, boolean isTemp) {
- super(cl, src, repository, isTemp);
- }
-
- @Override
- protected CtClass getCached(String classname) {
- return getCachedLocally(classname);
- }
-}
diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/StdScopedClassPoolFactory.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/StdScopedClassPoolFactory.java
deleted file mode 100644
index 411da77..0000000
--- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/StdScopedClassPoolFactory.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.common.javassist;
-
-import javassist.ClassPool;
-import javassist.scopedpool.ScopedClassPool;
-import javassist.scopedpool.ScopedClassPoolFactory;
-import javassist.scopedpool.ScopedClassPoolRepository;
-
-public class StdScopedClassPoolFactory implements ScopedClassPoolFactory {
- /**
- * Makes an instance.
- */
- public ScopedClassPool create(ClassLoader cl, ClassPool src,
- ScopedClassPoolRepository repository) {
- return new StdScopedClassPool(cl, src, repository, false);
- }
-
- /**
- * Makes an instance.
- */
- public ScopedClassPool create(ClassPool src,
- ScopedClassPoolRepository repository) {
- return new StdScopedClassPool(null, src, repository, true);
- }
-}
\ No newline at end of file
diff --git a/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtType.java b/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtType.java
deleted file mode 100644
index 1a6760e..0000000
--- a/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtType.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.common.javassist;
-
-import java.util.List;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.type.TypeFactory;
-
-import javassist.ClassPool;
-import javassist.CtClass;
-import javassist.NotFoundException;
-
-public class TestCtType {
- CtType ctType;
-
- @Test
- public void fromCtClass() {
- CtClass ctClass = Mockito.mock(CtClass.class);
- Mockito.when(ctClass.getName()).thenReturn("a.b.c");
- ctType = new CtType(ctClass);
-
- Assert.assertSame(ctClass, ctType.getCtClass());
- Assert.assertFalse(ctType.hasGenericTypes());
- Assert.assertEquals("La/b/c;", ctType.getGenericSignature());
- }
-
- @Test
- public void fromCtClass_fullInfo() {
- CtClass ctClass = Mockito.mock(CtClass.class);
- ctType = new CtType(ctClass, true, "Ljava/util/List<[B;>;");
-
- Assert.assertSame(ctClass, ctType.getCtClass());
- Assert.assertTrue(ctType.hasGenericTypes());
- Assert.assertEquals("Ljava/util/List<[B>;", ctType.getGenericSignature());
- }
-
- @Test
- public void fromJavaType() throws NotFoundException {
- Class<?> cls = String.class;
- JavaType javaType = TypeFactory.defaultInstance().constructType(cls);
- ctType = new CtType(javaType);
-
- Assert.assertSame(JavassistUtils.getOrCreateClassPool(cls.getClassLoader())
- .get(cls.getCanonicalName()), ctType.getCtClass());
- Assert.assertFalse(ctType.hasGenericTypes());
- Assert.assertEquals("Ljava/lang/String;", ctType.getGenericSignature());
- }
-
- @Test
- public void fromJavaType_primitive() throws NotFoundException {
- Class<?> cls = int.class;
- JavaType javaType = TypeFactory.defaultInstance().constructType(cls);
- ctType = new CtType(javaType);
-
- Assert.assertSame(JavassistUtils.getOrCreateClassPool(Integer.class.getClassLoader())
- .get(Integer.class.getCanonicalName()), ctType.getCtClass());
- Assert.assertFalse(ctType.hasGenericTypes());
- Assert.assertEquals("I;", ctType.getGenericSignature());
- }
-
- @Test
- public void fromJavaType_bytes() throws NotFoundException {
- Class<?> cls = byte[].class;
- JavaType javaType = TypeFactory.defaultInstance().constructType(cls);
- ctType = new CtType(javaType);
-
- Assert.assertSame(JavassistUtils.getOrCreateClassPool(cls.getClassLoader())
- .get(cls.getCanonicalName()), ctType.getCtClass());
- Assert.assertFalse(ctType.hasGenericTypes());
- Assert.assertEquals("[B;", ctType.getGenericSignature());
- }
-
- @Test
- public void fromJavaType_listBytes() throws NotFoundException {
- JavaType javaType = TypeFactory.defaultInstance().constructCollectionType(List.class, byte[].class);
- ctType = new CtType(javaType);
-
- Assert.assertSame(JavassistUtils.getOrCreateClassPool(List.class.getClassLoader())
- .get(List.class.getCanonicalName()), ctType.getCtClass());
- Assert.assertTrue(ctType.hasGenericTypes());
- Assert.assertEquals("Ljava/util/List<[B>;", ctType.getGenericSignature());
- }
-
- @Test
- public void fromCtTypeJavaType() throws NotFoundException {
- CtClass ctClass = ClassPool.getDefault().get(String.class.getCanonicalName());
- CtType otherCtType = new CtType(ctClass, false, "Ljava/lang/String;");
- CtTypeJavaType ctTypeJavaType = new CtTypeJavaType(otherCtType);
-
- ctType = new CtType(ctTypeJavaType);
-
- Assert.assertSame(ctClass, ctType.getCtClass());
- Assert.assertFalse(ctType.hasGenericTypes());
- Assert.assertEquals("Ljava/lang/String;", ctType.getGenericSignature());
- }
-
- @Test
- public void fromJavaType_void() {
- final JavaType voidJavaType = TypeFactory.defaultInstance().constructType(void.class);
- CtType voidCtType = new CtType(voidJavaType);
-
- Assert.assertTrue(voidCtType.getCtClass().isPrimitive());
- Assert.assertEquals("void", voidCtType.getCtClass().getName());
- }
-}
diff --git a/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtTypeJavaType.java b/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtTypeJavaType.java
deleted file mode 100644
index 9ec4ea9..0000000
--- a/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtTypeJavaType.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.servicecomb.common.javassist;
-
-import java.util.List;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.fasterxml.jackson.databind.JavaType;
-import com.fasterxml.jackson.databind.type.TypeFactory;
-
-public class TestCtTypeJavaType {
- Class<?> cls = TestCtTypeJavaType.class;
-
- JavaType javaType = TypeFactory.defaultInstance().constructType(cls);
-
- CtType ctType = new CtType(javaType);
-
- CtTypeJavaType ctTypeJavaType = new CtTypeJavaType(ctType);
-
- @Test
- public void construct() {
- Assert.assertSame(ctType, ctTypeJavaType.getType());
- Assert.assertEquals(cls.getTypeName(), ctTypeJavaType.buildCanonicalName());
- }
-
- @Test
- public void getGenericSignature() {
- JavaType listJavaType = TypeFactory.defaultInstance().constructCollectionType(List.class, ctTypeJavaType);
- Assert.assertEquals("Ljava/util/List<Lorg/apache/servicecomb/common/javassist/TestCtTypeJavaType;>;",
- listJavaType.getGenericSignature());
- }
-
- /**
- * The {@link CtTypeJavaType} with different CtType should holds different hash code.
- */
- @Test
- public void testHashCode() {
- JavaType newJavaType = TypeFactory.defaultInstance().constructType(String.class);
- CtType newCtType = new CtType(newJavaType);
- CtTypeJavaType newCtTypeJavaType = new CtTypeJavaType(newCtType);
- Assert.assertNotEquals(ctTypeJavaType.hashCode(), newCtTypeJavaType.hashCode());
-
- newJavaType = TypeFactory.defaultInstance().constructType(cls);
- newCtType = new CtType(newJavaType);
- newCtTypeJavaType = new CtTypeJavaType(newCtType);
- Assert.assertEquals(ctTypeJavaType.hashCode(), newCtTypeJavaType.hashCode());
- }
-
- /**
- * The {@link CtTypeJavaType}s holding different type information should not equal to each others.
- * While those holding the same type information should be equal.
- */
- @Test
- public void testEquals() {
- JavaType newJavaType = TypeFactory.defaultInstance().constructType(String.class);
- CtType newCtType = new CtType(newJavaType);
- CtTypeJavaType newCtTypeJavaType = new CtTypeJavaType(newCtType);
- Assert.assertNotEquals(ctTypeJavaType, newCtTypeJavaType);
-
- newJavaType = TypeFactory.defaultInstance().constructType(cls);
- newCtType = new CtType(newJavaType);
- newCtTypeJavaType = new CtTypeJavaType(newCtType);
- Assert.assertEquals(ctTypeJavaType, newCtTypeJavaType);
-
- // test subClass of CtTypeJavaType
- newJavaType = TypeFactory.defaultInstance().constructType(cls);
- newCtType = new CtType(newJavaType);
- newCtTypeJavaType = new CtTypeJavaType(newCtType) {
- private static final long serialVersionUID = 1876189050753964880L;
- };
- Assert.assertEquals(ctTypeJavaType, newCtTypeJavaType);
- }
-}
diff --git a/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestJavassistUtils.java b/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestJavassistUtils.java
deleted file mode 100644
index b28a4db..0000000
--- a/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestJavassistUtils.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.servicecomb.common.javassist;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.ws.rs.core.Response.Status;
-
-import org.apache.servicecomb.foundation.common.utils.ReflectUtils;
-import org.junit.Assert;
-import org.junit.Test;
-
-import com.fasterxml.jackson.databind.type.TypeFactory;
-import com.google.common.hash.Hashing;
-
-import javassist.ClassPool;
-import javassist.scopedpool.ScopedClassPoolRepositoryImpl;
-import mockit.Deencapsulation;
-
-public class TestJavassistUtils {
- @Test
- public void testField() throws Exception {
- ClassConfig classConfig = new ClassConfig();
- classConfig.setClassName("servicecomb.ut.testField");
-
- FieldConfig fieldConfig = classConfig.addField("intField", int.class);
- fieldConfig.setGenGetter(true);
- fieldConfig.setGenSetter(true);
-
- fieldConfig = classConfig.addField("intArrayField", int[].class);
- fieldConfig.setGenGetter(true);
- fieldConfig.setGenSetter(true);
-
- fieldConfig = classConfig
- .addField("listStringField", TypeFactory.defaultInstance().constructCollectionType(List.class, String.class));
- fieldConfig.setGenGetter(true);
- fieldConfig.setGenSetter(true);
-
- fieldConfig = classConfig.addField("bool", TypeFactory.defaultInstance().constructType(boolean.class));
- fieldConfig.setGenGetter(true);
-
- fieldConfig = classConfig.addField("wrapperBool", TypeFactory.defaultInstance().constructType(Boolean.class));
- fieldConfig.setGenGetter(true);
-
- Class<?> cls = JavassistUtils.createClass(classConfig);
-
- Field field = cls.getField("intField");
- Assert.assertEquals(Integer.class, field.getType());
-
- Method method = cls.getMethod("getIntField");
- Assert.assertEquals(Integer.class, method.getReturnType());
-
- field = cls.getField("intArrayField");
- Assert.assertEquals(int[].class, field.getType());
-
- method = cls.getMethod("getIntArrayField");
- Assert.assertEquals(int[].class, method.getReturnType());
-
- field = cls.getField("listStringField");
- Assert.assertEquals("java.util.List<java.lang.String>", field.getGenericType().getTypeName());
-
- method = cls.getMethod("getListStringField");
- Assert.assertEquals("java.util.List<java.lang.String>", method.getGenericReturnType().getTypeName());
-
- method = cls.getMethod("isBool");
- Assert.assertEquals(Boolean.class, method.getReturnType());
-
- method = cls.getMethod("isWrapperBool");
- Assert.assertEquals(Boolean.class, method.getReturnType());
- }
-
- @Test
- public void testAddParameter() {
- ClassConfig classConfig = new ClassConfig();
- classConfig.setIntf(true);
- String intfName = "servicecomb.ut.TestAddParameter";
- classConfig.setClassName(intfName);
-
- MethodConfig methodConfig = new MethodConfig();
- methodConfig.setName("method");
- methodConfig.setResult(TypeFactory.defaultInstance().constructCollectionType(List.class, String.class));
- methodConfig
- .addParameter("map", TypeFactory.defaultInstance().constructMapType(Map.class, String.class, String.class));
- methodConfig.addParameter("set", TypeFactory.defaultInstance().constructCollectionType(Set.class, String.class));
- classConfig.addMethod(methodConfig);
-
- Class<?> intf = JavassistUtils.createClass(classConfig);
-
- Assert.assertEquals(intfName, intf.getName());
- Method method = ReflectUtils.findMethod(intf, "method");
- Assert.assertEquals("method", method.getName());
- Assert.assertEquals("java.util.List<java.lang.String>", method.getGenericReturnType().getTypeName());
-
- Type[] types = method.getGenericParameterTypes();
- Assert.assertEquals("java.util.Map<java.lang.String, java.lang.String>", types[0].getTypeName());
- Assert.assertEquals("java.util.Set<java.lang.String>", types[1].getTypeName());
- }
-
- @Test
- public void testInterface() {
- ClassConfig classConfig = new ClassConfig();
- classConfig.setIntf(true);
- String intfName = "servicecomb.ut.TestInterface";
- classConfig.setClassName(intfName);
-
- String source = "java.util.List method(java.util.Map map, java.util.Set set);";
- String genericSignature =
- "(Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;Ljava/util/Set<Ljava/lang/String;>;)Ljava/util/List<Ljava/lang/String;>;";
- classConfig.addMethod(source, genericSignature);
-
- Class<?> intf = JavassistUtils.createClass(classConfig);
-
- Assert.assertEquals(intfName, intf.getName());
- Method method = ReflectUtils.findMethod(intf, "method");
- Assert.assertEquals("method", method.getName());
- Assert.assertEquals("java.util.List<java.lang.String>", method.getGenericReturnType().getTypeName());
-
- Type[] types = method.getGenericParameterTypes();
- Assert.assertEquals("java.util.Map<java.lang.String, java.lang.String>", types[0].getTypeName());
- Assert.assertEquals("java.util.Set<java.lang.String>", types[1].getTypeName());
- }
-
- @Test
- public void singleWrapperInt() throws Exception {
- ClassConfig classConfig = new ClassConfig();
- classConfig.setClassName("servicecomb.ut.single.IntWrapper");
- classConfig.addField("intField", TypeFactory.defaultInstance().constructType(int.class));
-
- JavassistUtils.genSingleWrapperInterface(classConfig);
-
- Class<?> wrapperClass = JavassistUtils.createClass(classConfig);
-
- SingleWrapper instance = (SingleWrapper) wrapperClass.newInstance();
- instance.writeField(100);
- int intFieldValue = (int) instance.readField();
- Assert.assertEquals(100, intFieldValue);
- }
-
- @Test
- public void multiWrapper() throws Exception {
- ClassConfig classConfig = new ClassConfig();
- classConfig.setClassName("servicecomb.ut.multi.Wrapper");
- classConfig.addField("intField", int.class);
- classConfig.addField("strField", String.class);
-
- JavassistUtils.genMultiWrapperInterface(classConfig);
-
- Class<?> wrapperClass = JavassistUtils.createClass(classConfig);
-
- MultiWrapper instance = (MultiWrapper) wrapperClass.newInstance();
- instance.writeFields(new Object[] {100, "test"});
- Object[] fieldValues = instance.readFields();
- Assert.assertEquals(100, fieldValues[0]);
- Assert.assertEquals("test", fieldValues[1]);
- }
-
- @Test
- public void getOrCreateEnumWithClassName_get() {
- Class<?> cls = Status.class;
-
- Assert.assertSame(cls,
- JavassistUtils.getOrCreateEnumWithClassName(Thread.currentThread().getContextClassLoader(),
- Status.class.getName(),
- null));
- }
-
- @Test
- public void getOrCreateEnumWithClassName_create()
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- String name = "servicecomb.ut.EnumAbc";
- Assert.assertNull(ClassPool.getDefault().getOrNull(name));
-
- @SuppressWarnings("rawtypes")
- Class<? extends Enum> cls =
- JavassistUtils
- .getOrCreateEnumWithClassName(Thread.currentThread().getContextClassLoader(),
- name,
- Arrays.asList("a", "b"));
- checkEnum(name, cls);
- }
-
- @Test
- public void getOrCreateEnumWithPackageName()
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- List<String> enums = Arrays.asList("a", "b");
- String packageName = "servicecomb.ut";
- String clsName =
- packageName + ".Enum_" + Hashing.sha256().hashString(enums.toString(), StandardCharsets.UTF_8).toString();
- Assert.assertNull(ClassPool.getDefault().getOrNull(clsName));
-
- @SuppressWarnings("rawtypes")
- Class<? extends Enum> cls =
- JavassistUtils
- .getOrCreateEnumWithPackageName(Thread.currentThread().getContextClassLoader(),
- packageName,
- Arrays.asList("a", "b"));
-
- checkEnum(clsName, cls);
- Assert.assertSame(cls,
- JavassistUtils
- .getOrCreateEnumWithPackageName(Thread.currentThread().getContextClassLoader(),
- packageName,
- Arrays.asList("a", "b")));
- }
-
- @Test
- public void testEnum() throws Exception {
- String name = "servicecomb.ut.EnumAbc2";
- @SuppressWarnings("rawtypes")
- Class<? extends Enum> cls = JavassistUtils.createEnum(name, "a", "b");
- checkEnum(name, cls);
- }
-
- @SuppressWarnings("rawtypes")
- protected void checkEnum(String expectName, Class<? extends Enum> cls)
- throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
- Method method = cls.getMethod("values");
- Enum<?>[] values = (Enum<?>[]) method.invoke(null);
-
- Assert.assertEquals(expectName, cls.getName());
- Assert.assertEquals(2, values.length);
- Assert.assertEquals("a", values[0].name());
- Assert.assertEquals(0, values[0].ordinal());
- Assert.assertEquals("b", values[1].name());
- Assert.assertEquals(1, values[1].ordinal());
- }
-
- @Test
- public void managerClassPool() {
- ClassLoader classLoader1 = new ClassLoader() {
- };
- ClassLoader classLoader2 = new ClassLoader() {
- };
-
- ClassPool p1 = Deencapsulation.invoke(JavassistUtils.class, "getOrCreateClassPool", classLoader1);
- ClassPool p2 = Deencapsulation.invoke(JavassistUtils.class, "getOrCreateClassPool", classLoader2);
- Assert.assertNotSame(p1, p2);
-
- JavassistUtils.clearByClassLoader(classLoader1);
- Assert.assertFalse(ScopedClassPoolRepositoryImpl.getInstance().getRegisteredCLs().containsKey(classLoader1));
-
- JavassistUtils.clearByClassLoader(classLoader2);
- Assert.assertFalse(ScopedClassPoolRepositoryImpl.getInstance().getRegisteredCLs().containsKey(classLoader2));
- }
-}
diff --git a/common/common-javassist/src/test/resources/log4j.properties b/common/common-javassist/src/test/resources/log4j.properties
deleted file mode 100644
index fbea91e..0000000
--- a/common/common-javassist/src/test/resources/log4j.properties
+++ /dev/null
@@ -1,30 +0,0 @@
-#
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements. See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-
-log4j.rootLogger=INFO, out, stdout
-
-# CONSOLE appender not used by default
-log4j.appender.stdout=org.apache.log4j.ConsoleAppender
-log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
-log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-
-# File appender
-log4j.appender.out=org.apache.log4j.FileAppender
-log4j.appender.out.layout=org.apache.log4j.PatternLayout
-log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] %-5p %-30.30c{1} - %m%n
-log4j.appender.out.file=target/test.log
-log4j.appender.out.append=true
diff --git a/common/common-protobuf/pom.xml b/common/common-protobuf/pom.xml
index 4e1a90a..6de3c06 100644
--- a/common/common-protobuf/pom.xml
+++ b/common/common-protobuf/pom.xml
@@ -38,11 +38,6 @@
<dependency>
<groupId>org.apache.servicecomb</groupId>
- <artifactId>common-javassist</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
<artifactId>foundation-protobuf</artifactId>
</dependency>
diff --git a/common/pom.xml b/common/pom.xml
index ec711bf..d462e65 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -28,7 +28,7 @@
<name>Java Chassis::Common</name>
<packaging>pom</packaging>
<modules>
- <module>common-javassist</module>
+
<module>common-protobuf</module>
<module>common-rest</module>
<module>common-access-log</module>
diff --git a/coverage-reports/pom.xml b/coverage-reports/pom.xml
index f897750..87605cf 100644
--- a/coverage-reports/pom.xml
+++ b/coverage-reports/pom.xml
@@ -116,10 +116,6 @@
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
- <artifactId>common-javassist</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
<artifactId>swagger-generator-core</artifactId>
</dependency>
<dependency>
diff --git a/dependencies/bom/pom.xml b/dependencies/bom/pom.xml
index 2a28e1d..3dc662f 100644
--- a/dependencies/bom/pom.xml
+++ b/dependencies/bom/pom.xml
@@ -76,11 +76,6 @@
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
- <artifactId>common-javassist</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
<artifactId>common-protobuf</artifactId>
<version>${project.version}</version>
</dependency>
diff --git a/dependencies/default/pom.xml b/dependencies/default/pom.xml
index ecde36f..018a513 100644
--- a/dependencies/default/pom.xml
+++ b/dependencies/default/pom.xml
@@ -62,7 +62,6 @@
<httpcomponents.version>4.5.7</httpcomponents.version>
<hystrix.version>1.5.18</hystrix.version>
<jackson.version>2.10.0</jackson.version>
- <javassist.version>3.24.0-GA</javassist.version>
<javakaffee.version>0.26</javakaffee.version>
<javax-annotation.version>1.3.2</javax-annotation.version>
<javax-inject.version>1</javax-inject.version>
@@ -787,12 +786,6 @@
</dependency>
<dependency>
- <groupId>org.javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>${javassist.version}</version>
- </dependency>
-
- <dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>${jmockit.version}</version>
diff --git a/distribution/pom.xml b/distribution/pom.xml
index a7d0854..e3ce963 100644
--- a/distribution/pom.xml
+++ b/distribution/pom.xml
@@ -64,10 +64,6 @@
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
- <artifactId>common-javassist</artifactId>
- </dependency>
- <dependency>
- <groupId>org.apache.servicecomb</groupId>
<artifactId>common-protobuf</artifactId>
</dependency>
<dependency>