@joebigelow / wix-1 / commits / 7a846e78

Add IBurnBackendHelper and TryAddTupleToDataManifest.

Sean Hall committed Jun 14, 2020 at 11:22 UTC 7a846e7869b2705fa0a184224ef53e2d89f2e8dd
3 files changed +85 -1
src/WixToolset.Extensibility/BaseBurnBackendExtension.cs
+23 -1
@@ -6,7 +6,7 @@ namespace WixToolset.Extensibility
6 using WixToolset.Extensibility.Data;
7 using WixToolset.Extensibility.Services;
8
9 - public class BaseBurnBackendExtension : IBurnBackendExtension
9 + public abstract class BaseBurnBackendExtension : IBurnBackendExtension
10 {
11 /// <summary>
12 /// Context for use by the extension.
@@ -18,10 +18,20 @@ namespace WixToolset.Extensibility
18 /// </summary>
19 protected IMessaging Messaging { get; private set; }
20
21 + /// <summary>
22 + /// Backend helper for use by the extension.
23 + /// </summary>
24 + protected IBurnBackendHelper BackendHelper { get; private set; }
25 +
26 public virtual void BundleFinalize()
27 {
28 }
29
30 + public virtual bool IsTupleForExtension(IntermediateTuple tuple)
31 + {
32 + return false;
33 + }
34 +
35 public virtual void PostBackendBind(IBindResult result)
36 {
37 }
@@ -30,6 +40,7 @@ namespace WixToolset.Extensibility
40 {
41 this.Context = context;
42 this.Messaging = context.ServiceProvider.GetService<IMessaging>();
43 + this.BackendHelper = context.ServiceProvider.GetService<IBurnBackendHelper>();
44 }
45
46 public virtual IResolveFileResult ResolveRelatedFile(string source, string relatedSource, string type, SourceLineNumber sourceLineNumbers, BindStage bindStage)
@@ -41,5 +52,16 @@ namespace WixToolset.Extensibility
52 {
53 return null;
54 }
55 +
56 + public virtual bool TryAddTupleToDataManifest(IntermediateSection section, IntermediateTuple tuple)
57 + {
58 + if (this.IsTupleForExtension(tuple) && tuple.HasTag(WixToolset.Data.Burn.BurnConstants.BootstrapperApplicationDataTupleDefinitionTag))
59 + {
60 + this.BackendHelper.AddBootstrapperApplicationData(tuple);
61 + return true;
62 + }
63 +
64 + return false;
65 + }
66 }
67 }
src/WixToolset.Extensibility/IBurnBackendExtension.cs
+12
@@ -16,6 +16,18 @@ namespace WixToolset.Extensibility
16
17 string ResolveUrl(string url, string fallbackUrl, string packageId, string payloadId, string fileName);
18
19 + /// <summary>
20 + /// Called for each extension tuple that hasn't been handled yet.
21 + /// Use IBurnBackendHelper to add data to the appropriate data manifest.
22 + /// </summary>
23 + /// <param name="section">The linked section.</param>
24 + /// <param name="tuple">The current tuple.</param>
25 + /// <returns>
26 + /// True if the extension handled the tuple, false otherwise.
27 + /// The Burn backend will warn on all unhandled tuples.
28 + /// </returns>
29 + bool TryAddTupleToDataManifest(IntermediateSection section, IntermediateTuple tuple);
30 +
31 /// <summary>
32 /// Called after all output changes occur and right before the output is bound into its final format.
33 /// </summary>
src/WixToolset.Extensibility/Services/IBurnBackendHelper.cs new
+50
@@ -0,0 +1,50 @@
1 +// 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.
2 +
3 +namespace WixToolset.Extensibility.Services
4 +{
5 + using WixToolset.Data;
6 +
7 + /// <summary>
8 + /// Interface provided to help Burn backend extensions.
9 + /// </summary>
10 + public interface IBurnBackendHelper
11 + {
12 + /// <summary>
13 + /// Adds the given XML to the BootstrapperApplicationData manifest.
14 + /// </summary>
15 + /// <param name="xml">A valid XML fragment.</param>
16 + void AddBootstrapperApplicationData(string xml);
17 +
18 + /// <summary>
19 + /// Adds an XML element for the given tuple to the BootstrapperApplicationData manifest.
20 + /// The tuple's name is used for the element's name.
21 + /// All of the tuple's fields are used for the element's attributes.
22 + /// </summary>
23 + /// <param name="tuple">The tuple to create the element from.</param>
24 + /// <param name="tupleIdIsIdAttribute">
25 + /// If true and the tuple has an Id,
26 + /// then an Id attribute is created with a value of the tuple's Id.
27 + /// </param>
28 + void AddBootstrapperApplicationData(IntermediateTuple tuple, bool tupleIdIsIdAttribute = false);
29 +
30 + /// <summary>
31 + /// Adds the given XML to the BundleExtensionData manifest for the given bundle extension.
32 + /// </summary>
33 + /// <param name="extensionId">The bundle extension's id.</param>
34 + /// <param name="xml">A valid XML fragment.</param>
35 + void AddBundleExtensionData(string extensionId, string xml);
36 +
37 + /// <summary>
38 + /// Adds an XML element for the given tuple to the BundleExtensionData manifest for the given bundle extension.
39 + /// The tuple's name is used for the element's name.
40 + /// All of the tuple's fields are used for the element's attributes.
41 + /// </summary>
42 + /// <param name="extensionId">The bundle extension's id.</param>
43 + /// <param name="tuple">The tuple to create the element from.</param>
44 + /// <param name="tupleIdIsIdAttribute">
45 + /// If true and the tuple has an Id,
46 + /// then an Id attribute is created with a value of the tuple's Id.
47 + /// </param>
48 + void AddBundleExtensionData(string extensionId, IntermediateTuple tuple, bool tupleIdIsIdAttribute = false);
49 + }
50 +}