Search in sources :

Example 1 with CodeGeneratorRequest

use of com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest in project toolkit by googleapis.

the class ProtocGeneratorMain method main.

public static void main(String[] args) {
    CodeGeneratorResponse response;
    CodeGeneratorRequest request;
    int exitCode = 0;
    try {
        request = PluginProtos.CodeGeneratorRequest.parseFrom(System.in);
    } catch (IOException e) {
        response = PluginProtos.CodeGeneratorResponse.newBuilder().setError(e.toString()).build();
        try {
            response.writeTo(System.out);
        } catch (IOException e2) {
            System.err.println("Unable to parse CodeGeneraterRequest from stdin.");
            e2.printStackTrace(System.err);
        }
        System.exit(1);
        return;
    }
    try {
        response = generate(request);
    } catch (Exception e) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw);
        pw.flush();
        response = PluginProtos.CodeGeneratorResponse.newBuilder().setError(sw.toString()).build();
        exitCode = 1;
    }
    try {
        response.writeTo(System.out);
    } catch (IOException e) {
        System.err.println("Failed to write out CodeGeneratorResponse.");
        e.printStackTrace(System.err);
        System.exit(1);
    }
    System.out.flush();
    System.exit(exitCode);
}
Also used : StringWriter(java.io.StringWriter) CodeGeneratorResponse(com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse) IOException(java.io.IOException) CodeGeneratorRequest(com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 2 with CodeGeneratorRequest

use of com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest in project toolkit by googleapis.

the class ProtocGapicPluginGeneratorTest method testFailingGenerator.

@Test
public void testFailingGenerator() {
    CodeGeneratorRequest codeGeneratorRequest = CodeGeneratorRequest.newBuilder().addAllProtoFile(model.getFiles().stream().map(ProtoFile::getProto).collect(Collectors.toList())).addFileToGenerate("fuuuuudge.proto").setParameter("transport=rest").build();
    CodeGeneratorResponse response = ProtocGeneratorMain.generate(codeGeneratorRequest);
    Truth.assertThat(response).isNotNull();
    Truth.assertThat(response.getError()).isNotEmpty();
}
Also used : CodeGeneratorResponse(com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse) CodeGeneratorRequest(com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest) GapicCodeGeneratorAnnotationsTest(com.google.api.codegen.protoannotations.GapicCodeGeneratorAnnotationsTest) Test(org.junit.Test)

Example 3 with CodeGeneratorRequest

use of com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest in project toolkit by googleapis.

the class ProtocGapicPluginGeneratorTest method testGenerator.

@Test
public void testGenerator() {
    CodeGeneratorRequest codeGeneratorRequest = CodeGeneratorRequest.newBuilder().addAllProtoFile(model.getFiles().stream().map(ProtoFile::getProto).collect(Collectors.toList())).addFileToGenerate("multiple_services.proto").setParameter("language=java,transport=grpc").build();
    CodeGeneratorResponse response = ProtocGeneratorMain.generate(codeGeneratorRequest);
    // TODO(andrealin): Look into setting these up as baseline files.
    Truth.assertThat(response).isNotNull();
    Truth.assertThat(response.getError()).isEmpty();
    Truth.assertThat(response.getFileCount()).isEqualTo(15);
    Truth.assertThat(response.getFile(0).getContent()).contains("DecrementerServiceClient");
}
Also used : CodeGeneratorResponse(com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse) CodeGeneratorRequest(com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest) GapicCodeGeneratorAnnotationsTest(com.google.api.codegen.protoannotations.GapicCodeGeneratorAnnotationsTest) Test(org.junit.Test)

Aggregations

CodeGeneratorRequest (com.google.protobuf.compiler.PluginProtos.CodeGeneratorRequest)3 CodeGeneratorResponse (com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse)3 GapicCodeGeneratorAnnotationsTest (com.google.api.codegen.protoannotations.GapicCodeGeneratorAnnotationsTest)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1