Class TemplateDescriptorsBuilder

java.lang.Object
com.azure.runtime.host.utils.templates.TemplateDescriptorsBuilder

public class TemplateDescriptorsBuilder extends Object
Facilitates the construction of template descriptors for processing template files. This builder pattern implementation allows for a fluent and intuitive way to specify multiple templates and their output paths, streamlining the setup for template processing.

The builder starts with a base template path and an optional output root path. Templates can be added with relative paths, and the builder will concatenate these paths with the base paths provided at the start. This design supports flexible template management, accommodating various project structures and output requirements.

Usage example:

List<TemplateDescriptor> descriptors = TemplateDescriptorsBuilder.begin("/templates/", "/output/")
    .with("configTemplate.bicep", "configOutput.bicep")
    .with("resourceTemplate.bicep", "resourceOutput.bicep")
    .build();
This example demonstrates setting up a builder to process templates located in the "/templates/" directory, with outputs directed to the "/output/" directory. Each call to with adds a new template descriptor to the list.
See Also:
  • Method Details

    • begin

      public static TemplateDescriptorsBuilder begin(String templatePath)
      Begins the process of specifying template files to be processed, which will be written to the root of the user-specified output directory by default.
      Parameters:
      templatePath - The path to the template files, relative to the root of the jar file / the resources directory.
      Returns:
      A new TemplateDescriptorsBuilder instance that can then be used to specify the template files to be processed.
    • begin

      public static TemplateDescriptorsBuilder begin(String templatePath, String outputRootPath)
      Begins the process of specifying template files to be processed.
      Parameters:
      templatePath - The path to the template files, relative to the root of the jar file / the resources directory.
      outputRootPath - The root path where the output files will be written to, relative to the user-specified output directory.
      Returns:
      A new TemplateDescriptorsBuilder instance that can then be used to specify the template files to be processed.
    • with

      public TemplateDescriptorsBuilder with(String inputFilename)
      Adds a template file to the list of descriptors with the same input and output filename, appended to the previously specified base paths.
      Parameters:
      inputFilename - The filename of the template file, relative to the base template path.
      Returns:
      This builder instance to allow for method chaining.
    • with

      public TemplateDescriptorsBuilder with(String inputFilename, String outputFilename)
      Adds a template file to the list of descriptors with specified input and output filenames, appended to the previously specified base paths.
      Parameters:
      inputFilename - The filename of the template file, relative to the base template path.
      outputFilename - The filename for the output file, relative to the base output path.
      Returns:
      This builder instance to allow for method chaining.
    • build

      public List<TemplateDescriptor> build()
      Completes the building process and returns the list of configured template descriptors.
      Returns:
      A list of TemplateDescriptor instances ready for template processing.