• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.api.generator.gapic.Generator;
19 import com.google.protobuf.ExtensionRegistry;
20 import com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest;
21 import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse;
22 import java.io.FileInputStream;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.OutputStream;
27 
28 // A generator entry point class, similar to Main but reads the CodeGeneratorRequest directly from a
29 // file instead of relying on protoc to pipe it in.
30 public class CodeGeneratorRequestFileToGapicMain {
main(String[] args)31   public static void main(String[] args) throws IOException {
32     ExtensionRegistry registry = ExtensionRegistry.newInstance();
33     ProtoRegistry.registerAllExtensions(registry);
34 
35     String inputFile = args[0];
36     String outputFile = args[1];
37 
38     try (InputStream inputStream = new FileInputStream(inputFile);
39         OutputStream outputStream = new FileOutputStream(outputFile)) {
40       CodeGeneratorRequest request = CodeGeneratorRequest.parseFrom(inputStream, registry);
41       CodeGeneratorResponse response = Generator.generateGapic(request);
42       response.writeTo(outputStream);
43     }
44   }
45 }
46