diff options
Diffstat (limited to 'src/wixext/PSCompiler.cs')
-rw-r--r-- | src/wixext/PSCompiler.cs | 106 |
1 files changed, 50 insertions, 56 deletions
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 @@ | |||
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. | 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 | 2 | ||
3 | namespace WixToolset.Extensions | 3 | namespace WixToolset.PowerShell |
4 | { | 4 | { |
5 | using System; | 5 | using System; |
6 | using System.Collections.Generic; | 6 | using System.Collections.Generic; |
7 | using System.Globalization; | 7 | using System.Globalization; |
8 | using System.Xml.Linq; | 8 | using System.Xml.Linq; |
9 | using WixToolset.Data; | 9 | using WixToolset.Data; |
10 | using WixToolset.Data.Rows; | 10 | using WixToolset.Data.Tuples; |
11 | using WixToolset.Extensibility; | 11 | using WixToolset.Extensibility; |
12 | 12 | ||
13 | /// <summary> | 13 | /// <summary> |
14 | /// The compiler for the WiX Toolset Internet Information Services Extension. | 14 | /// The compiler for the WiX Toolset PowerShell Extension. |
15 | /// </summary> | 15 | /// </summary> |
16 | public sealed class PSCompiler : CompilerExtension | 16 | public sealed class PSCompiler : BaseCompilerExtension |
17 | { | 17 | { |
18 | private const string KeyFormat = @"SOFTWARE\Microsoft\PowerShell\{0}\PowerShellSnapIns\{1}"; | 18 | private const string KeyFormat = @"SOFTWARE\Microsoft\PowerShell\{0}\PowerShellSnapIns\{1}"; |
19 | private const string VarPrefix = "PSVersionMajor"; | 19 | private const string VarPrefix = "PSVersionMajor"; |
20 | 20 | ||
21 | /// <summary> | 21 | public override XNamespace Namespace => "http://wixtoolset.org/schemas/v4/wxs/powershell"; |
22 | /// Instantiate a new PSCompiler. | ||
23 | /// </summary> | ||
24 | public PSCompiler() | ||
25 | { | ||
26 | this.Namespace = "http://wixtoolset.org/schemas/v4/wxs/powershell"; | ||
27 | } | ||
28 | 22 | ||
29 | /// <summary> | 23 | /// <summary> |
30 | /// Processes an element for the Compiler. | 24 | /// Processes an element for the Compiler. |
@@ -33,7 +27,7 @@ namespace WixToolset.Extensions | |||
33 | /// <param name="parentElement">Parent element of element to process.</param> | 27 | /// <param name="parentElement">Parent element of element to process.</param> |
34 | /// <param name="element">Element to process.</param> | 28 | /// <param name="element">Element to process.</param> |
35 | /// <param name="contextValues">Extra information about the context in which this element is being parsed.</param> | 29 | /// <param name="contextValues">Extra information about the context in which this element is being parsed.</param> |
36 | public override void ParseElement(XElement parentElement, XElement element, IDictionary<string, string> context) | 30 | public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context) |
37 | { | 31 | { |
38 | switch (parentElement.Name.LocalName) | 32 | switch (parentElement.Name.LocalName) |
39 | { | 33 | { |
@@ -44,25 +38,25 @@ namespace WixToolset.Extensions | |||
44 | switch (element.Name.LocalName) | 38 | switch (element.Name.LocalName) |
45 | { | 39 | { |
46 | case "FormatsFile": | 40 | case "FormatsFile": |
47 | this.ParseExtensionsFile(element, "Formats", fileId, componentId); | 41 | this.ParseExtensionsFile(intermediate, section, element, "Formats", fileId, componentId); |
48 | break; | 42 | break; |
49 | 43 | ||
50 | case "SnapIn": | 44 | case "SnapIn": |
51 | this.ParseSnapInElement(element, fileId, componentId); | 45 | this.ParseSnapInElement(intermediate, section, element, fileId, componentId); |
52 | break; | 46 | break; |
53 | 47 | ||
54 | case "TypesFile": | 48 | case "TypesFile": |
55 | this.ParseExtensionsFile(element, "Types", fileId, componentId); | 49 | this.ParseExtensionsFile(intermediate, section, element, "Types", fileId, componentId); |
56 | break; | 50 | break; |
57 | 51 | ||
58 | default: | 52 | default: |
59 | this.Core.UnexpectedElement(parentElement, element); | 53 | this.ParseHelper.UnexpectedElement(parentElement, element); |
60 | break; | 54 | break; |
61 | } | 55 | } |
62 | break; | 56 | break; |
63 | 57 | ||
64 | default: | 58 | default: |
65 | this.Core.UnexpectedElement(parentElement, element); | 59 | this.ParseHelper.UnexpectedElement(parentElement, element); |
66 | break; | 60 | break; |
67 | } | 61 | } |
68 | } | 62 | } |
@@ -73,9 +67,9 @@ namespace WixToolset.Extensions | |||
73 | /// <param name="node">Element to parse.</param> | 67 | /// <param name="node">Element to parse.</param> |
74 | /// <param name="fileId">Identifier for parent file.</param> | 68 | /// <param name="fileId">Identifier for parent file.</param> |
75 | /// <param name="componentId">Identifier for parent component.</param> | 69 | /// <param name="componentId">Identifier for parent component.</param> |
76 | private void ParseSnapInElement(XElement node, string fileId, string componentId) | 70 | private void ParseSnapInElement(Intermediate intermediate, IntermediateSection section, XElement node, string fileId, string componentId) |
77 | { | 71 | { |
78 | SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); | 72 | SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node); |
79 | string id = null; | 73 | string id = null; |
80 | string assemblyName = null; | 74 | string assemblyName = null; |
81 | string customSnapInType = null; | 75 | string customSnapInType = null; |
@@ -93,52 +87,52 @@ namespace WixToolset.Extensions | |||
93 | switch (attrib.Name.LocalName) | 87 | switch (attrib.Name.LocalName) |
94 | { | 88 | { |
95 | case "Id": | 89 | case "Id": |
96 | id = this.Core.GetAttributeIdentifierValue(sourceLineNumbers, attrib); | 90 | id = this.ParseHelper.GetAttributeIdentifierValue(sourceLineNumbers, attrib); |
97 | break; | 91 | break; |
98 | 92 | ||
99 | case "CustomSnapInType": | 93 | case "CustomSnapInType": |
100 | customSnapInType = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | 94 | customSnapInType = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); |
101 | break; | 95 | break; |
102 | 96 | ||
103 | case "Description": | 97 | case "Description": |
104 | description = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | 98 | description = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); |
105 | break; | 99 | break; |
106 | 100 | ||
107 | case "DescriptionIndirect": | 101 | case "DescriptionIndirect": |
108 | descriptionIndirect = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | 102 | descriptionIndirect = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); |
109 | break; | 103 | break; |
110 | 104 | ||
111 | case "RequiredPowerShellVersion": | 105 | case "RequiredPowerShellVersion": |
112 | string ver = this.Core.GetAttributeVersionValue(sourceLineNumbers, attrib); | 106 | string ver = this.ParseHelper.GetAttributeVersionValue(sourceLineNumbers, attrib); |
113 | requiredPowerShellVersion = new Version(ver); | 107 | requiredPowerShellVersion = new Version(ver); |
114 | break; | 108 | break; |
115 | 109 | ||
116 | case "Vendor": | 110 | case "Vendor": |
117 | vendor = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | 111 | vendor = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); |
118 | break; | 112 | break; |
119 | 113 | ||
120 | case "VendorIndirect": | 114 | case "VendorIndirect": |
121 | vendorIndirect = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | 115 | vendorIndirect = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); |
122 | break; | 116 | break; |
123 | 117 | ||
124 | case "Version": | 118 | case "Version": |
125 | version = this.Core.GetAttributeVersionValue(sourceLineNumbers, attrib); | 119 | version = this.ParseHelper.GetAttributeVersionValue(sourceLineNumbers, attrib); |
126 | break; | 120 | break; |
127 | 121 | ||
128 | default: | 122 | default: |
129 | this.Core.UnexpectedAttribute(node, attrib); | 123 | this.ParseHelper.UnexpectedAttribute(node, attrib); |
130 | break; | 124 | break; |
131 | } | 125 | } |
132 | } | 126 | } |
133 | else | 127 | else |
134 | { | 128 | { |
135 | this.Core.ParseExtensionAttribute(node, attrib); | 129 | this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, node, attrib); |
136 | } | 130 | } |
137 | } | 131 | } |
138 | 132 | ||
139 | if (null == id) | 133 | if (null == id) |
140 | { | 134 | { |
141 | this.Core.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id")); | 135 | this.Messaging.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id")); |
142 | } | 136 | } |
143 | 137 | ||
144 | // Default to require PowerShell 1.0. | 138 | // Default to require PowerShell 1.0. |
@@ -161,19 +155,19 @@ namespace WixToolset.Extensions | |||
161 | switch (child.Name.LocalName) | 155 | switch (child.Name.LocalName) |
162 | { | 156 | { |
163 | case "FormatsFile": | 157 | case "FormatsFile": |
164 | this.ParseExtensionsFile(child, "Formats", id, componentId); | 158 | this.ParseExtensionsFile(intermediate, section, child, "Formats", id, componentId); |
165 | break; | 159 | break; |
166 | case "TypesFile": | 160 | case "TypesFile": |
167 | this.ParseExtensionsFile(child, "Types", id, componentId); | 161 | this.ParseExtensionsFile(intermediate, section, child, "Types", id, componentId); |
168 | break; | 162 | break; |
169 | default: | 163 | default: |
170 | this.Core.UnexpectedElement(node, child); | 164 | this.ParseHelper.UnexpectedElement(node, child); |
171 | break; | 165 | break; |
172 | } | 166 | } |
173 | } | 167 | } |
174 | else | 168 | else |
175 | { | 169 | { |
176 | this.Core.ParseExtensionElement(node, child); | 170 | this.ParseHelper.ParseExtensionElement(this.Context.Extensions, intermediate, section, node, child); |
177 | } | 171 | } |
178 | } | 172 | } |
179 | 173 | ||
@@ -182,54 +176,54 @@ namespace WixToolset.Extensions | |||
182 | // for use in Formats and Types files. PowerShell v2 still uses 1. | 176 | // for use in Formats and Types files. PowerShell v2 still uses 1. |
183 | int major = (2 == requiredPowerShellVersion.Major) ? 1 : requiredPowerShellVersion.Major; | 177 | int major = (2 == requiredPowerShellVersion.Major) ? 1 : requiredPowerShellVersion.Major; |
184 | 178 | ||
185 | WixVariableRow wixVariableRow = (WixVariableRow)this.Core.CreateRow(sourceLineNumbers, "WixVariable"); | 179 | var variableId = new Identifier(AccessModifier.Public, String.Format(CultureInfo.InvariantCulture, "{0}_{1}", VarPrefix, id)); |
186 | wixVariableRow.Id = String.Format(CultureInfo.InvariantCulture, "{0}_{1}", VarPrefix, id); | 180 | var wixVariableRow = (WixVariableTuple)this.ParseHelper.CreateRow(section, sourceLineNumbers, "WixVariable", variableId); |
187 | wixVariableRow.Value = major.ToString(CultureInfo.InvariantCulture); | 181 | wixVariableRow.Value = major.ToString(CultureInfo.InvariantCulture); |
188 | wixVariableRow.Overridable = false; | 182 | wixVariableRow.Overridable = false; |
189 | 183 | ||
190 | int registryRoot = 2; // HKLM | 184 | int registryRoot = 2; // HKLM |
191 | string registryKey = String.Format(CultureInfo.InvariantCulture, KeyFormat, major, id); | 185 | string registryKey = String.Format(CultureInfo.InvariantCulture, KeyFormat, major, id); |
192 | 186 | ||
193 | this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "ApplicationBase", String.Format(CultureInfo.InvariantCulture, "[${0}]", componentId), componentId, false); | 187 | this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "ApplicationBase", String.Format(CultureInfo.InvariantCulture, "[${0}]", componentId), componentId, false); |
194 | 188 | ||
195 | // set the assembly name automatically when binding. | 189 | // set the assembly name automatically when binding. |
196 | // processorArchitecture is not handled correctly by PowerShell v1.0 | 190 | // processorArchitecture is not handled correctly by PowerShell v1.0 |
197 | // so format the assembly name explicitly. | 191 | // so format the assembly name explicitly. |
198 | assemblyName = String.Format(CultureInfo.InvariantCulture, "!(bind.assemblyName.{0}), Version=!(bind.assemblyVersion.{0}), Culture=!(bind.assemblyCulture.{0}), PublicKeyToken=!(bind.assemblyPublicKeyToken.{0})", fileId); | 192 | assemblyName = String.Format(CultureInfo.InvariantCulture, "!(bind.assemblyName.{0}), Version=!(bind.assemblyVersion.{0}), Culture=!(bind.assemblyCulture.{0}), PublicKeyToken=!(bind.assemblyPublicKeyToken.{0})", fileId); |
199 | this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "AssemblyName", assemblyName, componentId, false); | 193 | this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "AssemblyName", assemblyName, componentId, false); |
200 | 194 | ||
201 | if (null != customSnapInType) | 195 | if (null != customSnapInType) |
202 | { | 196 | { |
203 | this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "CustomPSSnapInType", customSnapInType, componentId, false); | 197 | this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "CustomPSSnapInType", customSnapInType, componentId, false); |
204 | } | 198 | } |
205 | 199 | ||
206 | if (null != description) | 200 | if (null != description) |
207 | { | 201 | { |
208 | this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "Description", description, componentId, false); | 202 | this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "Description", description, componentId, false); |
209 | } | 203 | } |
210 | 204 | ||
211 | if (null != descriptionIndirect) | 205 | if (null != descriptionIndirect) |
212 | { | 206 | { |
213 | this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "DescriptionIndirect", descriptionIndirect, componentId, false); | 207 | this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "DescriptionIndirect", descriptionIndirect, componentId, false); |
214 | } | 208 | } |
215 | 209 | ||
216 | this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "ModuleName", String.Format(CultureInfo.InvariantCulture, "[#{0}]", fileId), componentId, false); | 210 | this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "ModuleName", String.Format(CultureInfo.InvariantCulture, "[#{0}]", fileId), componentId, false); |
217 | 211 | ||
218 | this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "PowerShellVersion", requiredPowerShellVersion.ToString(2), componentId, false); | 212 | this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "PowerShellVersion", requiredPowerShellVersion.ToString(2), componentId, false); |
219 | 213 | ||
220 | if (null != vendor) | 214 | if (null != vendor) |
221 | { | 215 | { |
222 | this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "Vendor", vendor, componentId, false); | 216 | this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "Vendor", vendor, componentId, false); |
223 | } | 217 | } |
224 | 218 | ||
225 | if (null != vendorIndirect) | 219 | if (null != vendorIndirect) |
226 | { | 220 | { |
227 | this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "VendorIndirect", vendorIndirect, componentId, false); | 221 | this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "VendorIndirect", vendorIndirect, componentId, false); |
228 | } | 222 | } |
229 | 223 | ||
230 | if (null != version) | 224 | if (null != version) |
231 | { | 225 | { |
232 | this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "Version", version, componentId, false); | 226 | this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "Version", version, componentId, false); |
233 | } | 227 | } |
234 | } | 228 | } |
235 | 229 | ||
@@ -240,9 +234,9 @@ namespace WixToolset.Extensions | |||
240 | /// <param name="valueName">Registry value name.</param> | 234 | /// <param name="valueName">Registry value name.</param> |
241 | /// <param name="id">Idendifier for parent file or snap-in.</param> | 235 | /// <param name="id">Idendifier for parent file or snap-in.</param> |
242 | /// <param name="componentId">Identifier for parent component.</param> | 236 | /// <param name="componentId">Identifier for parent component.</param> |
243 | private void ParseExtensionsFile(XElement node, string valueName, string id, string componentId) | 237 | private void ParseExtensionsFile(Intermediate intermediate, IntermediateSection section, XElement node, string valueName, string id, string componentId) |
244 | { | 238 | { |
245 | SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); | 239 | SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node); |
246 | string fileId = null; | 240 | string fileId = null; |
247 | string snapIn = null; | 241 | string snapIn = null; |
248 | 242 | ||
@@ -253,38 +247,38 @@ namespace WixToolset.Extensions | |||
253 | switch (attrib.Name.LocalName) | 247 | switch (attrib.Name.LocalName) |
254 | { | 248 | { |
255 | case "FileId": | 249 | case "FileId": |
256 | fileId = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | 250 | fileId = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); |
257 | snapIn = id; | 251 | snapIn = id; |
258 | break; | 252 | break; |
259 | 253 | ||
260 | case "SnapIn": | 254 | case "SnapIn": |
261 | fileId = id; | 255 | fileId = id; |
262 | snapIn = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | 256 | snapIn = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); |
263 | break; | 257 | break; |
264 | 258 | ||
265 | default: | 259 | default: |
266 | this.Core.UnexpectedAttribute(node, attrib); | 260 | this.ParseHelper.UnexpectedAttribute(node, attrib); |
267 | break; | 261 | break; |
268 | } | 262 | } |
269 | } | 263 | } |
270 | else | 264 | else |
271 | { | 265 | { |
272 | this.Core.ParseExtensionAttribute(node, attrib); | 266 | this.ParseHelper.ParseExtensionAttribute(this.Context.Extensions, intermediate, section, node, attrib); |
273 | } | 267 | } |
274 | } | 268 | } |
275 | 269 | ||
276 | if (null == fileId && null == snapIn) | 270 | if (null == fileId && null == snapIn) |
277 | { | 271 | { |
278 | this.Core.OnMessage(PSErrors.NeitherIdSpecified(sourceLineNumbers, valueName)); | 272 | this.Messaging.Write(PSErrors.NeitherIdSpecified(sourceLineNumbers, valueName)); |
279 | } | 273 | } |
280 | 274 | ||
281 | this.Core.ParseForExtensionElements(node); | 275 | this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, node); |
282 | 276 | ||
283 | int registryRoot = 2; // HKLM | 277 | int registryRoot = 2; // HKLM |
284 | string registryKey = String.Format(CultureInfo.InvariantCulture, KeyFormat, String.Format(CultureInfo.InvariantCulture, "!(wix.{0}_{1})", VarPrefix, snapIn), snapIn); | 278 | string registryKey = String.Format(CultureInfo.InvariantCulture, KeyFormat, String.Format(CultureInfo.InvariantCulture, "!(wix.{0}_{1})", VarPrefix, snapIn), snapIn); |
285 | 279 | ||
286 | this.Core.CreateSimpleReference(sourceLineNumbers, "File", fileId); | 280 | this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "File", fileId); |
287 | this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, valueName, String.Format(CultureInfo.InvariantCulture, "[~][#{0}]", fileId), componentId, false); | 281 | this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, valueName, String.Format(CultureInfo.InvariantCulture, "[~][#{0}]", fileId), componentId, false); |
288 | } | 282 | } |
289 | } | 283 | } |
290 | } | 284 | } |