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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations