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;
}
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);
}
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();
}
Aggregations