use of com.google.api.codegen.gapic.ArtifactFlags in project toolkit by googleapis.
the class DiscoGapicGeneratorApp method getGenerators.
/**
* From config file paths, constructs the DiscoGapicGenerators to run.
*/
@VisibleForTesting
public static List<CodeGenerator<?>> getGenerators(String discoveryDocPath, List<String> configFileNames, String packageConfig2File, String dependencyConfigFile, String languageStr, List<String> enabledArtifacts, ArtifactType artifactType) throws IOException {
if (!new File(discoveryDocPath).exists()) {
throw new IOException("File not found: " + discoveryDocPath);
}
Reader reader = new InputStreamReader(new FileInputStream(new File(discoveryDocPath)));
ObjectMapper mapper = new ObjectMapper();
JsonNode root = mapper.readTree(reader);
// Read the YAML config and convert it to proto.
if (configFileNames.size() == 0) {
throw new IOException(String.format("--%s must be provided", GENERATOR_CONFIG_FILES.name()));
}
ConfigProto configProto = loadConfigFromFiles(configFileNames);
if (configProto == null) {
throw new IOException("Failed to load config proto.");
}
PackageMetadataConfig packageConfig = null;
if (!Strings.isNullOrEmpty(packageConfig2File)) {
ApiDefaultsConfig apiDefaultsConfig = ApiDefaultsConfig.load();
DependenciesConfig dependenciesConfig;
if (dependencyConfigFile != null) {
dependenciesConfig = DependenciesConfig.loadFromURL(new File(dependencyConfigFile).toURI().toURL());
} else {
dependenciesConfig = DependenciesConfig.load();
}
PackagingConfig packagingConfig = PackagingConfig.load(packageConfig2File);
packageConfig = PackageMetadataConfig.createFromPackaging(apiDefaultsConfig, dependenciesConfig, packagingConfig);
}
TargetLanguage language;
if (!Strings.isNullOrEmpty(languageStr)) {
language = TargetLanguage.fromString(languageStr.toUpperCase());
} else {
throw new IllegalArgumentException("Language not set by --language option.");
}
String defaultPackageName = configProto.getLanguageSettingsMap().get(languageStr).getPackageName();
DiscoApiModel model = new DiscoApiModel(Document.from(new DiscoveryNode(root)), defaultPackageName);
GapicProductConfig productConfig = GapicProductConfig.create(model, configProto, language);
ArtifactFlags artifactFlags = new ArtifactFlags(enabledArtifacts, artifactType, false);
return DiscoGapicGeneratorFactory.create(language, model, productConfig, packageConfig, artifactFlags);
}
Aggregations