Skip to content

Commit

Permalink
gRPC: fail code generation gracefully on default java package
Browse files Browse the repository at this point in the history
  • Loading branch information
michalszynkiewicz committed Jun 1, 2021
1 parent cb66731 commit eb7d130
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,25 @@ public List<PluginProtos.CodeGeneratorResponse.File> generateFiles(PluginProtos.
.collect(Collectors.toList());

List<ServiceContext> services = findServices(protosToGenerate, typeMap);
validateServices(services);
return generateFiles(services);
}

private void validateServices(List<ServiceContext> services) {
boolean failed = false;
for (ServiceContext service : services) {
if (service.packageName == null || service.packageName.isBlank()) {
System.err.println("Using the default java package is not supported for "
+ "gRPC code generation. Please specify `option java_package = \"your.package\"` in "
+ service.protoName);
failed = true;
}
}
if (failed) {
throw new IllegalArgumentException("Code generation failed. Please check the log above for details.");
}
}

private List<ServiceContext> findServices(List<DescriptorProtos.FileDescriptorProto> protos, ProtoTypeMap typeMap) {
List<ServiceContext> contexts = new ArrayList<>();

Expand Down

0 comments on commit eb7d130

Please sign in to comment.