aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Extensibility/Services
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-11-14 23:08:24 -0800
committerRob Mensching <rob@firegiant.com>2017-11-14 23:08:24 -0800
commit404f34f00ecce034a8a06fe4757789c6ce62f3f6 (patch)
tree7132435cfa13f0f9b0e872a57ab19d52a12bb103 /src/WixToolset.Extensibility/Services
parent3f6e936c5e9d7a9df7e3e0ed1bc17001c53db5b3 (diff)
downloadwix-404f34f00ecce034a8a06fe4757789c6ce62f3f6.tar.gz
wix-404f34f00ecce034a8a06fe4757789c6ce62f3f6.tar.bz2
wix-404f34f00ecce034a8a06fe4757789c6ce62f3f6.zip
Remove ICompilerCore, introduce IParseHelper and other small fixes
Diffstat (limited to 'src/WixToolset.Extensibility/Services')
-rw-r--r--src/WixToolset.Extensibility/Services/IParseHelper.cs334
1 files changed, 334 insertions, 0 deletions
diff --git a/src/WixToolset.Extensibility/Services/IParseHelper.cs b/src/WixToolset.Extensibility/Services/IParseHelper.cs
new file mode 100644
index 00000000..46ade2e1
--- /dev/null
+++ b/src/WixToolset.Extensibility/Services/IParseHelper.cs
@@ -0,0 +1,334 @@
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
3namespace WixToolset.Extensibility.Services
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Xml.Linq;
8 using WixToolset.Data;
9
10 /// <summary>
11 /// Core interface provided by the compiler.
12 /// </summary>
13 public interface IParseHelper
14 {
15 /// <summary>
16 /// Creates a version 3 name-based UUID.
17 /// </summary>
18 /// <param name="namespaceGuid">The namespace UUID.</param>
19 /// <param name="value">The value.</param>
20 /// <returns>The generated GUID for the given namespace and value.</returns>
21 string CreateGuid(Guid namespaceGuid, string value);
22
23 /// <summary>
24 /// Create an identifier by hashing data from the row.
25 /// </summary>
26 /// <param name="prefix">Three letter or less prefix for generated row identifier.</param>
27 /// <param name="args">Information to hash.</param>
28 /// <returns>The new identifier.</returns>
29 Identifier CreateIdentifier(string prefix, params string[] args);
30
31 /// <summary>
32 /// Create an identifier based on passed file name
33 /// </summary>
34 /// <param name="name">File name to generate identifer from</param>
35 /// <returns></returns>
36 Identifier CreateIdentifierFromFilename(string filename);
37
38 /// <summary>
39 /// Creates a row in the section.
40 /// </summary>
41 /// <param name="section">Section to add the new tuple to.</param>
42 /// <param name="sourceLineNumbers">Source and line number of current row.</param>
43 /// <param name="tableName">Name of table to create row in.</param>
44 /// <param name="identifier">Optional identifier for the row.</param>
45 /// <returns>New row.</returns>
46 IntermediateTuple CreateRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName, Identifier identifier = null);
47
48 /// <summary>
49 /// Creates a row in the section.
50 /// </summary>
51 /// <param name="section">Section to add the new tuple to.</param>
52 /// <param name="sourceLineNumbers">Source and line number of current row.</param>
53 /// <param name="tupleType">Type of tuple to create.</param>
54 /// <param name="identifier">Optional identifier for the row.</param>
55 /// <returns>New row.</returns>
56 IntermediateTuple CreateRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, TupleDefinitionType tupleType, Identifier identifier = null);
57
58 /// <summary>
59 /// Creates a directory row from a name.
60 /// </summary>
61 /// <param name="section">Section to add the new tuple to.</param>
62 /// <param name="sourceLineNumbers">Source line information.</param>
63 /// <param name="id">Optional identifier for the new row.</param>
64 /// <param name="parentId">Optional identifier for the parent row.</param>
65 /// <param name="name">Long name of the directory.</param>
66 /// <param name="shortName">Optional short name of the directory.</param>
67 /// <param name="sourceName">Optional source name for the directory.</param>
68 /// <param name="shortSourceName">Optional short source name for the directory.</param>
69 /// <returns>Identifier for the newly created row.</returns>
70 Identifier CreateDirectoryRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, Identifier id, string parentId, string name, string shortName = null, string sourceName = null, string shortSourceName = null, ISet<string> sectionInlinedDirectoryIds = null);
71
72 /// <summary>
73 /// Creates directories using the inline directory syntax.
74 /// </summary>
75 /// <param name="sourceLineNumbers">Source line information.</param>
76 /// <param name="attribute">The attribute to parse.</param>
77 /// <param name="parentId">Optional identifier of parent directory.</param>
78 /// <returns>Identifier of the leaf directory created.</returns>
79 string CreateDirectoryReferenceFromInlineSyntax(IntermediateSection section, SourceLineNumber sourceLineNumbers, XAttribute attribute, string parentId);
80
81 /// <summary>
82 /// Creates a Registry row in the active section.
83 /// </summary>
84 /// <param name="sourceLineNumbers">Source and line number of the current row.</param>
85 /// <param name="root">The registry entry root.</param>
86 /// <param name="key">The registry entry key.</param>
87 /// <param name="name">The registry entry name.</param>
88 /// <param name="value">The registry entry value.</param>
89 /// <param name="componentId">The component which will control installation/uninstallation of the registry entry.</param>
90 /// <param name="escapeLeadingHash">If true, "escape" leading '#' characters so the value is written as a REG_SZ.</param>
91 Identifier CreateRegistryRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, int root, string key, string name, string value, string componentId, bool escapeLeadingHash);
92
93 /// <summary>
94 /// Creates a short file/directory name using an identifier and long file/directory name as input.
95 /// </summary>
96 /// <param name="longName">The long file/directory name.</param>
97 /// <param name="keepExtension">The option to keep the extension on generated short names.</param>
98 /// <param name="allowWildcards">true if wildcards are allowed in the filename.</param>
99 /// <param name="args">Any additional information to include in the hash for the generated short name.</param>
100 /// <returns>The generated 8.3-compliant short file/directory name.</returns>
101 string CreateShortName(string longName, bool keepExtension, bool allowWildcards, params string[] args);
102
103 /// <summary>
104 /// Create a WixSimpleReference row in the active section.
105 /// </summary>
106 /// <param name="sourceLineNumbers">Source line information for the row.</param>
107 /// <param name="tableName">The table name of the simple reference.</param>
108 /// <param name="primaryKeys">The primary keys of the simple reference.</param>
109 void CreateSimpleReference(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName, params string[] primaryKeys);
110
111 /// <summary>
112 /// Creates WixComplexReference and WixGroup rows in the active section.
113 /// </summary>
114 /// <param name="sourceLineNumbers">Source line information.</param>
115 /// <param name="parentType">The parent type.</param>
116 /// <param name="parentId">The parent id.</param>
117 /// <param name="parentLanguage">The parent language.</param>
118 /// <param name="childType">The child type.</param>
119 /// <param name="childId">The child id.</param>
120 /// <param name="isPrimary">Whether the child is primary.</param>
121 void CreateComplexReference(IntermediateSection section, SourceLineNumber sourceLineNumbers, ComplexReferenceParentType parentType, string parentId, string parentLanguage, ComplexReferenceChildType childType, string childId, bool isPrimary);
122
123 /// <summary>
124 /// A row in the WixGroup table is added for this child node and its parent node.
125 /// </summary>
126 /// <param name="sourceLineNumbers">Source line information for the row.</param>
127 /// <param name="parentType">Type of child's complex reference parent.</param>
128 /// <param name="parentId">Id of the parenet node.</param>
129 /// <param name="childType">Complex reference type of child</param>
130 /// <param name="childId">Id of the Child Node.</param>
131 void CreateWixGroupRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, ComplexReferenceParentType parentType, string parentId, ComplexReferenceChildType childType, string childId);
132
133 /// <summary>
134 /// Checks if the string contains a property (i.e. "foo[Property]bar")
135 /// </summary>
136 /// <param name="possibleProperty">String to evaluate for properties.</param>
137 /// <returns>True if a property is found in the string.</returns>
138 bool ContainsProperty(string possibleProperty);
139
140 /// <summary>
141 /// Add the appropriate rows to make sure that the given table shows up in the resulting output.
142 /// </summary>
143 /// <param name="sourceLineNumbers">Source line numbers.</param>
144 /// <param name="tableName">Name of the table to ensure existance of.</param>
145 void EnsureTable(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName);
146
147 /// <summary>
148 /// Get an attribute value and displays an error if the value is empty by default.
149 /// </summary>
150 /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
151 /// <param name="attribute">The attribute containing the value to get.</param>
152 /// <param name="emptyRule">A rule for the contents of the value. If the contents do not follow the rule, an error is thrown.</param>
153 /// <returns>The attribute's value.</returns>
154 string GetAttributeValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, EmptyRule emptyRule = EmptyRule.CanBeWhitespaceOnly);
155
156 /// <summary>
157 /// Get a guid attribute value and displays an error for an illegal guid value.
158 /// </summary>
159 /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
160 /// <param name="attribute">The attribute containing the value to get.</param>
161 /// <param name="generatable">Determines whether the guid can be automatically generated.</param>
162 /// <param name="canBeEmpty">If true, no error is raised on empty value. If false, an error is raised.</param>
163 /// <returns>The attribute's guid value or a special value if an error occurred.</returns>
164 string GetAttributeGuidValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool generatable = false, bool canBeEmpty = false);
165
166 /// <summary>
167 /// Get an identifier attribute value and displays an error for an illegal identifier value.
168 /// </summary>
169 /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
170 /// <param name="attribute">The attribute containing the value to get.</param>
171 /// <returns>The attribute's identifier value or a special value if an error occurred.</returns>
172 Identifier GetAttributeIdentifier(SourceLineNumber sourceLineNumbers, XAttribute attribute);
173
174 /// <summary>
175 /// Get an identifier attribute value and displays an error for an illegal identifier value.
176 /// </summary>
177 /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
178 /// <param name="attribute">The attribute containing the value to get.</param>
179 /// <returns>The attribute's identifier value or a special value if an error occurred.</returns>
180 string GetAttributeIdentifierValue(SourceLineNumber sourceLineNumbers, XAttribute attribute);
181
182 /// <summary>
183 /// Gets the attribute value as inline directory syntax.
184 /// </summary>
185 /// <param name="sourceLineNumbers">Source line information.</param>
186 /// <param name="attribute">Attribute containing the value to get.</param>
187 /// <param name="resultUsedToCreateReference">Flag indicates whether the inline directory syntax should be processed to create a directory row or to create a directory reference.</param>
188 /// <returns>Inline directory syntax split into array of strings or null if the syntax did not parse.</returns>
189 string[] GetAttributeInlineDirectorySyntax(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool resultUsedToCreateReference);
190
191 /// <summary>
192 /// Get an integer attribute value and displays an error for an illegal integer value.
193 /// </summary>
194 /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
195 /// <param name="attribute">The attribute containing the value to get.</param>
196 /// <param name="minimum">The minimum legal value.</param>
197 /// <param name="maximum">The maximum legal value.</param>
198 /// <returns>The attribute's integer value or a special value if an error occurred during conversion.</returns>
199 int GetAttributeIntegerValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, int minimum, int maximum);
200
201 /// <summary>
202 /// Get a long integral attribute value and displays an error for an illegal long value.
203 /// </summary>
204 /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
205 /// <param name="attribute">The attribute containing the value to get.</param>
206 /// <param name="minimum">The minimum legal value.</param>
207 /// <param name="maximum">The maximum legal value.</param>
208 /// <returns>The attribute's long value or a special value if an error occurred during conversion.</returns>
209 long GetAttributeLongValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, long minimum, long maximum);
210
211 /// <summary>
212 /// Gets a long filename value and displays an error for an illegal long filename value.
213 /// </summary>
214 /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
215 /// <param name="attribute">The attribute containing the value to get.</param>
216 /// <param name="allowWildcards">true if wildcards are allowed in the filename.</param>
217 /// <param name="allowRelative">true if relative paths are allowed in the filename.</param>
218 /// <returns>The attribute's long filename value.</returns>
219 string GetAttributeLongFilename(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowWildcards = false, bool allowRelative = false);
220
221 /// <summary>
222 /// Gets a version value or possibly a binder variable and displays an error for an illegal version value.
223 /// </summary>
224 /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
225 /// <param name="attribute">The attribute containing the value to get.</param>
226 /// <returns>The attribute's version value.</returns>
227 string GetAttributeVersionValue(SourceLineNumber sourceLineNumbers, XAttribute attribute);
228
229 /// <summary>
230 /// Gets a yes/no value and displays an error for an illegal yes/no value.
231 /// </summary>
232 /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
233 /// <param name="attribute">The attribute containing the value to get.</param>
234 /// <returns>The attribute's YesNoType value.</returns>
235 YesNoType GetAttributeYesNoValue(SourceLineNumber sourceLineNumbers, XAttribute attribute);
236
237 /// <summary>
238 /// Gets a yes/no/default value and displays an error for an illegal yes/no/default value.
239 /// </summary>
240 /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
241 /// <param name="attribute">The attribute containing the value to get.</param>
242 /// <returns>The attribute's YesNoType value.</returns>
243 YesNoDefaultType GetAttributeYesNoDefaultValue(SourceLineNumber sourceLineNumbers, XAttribute attribute);
244
245 /// <summary>
246 /// Gets node's inner text and ensure's it is safe for use in a condition by trimming any extra whitespace.
247 /// </summary>
248 /// <param name="node">The node to ensure inner text is a condition.</param>
249 /// <returns>The value converted into a safe condition.</returns>
250 string GetConditionInnerText(XElement node);
251
252 /// <summary>
253 /// Get an element's inner text and trims any extra whitespace.
254 /// </summary>
255 /// <param name="element">The element with inner text to be trimmed.</param>
256 /// <returns>The node's inner text trimmed.</returns>
257 string GetTrimmedInnerText(XElement element);
258
259 /// <summary>
260 /// Verifies that a value is a legal identifier.
261 /// </summary>
262 /// <param name="value">The value to verify.</param>
263 /// <returns>true if the value is an identifier; false otherwise.</returns>
264 bool IsValidIdentifier(string value);
265
266 /// <summary>
267 /// Verifies if an identifier is a valid loc identifier.
268 /// </summary>
269 /// <param name="identifier">Identifier to verify.</param>
270 /// <returns>True if the identifier is a valid loc identifier.</returns>
271 bool IsValidLocIdentifier(string identifier);
272
273 /// <summary>
274 /// Verifies if a filename is a valid long filename.
275 /// </summary>
276 /// <param name="filename">Filename to verify.</param>
277 /// <param name="allowWildcards">true if wildcards are allowed in the filename.</param>
278 /// <param name="allowRelative">true if relative paths are allowed in the filename.</param>
279 /// <returns>True if the filename is a valid long filename</returns>
280 bool IsValidLongFilename(string filename, bool allowWildcards = false, bool allowRelative = false);
281
282 /// <summary>
283 /// Verifies if a filename is a valid short filename.
284 /// </summary>
285 /// <param name="filename">Filename to verify.</param>
286 /// <param name="allowWildcards">true if wildcards are allowed in the filename.</param>
287 /// <returns>True if the filename is a valid short filename</returns>
288 bool IsValidShortFilename(string filename, bool allowWildcards = false);
289
290 /// <summary>
291 /// Attempts to use an extension to parse the attribute.
292 /// </summary>
293 /// <param name="element">Element containing attribute to be parsed.</param>
294 /// <param name="attribute">Attribute to be parsed.</param>
295 /// <param name="context">Extra information about the context in which this element is being parsed.</param>
296 void ParseExtensionAttribute(IEnumerable<ICompilerExtension> extensions, Intermediate intermediate, IntermediateSection section, XElement element, XAttribute attribute, IDictionary<string, string> context = null);
297
298 /// <summary>
299 /// Attempts to use an extension to parse the element.
300 /// </summary>
301 /// <param name="parentElement">Element containing element to be parsed.</param>
302 /// <param name="element">Element to be parsed.</param>
303 /// <param name="contextValues">Extra information about the context in which this element is being parsed.</param>
304 void ParseExtensionElement(IEnumerable<ICompilerExtension> extensions, Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context = null);
305
306 /// <summary>
307 /// Attempts to use an extension to parse the element, with support for setting component keypath.
308 /// </summary>
309 /// <param name="parentElement">Element containing element to be parsed.</param>
310 /// <param name="element">Element to be parsed.</param>
311 /// <param name="contextValues">Extra information about the context in which this element is being parsed.</param>
312 ComponentKeyPath ParsePossibleKeyPathExtensionElement(IEnumerable<ICompilerExtension> extensions, Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context);
313
314 /// <summary>
315 /// Process all children of the element looking for extensions and erroring on the unexpected.
316 /// </summary>
317 /// <param name="element">Element to parse children.</param>
318 void ParseForExtensionElements(IEnumerable<ICompilerExtension> extensions, Intermediate intermediate, IntermediateSection section, XElement element);
319
320 /// <summary>
321 /// Called when the compiler encounters an unexpected attribute.
322 /// </summary>
323 /// <param name="parentElement">Parent element that found unexpected attribute.</param>
324 /// <param name="attribute">Unexpected attribute.</param>
325 void UnexpectedAttribute(XElement element, XAttribute attribute);
326
327 /// <summary>
328 /// Called when the compiler encounters an unexpected child element.
329 /// </summary>
330 /// <param name="parentElement">Parent element that found unexpected child.</param>
331 /// <param name="childElement">Unexpected child element.</param>
332 void UnexpectedElement(XElement parentElement, XElement childElement);
333 }
334}