From 86b7ea7a411813e03a2b238ca5c24fcebc947209 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 12 Jun 2020 12:46:48 -0700 Subject: Move validate guids to a command and execute it earlier --- .../Bind/BindDatabaseCommand.cs | 49 ++--------------- .../Bind/ValidateComponentGuidsCommand.cs | 63 ++++++++++++++++++++++ 2 files changed, 68 insertions(+), 44 deletions(-) create mode 100644 src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs index 65e4bf13..e0dd2b96 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs @@ -319,6 +319,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind command.Execute(); } + { + var command = new ValidateComponentGuidsCommand(this.Messaging, section); + command.Execute(); + } + // Add missing CreateFolder tuples to null-keypath components. { var command = new AddCreateFoldersCommand(section); @@ -407,8 +412,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind } #endif - this.ValidateComponentGuids(output); - // Stop processing if an error previously occurred. if (this.Messaging.EncounteredError) { @@ -579,48 +582,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind return wixout; } - /// - /// Validate that there are no duplicate GUIDs in the output. - /// - /// - /// Duplicate GUIDs without conditions are an error condition; with conditions, it's a - /// warning, as the conditions might be mutually exclusive. - /// - private void ValidateComponentGuids(WindowsInstallerData output) - { - if (output.TryGetTable("Component", out var componentTable)) - { - var componentGuidConditions = new Dictionary(componentTable.Rows.Count); - - foreach (Data.WindowsInstaller.Rows.ComponentRow row in componentTable.Rows) - { - // We don't care about unmanaged components and if there's a * GUID remaining, - // there's already an error that prevented it from being replaced with a real GUID. - if (!String.IsNullOrEmpty(row.Guid) && "*" != row.Guid) - { - var thisComponentHasCondition = !String.IsNullOrEmpty(row.Condition); - var allComponentsHaveConditions = thisComponentHasCondition; - - if (componentGuidConditions.ContainsKey(row.Guid)) - { - allComponentsHaveConditions = thisComponentHasCondition && componentGuidConditions[row.Guid]; - - if (allComponentsHaveConditions) - { - this.Messaging.Write(WarningMessages.DuplicateComponentGuidsMustHaveMutuallyExclusiveConditions(row.SourceLineNumbers, row.Component, row.Guid)); - } - else - { - this.Messaging.Write(ErrorMessages.DuplicateComponentGuids(row.SourceLineNumbers, row.Component, row.Guid)); - } - } - - componentGuidConditions[row.Guid] = allComponentsHaveConditions; - } - } - } - } - private string ResolveMedia(MediaTuple media, string mediaLayoutDirectory, string layoutDirectory) { string layout = null; diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs new file mode 100644 index 00000000..020a83fc --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs @@ -0,0 +1,63 @@ +// 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.Core.WindowsInstaller.Bind +{ + using System; + using System.Collections.Generic; + using System.Linq; + using WixToolset.Data; + using WixToolset.Data.Tuples; + using WixToolset.Extensibility.Services; + + /// + /// Validate that there are no duplicate GUIDs in the output. + /// + /// + /// Duplicate GUIDs without conditions are an error condition; with conditions, it's a + /// warning, as the conditions might be mutually exclusive. + /// + internal class ValidateComponentGuidsCommand + { + internal ValidateComponentGuidsCommand(IMessaging messaging, IntermediateSection section) + { + this.Messaging = messaging; + this.Section = section; + } + + private IMessaging Messaging { get; } + + private IntermediateSection Section { get; } + + public void Execute() + { + var componentGuidConditions = new Dictionary(); + + foreach (var componentTuple in this.Section.Tuples.OfType()) + { + // We don't care about unmanaged components and if there's a * GUID remaining, + // there's already an error that prevented it from being replaced with a real GUID. + if (!String.IsNullOrEmpty(componentTuple.ComponentId) && "*" != componentTuple.ComponentId) + { + var thisComponentHasCondition = !String.IsNullOrEmpty(componentTuple.Condition); + var allComponentsHaveConditions = thisComponentHasCondition; + + if (componentGuidConditions.TryGetValue(componentTuple.ComponentId, out var alreadyCheckedCondition)) + { + allComponentsHaveConditions = thisComponentHasCondition && alreadyCheckedCondition; + + if (allComponentsHaveConditions) + { + this.Messaging.Write(WarningMessages.DuplicateComponentGuidsMustHaveMutuallyExclusiveConditions(componentTuple.SourceLineNumbers, componentTuple.Id.Id, componentTuple.ComponentId)); + } + else + { + this.Messaging.Write(ErrorMessages.DuplicateComponentGuids(componentTuple.SourceLineNumbers, componentTuple.Id.Id, componentTuple.ComponentId)); + } + } + + componentGuidConditions[componentTuple.ComponentId] = allComponentsHaveConditions; + } + } + } + } +} -- cgit v1.2.3-55-g6feb