Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gRPC: fail code generation gracefully on default java package #17577

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import com.google.common.base.Strings;
Expand All @@ -19,6 +21,8 @@
*/
public class MutinyGrpcGenerator extends Generator {

private static final Logger log = Logger.getLogger(MutinyGrpcGenerator.class.getName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1


private static final int SERVICE_NUMBER_OF_PATHS = 2;
private static final int METHOD_NUMBER_OF_PATHS = 4;
public static final String CLASS_PREFIX = "Mutiny";
Expand All @@ -41,9 +45,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()) {
log.log(Level.SEVERE, "Using the default java package is not supported for "
+ "Quarkus 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