Search in sources :

Example 6 with GapicProvider

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;
}
Also used : GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ArrayList(java.util.ArrayList) GapicProvider(com.google.api.codegen.gapic.GapicProvider) Diag(com.google.api.tools.framework.model.Diag) TreeMap(java.util.TreeMap) GapicGeneratorConfig(com.google.api.codegen.gapic.GapicGeneratorConfig) Doc(com.google.api.tools.framework.snippet.Doc)

Aggregations

GapicProvider (com.google.api.codegen.gapic.GapicProvider)6 Doc (com.google.api.tools.framework.snippet.Doc)4 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)3 GapicGeneratorConfig (com.google.api.codegen.gapic.GapicGeneratorConfig)3 ArrayList (java.util.ArrayList)3 PackageMetadataConfig (com.google.api.codegen.config.PackageMetadataConfig)2 Diag (com.google.api.tools.framework.model.Diag)2 Adviser (com.google.api.codegen.advising.Adviser)1 DocumentToViewTransformer (com.google.api.codegen.discogapic.transformer.DocumentToViewTransformer)1 JavaDiscoGapicRequestToViewTransformer (com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicRequestToViewTransformer)1 JavaDiscoGapicResourceNameToViewTransformer (com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicResourceNameToViewTransformer)1 JavaDiscoGapicSchemaToViewTransformer (com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSchemaToViewTransformer)1 JavaDiscoGapicSurfaceTransformer (com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSurfaceTransformer)1 CommonGapicCodePathMapper (com.google.api.codegen.gapic.CommonGapicCodePathMapper)1 GapicCodePathMapper (com.google.api.codegen.gapic.GapicCodePathMapper)1 CommonSnippetSetRunner (com.google.api.codegen.rendering.CommonSnippetSetRunner)1 JavaSurfaceTestTransformer (com.google.api.codegen.transformer.java.JavaSurfaceTestTransformer)1 CommonRenderingUtil (com.google.api.codegen.util.CommonRenderingUtil)1 JavaRenderingUtil (com.google.api.codegen.util.java.JavaRenderingUtil)1 ConfigSource (com.google.api.tools.framework.model.ConfigSource)1