17
17
import java .util .List ;
18
18
import java .util .Locale ;
19
19
import java .util .Set ;
20
+ import java .util .stream .Collectors ;
20
21
import java .util .stream .Stream ;
21
22
22
23
import org .eclipse .microprofile .config .Config ;
@@ -100,11 +101,14 @@ public boolean trigger(CodeGenContext context) throws CodeGenException {
100
101
Collection <Path > protoFilesFromDependencies = gatherProtosFromDependencies (dirWithProtosFromDependencies , protoDirs ,
101
102
context );
102
103
if (!protoFilesFromDependencies .isEmpty ()) {
103
- protoFilesFromDependencies .stream ()
104
- .map (Path ::normalize )
105
- .map (Path ::toAbsolutePath )
106
- .map (Path ::toString )
107
- .forEach (protoFiles ::add );
104
+ for (Path files : protoFilesFromDependencies ) {
105
+ var pathToProtoFile = files .normalize ().toAbsolutePath ();
106
+ var pathToParentDir = files .getParent ();
107
+ // Add the proto file to the list of proto to compile, but also add the directory containing the
108
+ // proto file to the list of directories to include (it's a set, so no duplicate).
109
+ protoFiles .add (pathToProtoFile .toString ());
110
+ protoDirs .add (pathToParentDir .toString ());
111
+ }
108
112
}
109
113
110
114
if (!protoFiles .isEmpty ()) {
@@ -115,12 +119,12 @@ public boolean trigger(CodeGenContext context) throws CodeGenException {
115
119
116
120
List <String > command = new ArrayList <>();
117
121
command .add (executables .protoc .toString ());
118
- for (String protoImportDir : protosToImport ) {
119
- command .add (String .format ("-I=%s" , escapeWhitespace (protoImportDir )));
120
- }
121
122
for (String protoDir : protoDirs ) {
122
123
command .add (String .format ("-I=%s" , escapeWhitespace (protoDir )));
123
124
}
125
+ for (String protoImportDir : protosToImport ) {
126
+ command .add (String .format ("-I=%s" , escapeWhitespace (protoImportDir )));
127
+ }
124
128
125
129
command .addAll (asList ("--plugin=protoc-gen-grpc=" + executables .grpc ,
126
130
"--plugin=protoc-gen-q-grpc=" + executables .quarkusGrpc ,
@@ -203,17 +207,21 @@ private Collection<Path> gatherProtosFromDependencies(Path workDir, Set<String>
203
207
}
204
208
boolean scanAll = "all" .equalsIgnoreCase (scanDependencies );
205
209
206
- List <String > dependenciesToScan = asList (scanDependencies .split ("," ));
210
+ List <String > dependenciesToScan = Arrays .stream (scanDependencies .split ("," )).map (String ::trim )
211
+ .collect (Collectors .toList ());
207
212
208
213
ApplicationModel appModel = context .applicationModel ();
209
214
List <Path > protoFilesFromDependencies = new ArrayList <>();
210
215
for (ResolvedDependency artifact : appModel .getRuntimeDependencies ()) {
211
216
String packageId = String .format ("%s:%s" , artifact .getGroupId (), artifact .getArtifactId ());
212
217
Collection <String > includes = properties
213
- .getOptionalValues (String .format (SCAN_DEPENDENCIES_FOR_PROTO_INCLUDE_PATTERN , packageId ), String .class )
218
+ .getOptionalValue (String .format (SCAN_DEPENDENCIES_FOR_PROTO_INCLUDE_PATTERN , packageId ), String .class )
219
+ .map (s -> Arrays .stream (s .split ("," )).map (String ::trim ).collect (Collectors .toList ()))
214
220
.orElse (List .of ());
221
+
215
222
Collection <String > excludes = properties
216
- .getOptionalValues (String .format (SCAN_DEPENDENCIES_FOR_PROTO_EXCLUDE_PATTERN , packageId ), String .class )
223
+ .getOptionalValue (String .format (SCAN_DEPENDENCIES_FOR_PROTO_EXCLUDE_PATTERN , packageId ), String .class )
224
+ .map (s -> Arrays .stream (s .split ("," )).map (String ::trim ).collect (Collectors .toList ()))
217
225
.orElse (List .of ());
218
226
219
227
if (scanAll
@@ -247,7 +255,8 @@ private Collection<String> gatherDirectoriesWithImports(Path workDir, CodeGenCon
247
255
}
248
256
249
257
boolean scanAll = "all" .equals (scanForImports .toLowerCase (Locale .getDefault ()));
250
- List <String > dependenciesToScan = Arrays .asList (scanForImports .split ("," ));
258
+ List <String > dependenciesToScan = Arrays .stream (scanForImports .split ("," )).map (String ::trim )
259
+ .collect (Collectors .toList ());
251
260
252
261
Set <String > importDirectories = new HashSet <>();
253
262
ApplicationModel appModel = context .applicationModel ();
@@ -277,8 +286,15 @@ private void extractProtosFromArtifact(Path workDir, Collection<Path> protoFiles
277
286
protoDirectories .add (path .getParent ().normalize ().toAbsolutePath ().toString ());
278
287
} else { // archive
279
288
Path relativePath = path .getRoot ().relativize (path );
289
+ String uniqueName = artifact .getGroupId () + ":" + artifact .getArtifactId ();
290
+ if (artifact .getVersion () != null ) {
291
+ uniqueName += ":" + artifact .getVersion ();
292
+ }
293
+ if (artifact .getClassifier () != null ) {
294
+ uniqueName += "-" + artifact .getClassifier ();
295
+ }
280
296
Path protoUnzipDir = workDir
281
- .resolve (HashUtil .sha1 (root . normalize (). toAbsolutePath (). toString () ))
297
+ .resolve (HashUtil .sha1 (uniqueName ))
282
298
.normalize ().toAbsolutePath ();
283
299
try {
284
300
Files .createDirectories (protoUnzipDir );
0 commit comments