From 7a846e7869b2705fa0a184224ef53e2d89f2e8dd Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 14 Jun 2020 11:22:58 +1000 Subject: Add IBurnBackendHelper and TryAddTupleToDataManifest. --- .../BaseBurnBackendExtension.cs | 24 ++++++++++- .../IBurnBackendExtension.cs | 12 ++++++ .../Services/IBurnBackendHelper.cs | 50 ++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/WixToolset.Extensibility/Services/IBurnBackendHelper.cs (limited to 'src') diff --git a/src/WixToolset.Extensibility/BaseBurnBackendExtension.cs b/src/WixToolset.Extensibility/BaseBurnBackendExtension.cs index 58f96b31..5dc36715 100644 --- a/src/WixToolset.Extensibility/BaseBurnBackendExtension.cs +++ b/src/WixToolset.Extensibility/BaseBurnBackendExtension.cs @@ -6,7 +6,7 @@ namespace WixToolset.Extensibility using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; - public class BaseBurnBackendExtension : IBurnBackendExtension + public abstract class BaseBurnBackendExtension : IBurnBackendExtension { /// /// Context for use by the extension. @@ -18,10 +18,20 @@ namespace WixToolset.Extensibility /// protected IMessaging Messaging { get; private set; } + /// + /// Backend helper for use by the extension. + /// + protected IBurnBackendHelper BackendHelper { get; private set; } + public virtual void BundleFinalize() { } + public virtual bool IsTupleForExtension(IntermediateTuple tuple) + { + return false; + } + public virtual void PostBackendBind(IBindResult result) { } @@ -30,6 +40,7 @@ namespace WixToolset.Extensibility { this.Context = context; this.Messaging = context.ServiceProvider.GetService(); + this.BackendHelper = context.ServiceProvider.GetService(); } public virtual IResolveFileResult ResolveRelatedFile(string source, string relatedSource, string type, SourceLineNumber sourceLineNumbers, BindStage bindStage) @@ -41,5 +52,16 @@ namespace WixToolset.Extensibility { return null; } + + public virtual bool TryAddTupleToDataManifest(IntermediateSection section, IntermediateTuple tuple) + { + if (this.IsTupleForExtension(tuple) && tuple.HasTag(WixToolset.Data.Burn.BurnConstants.BootstrapperApplicationDataTupleDefinitionTag)) + { + this.BackendHelper.AddBootstrapperApplicationData(tuple); + return true; + } + + return false; + } } } diff --git a/src/WixToolset.Extensibility/IBurnBackendExtension.cs b/src/WixToolset.Extensibility/IBurnBackendExtension.cs index 569d8d10..d5f71107 100644 --- a/src/WixToolset.Extensibility/IBurnBackendExtension.cs +++ b/src/WixToolset.Extensibility/IBurnBackendExtension.cs @@ -16,6 +16,18 @@ namespace WixToolset.Extensibility string ResolveUrl(string url, string fallbackUrl, string packageId, string payloadId, string fileName); + /// + /// Called for each extension tuple that hasn't been handled yet. + /// Use IBurnBackendHelper to add data to the appropriate data manifest. + /// + /// The linked section. + /// The current tuple. + /// + /// True if the extension handled the tuple, false otherwise. + /// The Burn backend will warn on all unhandled tuples. + /// + bool TryAddTupleToDataManifest(IntermediateSection section, IntermediateTuple tuple); + /// /// Called after all output changes occur and right before the output is bound into its final format. /// diff --git a/src/WixToolset.Extensibility/Services/IBurnBackendHelper.cs b/src/WixToolset.Extensibility/Services/IBurnBackendHelper.cs new file mode 100644 index 00000000..f6ba7a8f --- /dev/null +++ b/src/WixToolset.Extensibility/Services/IBurnBackendHelper.cs @@ -0,0 +1,50 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Extensibility.Services +{ + using WixToolset.Data; + + /// + /// Interface provided to help Burn backend extensions. + /// + public interface IBurnBackendHelper + { + /// + /// Adds the given XML to the BootstrapperApplicationData manifest. + /// + /// A valid XML fragment. + void AddBootstrapperApplicationData(string xml); + + /// + /// Adds an XML element for the given tuple to the BootstrapperApplicationData manifest. + /// The tuple's name is used for the element's name. + /// All of the tuple's fields are used for the element's attributes. + /// + /// The tuple to create the element from. + /// + /// If true and the tuple has an Id, + /// then an Id attribute is created with a value of the tuple's Id. + /// + void AddBootstrapperApplicationData(IntermediateTuple tuple, bool tupleIdIsIdAttribute = false); + + /// + /// Adds the given XML to the BundleExtensionData manifest for the given bundle extension. + /// + /// The bundle extension's id. + /// A valid XML fragment. + void AddBundleExtensionData(string extensionId, string xml); + + /// + /// Adds an XML element for the given tuple to the BundleExtensionData manifest for the given bundle extension. + /// The tuple's name is used for the element's name. + /// All of the tuple's fields are used for the element's attributes. + /// + /// The bundle extension's id. + /// The tuple to create the element from. + /// + /// If true and the tuple has an Id, + /// then an Id attribute is created with a value of the tuple's Id. + /// + void AddBundleExtensionData(string extensionId, IntermediateTuple tuple, bool tupleIdIsIdAttribute = false); + } +} -- cgit v1.2.3-55-g6feb