Search in sources :

Example 1 with Doc

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;
}
Also used : ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) Doc(com.google.api.tools.framework.snippet.Doc) ViewModel(com.google.api.codegen.viewmodel.ViewModel) TreeMap(java.util.TreeMap)

Example 2 with Doc

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));
}
Also used : Doc(com.google.api.tools.framework.snippet.Doc) Diag(com.google.api.tools.framework.model.Diag)

Example 3 with Doc

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

Example 4 with Doc

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

Example 5 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)

Aggregations

Doc (com.google.api.tools.framework.snippet.Doc)18 GapicProvider (com.google.api.codegen.gapic.GapicProvider)4 ViewModel (com.google.api.codegen.viewmodel.ViewModel)4 ImmutableMap (com.google.common.collect.ImmutableMap)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 ArrayList (java.util.ArrayList)3 Nullable (javax.annotation.Nullable)3 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)2 PackageMetadataConfig (com.google.api.codegen.config.PackageMetadataConfig)2 GapicGeneratorConfig (com.google.api.codegen.gapic.GapicGeneratorConfig)2 PackageMetadataView (com.google.api.codegen.viewmodel.metadata.PackageMetadataView)2 ToolOptions (com.google.api.tools.framework.tools.ToolOptions)2 GeneratedResult (com.google.api.codegen.GeneratedResult)1 Adviser (com.google.api.codegen.advising.Adviser)1 GeneratedResult (com.google.api.codegen.common.GeneratedResult)1 TargetLanguage (com.google.api.codegen.common.TargetLanguage)1 ApiDefaultsConfig (com.google.api.codegen.config.ApiDefaultsConfig)1