From db22d99a4d603caab18fd42cb40881431c353912 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Tue, 15 Mar 2022 18:09:12 -0500 Subject: Enhance bundle backend validation. --- src/api/wix/WixToolset.Data/ErrorMessages.cs | 6 +++ src/api/wix/WixToolset.Data/WarningMessages.cs | 6 +++ .../Data/BundleConditionPhase.cs | 35 ++++++++++++++ .../Services/IBackendHelper.cs | 11 ----- .../Services/IBundleValidator.cs | 56 ++++++++++++++++++++++ .../Services/IBurnBackendHelper.cs | 2 +- .../Services/IParseHelper.cs | 13 +---- 7 files changed, 105 insertions(+), 24 deletions(-) create mode 100644 src/api/wix/WixToolset.Extensibility/Data/BundleConditionPhase.cs create mode 100644 src/api/wix/WixToolset.Extensibility/Services/IBundleValidator.cs (limited to 'src/api') diff --git a/src/api/wix/WixToolset.Data/ErrorMessages.cs b/src/api/wix/WixToolset.Data/ErrorMessages.cs index 80738f5e..a833452d 100644 --- a/src/api/wix/WixToolset.Data/ErrorMessages.cs +++ b/src/api/wix/WixToolset.Data/ErrorMessages.cs @@ -1184,6 +1184,11 @@ namespace WixToolset.Data return Message(null, Ids.InvalidCommandLineFileName, "Invalid file name specified on the command line: '{0}'. Error message: '{1}'", fileName, error); } + public static Message InvalidBundleCondition(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string condition) + { + return Message(sourceLineNumbers, Ids.InvalidBundleCondition, "The {0}/@{1} attribute's value '{2}' is not a valid bundle condition.", elementName, attributeName, condition); + } + public static Message InvalidDateTimeFormat(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string value) { return Message(sourceLineNumbers, Ids.InvalidDateTimeFormat, "The {0}/@{1} attribute's value '{2}' is not a valid date/time value. A date/time value should follow the format YYYY-MM-DDTHH:mm:ss.", elementName, attributeName, value); @@ -2686,6 +2691,7 @@ namespace WixToolset.Data MultiplePackagePayloads3 = 406, MissingPackagePayload = 407, ExpectedAttributeWithoutOtherAttributes = 408, + InvalidBundleCondition = 409, } } } diff --git a/src/api/wix/WixToolset.Data/WarningMessages.cs b/src/api/wix/WixToolset.Data/WarningMessages.cs index b749bcf4..f555fd93 100644 --- a/src/api/wix/WixToolset.Data/WarningMessages.cs +++ b/src/api/wix/WixToolset.Data/WarningMessages.cs @@ -593,6 +593,11 @@ namespace WixToolset.Data return Message(null, Ids.UnableToResetAcls, "Unable to reset acls on destination files. Exception detail: {0}", error); } + public static Message UnavailableBundleConditionVariable(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string variable, string illegalValueList) + { + return Message(sourceLineNumbers, Ids.UnavailableBundleConditionVariable, "{0}/@{1} contains the built-in Variable '{2}', which is not available when it is evaluated. (Unavailable Variables are: {3}.). Rewrite the condition to avoid Variables that are never valid during its evaluation.", elementName, attributeName, variable, illegalValueList); + } + public static Message UnclearShortcut(SourceLineNumber sourceLineNumbers, string shortcutId, string fileId, string componentId) { return Message(sourceLineNumbers, Ids.UnclearShortcut, "Because it is an advertised shortcut, the target of shortcut '{0}' will be the keypath of component '{2}' rather than parent file '{1}'. To eliminate this warning, you can (1) make the Shortcut element a child of the File element that is the keypath of component '{2}', (2) make file '{1}' the keypath of component '{2}', or (3) remove the @Advertise attribute so the shortcut is a non-advertised shortcut.", shortcutId, fileId, componentId); @@ -804,6 +809,7 @@ namespace WixToolset.Data DetectConditionRecommended = 1153, CollidingModularizationTypes = 1156, InvalidEnvironmentVariable = 1157, + UnavailableBundleConditionVariable = 1159, } } } diff --git a/src/api/wix/WixToolset.Extensibility/Data/BundleConditionPhase.cs b/src/api/wix/WixToolset.Extensibility/Data/BundleConditionPhase.cs new file mode 100644 index 00000000..6d876bcc --- /dev/null +++ b/src/api/wix/WixToolset.Extensibility/Data/BundleConditionPhase.cs @@ -0,0 +1,35 @@ +// 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.Data +{ + /// + /// The Burn execution phase during which a Condition will be evaluated. + /// + public enum BundleConditionPhase + { + /// + /// Condition is evaluated by the engine before loading the BootstrapperApplication (Bundle/@Condition). + /// + Startup, + + /// + /// Condition is evaluated during Detect (ExePackage/@DetectCondition). + /// + Detect, + + /// + /// Condition is evaluated during Plan (ExePackage/@InstallCondition). + /// + Plan, + + /// + /// Condition is evaluated during Apply (MsiProperty/@Condition). + /// + Execute, + + /// + /// Condition is evaluated after Apply. + /// + Shutdown, + } +} diff --git a/src/api/wix/WixToolset.Extensibility/Services/IBackendHelper.cs b/src/api/wix/WixToolset.Extensibility/Services/IBackendHelper.cs index 29b8f8e6..23ad44f5 100644 --- a/src/api/wix/WixToolset.Extensibility/Services/IBackendHelper.cs +++ b/src/api/wix/WixToolset.Extensibility/Services/IBackendHelper.cs @@ -73,17 +73,6 @@ namespace WixToolset.Extensibility.Services /// The generated identifier. string GenerateIdentifier(string prefix, params string[] args); - /// - /// Validates path is relative and canonicalizes it. - /// For example, "a\..\c\.\d.exe" => "c\d.exe". - /// - /// - /// - /// - /// - /// The original value if not relative, otherwise the canonicalized relative path. - string GetCanonicalRelativePath(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string relativePath); - /// /// Gets a valid code page from the given web name or integer value. /// diff --git a/src/api/wix/WixToolset.Extensibility/Services/IBundleValidator.cs b/src/api/wix/WixToolset.Extensibility/Services/IBundleValidator.cs new file mode 100644 index 00000000..fc88a443 --- /dev/null +++ b/src/api/wix/WixToolset.Extensibility/Services/IBundleValidator.cs @@ -0,0 +1,56 @@ +// 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; + using WixToolset.Extensibility.Data; + + /// + /// Interface provided to help with bundle validation. + /// + public interface IBundleValidator + { + + /// + /// Validates path is relative and canonicalizes it. + /// For example, "a\..\c\.\d.exe" => "c\d.exe". + /// + /// + /// + /// + /// + /// The original value if not relative, otherwise the canonicalized relative path. + string GetCanonicalRelativePath(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string relativePath); + + /// + /// Validates an MsiProperty name value and displays an error for an illegal value. + /// + /// + /// + /// + /// + /// Whether the name is valid. + bool ValidateBundleMsiPropertyName(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string propertyName); + + /// + /// Validates a Bundle variable name and displays an error for an illegal value. + /// + /// + /// + /// + /// + /// Whether the name is valid. + bool ValidateBundleVariableName(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string variableName); + + /// + /// Validates a bundle condition and displays an error for an illegal value. + /// + /// + /// + /// + /// + /// + /// Whether the condition is valid. + bool ValidateBundleCondition(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string condition, BundleConditionPhase phase); + } +} diff --git a/src/api/wix/WixToolset.Extensibility/Services/IBurnBackendHelper.cs b/src/api/wix/WixToolset.Extensibility/Services/IBurnBackendHelper.cs index ef5fcc65..1b6a2828 100644 --- a/src/api/wix/WixToolset.Extensibility/Services/IBurnBackendHelper.cs +++ b/src/api/wix/WixToolset.Extensibility/Services/IBurnBackendHelper.cs @@ -7,7 +7,7 @@ namespace WixToolset.Extensibility.Services /// /// Interface provided to help Burn backend extensions. /// - public interface IBurnBackendHelper : IBackendHelper + public interface IBurnBackendHelper : IBackendHelper, IBundleValidator { /// /// Adds the given XML to the BootstrapperApplicationData manifest. diff --git a/src/api/wix/WixToolset.Extensibility/Services/IParseHelper.cs b/src/api/wix/WixToolset.Extensibility/Services/IParseHelper.cs index fbe5aae4..de2c6f9f 100644 --- a/src/api/wix/WixToolset.Extensibility/Services/IParseHelper.cs +++ b/src/api/wix/WixToolset.Extensibility/Services/IParseHelper.cs @@ -13,7 +13,7 @@ namespace WixToolset.Extensibility.Services /// /// Interface provided to help compiler extensions parse. /// - public interface IParseHelper + public interface IParseHelper : IBundleValidator { /// /// Creates a version 3 name-based UUID. @@ -322,17 +322,6 @@ namespace WixToolset.Extensibility.Services /// The attribute's YesNoType value. YesNoDefaultType GetAttributeYesNoDefaultValue(SourceLineNumber sourceLineNumbers, XAttribute attribute); - /// - /// Validates path is relative and canonicalizes it. - /// For example, "a\..\c\.\d.exe" => "c\d.exe". - /// - /// - /// - /// - /// - /// The original value if not relative, otherwise the canonicalized relative path. - string GetCanonicalRelativePath(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string relativePath); - /// /// Gets a source line number for an element. /// -- cgit v1.2.3-55-g6feb