Commit 43008b08 by zhaojing

Initial commit

parents
*.iml
*.ipr
*.iws
*.log
.DS_Store
.history
logs/
.idea/
target/
node_modules/
# qpm-dependencies
> Maven 统一依赖管理
## 功能特性
- 统一管理 jar 版本
- 简化项目中的 pom.xml
- 默认引入常用 jar、plugins 及配置公共配置
## 如何使用
在你的 `pom.xml` 中加入如下代码:
```xml
<parent>
<groupId>com.qipeng</groupId>
<artifactId>qpm-parent</artifactId>
<version>${version}</version>
</parent>
```
[点击查看最新版本](http://nexus.taovip.com/nexus)
### Example
```xml
<?xml version="1.0" encoding="UTF-8"?>
<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>com.qipeng</groupId>
<artifactId>qpm-parent</artifactId>
<version>${version}</version>
</parent>
<artifactId>finance-mall</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<modules>
<module>finance-mall-impl</module>
<module>finance-mall-domain</module>
<module>finance-mall-rest</module>
</modules>
</project>
```
## Maintainers
- 架构组
<?xml version="1.0" encoding="UTF-8"?>
<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>
<groupId>com.qipeng</groupId>
<artifactId>checkstyle</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Credit Checkstyle Checker</name>
<description>Credit Checkstyle Checker</description>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.3</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.8.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.7.0</version>
<scope>test</scope>
</dependency>
<!-- Generally Useful Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.9.RELEASE</version>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.1</version>
</dependency>
<dependency>
<groupId>com.github.sevntu-checkstyle</groupId>
<artifactId>sevntu-checkstyle-maven-plugin</artifactId>
<version>1.24.2</version>
</dependency>
<dependency>
<groupId>com.qipeng</groupId>
<artifactId>checkstyle</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<configuration>
<configLocation>credit_checks.xml</configLocation>
<suppressionsLocation>credit_suppressions.xml</suppressionsLocation>
</configuration>
<executions>
<execution>
<id>checkstyle-validation</id>
<phase>validate</phase>
<configuration>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failOnViolation>true</failOnViolation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
-->
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>snapshots</id>
<url>http://nexus.taovip.com/nexus/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>releases</id>
<url>http://nexus.taovip.com/nexus/content/repositories/releases</url>
</repository>
</distributionManagement>
</project>
package com.qipeng.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
/**
* Logger 对象定义的检查类。
*
* @author tieguanyin
*/
@SuppressWarnings("all")
public class LoggerNameCheck extends AbstractCheck {
@Override
public int[] getDefaultTokens() {
return getAcceptableTokens();
}
@Override
public int[] getAcceptableTokens() {
return new int[]{TokenTypes.VARIABLE_DEF};
}
@Override
public int[] getRequiredTokens() {
return getAcceptableTokens();
}
@Override
public void visitToken(DetailAST ast) {
DetailAST type = ast.findFirstToken(TokenTypes.TYPE).getFirstChild();
if ("Logger".equals(type.getText())) {
final DetailAST modifiersAst = ast.findFirstToken(TokenTypes.MODIFIERS);
final boolean isFinal = modifiersAst.branchContains(TokenTypes.FINAL);
final boolean isStatic = modifiersAst.branchContains(TokenTypes.LITERAL_STATIC);
if (!isFinal || !isStatic) {
log(type.getLineNo(), type.getColumnNo(), "Logger 必须以 static final 修饰");
}
DetailAST variableName = ast.findFirstToken(TokenTypes.IDENT);
if (!"logger".equals(variableName.getText())) {
log(type.getLineNo(), type.getColumnNo(), "Logger 必须以 logger 命名");
}
}
}
}
package com.qipeng.checkstyle.checks;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import com.puppycrawl.tools.checkstyle.utils.CommonUtils;
/**
* 单行注释内容空格检查类。
*
* @author tieguanyin
*/
@SuppressWarnings("all")
public class SpacedCommentCheck extends AbstractCheck {
@Override
public int[] getDefaultTokens() {
return getAcceptableTokens();
}
@Override
public int[] getAcceptableTokens() {
return new int[]{TokenTypes.SINGLE_LINE_COMMENT};
}
@Override
public int[] getRequiredTokens() {
return CommonUtils.EMPTY_INT_ARRAY;
}
@Override
public boolean isCommentNodesRequired() {
return true;
}
@Override
public void visitToken(DetailAST ast) {
String comment = getCommentFirstLine(ast);
if (!isBlank(comment) && !comment.startsWith(" ")) {
log(ast.getLineNo(), "注释符 ''//'' 和注释内容之间应该保持一个空格。");
}
}
private static String getCommentFirstLine(DetailAST ast) {
String commentContent = "";
DetailAST firstChild = ast.getFirstChild();
if (firstChild != null && firstChild.getType() == TokenTypes.COMMENT_CONTENT) {
commentContent = firstChild.getText();
}
return commentContent;
}
private static boolean isBlank(CharSequence cs) {
int strLen = cs == null ? 0 : cs.length();
if (strLen == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
}
}
package com.qipeng.checkstyle.checks;
import antlr.CommonAST;
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
import com.puppycrawl.tools.checkstyle.api.DetailAST;
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Spring MVC 注解检查类。
*
* @author tieguanyin
*/
@SuppressWarnings("all")
public class SpringMvcAnnotationCheck extends AbstractCheck {
private static final Map<String, String> REQUEST_MAPPINGS = new HashMap<>();
static {
REQUEST_MAPPINGS.put("ALL", "RequestMapping");
REQUEST_MAPPINGS.put("GET", "GetMapping");
REQUEST_MAPPINGS.put("POST", "PostMapping");
REQUEST_MAPPINGS.put("PUT", "PutMapping");
REQUEST_MAPPINGS.put("PATCH", "PatchMapping");
REQUEST_MAPPINGS.put("DELETE", "DeleteMapping");
}
@Override
public int[] getDefaultTokens() {
return getAcceptableTokens();
}
@Override
public int[] getAcceptableTokens() {
return new int[]{TokenTypes.ANNOTATION};
}
@Override
public int[] getRequiredTokens() {
return getAcceptableTokens();
}
@Override
public void visitToken(DetailAST ast) {
DetailAST annotation = ast.findFirstToken(TokenTypes.IDENT);
// 检查方法上的 @ResponseBody
if ("RestController".equals(annotation.getText())) {
DetailAST classAst = ast.getParent().getParent();
processResponseBodyAnnotation(classAst);
return;
}
// 检查方法上的 @XxxMapping
if (REQUEST_MAPPINGS.values().contains(annotation.getText())) {
List<DetailAST> pairs = findAllAnnotationMemberValuePair(ast);
if (pairs.size() == 1) {
DetailAST pair = pairs.get(0);
String paramName = pair.findFirstToken(TokenTypes.IDENT).getText();
if ("value".equals(paramName) || "path".equals(paramName)) {
log(pair.getLineNo(), pair.getColumnNo(), "@{0} 的参数名 value/path 可以省略",
annotation.getText());
}
return;
}
DetailAST methodAst = ast.getParent().getParent();
if (methodAst.getType() == TokenTypes.METHOD_DEF) {
DetailAST methodReturnType = methodAst.findFirstToken(TokenTypes.TYPE)
.findFirstToken(TokenTypes.IDENT);
if (methodReturnType != null && "Object".equals(methodReturnType.getText())) {
log(methodReturnType.getLineNo(), methodReturnType.getColumnNo(),
"Controller 方法的返回值应该使用确定类型,使用 Object 容易引入 bug");
}
}
if ("RequestMapping".equals(annotation.getText())) {
String method = pairs.stream()
.filter(a -> "method".equals(a.findFirstToken(TokenTypes.IDENT).getText()))
.findFirst()
.map(a -> a.findFirstToken(TokenTypes.EXPR).getFirstChild())
.map(a -> a.getChildCount() > 1
? a.findFirstToken(TokenTypes.IDENT).getNextSibling() : a)
.map(CommonAST::getText)
.orElse(null);
if (REQUEST_MAPPINGS.containsKey(method)) {
log(ast.getLineNo(), ast.getColumnNo(), "请将 @{0} 替换为更简洁的 @{1}",
annotation.getText(), REQUEST_MAPPINGS.get(method));
}
}
}
}
private void processResponseBodyAnnotation(DetailAST ast) {
if (!ast.branchContains(TokenTypes.ANNOTATION)) {
return;
}
DetailAST childAst = ast.getFirstChild();
while (childAst != null) {
if (childAst.getType() == TokenTypes.ANNOTATION
&& "ResponseBody".equals(childAst.findFirstToken(TokenTypes.IDENT).getText())) {
log(childAst.getLineNo(), childAst.getColumnNo(),
"RestController 方法的 @ResponseBody 可以省略");
} else {
processResponseBodyAnnotation(childAst);
}
childAst = childAst.getNextSibling();
}
}
private static List<DetailAST> findAllAnnotationMemberValuePair(DetailAST ast) {
List<DetailAST> asts = new ArrayList<>();
DetailAST child = ast.getFirstChild();
while (child != null) {
if (child.getType() == TokenTypes.ANNOTATION_MEMBER_VALUE_PAIR) {
asts.add(child);
}
child = child.getNextSibling();
}
return asts;
}
}
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<suppress files=".*(Application|Benchmark|Test)\.java" id="SystemOut"/>
<suppress files=".*(Application|Benchmark|Test)\.java" checks="HideUtilityClassConstructor"/>
<suppress files="com[\\/].*[\\/]jooq[\\/].*\.java" checks=".*"/>
</suppressions>
package com.qipeng.checkstyle.demo;
import java.util.Collections;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Checkstyle Demo 类。
*
* @author tieguanyin
*/
@SuppressWarnings("all")
public class CheckDemo {
private static final Logger logger = LoggerFactory.getLogger(CheckDemo.class);
// a
public String sayHello(String name) { // b
//
// c
//
String newName = name;
if (name == null) {
String defaultName = "world";
newName = defaultName;
}
int a = 1;
int b = a * 2;
if (a != b) {
// test
return "Hello " + newName + "!"; // d
}
return "Hello " + newName + "!"; // d
}
public String[] newArray() {
return new String[0];
}
public List<String> newList() {
return Collections.emptyList();
}
enum DemoType {
FOO, BAR
}
enum DemoType2 {
FOO_TYPE, BAR_TYPE
}
enum DemoType3 {
Foo, Bar
}
}
package com.qipeng.checkstyle.demo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 测试 Checkstyle 的控制器。
*
* @author tieguanyin
*/
@RestController
// @Controller
// @ResponseBody
@RequestMapping("/foo")
@SuppressWarnings("all")
public class DemoController {
private static final Logger logger = LoggerFactory.getLogger(DemoController.class);
@RequestMapping("/bar")
// @ResponseBody
public String get() {
return null;
}
@PostMapping("/bar")
public String post() {
return null;
}
@PutMapping("/bar")
// @ResponseBody
public String put() {
return null;
}
@PatchMapping("/bar")
public String patch() {
return null;
}
@DeleteMapping("/bar")
// @ResponseBody
public void delete() {
}
}
#!/usr/bin/env bash
WORK_DIR=$(cd $(dirname $0);pwd)
set -e
export JAVA_HOME=~/.jenv/candidates/java/1.8.0_77/
alias mvn3=/home/admin/.jenv/candidates/maven/3.3.3/bin/mvn
shopt -s expand_aliases
if [ -f ${WORK_DIR}/sub_proj.txt ];then
while read sub_name
do
cd ${WORK_DIR}/${sub_name}
mvn3 deploy -Dmaven.test.skip=true -e
done < ${WORK_DIR}/sub_proj.txt
else
mvn3 deploy -Dmaven.test.skip=true -e
fi
\ No newline at end of file
#!/bin/bash
set -e
export JAVA_HOME=~/.jenv/candidates/java/1.8.0_77/
alias mvn3=/home/admin/.jenv/candidates/maven/3.3.3/bin/mvn
shopt -s expand_aliases
mvn3 clean package install -Dmaven.test.skip=true
\ No newline at end of file
This diff is collapsed. Click to expand it.
<?xml version="1.0" encoding="UTF-8"?>
<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.yixi</groupId>
<artifactId>yixi-dependencies</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<artifactId>yixi-parent</artifactId>
<packaging>pom</packaging>
<name>Base Project Parent</name>
<description>Base Project Parent</description>
<dependencies>
<!-- Generally Useful Test Dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-core.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>credit_checks.xml</configLocation>
<suppressionsLocation>credit_suppressions.xml</suppressionsLocation>
</configuration>
<executions>
<execution>
<id>checkstyle-validation</id>
<phase>validate</phase>
<configuration>
<skip>${disable.checks}</skip>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failOnViolation>true</failOnViolation>
<propertyExpansion>main.basedir=${main.basedir}</propertyExpansion>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-rules</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.8,)</version>
</requireJavaVersion>
<requireMavenVersion>
<version>[3.2.5,)</version>
</requireMavenVersion>
<requireProperty>
<property>main.basedir</property>
</requireProperty>
<requireProperty>
<property>project.name</property>
</requireProperty>
<requireProperty>
<property>project.description</property>
</requireProperty>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment