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());
}
use of com.google.api.tools.framework.snippet.Doc in project toolkit by googleapis.
the class DiscoGapicTestBase method run.
@Override
protected Map<String, Doc> run() {
Map<String, Doc> outputDocs = new LinkedHashMap<>();
for (GapicProvider provider : discoGapicProviders) {
Map<String, Doc> docs = provider.generate();
outputDocs.putAll(docs);
}
return outputDocs;
}
use of com.google.api.tools.framework.snippet.Doc in project toolkit by googleapis.
the class PackageMetadataGeneratorTest method run.
@Override
@Nullable
protected Object run() throws Exception {
String outFile = tempDir.getRoot().getPath() + File.separator + baselineFileName();
String metadataConfigPath = getTestDataLocator().findTestData(packageConfig).getPath();
ToolOptions options = ToolOptions.create();
options.set(GrpcMetadataGenerator.OUTPUT_DIR, outFile);
options.set(GrpcMetadataGenerator.INPUT_DIR, getTestDataLocator().findTestData("fakeprotodir").getPath());
options.set(GrpcMetadataGenerator.METADATA_CONFIG_FILE, metadataConfigPath);
options.set(GrpcMetadataGenerator.LANGUAGE, language);
options.set(GrpcMetadataGenerator.ARTIFACT_TYPE, artifactType);
Map<String, Doc> generatedDocs = new GrpcMetadataGenerator(options).generate(model);
if (TargetLanguage.fromString(language) == TargetLanguage.PYTHON) {
OutputCollector collector = new OutputCollector(Paths.get(outFile));
Files.walkFileTree(Paths.get(outFile), collector);
return new ImmutableMap.Builder<String, Doc>().putAll(generatedDocs).putAll(collector.getResults()).build();
} else {
return new ImmutableMap.Builder<String, Doc>().putAll(generatedDocs).build();
}
}
use of com.google.api.tools.framework.snippet.Doc in project toolkit by googleapis.
the class CommonGapicProvider method generate.
@Nullable
@Override
public Map<String, Doc> generate(String snippetFileName) {
Map<String, Doc> docs = new TreeMap<>();
List<GeneratedResult> generatedOutput = generateSnip(snippetFileName);
if (generatedOutput == null) {
return docs;
}
for (GeneratedResult result : generatedOutput) {
if (!result.getDoc().isWhitespace()) {
docs.put(result.getFilename(), result.getDoc());
}
}
return docs;
}
use of com.google.api.tools.framework.snippet.Doc in project toolkit by googleapis.
the class PythonGrpcMetadataProvider method generate.
@Override
public Map<String, Doc> generate(Model model, PackageMetadataConfig config) throws IOException {
ImmutableMap.Builder<String, Doc> docs = new ImmutableMap.Builder<String, Doc>();
ArrayList<PackageMetadataView> metadataViews = new ArrayList<>();
PythonPackageCopier copier = new PythonPackageCopier();
PythonPackageCopierResult copierResult = copier.run(options, config);
docs.putAll(copierResult.docs());
PythonGrpcMetadataTransformer pythonTransformer = new PythonGrpcMetadataTransformer(copierResult);
ProtoApiModel apiModel = new ProtoApiModel(model);
metadataViews.addAll(pythonTransformer.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();
}
Aggregations