use of com.google.api.tools.framework.snippet.Doc in project toolkit by googleapis.
the class ViewModelGapicProvider method generate.
@Override
public Map<String, Doc> generate(String snippetFileName) {
// Establish required stage for generation.
model.establishStage(Merged.KEY);
if (model.getDiagCollector().getErrorCount() > 0) {
return null;
}
List<ViewModel> surfaceDocs = modelToViewTransformer.transform(new ProtoApiModel(model), productConfig);
if (model.getDiagCollector().getErrorCount() > 0) {
return null;
}
Map<String, Doc> docs = new TreeMap<>();
for (ViewModel surfaceDoc : surfaceDocs) {
if (snippetFileName != null && !surfaceDoc.templateFileName().equals(snippetFileName)) {
continue;
}
Doc doc = snippetSetRunner.generate(surfaceDoc);
if (doc == null) {
// generation failed; failures are captured in the model.
continue;
}
docs.put(surfaceDoc.outputPath(), doc);
}
return docs;
}
use of com.google.api.tools.framework.snippet.Doc in project toolkit by googleapis.
the class GrpcMetadataGenerator method process.
@Override
protected void process() throws Exception {
model.establishStage(Merged.KEY);
if (model.getDiagCollector().getErrorCount() > 0) {
for (Diag diag : model.getDiagCollector().getDiags()) {
System.err.println(diag.toString());
}
return;
}
Map<String, Doc> docs = generate(model);
ToolUtil.writeFiles(docs, options.get(OUTPUT_DIR));
}
use of com.google.api.tools.framework.snippet.Doc in project toolkit by googleapis.
the class JavaGrpcMetadataProvider method generate.
@Override
public Map<String, Doc> generate(Model model, PackageMetadataConfig config) {
ImmutableMap.Builder<String, Doc> docs = new ImmutableMap.Builder<>();
ProtoApiModel apiModel = new ProtoApiModel(model);
ArrayList<PackageMetadataView> metadataViews = new ArrayList<>();
metadataViews.addAll(transformer.transform(apiModel, config));
for (PackageMetadataView view : metadataViews) {
CommonSnippetSetRunner runner = new CommonSnippetSetRunner(view);
Doc result = runner.generate(view);
if (!result.isWhitespace()) {
docs.put(view.outputPath(), result);
}
}
return docs.build();
}
use of com.google.api.tools.framework.snippet.Doc in project toolkit by googleapis.
the class ViewModelDiscoGapicProvider method generate.
@Override
public Map<String, Doc> generate(String snippetFileName) {
List<ViewModel> surfaceDocs = modelToViewTransformer.transform(model, productConfig);
if (model.getDiagCollector().getErrorCount() > 0) {
return null;
}
Map<String, Doc> docs = new TreeMap<>();
for (ViewModel surfaceDoc : surfaceDocs) {
if (snippetFileName != null && !surfaceDoc.templateFileName().equals(snippetFileName)) {
continue;
}
Doc doc = snippetSetRunner.generate(surfaceDoc);
if (doc == null) {
// generation failed; failures are captured in the model.
continue;
}
docs.put(surfaceDoc.outputPath(), doc);
}
return docs;
}
use of com.google.api.tools.framework.snippet.Doc in project toolkit by googleapis.
the class CodeGeneratorApiTest method writeCodeGenOutput.
@Test
public void writeCodeGenOutput() throws Exception {
Map<String, Doc> outputFiles = Maps.newHashMap();
outputFiles.put("tmp.txt", Doc.text("Sample data"));
outputFiles.put("tmp2.txt", Doc.text("Sample data"));
// Verify that files are outputed to a directory.
String outputDir = tempDir.getRoot().getPath();
CodeGeneratorApi.writeCodeGenOutput(outputFiles, outputDir);
assertTrue((new File(outputDir, "tmp.txt")).exists());
assertTrue((new File(outputDir, "tmp2.txt")).exists());
// Verify that files are outputed into a jar file.
File outputJar = new File(outputDir, "output.jar");
CodeGeneratorApi.writeCodeGenOutput(outputFiles, outputJar.getPath());
assertTrue(outputJar.exists());
}
Aggregations