Search in sources :

Example 16 with ImportSectionView

use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.

the class PythonGapicSurfaceTransformer method generateTypesView.

private ViewModel generateTypesView(Model model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new PythonSurfaceNamer(productConfig.getPackageName());
    ImportSectionView imports = importSectionTransformer.generateTypesImportSection(model, productConfig);
    return VersionIndexView.newBuilder().templateFileName(TYPES_TEMPLATE_FILENAME).outputPath(typesOutputFile(namer)).requireViews(ImmutableList.<VersionIndexRequireView>of()).apiVersion(namer.getApiWrapperModuleVersion()).namespace(namer.getVersionedDirectoryNamespace()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, imports, namer)).build();
}
Also used : SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 17 with ImportSectionView

use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.

the class RubyGapicSurfaceTestTransformer method createUnitTestViews.

// /////////////////////////////////// Unit Test ///////////////////////////////////////
private List<ClientTestFileView> createUnitTestViews(ApiModel model, GapicProductConfig productConfig) {
    ImmutableList.Builder<ClientTestFileView> views = ImmutableList.builder();
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    for (InterfaceModel apiInterface : model.getInterfaces(productConfig)) {
        if (!productConfig.hasInterfaceConfig(apiInterface)) {
            continue;
        }
        GapicInterfaceContext context = createContext(apiInterface, productConfig);
        String testClassName = namer.getUnitTestClassName(context.getInterfaceConfig());
        String outputPath = unitTestPathMapper.getOutputPath(context.getInterfaceModel().getFullName(), productConfig);
        ImportSectionView importSection = importSectionTransformer.generateTestImportSection(context);
        views.add(ClientTestFileView.newBuilder().templateFileName(UNIT_TEST_TEMPLATE_FILE).outputPath(namer.getSourceFilePath(outputPath, testClassName)).testClass(createUnitTestClassView(context, model.hasMultipleServices())).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer)).apiVersion(packageConfig.apiVersion()).build());
    }
    return views.build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) ImmutableList(com.google.common.collect.ImmutableList) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ClientTestFileView(com.google.api.codegen.viewmodel.testing.ClientTestFileView) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 18 with ImportSectionView

use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.

the class RubyGapicSurfaceTransformer method generateCredentialsView.

private ViewModel generateCredentialsView(ApiModel model, GapicProductConfig productConfig) {
    SurfaceNamer namer = new RubySurfaceNamer(productConfig.getPackageName());
    CredentialsClassView credentialsClass = generateCredentialsClass(model, productConfig);
    ImportSectionView importSection = ImportSectionView.newBuilder().externalImports(ImmutableList.of(ImportFileView.newBuilder().moduleName("googleauth").types(ImmutableList.<ImportTypeView>of()).build())).build();
    List<String> modules = namer.getApiModules();
    InterfaceModel apiInterface = model.getInterfaces(productConfig).stream().filter(productConfig::hasInterfaceConfig).findFirst().orElseThrow(() -> new NoSuchElementException("reachable API interfaces"));
    GapicInterfaceContext context = createContext(apiInterface, productConfig);
    String subPath = pathMapper.getOutputPath(context.getInterface().getFullName(), context.getProductConfig());
    return CredentialsClassFileView.newBuilder().outputPath(namer.getSourceFilePath(subPath, "Credentials")).templateFileName(CREDENTIALS_CLASS_TEMPLATE_FILE).credentialsClass(credentialsClass).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, namer, ImmutableList.copyOf(modules))).build();
}
Also used : InterfaceModel(com.google.api.codegen.config.InterfaceModel) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) CredentialsClassView(com.google.api.codegen.viewmodel.CredentialsClassView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) NoSuchElementException(java.util.NoSuchElementException) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 19 with ImportSectionView

use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.

the class RubyImportSectionTransformer method generateImportSection.

@Override
public ImportSectionView generateImportSection(TransformationContext transformationContext, String className) {
    // TODO support non-Gapic inputs
    GapicInterfaceContext context = (GapicInterfaceContext) transformationContext;
    Set<String> importFilenames = generateImportFilenames(context);
    ImportSectionView.Builder importSection = ImportSectionView.newBuilder();
    importSection.standardImports(generateStandardImports());
    importSection.externalImports(generateExternalImports(context));
    importSection.appImports(generateAppImports(context, importFilenames));
    importSection.serviceImports(generateServiceImports(context, importFilenames));
    return importSection.build();
}
Also used : GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Example 20 with ImportSectionView

use of com.google.api.codegen.viewmodel.ImportSectionView in project toolkit by googleapis.

the class RubyPackageMetadataTransformer method generateMetadataView.

private ViewModel generateMetadataView(ApiModel model, GapicProductConfig productConfig, String template, RubyPackageMetadataNamer namer, String filePrefix) {
    String noLeadingRubyDir = template.startsWith(RUBY_PREFIX) ? template.substring(RUBY_PREFIX.length()) : template;
    if (!Strings.isNullOrEmpty(filePrefix)) {
        noLeadingRubyDir = filePrefix + noLeadingRubyDir;
    }
    int extensionIndex = noLeadingRubyDir.lastIndexOf(".");
    String outputPath = noLeadingRubyDir.substring(0, extensionIndex);
    Collection<InterfaceModel> interfaceModels = model.getInterfaces(productConfig).stream().filter(productConfig::hasInterfaceConfig).collect(ImmutableList.toImmutableList());
    List<GapicInterfaceContext> contexts = interfaceModels.stream().map(i -> createContext(i, productConfig)).collect(ImmutableList.toImmutableList());
    boolean hasSmokeTests = contexts.stream().map(InterfaceContext::getInterfaceConfig).map(InterfaceConfig::getSmokeTestConfig).anyMatch(Objects::nonNull);
    SurfaceNamer surfaceNamer = new RubySurfaceNamer(productConfig.getPackageName());
    ImportSectionView importSection = importSectionTransformer.generateRakefileAcceptanceTaskImportSection(contexts);
    return metadataTransformer.generateMetadataView(namer, packageConfig, model, template, outputPath, TargetLanguage.RUBY).identifier(namer.getMetadataIdentifier()).fileHeader(fileHeaderTransformer.generateFileHeader(productConfig, importSection, surfaceNamer)).hasSmokeTests(hasSmokeTests).versionPath(surfaceNamer.getVersionIndexFileImportName()).versionNamespace(validVersionNamespace(interfaceModels, surfaceNamer)).credentialsClassName(surfaceNamer.getFullyQualifiedCredentialsClassName()).smokeTestProjectVariable(namer.getProjectVariable(true)).smokeTestKeyfileVariable(namer.getKeyfileVariable(true)).smokeTestJsonKeyVariable(namer.getJsonKeyVariable(true)).projectVariable(namer.getProjectVariable(false)).jsonKeyVariable(namer.getJsonKeyVariable(false)).build();
}
Also used : PackageMetadataConfig(com.google.api.codegen.config.PackageMetadataConfig) GapicMethodContext(com.google.api.codegen.config.GapicMethodContext) TestCaseTransformer(com.google.api.codegen.transformer.TestCaseTransformer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView) RubyTypeTable(com.google.api.codegen.util.ruby.RubyTypeTable) FlatteningConfig(com.google.api.codegen.config.FlatteningConfig) HashSet(java.util.HashSet) InterfaceContext(com.google.api.codegen.config.InterfaceContext) Strings(com.google.common.base.Strings) ImmutableList(com.google.common.collect.ImmutableList) MethodModel(com.google.api.codegen.config.MethodModel) ViewModel(com.google.api.codegen.viewmodel.ViewModel) ModelTypeTable(com.google.api.codegen.transformer.ModelTypeTable) TargetLanguage(com.google.api.codegen.common.TargetLanguage) ValueProducer(com.google.api.codegen.util.testing.ValueProducer) PackageMetadataTransformer(com.google.api.codegen.transformer.PackageMetadataTransformer) InitCodeView(com.google.api.codegen.viewmodel.InitCodeView) ImmutableSet(com.google.common.collect.ImmutableSet) OptionalArrayMethodView(com.google.api.codegen.viewmodel.OptionalArrayMethodView) TocContentView(com.google.api.codegen.viewmodel.metadata.TocContentView) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) StandardValueProducer(com.google.api.codegen.util.testing.StandardValueProducer) Collection(java.util.Collection) Set(java.util.Set) FileHeaderTransformer(com.google.api.codegen.transformer.FileHeaderTransformer) PackageDependencyView(com.google.api.codegen.viewmodel.metadata.PackageDependencyView) ApiMethodView(com.google.api.codegen.viewmodel.ApiMethodView) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) DynamicLangApiMethodTransformer(com.google.api.codegen.transformer.DynamicLangApiMethodTransformer) InitCodeTransformer(com.google.api.codegen.transformer.InitCodeTransformer) List(java.util.List) ApiModel(com.google.api.codegen.config.ApiModel) InterfaceModel(com.google.api.codegen.config.InterfaceModel) ReadmeMetadataView(com.google.api.codegen.viewmodel.metadata.ReadmeMetadataView) InterfaceConfig(com.google.api.codegen.config.InterfaceConfig) ModelToViewTransformer(com.google.api.codegen.transformer.ModelToViewTransformer) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) InterfaceContext(com.google.api.codegen.config.InterfaceContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) InterfaceModel(com.google.api.codegen.config.InterfaceModel) Objects(java.util.Objects) SurfaceNamer(com.google.api.codegen.transformer.SurfaceNamer) ImportSectionView(com.google.api.codegen.viewmodel.ImportSectionView)

Aggregations

ImportSectionView (com.google.api.codegen.viewmodel.ImportSectionView)20 SurfaceNamer (com.google.api.codegen.transformer.SurfaceNamer)13 GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)9 InterfaceModel (com.google.api.codegen.config.InterfaceModel)8 ModelTypeTable (com.google.api.codegen.transformer.ModelTypeTable)5 ImmutableList (com.google.common.collect.ImmutableList)5 ClientTestClassView (com.google.api.codegen.viewmodel.testing.ClientTestClassView)4 FlatteningConfig (com.google.api.codegen.config.FlatteningConfig)3 GapicMethodContext (com.google.api.codegen.config.GapicMethodContext)3 MethodModel (com.google.api.codegen.config.MethodModel)3 InitCodeView (com.google.api.codegen.viewmodel.InitCodeView)3 ViewModel (com.google.api.codegen.viewmodel.ViewModel)3 OutputContext (com.google.api.codegen.config.OutputContext)2 OptionalArrayMethodView (com.google.api.codegen.viewmodel.OptionalArrayMethodView)2 ClientTestFileView (com.google.api.codegen.viewmodel.testing.ClientTestFileView)2 MockServiceImplView (com.google.api.codegen.viewmodel.testing.MockServiceImplView)2 ArrayList (java.util.ArrayList)2 OutputSpec (com.google.api.codegen.OutputSpec)1 SampleValueSet (com.google.api.codegen.SampleValueSet)1 TargetLanguage (com.google.api.codegen.common.TargetLanguage)1