github.com/stackb/rules_proto@v0.0.0-20240221195024-5428336c51f1/pkg/plugin/grpc/grpcjava/protoc-gen-grpc-java.go (about) 1 package java 2 3 import ( 4 "path" 5 6 "github.com/bazelbuild/bazel-gazelle/label" 7 "github.com/stackb/rules_proto/pkg/protoc" 8 ) 9 10 func init() { 11 protoc.Plugins().MustRegisterPlugin(&ProtocGenGrpcJavaPlugin{}) 12 } 13 14 // ProtocGenGrpcJavaPlugin implements Plugin for the grpc java plugin. 15 type ProtocGenGrpcJavaPlugin struct{} 16 17 // Name implements part of the Plugin interface. 18 func (p *ProtocGenGrpcJavaPlugin) Name() string { 19 return "grpc:grpc-java:protoc-gen-grpc-java" 20 } 21 22 // Configure implements part of the Plugin interface. 23 func (p *ProtocGenGrpcJavaPlugin) Configure(ctx *protoc.PluginContext) *protoc.PluginConfiguration { 24 if !p.shouldApply(ctx.ProtoLibrary) { 25 return nil 26 } 27 srcjar := path.Join(ctx.Rel, ctx.ProtoLibrary.BaseName()+"_grpc.srcjar") 28 return &protoc.PluginConfiguration{ 29 Label: label.New("build_stack_rules_proto", "plugin/grpc/grpc-java", "protoc-gen-grpc-java"), 30 Outputs: []string{srcjar}, 31 Out: srcjar, 32 Options: ctx.PluginConfig.GetOptions(), 33 } 34 } 35 36 func (p *ProtocGenGrpcJavaPlugin) shouldApply(lib protoc.ProtoLibrary) bool { 37 for _, f := range lib.Files() { 38 if f.HasServices() { 39 return true 40 } 41 } 42 return false 43 }