测试基本proto生成
This commit is contained in:
parent
c9c4396fe9
commit
c8f71d1d25
8
pom.xml
8
pom.xml
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
@ -108,6 +109,11 @@
|
|||||||
<artifactId>spring-security-test</artifactId>
|
<artifactId>spring-security-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.protobuf</groupId>
|
||||||
|
<artifactId>protobuf-java</artifactId>
|
||||||
|
<version>3.23.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
6
src/main/resources/application-dev.yml
Normal file
6
src/main/resources/application-dev.yml
Normal 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
|
@ -2,20 +2,22 @@ server:
|
|||||||
port: 9071
|
port: 9071
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
|
profiles:
|
||||||
|
default: dev
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
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
|
url: jdbc:mysql://192.168.3.233:3306/xian-ncc-da?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||||
username: root
|
username: root
|
||||||
password: joylink0503
|
password: joylink0503
|
||||||
hikari:
|
hikari:
|
||||||
minimum-idle: 5 # ?????????????
|
minimum-idle: 5 # 连接池维护的最小空闲连接数
|
||||||
maximum-pool-size: 10 # ?????????
|
maximum-pool-size: 10 #配置最大连接池大小
|
||||||
auto-commit: true # ??????????????????
|
auto-commit: true #配置从池返回的连接的默认自动提交行为
|
||||||
idle-timeout: 30000 # ???????????????????ms
|
idle-timeout: 30000 # 允许连接在连接池中空闲的最长时间,单位ms
|
||||||
pool-name: HikariPool
|
pool-name: HikariPool
|
||||||
max-lifetime: 1800000 # ?????????????????ms
|
max-lifetime: 1800000 # 池中连接关闭后的最长生命周期,单位ms
|
||||||
connection-timeout: 30000 # ????????????ms
|
connection-timeout: 30000 # 等待连接的超时时间,单位ms
|
||||||
connection-test-query: select 1 # ???????
|
connection-test-query: select 1
|
||||||
security:
|
security:
|
||||||
oauth2:
|
oauth2:
|
||||||
resource-server:
|
resource-server:
|
||||||
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
@ -45,7 +45,7 @@ public class MybatisPlusGenerator {
|
|||||||
.strategyConfig(builder -> {
|
.strategyConfig(builder -> {
|
||||||
builder.addExclude(ExcludeTableList);
|
builder.addExclude(ExcludeTableList);
|
||||||
// entity
|
// entity
|
||||||
builder.entityBuilder()
|
builder.entityBuilder().enableLombok()
|
||||||
.disableSerialVersionUID()
|
.disableSerialVersionUID()
|
||||||
.enableFileOverride() // 覆盖旧文件
|
.enableFileOverride() // 覆盖旧文件
|
||||||
.enableColumnConstant() // 开启生成字段常量
|
.enableColumnConstant() // 开启生成字段常量
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 9aa54608cd592ff96fc506e310fb19caff67f809
|
Subproject commit 51743f0de38e3abf76bc2f6456000a25acbff33e
|
Loading…
Reference in New Issue
Block a user