Search in sources :

Example 6 with Doc

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());
}
Also used : Doc(com.google.api.tools.framework.snippet.Doc) File(java.io.File) Test(org.junit.Test)

Example 7 with Doc

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;
}
Also used : GapicProvider(com.google.api.codegen.gapic.GapicProvider) Doc(com.google.api.tools.framework.snippet.Doc) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with Doc

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();
    }
}
Also used : Doc(com.google.api.tools.framework.snippet.Doc) ToolOptions(com.google.api.tools.framework.tools.ToolOptions) ImmutableMap(com.google.common.collect.ImmutableMap) Nullable(javax.annotation.Nullable)

Example 9 with Doc

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;
}
Also used : GeneratedResult(com.google.api.codegen.GeneratedResult) Doc(com.google.api.tools.framework.snippet.Doc) TreeMap(java.util.TreeMap) Nullable(javax.annotation.Nullable)

Example 10 with Doc

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();
}
Also used : CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) ArrayList(java.util.ArrayList) ImmutableMap(com.google.common.collect.ImmutableMap) Doc(com.google.api.tools.framework.snippet.Doc) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) PackageMetadataView(com.google.api.codegen.viewmodel.metadata.PackageMetadataView)

Aggregations

Doc (com.google.api.tools.framework.snippet.Doc)15 GapicProvider (com.google.api.codegen.gapic.GapicProvider)4 ViewModel (com.google.api.codegen.viewmodel.ViewModel)4 TreeMap (java.util.TreeMap)4 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)3 CommonSnippetSetRunner (com.google.api.codegen.rendering.CommonSnippetSetRunner)3 Diag (com.google.api.tools.framework.model.Diag)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ArrayList (java.util.ArrayList)3 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)2 GapicGeneratorConfig (com.google.api.codegen.gapic.GapicGeneratorConfig)2 PackageMetadataView (com.google.api.codegen.viewmodel.metadata.PackageMetadataView)2 Nullable (javax.annotation.Nullable)2 GeneratedResult (com.google.api.codegen.GeneratedResult)1 Adviser (com.google.api.codegen.advising.Adviser)1 DiscoApiModel (com.google.api.codegen.config.DiscoApiModel)1 PackageMetadataConfig (com.google.api.codegen.config.PackageMetadataConfig)1 DiscoConfigTransformer (com.google.api.codegen.configgen.transformer.DiscoConfigTransformer)1 DocumentToViewTransformer (com.google.api.codegen.discogapic.transformer.DocumentToViewTransformer)1 Document (com.google.api.codegen.discovery.Document)1