use of com.google.api.codegen.gapic.GapicProvider in project toolkit by googleapis.
the class GapicTestBase2 method run.
@Override
public Map<String, Doc> run() {
model.establishStage(Merged.KEY);
if (model.getDiagCollector().getErrorCount() > 0) {
for (Diag diag : model.getDiagCollector().getDiags()) {
System.err.println(diag.toString());
}
return null;
}
GapicProductConfig productConfig = GapicProductConfig.create(model, gapicConfig);
if (productConfig == null) {
for (Diag diag : model.getDiagCollector().getDiags()) {
System.err.println(diag.toString());
}
return null;
}
List<String> enabledArtifacts = new ArrayList<>();
if (hasSmokeTestConfig(productConfig)) {
enabledArtifacts.addAll(Arrays.asList("surface", "test"));
}
GapicGeneratorConfig generatorConfig = GapicGeneratorConfig.newBuilder().id(idForFactory).enabledArtifacts(enabledArtifacts).build();
List<GapicProvider> providers = MainGapicProviderFactory.defaultCreate(model, productConfig, generatorConfig, packageConfig);
List<String> disabledGen = new ArrayList<>(snippetNames);
for (GapicProvider provider : providers) {
disabledGen.removeAll(provider.getSnippetFileNames());
}
for (String gen : disabledGen) {
testOutput().printf("%s generation is not enabled for this test case.\n", gen);
}
// Don't run any providers we're not testing.
ArrayList<GapicProvider> testedProviders = new ArrayList<>();
for (GapicProvider provider : providers) {
if (!Collections.disjoint(provider.getSnippetFileNames(), snippetNames)) {
testedProviders.add(provider);
}
}
boolean reportDiag = false;
Map<String, Doc> output = new TreeMap<>();
for (GapicProvider provider : testedProviders) {
Map<String, Doc> out = provider.generate();
if (output == null) {
reportDiag = true;
} else {
if (!Collections.disjoint(out.keySet(), output.keySet())) {
throw new IllegalStateException("file conflict");
}
output.putAll(out);
}
}
if (reportDiag) {
for (Diag diag : model.getDiagCollector().getDiags()) {
testOutput().println(diag.toString());
}
}
return output;
}
Aggregations