templating icon indicating copy to clipboard operation
templating copied to clipboard

changes to `IGenerator` APIs to enable validation

Open vlada-shubina opened this issue 3 years ago • 1 comments

Solution

follow up on: https://github.com/dotnet/templating/pull/5329

Abstractions

  • improved IGenerator APIs
    • IReadOnlyList<IScanTemplateInfo> GetTemplatesFromMountPoint(IMountPoint source);
    • bool TryLoadTemplateFromTemplateInfo(IEngineEnvironmentSettings settings, ITemplateLocator config, out ITemplate? template, string? baselineName = null);
  • IScanTemplateInfo - new interface representing found templates during scanning
  • ITemplateLocator \ IExtendedTemplateLocator representing the template to be loaded (with selected loc and host file)
  • IValidationEntry - new interface representing generic validation entry
  • exposed validation errors in ITemplate and IScanTemplateInfo

Orchestrator.RunnableProjects

To get ready for validation, the correct entry point for it is needed. TemplateConfigModel is not sufficient, as it doesn't know about template sources. RunnableProjectConfig is already overloaded. I created an abstract intermediate layer for it: DirectoryBasedTemplate. This class will also implement validation further on. There ate 2 implementations of DirectoryBasedTemplate

  • ScannedTemplateInfo - lightweight implementation containing info about all localization available. It is used as the result of template scanning but it is not ready to be run (IScanTemplateInfo). Now returns all localizations and all found host files (and Edge is processing host files).
  • RunnableProjectConfig - remains entry point for running the template (remains ITemplate) and holds mount point for template sources, therefore needs to be disposed.

Checks:

  • [ ] Added unit tests
  • [x] Added #nullable enable to all the modified files ?

vlada-shubina avatar Oct 11 '22 15:10 vlada-shubina

https://github.com/dotnet/templating/pull/5398/commits/cdf377e1d7d8b7fcf674e13aa819206adc5ccb18 changes APIs to be async:

  • both new methods may be long running (especially scanning) and async processing may be of benefit
  • validation logic will be partially async, therefore need async methods not to block the calls

vlada-shubina avatar Oct 12 '22 21:10 vlada-shubina