From 985ba427f8cd12b7b74d62f83a8b304764e6077b Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sat, 19 Jan 2019 13:03:02 -0600 Subject: Integrate into latest v4 --- src/wixext/PSCompiler.cs | 106 +++++++++++------------- src/wixext/PSErrors.cs | 30 +++++++ src/wixext/PSExtensionData.cs | 26 +++--- src/wixext/PSWarnings.cs | 30 +++++++ src/wixext/PowerShellExtensionFactory.cs | 17 ++++ src/wixext/WixPSExtension.csproj | 43 ---------- src/wixext/WixToolset.PowerShell.wixext.csproj | 29 +++++++ src/wixext/WixToolset.PowerShell.wixext.targets | 11 +++ src/wixext/messages.xml | 20 ----- 9 files changed, 178 insertions(+), 134 deletions(-) create mode 100644 src/wixext/PSErrors.cs create mode 100644 src/wixext/PSWarnings.cs create mode 100644 src/wixext/PowerShellExtensionFactory.cs delete mode 100644 src/wixext/WixPSExtension.csproj create mode 100644 src/wixext/WixToolset.PowerShell.wixext.csproj create mode 100644 src/wixext/WixToolset.PowerShell.wixext.targets delete mode 100644 src/wixext/messages.xml (limited to 'src/wixext') diff --git a/src/wixext/PSCompiler.cs b/src/wixext/PSCompiler.cs index 61eb287c..200d3fb4 100644 --- a/src/wixext/PSCompiler.cs +++ b/src/wixext/PSCompiler.cs @@ -1,30 +1,24 @@ // 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.Extensions +namespace WixToolset.PowerShell { using System; using System.Collections.Generic; using System.Globalization; using System.Xml.Linq; using WixToolset.Data; - using WixToolset.Data.Rows; + using WixToolset.Data.Tuples; using WixToolset.Extensibility; /// - /// The compiler for the WiX Toolset Internet Information Services Extension. + /// The compiler for the WiX Toolset PowerShell Extension. /// - public sealed class PSCompiler : CompilerExtension + public sealed class PSCompiler : BaseCompilerExtension { private const string KeyFormat = @"SOFTWARE\Microsoft\PowerShell\{0}\PowerShellSnapIns\{1}"; private const string VarPrefix = "PSVersionMajor"; - /// - /// Instantiate a new PSCompiler. - /// - public PSCompiler() - { - this.Namespace = "http://wixtoolset.org/schemas/v4/wxs/powershell"; - } + public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/powershell"; /// /// Processes an element for the Compiler. @@ -33,7 +27,7 @@ namespace WixToolset.Extensions /// Parent element of element to process. /// Element to process. /// Extra information about the context in which this element is being parsed. - public override void ParseElement(XElement parentElement, XElement element, IDictionary context) + public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary context) { switch (parentElement.Name.LocalName) { @@ -44,25 +38,25 @@ namespace WixToolset.Extensions switch (element.Name.LocalName) { case "FormatsFile": - this.ParseExtensionsFile(element, "Formats", fileId, componentId); + this.ParseExtensionsFile(intermediate, section, element, "Formats", fileId, componentId); break; case "SnapIn": - this.ParseSnapInElement(element, fileId, componentId); + this.ParseSnapInElement(intermediate, section, element, fileId, componentId); break; case "TypesFile": - this.ParseExtensionsFile(element, "Types", fileId, componentId); + this.ParseExtensionsFile(intermediate, section, element, "Types", fileId, componentId); break; default: - this.Core.UnexpectedElement(parentElement, element); + this.ParseHelper.UnexpectedElement(parentElement, element); break; } break; default: - this.Core.UnexpectedElement(parentElement, element); + this.ParseHelper.UnexpectedElement(parentElement, element); break; } } @@ -73,9 +67,9 @@ namespace WixToolset.Extensions /// Element to parse. /// Identifier for parent file. /// Identifier for parent component. - private void ParseSnapInElement(XElement node, string fileId, string componentId) + private void ParseSnapInElement(Intermediate intermediate, IntermediateSection section, XElement node, string fileId, string componentId) { - SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); + SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node); string id = null; string assemblyName = null; string customSnapInType = null; @@ -93,52 +87,52 @@ namespace WixToolset.Extensions switch (attrib.Name.LocalName) { case "Id": - id = this.Core.GetAttributeIdentifierValue(sourceLineNumbers, attrib); + id = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); break; case "CustomSnapInType": - customSnapInType = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + customSnapInType = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); break; case "Description": - description = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + description = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); break; case "DescriptionIndirect": - descriptionIndirect = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + descriptionIndirect = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); break; case "RequiredPowerShellVersion": - string ver = this.Core.GetAttributeVersionValue(sourceLineNumbers, attrib); + string ver = this.ParseHelper.GetAttributeVersionValue(sourceLineNumbers, attrib); requiredPowerShellVersion = new Version(ver); break; case "Vendor": - vendor = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + vendor = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); break; case "VendorIndirect": - vendorIndirect = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + vendorIndirect = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); break; case "Version": - version = this.Core.GetAttributeVersionValue(sourceLineNumbers, attrib); + version = this.ParseHelper.GetAttributeVersionValue(sourceLineNumbers, attrib); break; default: - this.Core.UnexpectedAttribute(node, attrib); + this.ParseHelper.UnexpectedAttribute(node, attrib); break; } } else { - this.Core.ParseExtensionAttribute(node, attrib); + this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, node, attrib); } } if (null == id) { - this.Core.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id")); + this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id")); } // Default to require PowerShell 1.0. @@ -161,19 +155,19 @@ namespace WixToolset.Extensions switch (child.Name.LocalName) { case "FormatsFile": - this.ParseExtensionsFile(child, "Formats", id, componentId); + this.ParseExtensionsFile(intermediate, section, child, "Formats", id, componentId); break; case "TypesFile": - this.ParseExtensionsFile(child, "Types", id, componentId); + this.ParseExtensionsFile(intermediate, section, child, "Types", id, componentId); break; default: - this.Core.UnexpectedElement(node, child); + this.ParseHelper.UnexpectedElement(node, child); break; } } else { - this.Core.ParseExtensionElement(node, child); + this.ParseHelper.ParseExtensionElement(this.Context.Extensions, intermediate, section, node, child); } } @@ -182,54 +176,54 @@ namespace WixToolset.Extensions // for use in Formats and Types files. PowerShell v2 still uses 1. int major = (2 == requiredPowerShellVersion.Major) ? 1 : requiredPowerShellVersion.Major; - WixVariableRow wixVariableRow = (WixVariableRow)this.Core.CreateRow(sourceLineNumbers, "WixVariable"); - wixVariableRow.Id = String.Format(CultureInfo.InvariantCulture, "{0}_{1}", VarPrefix, id); + var variableId = new Identifier(AccessModifier.Public, String.Format(CultureInfo.InvariantCulture, "{0}_{1}", VarPrefix, id)); + var wixVariableRow = (WixVariableTuple)this.ParseHelper.CreateRow(section, sourceLineNumbers, "WixVariable", variableId); wixVariableRow.Value = major.ToString(CultureInfo.InvariantCulture); wixVariableRow.Overridable = false; int registryRoot = 2; // HKLM string registryKey = String.Format(CultureInfo.InvariantCulture, KeyFormat, major, id); - this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "ApplicationBase", String.Format(CultureInfo.InvariantCulture, "[${0}]", componentId), componentId, false); + this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "ApplicationBase", String.Format(CultureInfo.InvariantCulture, "[${0}]", componentId), componentId, false); // set the assembly name automatically when binding. // processorArchitecture is not handled correctly by PowerShell v1.0 // so format the assembly name explicitly. assemblyName = String.Format(CultureInfo.InvariantCulture, "!(bind.assemblyName.{0}), Version=!(bind.assemblyVersion.{0}), Culture=!(bind.assemblyCulture.{0}), PublicKeyToken=!(bind.assemblyPublicKeyToken.{0})", fileId); - this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "AssemblyName", assemblyName, componentId, false); + this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "AssemblyName", assemblyName, componentId, false); if (null != customSnapInType) { - this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "CustomPSSnapInType", customSnapInType, componentId, false); + this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "CustomPSSnapInType", customSnapInType, componentId, false); } if (null != description) { - this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "Description", description, componentId, false); + this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "Description", description, componentId, false); } if (null != descriptionIndirect) { - this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "DescriptionIndirect", descriptionIndirect, componentId, false); + this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "DescriptionIndirect", descriptionIndirect, componentId, false); } - this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "ModuleName", String.Format(CultureInfo.InvariantCulture, "[#{0}]", fileId), componentId, false); + this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "ModuleName", String.Format(CultureInfo.InvariantCulture, "[#{0}]", fileId), componentId, false); - this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "PowerShellVersion", requiredPowerShellVersion.ToString(2), componentId, false); + this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "PowerShellVersion", requiredPowerShellVersion.ToString(2), componentId, false); if (null != vendor) { - this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "Vendor", vendor, componentId, false); + this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "Vendor", vendor, componentId, false); } if (null != vendorIndirect) { - this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "VendorIndirect", vendorIndirect, componentId, false); + this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "VendorIndirect", vendorIndirect, componentId, false); } if (null != version) { - this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "Version", version, componentId, false); + this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "Version", version, componentId, false); } } @@ -240,9 +234,9 @@ namespace WixToolset.Extensions /// Registry value name. /// Idendifier for parent file or snap-in. /// Identifier for parent component. - private void ParseExtensionsFile(XElement node, string valueName, string id, string componentId) + private void ParseExtensionsFile(Intermediate intermediate, IntermediateSection section, XElement node, string valueName, string id, string componentId) { - SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); + SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node); string fileId = null; string snapIn = null; @@ -253,38 +247,38 @@ namespace WixToolset.Extensions switch (attrib.Name.LocalName) { case "FileId": - fileId = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + fileId = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); snapIn = id; break; case "SnapIn": fileId = id; - snapIn = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + snapIn = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); break; default: - this.Core.UnexpectedAttribute(node, attrib); + this.ParseHelper.UnexpectedAttribute(node, attrib); break; } } else { - this.Core.ParseExtensionAttribute(node, attrib); + this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, node, attrib); } } if (null == fileId && null == snapIn) { - this.Core.OnMessage(PSErrors.NeitherIdSpecified(sourceLineNumbers, valueName)); + this.Messaging.Write(PSErrors.NeitherIdSpecified(sourceLineNumbers, valueName)); } - this.Core.ParseForExtensionElements(node); + this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, node); int registryRoot = 2; // HKLM string registryKey = String.Format(CultureInfo.InvariantCulture, KeyFormat, String.Format(CultureInfo.InvariantCulture, "!(wix.{0}_{1})", VarPrefix, snapIn), snapIn); - this.Core.CreateSimpleReference(sourceLineNumbers, "File", fileId); - this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, valueName, String.Format(CultureInfo.InvariantCulture, "[~][#{0}]", fileId), componentId, false); + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "File", fileId); + this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, valueName, String.Format(CultureInfo.InvariantCulture, "[~][#{0}]", fileId), componentId, false); } } } diff --git a/src/wixext/PSErrors.cs b/src/wixext/PSErrors.cs new file mode 100644 index 00000000..704cf5cd --- /dev/null +++ b/src/wixext/PSErrors.cs @@ -0,0 +1,30 @@ +// 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.PowerShell +{ + using System.Resources; + using WixToolset.Data; + + public static class PSErrors + { + public static Message NeitherIdSpecified(SourceLineNumber sourceLineNumbers, string element) + { + return Message(sourceLineNumbers, Ids.NeitherIdSpecified, "Either the {0}/@FileId attribute must be specified if nested under a SnapIn element, or the {0}/@SnapIn attribute must be specified if nested under under a File element.", element); + } + + private static Message Message(SourceLineNumber sourceLineNumber, Ids id, string format, params object[] args) + { + return new Message(sourceLineNumber, MessageLevel.Error, (int)id, format, args); + } + + private static Message Message(SourceLineNumber sourceLineNumber, Ids id, ResourceManager resourceManager, string resourceName, params object[] args) + { + return new Message(sourceLineNumber, MessageLevel.Error, (int)id, resourceManager, resourceName, args); + } + + public enum Ids + { + NeitherIdSpecified = 5301, + } + } +} diff --git a/src/wixext/PSExtensionData.cs b/src/wixext/PSExtensionData.cs index 578bda91..d9a2d2e7 100644 --- a/src/wixext/PSExtensionData.cs +++ b/src/wixext/PSExtensionData.cs @@ -1,34 +1,30 @@ // 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.Extensions +namespace WixToolset.PowerShell { - using System; - using System.Reflection; using WixToolset.Data; using WixToolset.Extensibility; /// /// The WiX Toolset PowerShell Extension. /// - public sealed class PSExtensionData : ExtensionData + public sealed class PSExtensionData : BaseExtensionData { /// - /// Gets the library associated with this extension. + /// Gets the default culture. /// - /// The table definitions to use while loading the library. - /// The loaded library. - public override Library GetLibrary(TableDefinitionCollection tableDefinitions) + /// The default culture. + public override string DefaultCulture => "en-US"; + + public override bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition) { - return PSExtensionData.GetExtensionLibrary(tableDefinitions); + tupleDefinition = null; + return tupleDefinition != null; } - /// - /// Internal mechanism to access the extension's library. - /// - /// Extension's library. - internal static Library GetExtensionLibrary(TableDefinitionCollection tableDefinitions) + public override Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions) { - return ExtensionData.LoadLibraryHelper(Assembly.GetExecutingAssembly(), "WixToolset.Extensions.Data.ps.wixlib", tableDefinitions); + return Intermediate.Load(typeof(PSExtensionData).Assembly, "WixToolset.PowerShell.powershell.wixlib", tupleDefinitions); } } } diff --git a/src/wixext/PSWarnings.cs b/src/wixext/PSWarnings.cs new file mode 100644 index 00000000..9be14948 --- /dev/null +++ b/src/wixext/PSWarnings.cs @@ -0,0 +1,30 @@ +// 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.PowerShell +{ + using System.Resources; + using WixToolset.Data; + + public static class PSWarnings + { + public static Message DeprecatedAssemblyNameAttribute(SourceLineNumber sourceLineNumbers) + { + return Message(sourceLineNumbers, Ids.DeprecatedAssemblyNameAttribute, "The SnapIn/@AssemblyName attribute is deprecated. It is assigned automatically."); + } + + private static Message Message(SourceLineNumber sourceLineNumber, Ids id, string format, params object[] args) + { + return new Message(sourceLineNumber, MessageLevel.Warning, (int)id, format, args); + } + + private static Message Message(SourceLineNumber sourceLineNumber, Ids id, ResourceManager resourceManager, string resourceName, params object[] args) + { + return new Message(sourceLineNumber, MessageLevel.Warning, (int)id, resourceManager, resourceName, args); + } + + public enum Ids + { + DeprecatedAssemblyNameAttribute = 5350, + } + } +} diff --git a/src/wixext/PowerShellExtensionFactory.cs b/src/wixext/PowerShellExtensionFactory.cs new file mode 100644 index 00000000..22a4ad88 --- /dev/null +++ b/src/wixext/PowerShellExtensionFactory.cs @@ -0,0 +1,17 @@ +// 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.PowerShell +{ + using System; + using System.Collections.Generic; + using WixToolset.Extensibility; + + public class PowerShellExtensionFactory : BaseExtensionFactory + { + protected override IEnumerable ExtensionTypes => new[] + { + typeof(PSCompiler), + typeof(PSExtensionData), + }; + } +} diff --git a/src/wixext/WixPSExtension.csproj b/src/wixext/WixPSExtension.csproj deleted file mode 100644 index f9349ef1..00000000 --- a/src/wixext/WixPSExtension.csproj +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - {6F1482DF-1598-4D88-BDAA-B9D0E0242139} - WixPSExtension - Library - WixToolset.Extensions - - - - - - - $(RootNamespace).Data.Messages.resources - - - $(RootNamespace).Xsd.ps.xsd - PreserveNewest - - - WixToolset.Data.Serialize - WixToolset.Extensions.Serialize.PS - - - Data\ps.wixlib - - - - - - - - - - false - - - - - diff --git a/src/wixext/WixToolset.PowerShell.wixext.csproj b/src/wixext/WixToolset.PowerShell.wixext.csproj new file mode 100644 index 00000000..666e8aba --- /dev/null +++ b/src/wixext/WixToolset.PowerShell.wixext.csproj @@ -0,0 +1,29 @@ + + + + + + netstandard2.0 + WixToolset.PowerShell + WiX Toolset PowerShell Extension + WiX Toolset PowerShell Extension + true + build + + + + + + + + + + + + + + + + + + diff --git a/src/wixext/WixToolset.PowerShell.wixext.targets b/src/wixext/WixToolset.PowerShell.wixext.targets new file mode 100644 index 00000000..bf06e1e4 --- /dev/null +++ b/src/wixext/WixToolset.PowerShell.wixext.targets @@ -0,0 +1,11 @@ + + + + + + $(MSBuildThisFileDirectory)..\tools\WixToolset.PowerShell.wixext.dll + + + + + diff --git a/src/wixext/messages.xml b/src/wixext/messages.xml deleted file mode 100644 index ef715640..00000000 --- a/src/wixext/messages.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - Either the {0}/@FileId attribute must be specified if nested under a SnapIn element, or the {0}/@SnapIn attribute must be specified if nested under under a File element. - - - - - - - The SnapIn/@AssemblyName attribute is deprecated. It is assigned automatically. - - - - - -- cgit v1.2.3-55-g6feb