Search in sources :

Example 6 with GeneratedResult

use of com.google.api.codegen.common.GeneratedResult in project toolkit by googleapis.

the class DiscoConfigGeneratorApp method generateConfig.

private Map<String, Doc> generateConfig(String outputPath) {
    Document document = setupDocument(options.get(DiscoGapicGeneratorApp.DISCOVERY_DOC), getDiagCollector());
    ViewModel viewModel = new DiscoConfigTransformer().generateConfig(new DiscoApiModel(document, ""), outputPath);
    Map<String, GeneratedResult<Doc>> generatedConfig = new CommonSnippetSetRunner(new CommonRenderingUtil(), true).generate(viewModel);
    return GeneratedResult.extractBodies(generatedConfig);
}
Also used : DiscoApiModel(com.google.api.codegen.config.DiscoApiModel) CommonRenderingUtil(com.google.api.codegen.util.CommonRenderingUtil) CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) GeneratedResult(com.google.api.codegen.common.GeneratedResult) ViewModel(com.google.api.codegen.viewmodel.ViewModel) DiscoConfigTransformer(com.google.api.codegen.configgen.transformer.DiscoConfigTransformer) Document(com.google.api.codegen.discovery.Document)

Example 7 with GeneratedResult

use of com.google.api.codegen.common.GeneratedResult in project toolkit by googleapis.

the class LegacyGapicGenerator method generate.

private Map<String, GeneratedResult<Doc>> generate(String snippetFileName) {
    // Establish required stage for generation.
    model.establishStage(Merged.KEY);
    if (model.getDiagReporter().getDiagCollector().getErrorCount() > 0) {
        return ImmutableMap.of();
    }
    // Run the generator for each service.
    Map<String, GeneratedResult<Doc>> generated = new TreeMap<>();
    for (Interface modelInterface : ProtoModels.getInterfaces(model, context.getApiConfig())) {
        if (context.getApiConfig().getInterfaceConfig(modelInterface) == null) {
            continue;
        }
        String subPath;
        if (modelInterface == null) {
            subPath = pathMapper.getOutputPath(null, context.getApiConfig());
        } else {
            subPath = pathMapper.getOutputPath(modelInterface.getFullName(), context.getApiConfig());
        }
        Map<String, GeneratedResult<Doc>> result = generator.generate(modelInterface, snippetFileName, context);
        for (Map.Entry<String, GeneratedResult<Doc>> resEntry : result.entrySet()) {
            String resSubPath = Strings.isNullOrEmpty(subPath) ? resEntry.getKey() : subPath + "/" + resEntry.getKey();
            generated.put(resSubPath, resEntry.getValue());
        }
    }
    // Return result.
    if (model.getDiagReporter().getDiagCollector().getErrorCount() > 0) {
        return ImmutableMap.of();
    }
    return generated;
}
Also used : GeneratedResult(com.google.api.codegen.common.GeneratedResult) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Interface(com.google.api.tools.framework.model.Interface)

Example 8 with GeneratedResult

use of com.google.api.codegen.common.GeneratedResult in project toolkit by googleapis.

the class PackageGeneratorApp method process.

@Override
protected void process() throws Exception {
    model.establishStage(Merged.KEY);
    if (model.getDiagReporter().getDiagCollector().getErrorCount() > 0) {
        for (Diag diag : model.getDiagReporter().getDiagCollector().getDiags()) {
            System.err.println(diag.toString());
        }
        return;
    }
    Map<String, GeneratedResult<Doc>> results = generate(model);
    ToolUtil.writeFiles(GeneratedResult.extractBodies(results), options.get(OUTPUT_DIR));
}
Also used : GeneratedResult(com.google.api.codegen.common.GeneratedResult) Diag(com.google.api.tools.framework.model.Diag)

Aggregations

GeneratedResult (com.google.api.codegen.common.GeneratedResult)8 ImmutableMap (com.google.common.collect.ImmutableMap)5 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)3 CommonSnippetSetRunner (com.google.api.codegen.rendering.CommonSnippetSetRunner)3 ViewModel (com.google.api.codegen.viewmodel.ViewModel)2 PackageMetadataView (com.google.api.codegen.viewmodel.metadata.PackageMetadataView)2 Diag (com.google.api.tools.framework.model.Diag)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 ConfigProto (com.google.api.codegen.ConfigProto)1 CodeGenerator (com.google.api.codegen.common.CodeGenerator)1 TargetLanguage (com.google.api.codegen.common.TargetLanguage)1 ApiDefaultsConfig (com.google.api.codegen.config.ApiDefaultsConfig)1 DependenciesConfig (com.google.api.codegen.config.DependenciesConfig)1 DiscoApiModel (com.google.api.codegen.config.DiscoApiModel)1 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)1 PackageMetadataConfig (com.google.api.codegen.config.PackageMetadataConfig)1 PackagingConfig (com.google.api.codegen.config.PackagingConfig)1 TransportProtocol (com.google.api.codegen.config.TransportProtocol)1 DiscoConfigTransformer (com.google.api.codegen.configgen.transformer.DiscoConfigTransformer)1