use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.
the class Writer method write.
public static CodeGeneratorResponse write(GapicContext context, List<GapicClass> clazzes, GapicPackageInfo gapicPackageInfo, String outputFilePath) {
ByteString.Output output = ByteString.newOutput();
JavaWriterVisitor codeWriter = new JavaWriterVisitor();
JarOutputStream jos;
try {
jos = new JarOutputStream(output);
} catch (IOException e) {
throw new GapicWriterException(e.getMessage(), e);
}
for (GapicClass gapicClazz : clazzes) {
String classPath = writeClazz(gapicClazz, codeWriter, jos);
writeSamples(gapicClazz, getSamplePackage(gapicClazz), classPath, jos);
}
writeMetadataFile(context, writePackageInfo(gapicPackageInfo, codeWriter, jos), jos);
try {
jos.finish();
jos.flush();
} catch (IOException e) {
throw new GapicWriterException(e.getMessage(), e);
}
CodeGeneratorResponse.Builder response = CodeGeneratorResponse.newBuilder();
response.setSupportedFeatures(CodeGeneratorResponse.Feature.FEATURE_PROTO3_OPTIONAL_VALUE).addFileBuilder().setName(outputFilePath).setContentBytes(output.toByteString());
return response.build();
}
use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.
the class ServiceSettingsClassComposerTest method generateServiceClasses.
@Test
public void generateServiceClasses() {
GapicContext context = RestTestProtoLoader.instance().parseCompliance();
Service echoProtoService = context.services().get(0);
GapicClass clazz = ServiceSettingsClassComposer.instance().generate(context, echoProtoService);
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "ComplianceSettings.golden", visitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "ComplianceSettings.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.
the class ServiceClientTestClassComposerTest method generateServiceClasses.
@Test
public void generateServiceClasses() {
GapicContext context = GrpcRestTestProtoLoader.instance().parseShowcaseEcho();
Service echoProtoService = context.services().get(0);
GapicClass clazz = ServiceClientTestClassComposer.instance().generate(context, echoProtoService);
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "EchoClientTest.golden", visitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "EchoClientTest.golden");
assertCodeEquals(goldenFilePath, visitor.write());
}
use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.
the class ResourceNameHelperClassComposerTest method generateResourceNameClass_testingSessionOnePattern.
@Test
public void generateResourceNameClass_testingSessionOnePattern() {
FileDescriptor testingFileDescriptor = TestingOuterClass.getDescriptor();
ServiceDescriptor testingService = testingFileDescriptor.getServices().get(0);
assertEquals(testingService.getName(), "Testing");
Map<String, Message> messageTypes = Parser.parseMessages(testingFileDescriptor);
Map<String, ResourceName> resourceNames = Parser.parseResourceNames(testingFileDescriptor);
Set<ResourceName> outputResourceNames = new HashSet<>();
Parser.parseService(testingFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
ResourceName sessionResname = resourceNames.get("showcase.googleapis.com/Session");
assertThat(outputResourceNames).contains(sessionResname);
GapicClass clazz = ResourceNameHelperClassComposer.instance().generate(sessionResname, TestProtoLoader.instance().parseShowcaseTesting());
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "SessionName.golden", visitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "SessionName.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
use of com.google.api.generator.engine.writer.JavaWriterVisitor in project gapic-generator-java by googleapis.
the class ResourceNameHelperClassComposerTest method generateResourceNameClass_echoFoobarMultiplePatterns.
@Test
public void generateResourceNameClass_echoFoobarMultiplePatterns() {
Map<String, Message> messageTypes = Parser.parseMessages(echoFileDescriptor);
Map<String, ResourceName> resourceNames = Parser.parseResourceNames(echoFileDescriptor);
Set<ResourceName> outputResourceNames = new HashSet<>();
Parser.parseService(echoFileDescriptor, messageTypes, resourceNames, Optional.empty(), outputResourceNames);
ResourceName foobarResname = resourceNames.get("showcase.googleapis.com/Foobar");
assertThat(outputResourceNames).contains(foobarResname);
GapicClass clazz = ResourceNameHelperClassComposer.instance().generate(foobarResname, TestProtoLoader.instance().parseShowcaseEcho());
JavaWriterVisitor visitor = new JavaWriterVisitor();
clazz.classDefinition().accept(visitor);
Utils.saveCodegenToFile(this.getClass(), "FoobarName.golden", visitor.write());
Path goldenFilePath = Paths.get(Utils.getGoldenDir(this.getClass()), "FoobarName.golden");
Assert.assertCodeEquals(goldenFilePath, visitor.write());
}
Aggregations