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);
}
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();
}
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");
}
Aggregations