use of com.google.api.codegen.gapic.GapicProvider in project toolkit by googleapis.
the class MainDiscoGapicProviderFactory method defaultCreate.
/**
* Create the DiscoGapicProvider based on the given id
*/
public static List<GapicProvider> defaultCreate(DiscoApiModel model, GapicProductConfig productConfig, GapicGeneratorConfig generatorConfig, PackageMetadataConfig packageConfig) {
ArrayList<GapicProvider> providers = new ArrayList<>();
String id = generatorConfig.id();
// Please keep the following IDs in alphabetical order
if (id.equals(JAVA)) {
if (generatorConfig.enableSurfaceGenerator()) {
GapicCodePathMapper javaPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("src/main/java").setShouldAppendPackage(true).build();
List<DocumentToViewTransformer> transformers = Arrays.asList(new JavaDiscoGapicResourceNameToViewTransformer(javaPathMapper, packageConfig), new JavaDiscoGapicSchemaToViewTransformer(javaPathMapper, packageConfig), new JavaDiscoGapicRequestToViewTransformer(javaPathMapper, packageConfig), new JavaDiscoGapicSurfaceTransformer(javaPathMapper, packageConfig));
DiscoGapicProvider provider = DiscoGapicProvider.newBuilder().setDiscoApiModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new JavaRenderingUtil())).setDocumentToViewTransformers(transformers).build();
providers.add(provider);
}
if (generatorConfig.enableTestGenerator()) {
GapicCodePathMapper javaTestPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("src/test/java").setShouldAppendPackage(true).build();
GapicProvider testProvider = ViewModelDiscoGapicProvider.newBuilder().setModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformer(new JavaSurfaceTestTransformer(javaTestPathMapper, new JavaDiscoGapicSurfaceTransformer(javaTestPathMapper, packageConfig), "java/http_test.snip")).build();
providers.add(testProvider);
}
return providers;
} else {
throw new NotImplementedException("DiscoGapicProviderFactory: invalid id \"" + id + "\"");
}
}
use of com.google.api.codegen.gapic.GapicProvider in project toolkit by googleapis.
the class DiscoGapicTestBase method run.
@Override
protected Map<String, Doc> run() {
Map<String, Doc> outputDocs = new LinkedHashMap<>();
for (GapicProvider provider : discoGapicProviders) {
Map<String, Doc> docs = provider.generate();
outputDocs.putAll(docs);
}
return outputDocs;
}
use of com.google.api.codegen.gapic.GapicProvider in project toolkit by googleapis.
the class CodeGeneratorApi method process.
@Override
protected void process() throws Exception {
// Read the YAML config and convert it to proto.
List<String> configFileNames = options.get(GENERATOR_CONFIG_FILES);
if (configFileNames.size() == 0) {
error(String.format("--%s must be provided", GENERATOR_CONFIG_FILES.name()));
return;
}
ConfigSource configSource = loadConfigFromFiles(configFileNames);
if (configSource == null) {
return;
}
ConfigProto configProto = (ConfigProto) configSource.getConfig();
if (configProto == null) {
return;
}
model.establishStage(Merged.KEY);
List<String> adviceSuppressors = options.get(ADVICE_SUPPRESSORS);
Adviser adviser = new Adviser(adviceSuppressors);
adviser.advise(model, configProto);
if (model.getDiagCollector().getErrorCount() > 0) {
for (Diag diag : model.getDiagCollector().getDiags()) {
System.err.println(diag.toString());
}
return;
}
PackageMetadataConfig packageConfig = null;
if (!Strings.isNullOrEmpty(options.get(PACKAGE_CONFIG_FILE))) {
String contents = new String(Files.readAllBytes(Paths.get(options.get(PACKAGE_CONFIG_FILE))), StandardCharsets.UTF_8);
packageConfig = PackageMetadataConfig.createFromString(contents);
}
GeneratorProto generator = configProto.getGenerator();
GapicProductConfig productConfig = GapicProductConfig.create(model, configProto);
if (productConfig == null) {
return;
}
if (generator != null) {
String factory = generator.getFactory();
String id = generator.getId();
GapicProviderFactory<GapicProvider> providerFactory = createProviderFactory(model, factory);
GapicGeneratorConfig generatorConfig = GapicGeneratorConfig.newBuilder().id(id).enabledArtifacts(options.get(ENABLED_ARTIFACTS)).build();
String outputPath = options.get(OUTPUT_FILE);
List<GapicProvider> providers = providerFactory.create(model, productConfig, generatorConfig, packageConfig);
Map<String, Doc> outputFiles = Maps.newHashMap();
for (GapicProvider provider : providers) {
outputFiles.putAll(provider.generate());
}
writeCodeGenOutput(outputFiles, outputPath);
}
}
use of com.google.api.codegen.gapic.GapicProvider in project toolkit by googleapis.
the class DiscoGapicGeneratorApi method run.
public void run() throws Exception {
String discoveryDocPath = options.get(DISCOVERY_DOC);
List<String> configFileNames = options.get(GENERATOR_CONFIG_FILES);
String packageConfigFile = options.get(PACKAGE_CONFIG_FILE);
List<String> enabledArtifacts = options.get(ENABLED_ARTIFACTS);
List<GapicProvider> providers = getProviders(discoveryDocPath, configFileNames, packageConfigFile, enabledArtifacts);
Map<String, Doc> outputFiles = Maps.newHashMap();
for (GapicProvider provider : providers) {
outputFiles.putAll(provider.generate());
}
ToolUtil.writeFiles(outputFiles, options.get(OUTPUT_FILE));
}
use of com.google.api.codegen.gapic.GapicProvider in project toolkit by googleapis.
the class GapicTestBase2 method createTestConfig.
/**
* Creates the constructor arguments to be passed onto this class (GapicTestBase2) to create test
* methods. The idForFactory String is passed to GapicProviderFactory to get the GapicProviders
* provided by that id, and then the snippet file names are scraped from those providers, and a
* set of arguments is created for each combination of GapicProvider x snippet that
* GapicProviderFactory returns.
*/
public static Object[] createTestConfig(String idForFactory, String[] gapicConfigFileNames, String packageConfigFileName, String apiName) {
Model model = Model.create(Service.getDefaultInstance());
GapicProductConfig productConfig = GapicProductConfig.createDummyInstance();
PackageMetadataConfig packageConfig = PackageMetadataConfig.createDummyPackageMetadataConfig();
GapicGeneratorConfig generatorConfig = GapicGeneratorConfig.newBuilder().id(idForFactory).enabledArtifacts(Arrays.asList("surface", "test")).build();
List<GapicProvider> providers = MainGapicProviderFactory.defaultCreate(model, productConfig, generatorConfig, packageConfig);
List<String> snippetNames = new ArrayList<>();
for (GapicProvider provider : providers) {
snippetNames.addAll(provider.getSnippetFileNames());
}
String baseline = idForFactory + "_" + apiName + ".baseline";
return new Object[] { idForFactory, gapicConfigFileNames, packageConfigFileName, snippetNames, apiName, baseline };
}
Aggregations