Search in sources :

Example 1 with JavaDiscoGapicSchemaToViewTransformer

use of com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSchemaToViewTransformer 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 + "\"");
    }
}
Also used : JavaDiscoGapicResourceNameToViewTransformer(com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicResourceNameToViewTransformer) JavaDiscoGapicRequestToViewTransformer(com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicRequestToViewTransformer) CommonGapicCodePathMapper(com.google.api.codegen.gapic.CommonGapicCodePathMapper) GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) JavaRenderingUtil(com.google.api.codegen.util.java.JavaRenderingUtil) NotImplementedException(org.apache.commons.lang3.NotImplementedException) GapicProvider(com.google.api.codegen.gapic.GapicProvider) ArrayList(java.util.ArrayList) JavaSurfaceTestTransformer(com.google.api.codegen.transformer.java.JavaSurfaceTestTransformer) JavaDiscoGapicSchemaToViewTransformer(com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSchemaToViewTransformer) JavaDiscoGapicSurfaceTransformer(com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSurfaceTransformer) CommonRenderingUtil(com.google.api.codegen.util.CommonRenderingUtil) DocumentToViewTransformer(com.google.api.codegen.discogapic.transformer.DocumentToViewTransformer)

Example 2 with JavaDiscoGapicSchemaToViewTransformer

use of com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSchemaToViewTransformer in project toolkit by googleapis.

the class DiscoGapicGeneratorFactory method create.

/**
 * Create the DiscoGapicGenerator based on the given id
 */
public static List<CodeGenerator<?>> create(TargetLanguage language, DiscoApiModel model, GapicProductConfig productConfig, PackageMetadataConfig packageConfig, ArtifactFlags artifactFlags) {
    ArrayList<CodeGenerator<?>> generators = new ArrayList<>();
    // Please keep the following IDs in alphabetical order
    if (language.equals(JAVA)) {
        if (artifactFlags.surfaceGeneratorEnabled()) {
            if (artifactFlags.codeFilesEnabled()) {
                GapicCodePathMapper javaPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("src/main/java").setShouldAppendPackage(true).build();
                List<ModelToViewTransformer<DiscoApiModel>> transformers = Arrays.asList(new JavaDiscoGapicResourceNameToViewTransformer(javaPathMapper), new JavaDiscoGapicSchemaToViewTransformer(javaPathMapper), new JavaDiscoGapicRequestToViewTransformer(javaPathMapper), new JavaDiscoGapicSurfaceTransformer(javaPathMapper));
                DiscoGapicGenerator generator = DiscoGapicGenerator.newBuilder().setDiscoApiModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new JavaRenderingUtil())).setModelToViewTransformers(transformers).build();
                generators.add(generator);
            }
            if (artifactFlags.packagingFilesEnabled()) {
                CodeGenerator metadataGenerator = DiscoGapicGenerator.newBuilder().setDiscoApiModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new JavaRenderingUtil())).setModelToViewTransformers(Collections.singletonList(new JavaGapicPackageTransformer<>(packageConfig))).build();
                generators.add(metadataGenerator);
            }
        }
        if (artifactFlags.testGeneratorEnabled()) {
            GapicCodePathMapper javaTestPathMapper = CommonGapicCodePathMapper.newBuilder().setPrefix("src/test/java").setShouldAppendPackage(true).build();
            CodeGenerator<?> testGenerator = DiscoGapicGenerator.newBuilder().setDiscoApiModel(model).setProductConfig(productConfig).setSnippetSetRunner(new CommonSnippetSetRunner(new CommonRenderingUtil())).setModelToViewTransformers(Arrays.asList(new JavaSurfaceTestTransformer<>(javaTestPathMapper, new JavaDiscoGapicSurfaceTransformer(javaTestPathMapper), "java/http_test.snip"))).build();
            generators.add(testGenerator);
        }
        return generators;
    } else {
        throw new UnsupportedOperationException("DiscoGapicGeneratorFactory: unsupported language \"" + language + "\"");
    }
}
Also used : ModelToViewTransformer(com.google.api.codegen.transformer.ModelToViewTransformer) JavaDiscoGapicResourceNameToViewTransformer(com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicResourceNameToViewTransformer) JavaDiscoGapicRequestToViewTransformer(com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicRequestToViewTransformer) CommonGapicCodePathMapper(com.google.api.codegen.gapic.CommonGapicCodePathMapper) GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) CommonSnippetSetRunner(com.google.api.codegen.rendering.CommonSnippetSetRunner) JavaRenderingUtil(com.google.api.codegen.util.java.JavaRenderingUtil) ArrayList(java.util.ArrayList) CodeGenerator(com.google.api.codegen.common.CodeGenerator) JavaDiscoGapicSchemaToViewTransformer(com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSchemaToViewTransformer) JavaDiscoGapicSurfaceTransformer(com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSurfaceTransformer) CommonRenderingUtil(com.google.api.codegen.util.CommonRenderingUtil)

Aggregations

JavaDiscoGapicRequestToViewTransformer (com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicRequestToViewTransformer)2 JavaDiscoGapicResourceNameToViewTransformer (com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicResourceNameToViewTransformer)2 JavaDiscoGapicSchemaToViewTransformer (com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSchemaToViewTransformer)2 JavaDiscoGapicSurfaceTransformer (com.google.api.codegen.discogapic.transformer.java.JavaDiscoGapicSurfaceTransformer)2 CommonGapicCodePathMapper (com.google.api.codegen.gapic.CommonGapicCodePathMapper)2 GapicCodePathMapper (com.google.api.codegen.gapic.GapicCodePathMapper)2 CommonSnippetSetRunner (com.google.api.codegen.rendering.CommonSnippetSetRunner)2 CommonRenderingUtil (com.google.api.codegen.util.CommonRenderingUtil)2 JavaRenderingUtil (com.google.api.codegen.util.java.JavaRenderingUtil)2 ArrayList (java.util.ArrayList)2 CodeGenerator (com.google.api.codegen.common.CodeGenerator)1 DocumentToViewTransformer (com.google.api.codegen.discogapic.transformer.DocumentToViewTransformer)1 GapicProvider (com.google.api.codegen.gapic.GapicProvider)1 ModelToViewTransformer (com.google.api.codegen.transformer.ModelToViewTransformer)1 JavaSurfaceTestTransformer (com.google.api.codegen.transformer.java.JavaSurfaceTestTransformer)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1