From 155a6e96346e0cb3d9ab6f5372fa29b46ebaee89 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 19 Dec 2017 12:25:40 -0800 Subject: Integrate simplified message handling --- .../ExtensibilityServices/ExtensionManager.cs | 113 ++++++++++++ .../ExtensibilityServices/Messaging.cs | 194 +++++++++++++++++++++ .../ExtensibilityServices/ParseHelper.cs | 66 +++---- .../ExtensibilityServices/PreprocessHelper.cs | 38 ++-- 4 files changed, 361 insertions(+), 50 deletions(-) create mode 100644 src/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs create mode 100644 src/WixToolset.Core/ExtensibilityServices/Messaging.cs (limited to 'src/WixToolset.Core/ExtensibilityServices') diff --git a/src/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs b/src/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs new file mode 100644 index 00000000..5714701a --- /dev/null +++ b/src/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs @@ -0,0 +1,113 @@ +// 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.ExtensibilityServices +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Reflection; + using WixToolset.Data; + using WixToolset.Extensibility; + using WixToolset.Extensibility.Services; + + internal class ExtensionManager : IExtensionManager + { + private List extensionFactories = new List(); + private Dictionary> loadedExtensionsByType = new Dictionary>(); + + public void Add(Assembly extensionAssembly) + { + var types = extensionAssembly.GetTypes().Where(t => !t.IsAbstract && !t.IsInterface && typeof(IExtensionFactory).IsAssignableFrom(t)); + var factories = types.Select(t => (IExtensionFactory)Activator.CreateInstance(t)).ToList(); + + this.extensionFactories.AddRange(factories); + } + + public void Load(string extensionPath) + { + Assembly assembly; + + // Absolute path to an assembly which means only "load from" will work even though we'd prefer to + // use Assembly.Load (see the documentation for Assembly.LoadFrom why). + if (Path.IsPathRooted(extensionPath)) + { + assembly = ExtensionManager.ExtensionLoadFrom(extensionPath); + } + else if (ExtensionManager.TryExtensionLoad(extensionPath, out assembly)) + { + // Loaded the assembly by name from the probing path. + } + else if (ExtensionManager.TryExtensionLoad(Path.GetFileNameWithoutExtension(extensionPath), out assembly)) + { + // Loaded the assembly by filename alone along the probing path. + } + else // relative path to an assembly + { + // We want to use Assembly.Load when we can because it has some benefits over Assembly.LoadFrom + // (see the documentation for Assembly.LoadFrom). However, it may fail when the path is a relative + // path, so we should try Assembly.LoadFrom one last time. We could have detected a directory + // separator character and used Assembly.LoadFrom directly, but dealing with path canonicalization + // issues is something we don't want to deal with if we don't have to. + assembly = ExtensionManager.ExtensionLoadFrom(extensionPath); + } + + this.Add(assembly); + } + + public IEnumerable Create() where T : class + { + if (!this.loadedExtensionsByType.TryGetValue(typeof(T), out var extensions)) + { + extensions = new List(); + + foreach (var factory in this.extensionFactories) + { + if (factory.TryCreateExtension(typeof(T), out var obj) && obj is T extension) + { + extensions.Add(extension); + } + } + + this.loadedExtensionsByType.Add(typeof(T), extensions); + } + + return extensions.Cast().ToList(); + } + + private static Assembly ExtensionLoadFrom(string assemblyName) + { + try + { + return Assembly.LoadFrom(assemblyName); + } + catch (Exception e) + { + throw new WixException(ErrorMessages.InvalidExtension(assemblyName, e.Message), e); + } + } + + private static bool TryExtensionLoad(string assemblyName, out Assembly assembly) + { + try + { + assembly = Assembly.Load(assemblyName); + return true; + } + catch (IOException innerE) + { + if (innerE is FileLoadException || innerE is FileNotFoundException) + { + assembly = null; + return false; + } + + throw new WixException(ErrorMessages.InvalidExtension(assemblyName, innerE.Message), innerE); + } + catch (Exception e) + { + throw new WixException(ErrorMessages.InvalidExtension(assemblyName, e.Message), e); + } + } + } +} diff --git a/src/WixToolset.Core/ExtensibilityServices/Messaging.cs b/src/WixToolset.Core/ExtensibilityServices/Messaging.cs new file mode 100644 index 00000000..4510f264 --- /dev/null +++ b/src/WixToolset.Core/ExtensibilityServices/Messaging.cs @@ -0,0 +1,194 @@ +// 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.ExtensibilityServices +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Text; + using WixToolset.Data; + using WixToolset.Extensibility; + using WixToolset.Extensibility.Services; + + internal class Messaging : IMessaging + { + private IMessageListener listener; + private HashSet suppressedWarnings = new HashSet(); + private HashSet warningsAsErrors = new HashSet(); + + public bool EncounteredError { get; private set; } + + public int LastErrorNumber { get; private set; } + + public bool ShowVerboseMessages { get; set; } + + public bool SuppressAllWarnings { get; set; } + + public bool WarningsAsError { get; set; } + + public void ElevateWarningMessage(int warningNumber) + { + this.warningsAsErrors.Add(warningNumber); + } + + public void SetListener(IMessageListener listener) + { + this.listener = listener; + } + + public void SuppressWarningMessage(int warningNumber) + { + this.suppressedWarnings.Add(warningNumber); + } + + public string FormatMessage(Message message) + { + var level = CalculateMessageLevel(message); + + if (level == MessageLevel.Nothing) + { + return String.Empty; + } + + var shortAppName = String.IsNullOrEmpty(this.listener?.ShortAppName) ? "WIX" : this.listener.ShortAppName; + var longAppName = String.IsNullOrEmpty(this.listener?.LongAppName) ? "WIX" : this.listener.LongAppName; + + var fileNames = new List(); + var errorFileName = longAppName; + for (var sln = message.SourceLineNumbers; null != sln; sln = sln.Parent) + { + if (String.IsNullOrEmpty(sln.FileName)) + { + continue; + } + else if (sln.LineNumber.HasValue) + { + if (fileNames.Count == 0) + { + errorFileName = String.Format(CultureInfo.CurrentUICulture, WixStrings.Format_FirstLineNumber, sln.FileName, sln.LineNumber); + } + + fileNames.Add(String.Format(CultureInfo.CurrentUICulture, WixStrings.Format_LineNumber, sln.FileName, sln.LineNumber)); + } + else + { + if (fileNames.Count == 0) + { + errorFileName = sln.FileName; + } + + fileNames.Add(sln.FileName); + } + } + + var levelString = String.Empty; + if (MessageLevel.Warning == level) + { + levelString = WixStrings.MessageType_Warning; + } + else if (MessageLevel.Error == level) + { + levelString = WixStrings.MessageType_Error; + } + + string formatted; + if (message.ResourceManager == null) + { + formatted = String.Format(CultureInfo.InvariantCulture, message.ResourceNameOrFormat, message.MessageArgs); + } + else + { + formatted = String.Format(CultureInfo.InvariantCulture, message.ResourceManager.GetString(message.ResourceNameOrFormat), message.MessageArgs); + } + + var builder = new StringBuilder(); + if (level == MessageLevel.Information || level == MessageLevel.Verbose) + { + builder.AppendFormat(WixStrings.Format_InfoMessage, formatted); + } + else + { + builder.AppendFormat(WixStrings.Format_NonInfoMessage, errorFileName, levelString, shortAppName, message.Id, formatted); + } + + if (fileNames.Count > 1) + { + builder.AppendFormat(WixStrings.INF_SourceTrace, Environment.NewLine); + + foreach (var fileName in fileNames) + { + builder.AppendFormat(WixStrings.INF_SourceTraceLocation, fileName, Environment.NewLine); + } + + builder.AppendLine(); + } + + return builder.ToString(); + } + + public void Write(Message message) + { + var level = CalculateMessageLevel(message); + + if (level == MessageLevel.Nothing) + { + return; + } + + if (level == MessageLevel.Error) + { + this.EncounteredError = true; + this.LastErrorNumber = message.Id; + } + + if (this.listener != null) + { + this.listener.Write(message); + } + else if (level == MessageLevel.Error) + { + throw new WixException(message); + } + } + + public void Write(string message, bool verbose = false) + { + if (!verbose || this.ShowVerboseMessages) + { + this.listener?.Write(message); + } + } + + /// + /// Determines the level of this message, when taking into account warning-as-error, + /// warning level, verbosity level and message suppressed by the caller. + /// + /// Event arguments for the message. + /// MessageLevel representing the level of this message. + private MessageLevel CalculateMessageLevel(Message message) + { + var level = message.Level; + + if (level == MessageLevel.Verbose) + { + if (!this.ShowVerboseMessages) + { + level = MessageLevel.Nothing; + } + } + else if (level == MessageLevel.Warning) + { + if (this.SuppressAllWarnings || this.suppressedWarnings.Contains(message.Id)) + { + level = MessageLevel.Nothing; + } + else if (this.WarningsAsError || this.warningsAsErrors.Contains(message.Id)) + { + level = MessageLevel.Error; + } + } + + return level; + } + } +} diff --git a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs index 8a67efe9..d2486890 100644 --- a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs +++ b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs @@ -34,10 +34,14 @@ namespace WixToolset.Core.ExtensibilityServices public ParseHelper(IServiceProvider serviceProvider) { this.ServiceProvider = serviceProvider; + + this.Messaging = serviceProvider.GetService(); } private IServiceProvider ServiceProvider { get; } + private IMessaging Messaging { get; } + private ITupleDefinitionCreator Creator { get; set; } public bool ContainsProperty(string possibleProperty) @@ -136,7 +140,7 @@ namespace WixToolset.Core.ExtensibilityServices // TODO: should overriding the parent identifier with a specific id be an error or a warning or just let it slide? //if (null != parentId) //{ - // this.core.OnMessage(WixErrors.Xxx(sourceLineNumbers)); + // this.core.Write(WixErrors.Xxx(sourceLineNumbers)); //} id = inlineSyntax[0].TrimEnd(':'); @@ -360,7 +364,7 @@ namespace WixToolset.Core.ExtensibilityServices if (ParseHelper.PutGuidHere.IsMatch(value)) { - Messaging.Instance.OnMessage(WixErrors.ExampleGuid(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(ErrorMessages.ExampleGuid(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); return CompilerConstants.IllegalGuid; } else if (value.StartsWith("!(loc", StringComparison.Ordinal) || value.StartsWith("$(loc", StringComparison.Ordinal) || value.StartsWith("!(wix", StringComparison.Ordinal)) @@ -374,14 +378,14 @@ namespace WixToolset.Core.ExtensibilityServices // TODO: This used to be a pedantic error, what should it be now? //if (uppercaseGuid != value) //{ - // Messaging.Instance.OnMessage(WixErrors.GuidContainsLowercaseLetters(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + // this.Messaging.Write(WixErrors.GuidContainsLowercaseLetters(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); //} return String.Concat("{", uppercaseGuid, "}"); } else { - Messaging.Instance.OnMessage(WixErrors.IllegalGuidValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(ErrorMessages.IllegalGuidValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } } @@ -391,7 +395,7 @@ namespace WixToolset.Core.ExtensibilityServices public Identifier GetAttributeIdentifier(SourceLineNumber sourceLineNumbers, XAttribute attribute) { var access = AccessModifier.Public; - var value = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeEmpty); + var value = Common.GetAttributeValue(this.Messaging, sourceLineNumbers, attribute, EmptyRule.CanBeEmpty); var match = ParseHelper.LegalIdentifierWithAccess.Match(value); if (!match.Success) @@ -407,7 +411,7 @@ namespace WixToolset.Core.ExtensibilityServices if (Common.IsIdentifier(value) && 72 < value.Length) { - Messaging.Instance.OnMessage(WixWarnings.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(WarningMessages.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } return new Identifier(value, access); @@ -415,7 +419,7 @@ namespace WixToolset.Core.ExtensibilityServices public string GetAttributeIdentifierValue(SourceLineNumber sourceLineNumbers, XAttribute attribute) { - return Common.GetAttributeIdentifierValue(sourceLineNumbers, attribute); + return Common.GetAttributeIdentifierValue(this.Messaging, sourceLineNumbers, attribute); } public string[] GetAttributeInlineDirectorySyntax(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool resultUsedToCreateReference = false) @@ -432,12 +436,12 @@ namespace WixToolset.Core.ExtensibilityServices string id = result[0].TrimEnd(':'); if (1 == result.Length) { - Messaging.Instance.OnMessage(WixErrors.InlineDirectorySyntaxRequiresPath(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, id)); + this.Messaging.Write(ErrorMessages.InlineDirectorySyntaxRequiresPath(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, id)); return null; } else if (!this.IsValidIdentifier(id)) { - Messaging.Instance.OnMessage(WixErrors.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, id)); + this.Messaging.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, id)); return null; } @@ -449,13 +453,13 @@ namespace WixToolset.Core.ExtensibilityServices { if (!this.IsValidLongFilename(result[0], false, false)) { - Messaging.Instance.OnMessage(WixErrors.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, result[0])); + this.Messaging.Write(ErrorMessages.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, result[0])); return null; } } else if (!this.IsValidIdentifier(result[0])) { - Messaging.Instance.OnMessage(WixErrors.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, result[0])); + this.Messaging.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, result[0])); return null; } @@ -467,14 +471,14 @@ namespace WixToolset.Core.ExtensibilityServices { if (!this.IsValidLongFilename(result[i], false, false)) { - Messaging.Instance.OnMessage(WixErrors.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, result[i])); + this.Messaging.Write(ErrorMessages.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value, result[i])); return null; } } if (1 < result.Length && !value.EndsWith("\\")) { - Messaging.Instance.OnMessage(WixWarnings.BackslashTerminateInlineDirectorySyntax(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(WarningMessages.BackslashTerminateInlineDirectorySyntax(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } } @@ -483,7 +487,7 @@ namespace WixToolset.Core.ExtensibilityServices public int GetAttributeIntegerValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, int minimum, int maximum) { - return Common.GetAttributeIntegerValue(sourceLineNumbers, attribute, minimum, maximum); + return Common.GetAttributeIntegerValue(this.Messaging, sourceLineNumbers, attribute, minimum, maximum); } public string GetAttributeLongFilename(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowWildcards, bool allowRelative) @@ -501,11 +505,11 @@ namespace WixToolset.Core.ExtensibilityServices { if (allowRelative) { - Messaging.Instance.OnMessage(WixErrors.IllegalRelativeLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(ErrorMessages.IllegalRelativeLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } else { - Messaging.Instance.OnMessage(WixErrors.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(ErrorMessages.IllegalLongFilename(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } } else if (allowRelative) @@ -513,12 +517,12 @@ namespace WixToolset.Core.ExtensibilityServices string normalizedPath = value.Replace('\\', '/'); if (normalizedPath.StartsWith("../", StringComparison.Ordinal) || normalizedPath.Contains("/../")) { - Messaging.Instance.OnMessage(WixErrors.PayloadMustBeRelativeToCache(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(ErrorMessages.PayloadMustBeRelativeToCache(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } } else if (CompilerCore.IsAmbiguousFilename(value)) { - Messaging.Instance.OnMessage(WixWarnings.AmbiguousFileOrDirectoryName(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(WarningMessages.AmbiguousFileOrDirectoryName(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } } @@ -539,11 +543,11 @@ namespace WixToolset.Core.ExtensibilityServices if (CompilerConstants.LongNotSet == longValue || CompilerConstants.IllegalLong == longValue) { - Messaging.Instance.OnMessage(WixErrors.IntegralValueSentinelCollision(sourceLineNumbers, longValue)); + this.Messaging.Write(ErrorMessages.IntegralValueSentinelCollision(sourceLineNumbers, longValue)); } else if (minimum > longValue || maximum < longValue) { - Messaging.Instance.OnMessage(WixErrors.IntegralValueOutOfRange(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, longValue, minimum, maximum)); + this.Messaging.Write(ErrorMessages.IntegralValueOutOfRange(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, longValue, minimum, maximum)); longValue = CompilerConstants.IllegalLong; } @@ -551,11 +555,11 @@ namespace WixToolset.Core.ExtensibilityServices } catch (FormatException) { - Messaging.Instance.OnMessage(WixErrors.IllegalLongValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(ErrorMessages.IllegalLongValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } catch (OverflowException) { - Messaging.Instance.OnMessage(WixErrors.IllegalLongValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(ErrorMessages.IllegalLongValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } } @@ -564,7 +568,7 @@ namespace WixToolset.Core.ExtensibilityServices public string GetAttributeValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, EmptyRule emptyRule = EmptyRule.CanBeWhitespaceOnly) { - return Common.GetAttributeValue(sourceLineNumbers, attribute, emptyRule); + return Common.GetAttributeValue(this.Messaging, sourceLineNumbers, attribute, emptyRule); } public string GetAttributeVersionValue(SourceLineNumber sourceLineNumbers, XAttribute attribute) @@ -584,7 +588,7 @@ namespace WixToolset.Core.ExtensibilityServices return value; } - Messaging.Instance.OnMessage(WixErrors.IllegalVersionValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(ErrorMessages.IllegalVersionValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); } return null; @@ -608,7 +612,7 @@ namespace WixToolset.Core.ExtensibilityServices return YesNoDefaultType.Default; default: - Messaging.Instance.OnMessage(WixErrors.IllegalYesNoDefaultValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(ErrorMessages.IllegalYesNoDefaultValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); return YesNoDefaultType.IllegalValue; } } @@ -628,7 +632,7 @@ namespace WixToolset.Core.ExtensibilityServices return YesNoType.No; default: - Messaging.Instance.OnMessage(WixErrors.IllegalYesNoValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); + this.Messaging.Write(ErrorMessages.IllegalYesNoValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); return YesNoType.IllegalValue; } } @@ -722,7 +726,7 @@ namespace WixToolset.Core.ExtensibilityServices else { var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(element); - Messaging.Instance.OnMessage(WixErrors.UnhandledExtensionAttribute(sourceLineNumbers, element.Name.LocalName, attribute.Name.LocalName, attribute.Name.NamespaceName)); + this.Messaging.Write(ErrorMessages.UnhandledExtensionAttribute(sourceLineNumbers, element.Name.LocalName, attribute.Name.LocalName, attribute.Name.NamespaceName)); } } @@ -736,7 +740,7 @@ namespace WixToolset.Core.ExtensibilityServices else { var childSourceLineNumbers = Preprocessor.GetSourceLineNumbers(element); - Messaging.Instance.OnMessage(WixErrors.UnhandledExtensionElement(childSourceLineNumbers, parentElement.Name.LocalName, element.Name.LocalName, element.Name.NamespaceName)); + this.Messaging.Write(ErrorMessages.UnhandledExtensionElement(childSourceLineNumbers, parentElement.Name.LocalName, element.Name.LocalName, element.Name.NamespaceName)); } } @@ -751,7 +755,7 @@ namespace WixToolset.Core.ExtensibilityServices else { var childSourceLineNumbers = Preprocessor.GetSourceLineNumbers(element); - Messaging.Instance.OnMessage(WixErrors.UnhandledExtensionElement(childSourceLineNumbers, parentElement.Name.LocalName, element.Name.LocalName, element.Name.NamespaceName)); + this.Messaging.Write(ErrorMessages.UnhandledExtensionElement(childSourceLineNumbers, parentElement.Name.LocalName, element.Name.LocalName, element.Name.NamespaceName)); } return keyPath; @@ -775,13 +779,13 @@ namespace WixToolset.Core.ExtensibilityServices public void UnexpectedAttribute(XElement element, XAttribute attribute) { var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(element); - Common.UnexpectedAttribute(sourceLineNumbers, attribute); + Common.UnexpectedAttribute(this.Messaging, sourceLineNumbers, attribute); } public void UnexpectedElement(XElement parentElement, XElement childElement) { var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(childElement); - Messaging.Instance.OnMessage(WixErrors.UnexpectedElement(sourceLineNumbers, parentElement.Name.LocalName, childElement.Name.LocalName)); + this.Messaging.Write(ErrorMessages.UnexpectedElement(sourceLineNumbers, parentElement.Name.LocalName, childElement.Name.LocalName)); } private void CreateTupleDefinitionCreator() diff --git a/src/WixToolset.Core/ExtensibilityServices/PreprocessHelper.cs b/src/WixToolset.Core/ExtensibilityServices/PreprocessHelper.cs index bcbd6a67..0e3e0bfd 100644 --- a/src/WixToolset.Core/ExtensibilityServices/PreprocessHelper.cs +++ b/src/WixToolset.Core/ExtensibilityServices/PreprocessHelper.cs @@ -42,7 +42,7 @@ namespace WixToolset.Core.ExtensibilityServices { if (showWarning) { - context.Messaging.OnMessage(WixWarnings.VariableDeclarationCollision(context.CurrentSourceLineNumber, name, value, currentValue)); + context.Messaging.Write(WarningMessages.VariableDeclarationCollision(context.CurrentSourceLineNumber, name, value, currentValue)); } context.Variables[name] = value; @@ -56,7 +56,7 @@ namespace WixToolset.Core.ExtensibilityServices // Check to make sure there are 2 parts and neither is an empty string. if (2 != prefixParts.Length || 0 >= prefixParts[0].Length || 0 >= prefixParts[1].Length) { - throw new WixException(WixErrors.InvalidPreprocessorFunction(context.CurrentSourceLineNumber, function)); + throw new WixException(ErrorMessages.InvalidPreprocessorFunction(context.CurrentSourceLineNumber, function)); } var prefix = prefixParts[0]; @@ -65,7 +65,7 @@ namespace WixToolset.Core.ExtensibilityServices // Check to make sure there are 2 parts, neither is an empty string, and the second part ends with a closing paren. if (2 != functionParts.Length || 0 >= functionParts[0].Length || 0 >= functionParts[1].Length || !functionParts[1].EndsWith(")", StringComparison.Ordinal)) { - throw new WixException(WixErrors.InvalidPreprocessorFunction(context.CurrentSourceLineNumber, function)); + throw new WixException(ErrorMessages.InvalidPreprocessorFunction(context.CurrentSourceLineNumber, function)); } var functionName = functionParts[0]; @@ -113,7 +113,7 @@ namespace WixToolset.Core.ExtensibilityServices // Make sure the base version is specified if (args.Length == 0 || String.IsNullOrEmpty(args[0])) { - throw new WixException(WixErrors.InvalidPreprocessorFunctionAutoVersion(context.CurrentSourceLineNumber)); + throw new WixException(ErrorMessages.InvalidPreprocessorFunctionAutoVersion(context.CurrentSourceLineNumber)); } // Build = days since 1/1/2000; Revision = seconds since midnight / 2 @@ -137,7 +137,7 @@ namespace WixToolset.Core.ExtensibilityServices } catch (Exception e) { - throw new WixException(WixErrors.PreprocessorExtensionEvaluateFunctionFailed(context.CurrentSourceLineNumber, prefix, function, String.Join(",", args), e.Message)); + throw new WixException(ErrorMessages.PreprocessorExtensionEvaluateFunctionFailed(context.CurrentSourceLineNumber, prefix, function, String.Join(",", args), e.Message)); } } else @@ -165,7 +165,7 @@ namespace WixToolset.Core.ExtensibilityServices } else { - throw new WixException(WixErrors.InvalidPreprocessorVariable(context.CurrentSourceLineNumber, variable)); + throw new WixException(ErrorMessages.InvalidPreprocessorVariable(context.CurrentSourceLineNumber, variable)); } } else @@ -185,7 +185,7 @@ namespace WixToolset.Core.ExtensibilityServices } else { - throw new WixException(WixErrors.InvalidPreprocessorVariable(context.CurrentSourceLineNumber, variable)); + throw new WixException(ErrorMessages.InvalidPreprocessorVariable(context.CurrentSourceLineNumber, variable)); } } } @@ -220,7 +220,7 @@ namespace WixToolset.Core.ExtensibilityServices return context.CurrentSourceLineNumber.FileName; case "PLATFORM": - context.Messaging.OnMessage(WixWarnings.DeprecatedPreProcVariable(context.CurrentSourceLineNumber, "$(sys.PLATFORM)", "$(sys.BUILDARCH)")); + context.Messaging.Write(WarningMessages.DeprecatedPreProcVariable(context.CurrentSourceLineNumber, "$(sys.PLATFORM)", "$(sys.BUILDARCH)")); goto case "BUILDARCH"; @@ -260,7 +260,7 @@ namespace WixToolset.Core.ExtensibilityServices } catch (Exception e) { - throw new WixException(WixErrors.PreprocessorExtensionGetVariableValueFailed(context.CurrentSourceLineNumber, prefix, name, e.Message)); + throw new WixException(ErrorMessages.PreprocessorExtensionGetVariableValueFailed(context.CurrentSourceLineNumber, prefix, name, e.Message)); } } else @@ -277,7 +277,7 @@ namespace WixToolset.Core.ExtensibilityServices // Check to make sure there are 2 parts and neither is an empty string. if (2 != prefixParts.Length) { - throw new WixException(WixErrors.InvalidPreprocessorPragma(context.CurrentSourceLineNumber, pragmaName)); + throw new WixException(ErrorMessages.InvalidPreprocessorPragma(context.CurrentSourceLineNumber, pragmaName)); } var prefix = prefixParts[0]; @@ -285,7 +285,7 @@ namespace WixToolset.Core.ExtensibilityServices if (String.IsNullOrEmpty(prefix) || String.IsNullOrEmpty(pragma)) { - throw new WixException(WixErrors.InvalidPreprocessorPragma(context.CurrentSourceLineNumber, pragmaName)); + throw new WixException(ErrorMessages.InvalidPreprocessorPragma(context.CurrentSourceLineNumber, pragmaName)); } switch (prefix) @@ -295,7 +295,7 @@ namespace WixToolset.Core.ExtensibilityServices { // Add any core defined pragmas here default: - context.Messaging.OnMessage(WixWarnings.PreprocessorUnknownPragma(context.CurrentSourceLineNumber, pragmaName)); + context.Messaging.Write(WarningMessages.PreprocessorUnknownPragma(context.CurrentSourceLineNumber, pragmaName)); break; } break; @@ -306,7 +306,7 @@ namespace WixToolset.Core.ExtensibilityServices { if (!extension.ProcessPragma(prefix, pragma, args, parent)) { - context.Messaging.OnMessage(WixWarnings.PreprocessorUnknownPragma(context.CurrentSourceLineNumber, pragmaName)); + context.Messaging.Write(WarningMessages.PreprocessorUnknownPragma(context.CurrentSourceLineNumber, pragmaName)); } } break; @@ -339,7 +339,7 @@ namespace WixToolset.Core.ExtensibilityServices currentPosition = remainder.IndexOf(')'); if (-1 == currentPosition) { - context.Messaging.OnMessage(WixErrors.InvalidPreprocessorVariable(context.CurrentSourceLineNumber, remainder)); + context.Messaging.Write(ErrorMessages.InvalidPreprocessorVariable(context.CurrentSourceLineNumber, remainder)); break; } @@ -385,12 +385,12 @@ namespace WixToolset.Core.ExtensibilityServices { if (isFunction) { - context.Messaging.OnMessage(WixErrors.InvalidPreprocessorFunction(context.CurrentSourceLineNumber, remainder)); + context.Messaging.Write(ErrorMessages.InvalidPreprocessorFunction(context.CurrentSourceLineNumber, remainder)); break; } else { - context.Messaging.OnMessage(WixErrors.InvalidPreprocessorVariable(context.CurrentSourceLineNumber, remainder)); + context.Messaging.Write(ErrorMessages.InvalidPreprocessorVariable(context.CurrentSourceLineNumber, remainder)); break; } } @@ -410,12 +410,12 @@ namespace WixToolset.Core.ExtensibilityServices { if (isFunction) { - context.Messaging.OnMessage(WixErrors.UndefinedPreprocessorFunction(context.CurrentSourceLineNumber, subString)); + context.Messaging.Write(ErrorMessages.UndefinedPreprocessorFunction(context.CurrentSourceLineNumber, subString)); break; } else { - context.Messaging.OnMessage(WixErrors.UndefinedPreprocessorVariable(context.CurrentSourceLineNumber, subString)); + context.Messaging.Write(ErrorMessages.UndefinedPreprocessorVariable(context.CurrentSourceLineNumber, subString)); break; } } @@ -448,7 +448,7 @@ namespace WixToolset.Core.ExtensibilityServices { if (!context.Variables.Remove(name)) { - context.Messaging.OnMessage(WixErrors.CannotReundefineVariable(context.CurrentSourceLineNumber, name)); + context.Messaging.Write(ErrorMessages.CannotReundefineVariable(context.CurrentSourceLineNumber, name)); } } -- cgit v1.2.3-55-g6feb