Search in sources :

Example 1 with TargetLanguage

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

the class PackageMetadataConfig method buildMapWithDefault.

/**
 * Transforms entries of the input map into TargetLanguage, taking into account an optional
 * default setting.
 */
private static <V> Map<TargetLanguage, V> buildMapWithDefault(Map<String, V> inputMap) {
    Map<TargetLanguage, V> outputMap = new HashMap<>();
    Set<TargetLanguage> configuredLanguages = new HashSet<>();
    V defaultValue = null;
    for (Map.Entry<String, V> entry : inputMap.entrySet()) {
        if (entry.getKey().equals(CONFIG_KEY_DEFAULT)) {
            defaultValue = entry.getValue();
        } else {
            TargetLanguage targetLanguage = TargetLanguage.fromString(entry.getKey());
            configuredLanguages.add(targetLanguage);
            outputMap.put(targetLanguage, entry.getValue());
        }
        for (TargetLanguage language : TargetLanguage.values()) {
            if (!configuredLanguages.contains(language)) {
                outputMap.put(language, defaultValue);
            }
        }
    }
    return outputMap;
}
Also used : HashMap(java.util.HashMap) TargetLanguage(com.google.api.codegen.TargetLanguage) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with TargetLanguage

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

the class GrpcMetadataGenerator method generate.

protected Map<String, Doc> generate(Model model) throws IOException {
    TargetLanguage language = TargetLanguage.fromString(options.get(LANGUAGE));
    String configContent = new String(Files.readAllBytes(Paths.get(options.get(METADATA_CONFIG_FILE))), StandardCharsets.UTF_8);
    PackageMetadataConfig config = PackageMetadataConfig.createFromString(configContent);
    ArtifactType artifactType = options.get(GrpcMetadataGenerator.ARTIFACT_TYPE);
    if (artifactType == null) {
        artifactType = config.artifactType();
    }
    GrpcMetadataProvider provider = GrpcMetadataProviderFactory.create(language, artifactType, options);
    return provider.generate(model, config);
}
Also used : PackageMetadataConfig(com.google.api.codegen.config.PackageMetadataConfig) TargetLanguage(com.google.api.codegen.TargetLanguage)

Example 3 with TargetLanguage

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

the class GrpcMetadataGeneratorTool method generate.

private static void generate(String descriptorSet, String[] configs, String inputDir, String outputDir, String languageString, String metadataConfig, String artifactType) {
    TargetLanguage language = TargetLanguage.fromString(languageString);
    ToolOptions options = ToolOptions.create();
    options.set(GrpcMetadataGenerator.INPUT_DIR, inputDir);
    options.set(GrpcMetadataGenerator.OUTPUT_DIR, outputDir);
    options.set(ToolOptions.DESCRIPTOR_SET, descriptorSet);
    if (configs != null) {
        options.set(ToolOptions.CONFIG_FILES, Lists.newArrayList(configs));
    }
    options.set(GrpcMetadataGenerator.METADATA_CONFIG_FILE, metadataConfig);
    options.set(GrpcMetadataGenerator.LANGUAGE, languageString);
    if (artifactType != null) {
        options.set(GrpcMetadataGenerator.ARTIFACT_TYPE, ArtifactType.of(artifactType));
    }
    GrpcMetadataGenerator generator = new GrpcMetadataGenerator(options);
    generator.run();
}
Also used : ToolOptions(com.google.api.tools.framework.tools.ToolOptions) TargetLanguage(com.google.api.codegen.TargetLanguage)

Aggregations

TargetLanguage (com.google.api.codegen.TargetLanguage)3 PackageMetadataConfig (com.google.api.codegen.config.PackageMetadataConfig)1 ToolOptions (com.google.api.tools.framework.tools.ToolOptions)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1