Search in sources :

Example 1 with ProtocGapicWriter

use of com.google.api.codegen.gapic.ProtocGapicWriter in project toolkit by googleapis.

the class ProtocGeneratorMain method generate.

@VisibleForTesting
public static // CodeGeneratorResponse.
CodeGeneratorResponse generate(CodeGeneratorRequest request) {
    try {
        ToolOptions toolOptions = parseOptions(request);
        ProtocGapicWriter gapicWriter = new ProtocGapicWriter();
        GapicGeneratorApp codeGen = new GapicGeneratorApp(toolOptions, DEFAULT_ARTIFACT_TYPE, gapicWriter);
        codeGen.run();
        CodeGeneratorResponse response = gapicWriter.getCodegenResponse();
        if (response == null) {
            throw new RuntimeException(collectDiags(codeGen));
        }
        return response;
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        pw.flush();
        return PluginProtos.CodeGeneratorResponse.newBuilder().setError(sw.toString()).build();
    }
}
Also used : StringWriter(java.io.StringWriter) GapicGeneratorApp(com.google.api.codegen.gapic.GapicGeneratorApp) CodeGeneratorResponse(com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse) ToolOptions(com.google.api.tools.framework.tools.ToolOptions) ProtocGapicWriter(com.google.api.codegen.gapic.ProtocGapicWriter) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

GapicGeneratorApp (com.google.api.codegen.gapic.GapicGeneratorApp)1 ProtocGapicWriter (com.google.api.codegen.gapic.ProtocGapicWriter)1 ToolOptions (com.google.api.tools.framework.tools.ToolOptions)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CodeGeneratorResponse (com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse)1 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1