1 // Copyright 2021 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package com.google.api.generator.debug; 16 17 import com.google.api.generator.ProtoRegistry; 18 import com.google.protobuf.ExtensionRegistry; 19 import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest; 20 import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse; 21 import java.io.IOException; 22 23 // Request dumper class, which dumps the CodeGeneratorRequest to a file on disk which will be 24 // identical to the one passed to the Main class during normal execution. The dumped file then can 25 // be used to run this gapic-generator directly (instead of relying on protoc to start the process), 26 // which would give much greater flexibility in terms of debugging features, like attaching a 27 // debugger, easier work with stdout and stderr etc. 28 public class CodeGeneratorRequestDumper { main(String[] args)29 public static void main(String[] args) throws IOException { 30 ExtensionRegistry registry = ExtensionRegistry.newInstance(); 31 ProtoRegistry.registerAllExtensions(registry); 32 CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(System.in, registry); 33 34 CodeGeneratorResponse.Builder response = CodeGeneratorResponse.newBuilder(); 35 response 36 .setSupportedFeatures(CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL_VALUE) 37 .addFileBuilder() 38 .setName("desc-dump.bin") 39 .setContentBytes(request.toByteString()); 40 response.build().writeTo(System.out); 41 } 42 } 43