Skip to content

Commit bea1465

Browse files
authored
feat: maven plugin protoSourceRoot参数支持读取文件夹 (#104)
1 parent 9dca999 commit bea1465

5 files changed

Lines changed: 79 additions & 1 deletion

File tree

trpc-code-generator/src/main/java/com/tencent/trpc/codegen/TRpcCodeGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public void generateCode() throws TRpcCodeGenerateException {
122122
try {
123123
Files.createDirectories(tmpPath);
124124
List<Path> importPaths = prepareImportPaths();
125-
Path descriptorFile = generateDescriptorFile(getProtoFiles(true), importPaths);
125+
Path descriptorFile = generateDescriptorFile(getProtoFiles(false), importPaths);
126126
Files.createDirectories(tmpOutPath);
127127
List<Descriptors.FileDescriptor> fdList = compileDescriptorSet(descriptorFile);
128128
Map<String, Object> customVariables = codeGeneratorHook.getCustomVariables(fdList);

trpc-maven-plugin/src/test/java/com/tencent/trpc/maven/plugin/TRpcMavenPluginTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@ public void test4() throws Exception {
107107
assertTrue(Files.exists(base.resolve("pom.xml")));
108108
}
109109

110+
/**
111+
* Simulate 'mvn trpc:gen-code' on maven project at src/test/resources/TEST-5.
112+
*/
113+
public void test5() throws Exception {
114+
executeTest("TEST-5");
115+
Path base = Paths.get("src", "test", "resources", "TEST-5", "target", "generated-sources",
116+
"trpc", "java").toAbsolutePath();
117+
Path output = base.resolve(Paths.get("com", "tencent", "test", "helloworld"));
118+
assertTrue(Files.exists(output));
119+
assertTrue(Files.exists(output.resolve("module1/GreeterAPI.java")));
120+
assertTrue(Files.exists(output.resolve("module1/GreeterAsyncAPI.java")));
121+
assertTrue(Files.exists(output.resolve("module1/GreeterSvr.java")));
122+
assertTrue(Files.exists(output.resolve("module1/GreeterSvrValidator.java")));
123+
assertTrue(Files.exists(output.resolve("module2/GreeterAPI.java")));
124+
assertTrue(Files.exists(output.resolve("module2/GreeterAsyncAPI.java")));
125+
assertTrue(Files.exists(output.resolve("module2/GreeterSvr.java")));
126+
assertTrue(Files.exists(output.resolve("module2/GreeterSvrValidator.java")));
127+
assertTrue(Files.exists(base.resolve("pom.xml")));
128+
}
129+
110130
private void executeTest(String root) throws Exception {
111131
MavenProject project = readMavenProject(new File("src/test/resources/" + root));
112132
MavenSession session = newMavenSession(project);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>trpc-maven-plugin-test</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>8</maven.compiler.source>
13+
<maven.compiler.target>8</maven.compiler.target>
14+
</properties>
15+
16+
<build>
17+
<plugins>
18+
<plugin>
19+
<groupId>com.tencent.trpc</groupId>
20+
<artifactId>trpc-maven-plugin</artifactId>
21+
<configuration>
22+
</configuration>
23+
</plugin>
24+
</plugins>
25+
</build>
26+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
syntax = "proto3";
2+
package trpc.test.helloworld.module1;
3+
import "validate.proto";
4+
option java_package = "com.tencent.test.helloworld.module1";
5+
option java_outer_classname = "GreeterSvr";
6+
// 请求协议头
7+
message HelloRequest {
8+
string message = 1 [(validate.rules).string.min_len = 2];
9+
}
10+
// 响应协议头
11+
message HelloResponse {
12+
string message = 1;
13+
}
14+
service Greeter {
15+
rpc sayHello (HelloRequest) returns (HelloResponse);
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
syntax = "proto3";
2+
package trpc.test.helloworld.module2;
3+
import "validate.proto";
4+
option java_package = "com.tencent.test.helloworld.module2";
5+
option java_outer_classname = "GreeterSvr";
6+
// 请求协议头
7+
message HelloRequest {
8+
string message = 1 [(validate.rules).string.min_len = 2];
9+
}
10+
// 响应协议头
11+
message HelloResponse {
12+
string message = 1;
13+
}
14+
service Greeter {
15+
rpc sayHello (HelloRequest) returns (HelloResponse);
16+
}

0 commit comments

Comments
 (0)