Search in sources :

Example 1 with SampleManifestView

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());
}
Also used : GapicCodePathMapper(com.google.api.codegen.gapic.GapicCodePathMapper) SampleContext(com.google.api.codegen.config.SampleContext) Streams(com.google.common.collect.Streams) Function(java.util.function.Function) GapicProductConfig(com.google.api.codegen.config.GapicProductConfig) InterfaceContext(com.google.api.codegen.config.InterfaceContext) ProtoApiModel(com.google.api.codegen.config.ProtoApiModel) SampleManifestView(com.google.api.codegen.viewmodel.metadata.SampleManifestView) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Paths(java.nio.file.Paths) ViewModel(com.google.api.codegen.viewmodel.ViewModel) VersionMatcher(com.google.api.codegen.util.VersionMatcher) Splitter(com.google.common.base.Splitter) Collections(java.util.Collections) ImmutableList(com.google.common.collect.ImmutableList) InterfaceContext(com.google.api.codegen.config.InterfaceContext) GapicInterfaceContext(com.google.api.codegen.config.GapicInterfaceContext) SampleManifestView(com.google.api.codegen.viewmodel.metadata.SampleManifestView) SampleContext(com.google.api.codegen.config.SampleContext)

Aggregations

GapicInterfaceContext (com.google.api.codegen.config.GapicInterfaceContext)1 GapicProductConfig (com.google.api.codegen.config.GapicProductConfig)1 InterfaceContext (com.google.api.codegen.config.InterfaceContext)1 ProtoApiModel (com.google.api.codegen.config.ProtoApiModel)1 SampleContext (com.google.api.codegen.config.SampleContext)1 GapicCodePathMapper (com.google.api.codegen.gapic.GapicCodePathMapper)1 VersionMatcher (com.google.api.codegen.util.VersionMatcher)1 ViewModel (com.google.api.codegen.viewmodel.ViewModel)1 SampleManifestView (com.google.api.codegen.viewmodel.metadata.SampleManifestView)1 Splitter (com.google.common.base.Splitter)1 ImmutableList (com.google.common.collect.ImmutableList)1 Streams (com.google.common.collect.Streams)1 Paths (java.nio.file.Paths)1 Collections (java.util.Collections)1 List (java.util.List)1 Function (java.util.function.Function)1