You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2021/02/04 06:55:03 UTC
[dubbo-spi-extensions] 37/44: 增加checkstyle 和 rat, 并相应修改
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch 2.7.x
in repository https://gitbox.apache.org/repos/asf/dubbo-spi-extensions.git
commit fa8e7e1f83beb8336ed900d309f5980520e25db9
Author: qq213539 <21...@qq.com>
AuthorDate: Sat Jan 30 10:31:45 2021 +0800
增加checkstyle 和 rat, 并相应修改
---
dubbo-api-docs/codestyle/checkstyle.xml | 25 +++++++
.../codestyle/dubbo_codestyle_for_idea.xml | 33 +++++++++
.../core/DubboApiDocsAnnotationScanner.java | 7 +-
.../apache/dubbo/apidocs/utils/ClassTypeUtil.java | 29 +++++---
.../examples/params/QuickStartRequestBase.java | 16 +++++
.../src/main/resources/application.yml | 17 +++++
.../src/main/resources/bootstrap.yml | 17 +++++
.../examples/spi/DubboDocExporterListener.java | 16 +++++
.../examples/spi/TestConfigInitializer.java | 16 +++++
.../examples/spi/TestConfigPostProcessor.java | 16 +++++
.../src/main/resources/application.yml | 17 +++++
dubbo-api-docs/pom.xml | 82 +++++++++++++++++++++-
12 files changed, 279 insertions(+), 12 deletions(-)
diff --git a/dubbo-api-docs/codestyle/checkstyle.xml b/dubbo-api-docs/codestyle/checkstyle.xml
new file mode 100644
index 0000000..9c7581b
--- /dev/null
+++ b/dubbo-api-docs/codestyle/checkstyle.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0"?>
+<!DOCTYPE module PUBLIC
+ "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
+ "http://checkstyle.sourceforge.net/dtds/configuration_1_3.dtd">
+
+<module name="Checker">
+ <property name="charset" value="UTF-8"/>
+ <property name="fileExtensions" value="java"/>
+
+ <!-- TreeWalker Checks -->
+ <module name="TreeWalker">
+ <module name="SuppressWarningsHolder" />
+
+ <module name="AvoidStarImport"/>
+ <module name="AvoidEscapedUnicodeCharacters">
+ <property name="allowEscapesForControlCharacters" value="true"/>
+ <property name="allowByTailComment" value="true"/>
+ <property name="allowNonPrintableEscapes" value="true"/>
+ </module>
+ <module name="NoLineWrap"/>
+ <module name="OuterTypeFilename"/>
+ <module name="UnusedImports"/>
+
+ </module>
+</module>
diff --git a/dubbo-api-docs/codestyle/dubbo_codestyle_for_idea.xml b/dubbo-api-docs/codestyle/dubbo_codestyle_for_idea.xml
new file mode 100644
index 0000000..1cbbe37
--- /dev/null
+++ b/dubbo-api-docs/codestyle/dubbo_codestyle_for_idea.xml
@@ -0,0 +1,33 @@
+<!--
+ ~ 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.
+ -->
+
+<code_scheme name="dubbo_codestyle">
+ <option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99"/>
+ <option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99"/>
+ <option name="IMPORT_LAYOUT_TABLE">
+ <value>
+ <package name="org.apache.dubbo.admin" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="javax" withSubpackages="true" static="false"/>
+ <package name="java" withSubpackages="true" static="false"/>
+ <emptyLine/>
+ <package name="" withSubpackages="true" static="true"/>
+ </value>
+ </option>
+</code_scheme>
diff --git a/dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/core/DubboApiDocsAnnotationScanner.java b/dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/core/DubboApiDocsAnnotationScanner.java
index 5878d3c..f53f282 100644
--- a/dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/core/DubboApiDocsAnnotationScanner.java
+++ b/dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/core/DubboApiDocsAnnotationScanner.java
@@ -31,7 +31,9 @@ import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.dubbo.config.annotation.Service;
-import org.apache.dubbo.apidocs.annotations.*;
+import org.apache.dubbo.apidocs.annotations.ApiModule;
+import org.apache.dubbo.apidocs.annotations.ApiDoc;
+import org.apache.dubbo.apidocs.annotations.RequestParam;
import org.apache.dubbo.apidocs.utils.ClassTypeUtil;
import com.alibaba.fastjson.JSON;
@@ -54,6 +56,7 @@ import java.lang.reflect.TypeVariable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -236,7 +239,7 @@ public class DubboApiDocsAnnotationScanner implements ApplicationListener<Applic
genericTypeAndNamesMap.put(typeVariables[i].getTypeName(), actualTypeArguments[i].getTypeName());
}
} else {
- genericTypeAndNamesMap = new HashMap<>(0);
+ genericTypeAndNamesMap = Collections.EMPTY_MAP;
}
List<ParamBean> apiParamsList = new ArrayList(16);
diff --git a/dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/utils/ClassTypeUtil.java b/dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/utils/ClassTypeUtil.java
index 2efacd5..7379ff9 100644
--- a/dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/utils/ClassTypeUtil.java
+++ b/dubbo-api-docs/dubbo-api-docs-core/src/main/java/org/apache/dubbo/apidocs/utils/ClassTypeUtil.java
@@ -21,15 +21,28 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
import org.apache.commons.lang3.StringUtils;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;
-import java.lang.reflect.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.LocalDateTime;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.CompletableFuture;
-import org.apache.dubbo.apidocs.annotations.*;
+import org.apache.dubbo.apidocs.annotations.RequestParam;
+import org.apache.dubbo.apidocs.annotations.ResponseProperty;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
@@ -85,9 +98,9 @@ public class ClassTypeUtil {
/**
* Instantiate class and its fields.
*
- * @param genericType genericType
- * @param classType classType
- * @param processCount processCount
+ * @param genericType genericType
+ * @param classType classType
+ * @param processCount processCount
* @param isBuildClassAttribute isBuildClassAttribute
* @return java.lang.Object
*/
@@ -110,12 +123,12 @@ public class ClassTypeUtil {
ParameterizedTypeImpl parameterTypeImpl = (ParameterizedTypeImpl) genericType;
TypeVariable<? extends Class<?>>[] typeVariables = parameterTypeImpl.getRawType().getTypeParameters();
Type[] actualTypeArguments = parameterTypeImpl.getActualTypeArguments();
- genericTypeAndNamesMap = new HashMap<>(typeVariables.length);
+ genericTypeAndNamesMap = new HashMap<>(typeVariables.length);
for (int i = 0; i < typeVariables.length; i++) {
genericTypeAndNamesMap.put(typeVariables[i].getTypeName(), actualTypeArguments[i].getTypeName());
}
} else {
- genericTypeAndNamesMap = new HashMap<>(0);
+ genericTypeAndNamesMap = Collections.EMPTY_MAP;
}
Map<String, Object> result = new HashMap<>(16);
diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-api/src/main/java/org/apache/dubbo/apidocs/examples/params/QuickStartRequestBase.java b/dubbo-api-docs/dubbo-api-docs-examples/examples-api/src/main/java/org/apache/dubbo/apidocs/examples/params/QuickStartRequestBase.java
index 5453ca9..fd37785 100644
--- a/dubbo-api-docs/dubbo-api-docs-examples/examples-api/src/main/java/org/apache/dubbo/apidocs/examples/params/QuickStartRequestBase.java
+++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-api/src/main/java/org/apache/dubbo/apidocs/examples/params/QuickStartRequestBase.java
@@ -1,3 +1,19 @@
+/*
+ * 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.dubbo.apidocs.examples.params;
import org.apache.dubbo.apidocs.annotations.RequestParam;
diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/resources/application.yml b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/resources/application.yml
index c8209d5..54190bd 100644
--- a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/resources/application.yml
+++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/resources/application.yml
@@ -1,3 +1,20 @@
+#
+# 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.
+#
+
dubbo:
registry:
address: spring-cloud://localhost
diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/resources/bootstrap.yml b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/resources/bootstrap.yml
index d5cab0c..8220792 100644
--- a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/resources/bootstrap.yml
+++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider-sca/src/main/resources/bootstrap.yml
@@ -1,3 +1,20 @@
+#
+# 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.
+#
+
spring:
application:
name: dubbo-api-docs-example-provider-sca
diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/java/org/apache/dubbo/apidocs/examples/spi/DubboDocExporterListener.java b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/java/org/apache/dubbo/apidocs/examples/spi/DubboDocExporterListener.java
index bf37d55..a2c4e45 100644
--- a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/java/org/apache/dubbo/apidocs/examples/spi/DubboDocExporterListener.java
+++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/java/org/apache/dubbo/apidocs/examples/spi/DubboDocExporterListener.java
@@ -1,3 +1,19 @@
+/*
+ * 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.dubbo.apidocs.examples.spi;
import org.apache.dubbo.common.extension.Activate;
diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/java/org/apache/dubbo/apidocs/examples/spi/TestConfigInitializer.java b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/java/org/apache/dubbo/apidocs/examples/spi/TestConfigInitializer.java
index e4900cd..febae4a 100644
--- a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/java/org/apache/dubbo/apidocs/examples/spi/TestConfigInitializer.java
+++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/java/org/apache/dubbo/apidocs/examples/spi/TestConfigInitializer.java
@@ -1,3 +1,19 @@
+/*
+ * 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.dubbo.apidocs.examples.spi;
import org.apache.dubbo.common.extension.Activate;
diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/java/org/apache/dubbo/apidocs/examples/spi/TestConfigPostProcessor.java b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/java/org/apache/dubbo/apidocs/examples/spi/TestConfigPostProcessor.java
index d600abd..2708594 100644
--- a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/java/org/apache/dubbo/apidocs/examples/spi/TestConfigPostProcessor.java
+++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/java/org/apache/dubbo/apidocs/examples/spi/TestConfigPostProcessor.java
@@ -1,3 +1,19 @@
+/*
+ * 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.dubbo.apidocs.examples.spi;
import org.apache.dubbo.common.extension.Activate;
diff --git a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/resources/application.yml b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/resources/application.yml
index 2e8048a..47b3b05 100644
--- a/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/resources/application.yml
+++ b/dubbo-api-docs/dubbo-api-docs-examples/examples-provider/src/main/resources/application.yml
@@ -1,3 +1,20 @@
+#
+# 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.
+#
+
spring:
application:
name: dubbo-api-docs-example-provider
diff --git a/dubbo-api-docs/pom.xml b/dubbo-api-docs/pom.xml
index 28c4f00..0b97573 100644
--- a/dubbo-api-docs/pom.xml
+++ b/dubbo-api-docs/pom.xml
@@ -89,9 +89,10 @@
<project.build.jdkVersion>1.8</project.build.jdkVersion>
<argLine>-Dfile.encoding=UTF-8</argLine>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <skipJunitTest>true</skipJunitTest>
+ <skip_maven_deploy>false</skip_maven_deploy>
<maven-flatten-version>1.1.0</maven-flatten-version>
+ <maven-checkstyle-plugin-version>3.0.0</maven-checkstyle-plugin-version>
<spring-boot.version>2.3.4.RELEASE</spring-boot.version>
<dubbo.version>2.7.8</dubbo.version>
@@ -215,6 +216,84 @@
<build>
<plugins>
<plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${maven-checkstyle-plugin-version}</version>
+ <dependencies>
+ <dependency>
+ <groupId>com.puppycrawl.tools</groupId>
+ <artifactId>checkstyle</artifactId>
+ <version>8.18</version>
+ </dependency>
+ </dependencies>
+ <executions>
+ <execution>
+ <id>checkstyle-validation</id>
+ <phase>validate</phase>
+ <configuration>
+ <configLocation>codestyle/checkstyle.xml</configLocation>
+ <encoding>UTF-8</encoding>
+ <consoleOutput>true</consoleOutput>
+ <failOnViolation>true</failOnViolation>
+ </configuration>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.rat</groupId>
+ <artifactId>apache-rat-plugin</artifactId>
+ <version>0.12</version>
+ <executions>
+ <execution>
+ <id>verify.rat</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <configuration>
+ <excludes>
+ <exclude>**/.idea/</exclude>
+ <exclude>**/*.iml</exclude>
+ <exclude>**/*.txt</exclude>
+ <exclude>**/*.sh</exclude>
+ <exclude>**/*.bat</exclude>
+ <exclude>**/*.md</exclude>
+ <exclude>.git/</exclude>
+ <exclude>**/*.git*</exclude>
+ <exclude>.gitignore</exclude>
+ <exclude>**/.settings/*</exclude>
+ <exclude>**/.classpath</exclude>
+ <exclude>**/*.properties</exclude>
+ <exclude>**/.project</exclude>
+ <exclude>**/target/**</exclude>
+ <exclude>**/*.log</exclude>
+ <exclude>.codecov.yml</exclude>
+ <exclude>.travis.yml</exclude>
+ <exclude>**/codestyle/*</exclude>
+ <exclude>**/node_modules/**</exclude>
+ <exclude>**/.babelrc</exclude>
+ <exclude>**/.editorconfig</exclude>
+ <exclude>**/package-lock.json</exclude>
+ <exclude>**/package.json</exclude>
+ <exclude>**/OpenSans.css</exclude>
+ <exclude>**/.eslintignore</exclude>
+ <exclude>**/.browserslistrc</exclude>
+ <exclude>**/resources/META-INF/**</exclude>
+ <exclude>**/src/main/resources/public/**</exclude>
+ <exclude>**/src/licenses/**</exclude>
+ <exclude>.github/**</exclude>
+ <exclude>**/assets/**</exclude>
+ <exclude>**/yarn.lock</exclude>
+ <exclude>**/node/**</exclude>
+ </excludes>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>flatten-maven-plugin</artifactId>
<version>${maven-flatten-version}</version>
@@ -273,7 +352,6 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
- <skip>${skipJunitTest}</skip>
</configuration>
</plugin>
<plugin>