测试基本proto生成

This commit is contained in:
tiger_zhou 2023-05-24 15:53:50 +08:00
parent c9c4396fe9
commit c8f71d1d25
6 changed files with 202 additions and 95 deletions

178
pom.xml
View File

@ -1,44 +1,45 @@
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>club.joylink</groupId>
<artifactId>xian-ncc-da</artifactId>
<version>0.1</version>
<name>xian-ncc-da</name>
<description>xian 城市轨道交通ncc决策辅助系统</description>
<properties>
<java.version>17</java.version>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>club.joylink</groupId>
<artifactId>xian-ncc-da</artifactId>
<version>0.1</version>
<name>xian-ncc-da</name>
<description>xian 城市轨道交通ncc决策辅助系统</description>
<properties>
<java.version>17</java.version>
<spring-boot.version>3.1.0</spring-boot.version>
<mybatis-plus-version>3.5.3.1</mybatis-plus-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
@ -77,55 +78,60 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.23.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,6 @@
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.3.233:3306/xian-ncc-da?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root
password: joylink0503

View File

@ -2,20 +2,22 @@ server:
port: 9071
spring:
profiles:
default: dev
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://192.168.3.233:3306/xian-ncc-da?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root
password: joylink0503
hikari:
minimum-idle: 5 # ?????????????
maximum-pool-size: 10 # ?????????
auto-commit: true # ??????????????????
idle-timeout: 30000 # ???????????????????ms
minimum-idle: 5 # 连接池维护的最小空闲连接数
maximum-pool-size: 10 #配置最大连接池大小
auto-commit: true #配置从池返回的连接的默认自动提交行为
idle-timeout: 30000 # 允许连接在连接池中空闲的最长时间,单位ms
pool-name: HikariPool
max-lifetime: 1800000 # ?????????????????ms
connection-timeout: 30000 # ????????????ms
connection-test-query: select 1 # ???????
max-lifetime: 1800000 # 池中连接关闭后的最长生命周期,单位ms
connection-timeout: 30000 # 等待连接的超时时间,单位ms
connection-test-query: select 1
security:
oauth2:
resource-server:

View File

@ -0,0 +1,93 @@
package club.joylink.xiannccda;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import org.assertj.core.util.Lists;
public class GenertateProtoBufUtil {
private final static String EXE_BIN_FILE = String.join(File.separator,
System.getProperty("user.dir"), "xian-ncc-da-message",
"protoc-23.1-win64", "bin",
"protoc");
private File protoFilePath;
private String outPath;
private boolean pullMessage;
// private String gitPullPath;
public GenertateProtoBufUtil(String rootPath, boolean pullMessage) {
this.pullMessage = pullMessage;
String sourcePath = String.join(File.separator, rootPath,
"xian-ncc-da-message", "protos");
this.outPath = String.join(File.separator, rootPath,
"src", "main", "java");
this.protoFilePath = new File(sourcePath);
if (!protoFilePath.exists() || !protoFilePath.isDirectory()) {
throw new RuntimeException("proto不是目录或目录不存在");
}
}
public List<File> findFiles() {
return this.findFiles(this.protoFilePath);
}
public void execCommand() throws IOException {
if (this.pullMessage) {
this.PullTmmsMessage();
}
for (File file : this.findFiles()) {
String command = String.format("%s --proto_path=%s -I=%s --java_out=%s %s", EXE_BIN_FILE,
this.protoFilePath.getPath(), file.getParentFile().getAbsolutePath(), this.outPath,
file.getName());
this.genertateFile(command);
}
}
private void genertateFile(String command) throws IOException {
System.out.println(String.format("执行指令: %s", command));
InputStream errorStream = Runtime.getRuntime().exec(command).getErrorStream();
byte[] ebs = new byte[512];
StringBuilder sb = new StringBuilder();
int size;
while ((size = errorStream.read(ebs)) > 0) {
String err = new String(Arrays.copyOf(ebs, size), Charset.forName("UTF-8"));
sb.append(err);
}
System.out.println(sb);
}
private List<File> findFiles(File file) {
List<File> findFiles = Lists.newArrayList();
for (File files : file.listFiles()) {
if (files.isDirectory()) {
findFiles.addAll(this.findFiles(files));
} else if (files.getName().endsWith(".proto")) {
findFiles.add(files);
}
}
return findFiles;
}
private void PullTmmsMessage() throws IOException {
InputStream inputStream = Runtime.getRuntime()
.exec("git pull", null, protoFilePath).getInputStream();
byte[] ebs = new byte[512];
StringBuilder sb = new StringBuilder();
int size;
while ((size = inputStream.read(ebs)) > 0) {
String err = new String(Arrays.copyOf(ebs, size), Charset.forName("UTF-8"));
sb.append(err);
}
System.out.println(sb);
}
public static void main(String[] args) throws IOException {
GenertateProtoBufUtil gu = new GenertateProtoBufUtil(System.getProperty("user.dir"), true);
gu.execCommand();
}
}

View File

@ -45,7 +45,7 @@ public class MybatisPlusGenerator {
.strategyConfig(builder -> {
builder.addExclude(ExcludeTableList);
// entity
builder.entityBuilder()
builder.entityBuilder().enableLombok()
.disableSerialVersionUID()
.enableFileOverride() // 覆盖旧文件
.enableColumnConstant() // 开启生成字段常量

@ -1 +1 @@
Subproject commit 9aa54608cd592ff96fc506e310fb19caff67f809
Subproject commit 51743f0de38e3abf76bc2f6456000a25acbff33e