use of com.google.api.codegen.viewmodel.metadata.SampleManifestView in project toolkit by googleapis.
the class SampleManifestTransformer method transform.
@Override
public List<ViewModel> transform(ProtoApiModel model, GapicProductConfig productConfig) {
SurfaceNamer surfaceNamer = newSurfaceNamer.apply(productConfig);
ModelTypeTable typeTable = newTypeTable.apply(productConfig.getPackageName());
FeatureConfig featureConfig = newFeatureConfig.apply(productConfig);
ImmutableList.Builder<SampleManifestView.SampleEntry> builder = ImmutableList.builder();
List<InterfaceContext> interfaceContexts = Streams.stream(model.getInterfaces(productConfig)).filter(iface -> productConfig.hasInterfaceConfig(iface)).map(iface -> GapicInterfaceContext.create(iface, productConfig, typeTable, surfaceNamer, featureConfig)).collect(ImmutableList.toImmutableList());
List<SampleContext> sampleContexts = metadataNamer.getSampleContexts(interfaceContexts, productConfig);
for (SampleContext context : sampleContexts) {
String sample = context.uniqueSampleId();
String path = metadataNamer.getSamplePath(sample);
String regionTag = context.sampleConfig().regionTag();
String className = metadataNamer.getSampleClassName(sample);
builder.add(SampleManifestView.SampleEntry.create(sample, path, className, regionTag));
}
ImmutableList<SampleManifestView.SampleEntry> entries = builder.build();
// Only generate manifest files when samples are configured through sample config.
if (entries.isEmpty()) {
return Collections.emptyList();
}
SampleManifestView.Builder sampleManifestView = SampleManifestView.newBuilder();
sampleManifestView.environment(metadataNamer.getEnvironment());
sampleManifestView.bin(metadataNamer.getBin());
sampleManifestView.basePath(metadataNamer.getBasePath(productConfig));
sampleManifestView.packageName(metadataNamer.getPackageName(productConfig));
sampleManifestView.invocation(metadataNamer.getInvocation());
sampleManifestView.schemaVersion(MANIFEST_SCHEMA_VERSION);
sampleManifestView.sampleEntries(entries);
sampleManifestView.outputPath(getManifestOutputPath(model, productConfig));
sampleManifestView.templateFileName(TEMPLATE_NAME);
return Collections.singletonList(sampleManifestView.build());
}
Aggregations