From 404f34f00ecce034a8a06fe4757789c6ce62f3f6 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 14 Nov 2017 23:08:24 -0800 Subject: Remove ICompilerCore, introduce IParseHelper and other small fixes --- .../Services/IParseHelper.cs | 334 +++++++++++++++++++++ 1 file changed, 334 insertions(+) create mode 100644 src/WixToolset.Extensibility/Services/IParseHelper.cs (limited to 'src/WixToolset.Extensibility/Services') 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 @@ +// 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.Extensibility.Services +{ + using System; + using System.Collections.Generic; + using System.Xml.Linq; + using WixToolset.Data; + + /// + /// Core interface provided by the compiler. + /// + public interface IParseHelper + { + /// + /// Creates a version 3 name-based UUID. + /// + /// The namespace UUID. + /// The value. + /// The generated GUID for the given namespace and value. + string CreateGuid(Guid namespaceGuid, string value); + + /// + /// Create an identifier by hashing data from the row. + /// + /// Three letter or less prefix for generated row identifier. + /// Information to hash. + /// The new identifier. + Identifier CreateIdentifier(string prefix, params string[] args); + + /// + /// Create an identifier based on passed file name + /// + /// File name to generate identifer from + /// + Identifier CreateIdentifierFromFilename(string filename); + + /// + /// Creates a row in the section. + /// + /// Section to add the new tuple to. + /// Source and line number of current row. + /// Name of table to create row in. + /// Optional identifier for the row. + /// New row. + IntermediateTuple CreateRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName, Identifier identifier = null); + + /// + /// Creates a row in the section. + /// + /// Section to add the new tuple to. + /// Source and line number of current row. + /// Type of tuple to create. + /// Optional identifier for the row. + /// New row. + IntermediateTuple CreateRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, TupleDefinitionType tupleType, Identifier identifier = null); + + /// + /// Creates a directory row from a name. + /// + /// Section to add the new tuple to. + /// Source line information. + /// Optional identifier for the new row. + /// Optional identifier for the parent row. + /// Long name of the directory. + /// Optional short name of the directory. + /// Optional source name for the directory. + /// Optional short source name for the directory. + /// Identifier for the newly created row. + Identifier CreateDirectoryRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, Identifier id, string parentId, string name, string shortName = null, string sourceName = null, string shortSourceName = null, ISet sectionInlinedDirectoryIds = null); + + /// + /// Creates directories using the inline directory syntax. + /// + /// Source line information. + /// The attribute to parse. + /// Optional identifier of parent directory. + /// Identifier of the leaf directory created. + string CreateDirectoryReferenceFromInlineSyntax(IntermediateSection section, SourceLineNumber sourceLineNumbers, XAttribute attribute, string parentId); + + /// + /// Creates a Registry row in the active section. + /// + /// Source and line number of the current row. + /// The registry entry root. + /// The registry entry key. + /// The registry entry name. + /// The registry entry value. + /// The component which will control installation/uninstallation of the registry entry. + /// If true, "escape" leading '#' characters so the value is written as a REG_SZ. + Identifier CreateRegistryRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, int root, string key, string name, string value, string componentId, bool escapeLeadingHash); + + /// + /// Creates a short file/directory name using an identifier and long file/directory name as input. + /// + /// The long file/directory name. + /// The option to keep the extension on generated short names. + /// true if wildcards are allowed in the filename. + /// Any additional information to include in the hash for the generated short name. + /// The generated 8.3-compliant short file/directory name. + string CreateShortName(string longName, bool keepExtension, bool allowWildcards, params string[] args); + + /// + /// Create a WixSimpleReference row in the active section. + /// + /// Source line information for the row. + /// The table name of the simple reference. + /// The primary keys of the simple reference. + void CreateSimpleReference(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName, params string[] primaryKeys); + + /// + /// Creates WixComplexReference and WixGroup rows in the active section. + /// + /// Source line information. + /// The parent type. + /// The parent id. + /// The parent language. + /// The child type. + /// The child id. + /// Whether the child is primary. + void CreateComplexReference(IntermediateSection section, SourceLineNumber sourceLineNumbers, ComplexReferenceParentType parentType, string parentId, string parentLanguage, ComplexReferenceChildType childType, string childId, bool isPrimary); + + /// + /// A row in the WixGroup table is added for this child node and its parent node. + /// + /// Source line information for the row. + /// Type of child's complex reference parent. + /// Id of the parenet node. + /// Complex reference type of child + /// Id of the Child Node. + void CreateWixGroupRow(IntermediateSection section, SourceLineNumber sourceLineNumbers, ComplexReferenceParentType parentType, string parentId, ComplexReferenceChildType childType, string childId); + + /// + /// Checks if the string contains a property (i.e. "foo[Property]bar") + /// + /// String to evaluate for properties. + /// True if a property is found in the string. + bool ContainsProperty(string possibleProperty); + + /// + /// Add the appropriate rows to make sure that the given table shows up in the resulting output. + /// + /// Source line numbers. + /// Name of the table to ensure existance of. + void EnsureTable(IntermediateSection section, SourceLineNumber sourceLineNumbers, string tableName); + + /// + /// Get an attribute value and displays an error if the value is empty by default. + /// + /// Source line information about the owner element. + /// The attribute containing the value to get. + /// A rule for the contents of the value. If the contents do not follow the rule, an error is thrown. + /// The attribute's value. + string GetAttributeValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, EmptyRule emptyRule = EmptyRule.CanBeWhitespaceOnly); + + /// + /// Get a guid attribute value and displays an error for an illegal guid value. + /// + /// Source line information about the owner element. + /// The attribute containing the value to get. + /// Determines whether the guid can be automatically generated. + /// If true, no error is raised on empty value. If false, an error is raised. + /// The attribute's guid value or a special value if an error occurred. + string GetAttributeGuidValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool generatable = false, bool canBeEmpty = false); + + /// + /// Get an identifier attribute value and displays an error for an illegal identifier value. + /// + /// Source line information about the owner element. + /// The attribute containing the value to get. + /// The attribute's identifier value or a special value if an error occurred. + Identifier GetAttributeIdentifier(SourceLineNumber sourceLineNumbers, XAttribute attribute); + + /// + /// Get an identifier attribute value and displays an error for an illegal identifier value. + /// + /// Source line information about the owner element. + /// The attribute containing the value to get. + /// The attribute's identifier value or a special value if an error occurred. + string GetAttributeIdentifierValue(SourceLineNumber sourceLineNumbers, XAttribute attribute); + + /// + /// Gets the attribute value as inline directory syntax. + /// + /// Source line information. + /// Attribute containing the value to get. + /// Flag indicates whether the inline directory syntax should be processed to create a directory row or to create a directory reference. + /// Inline directory syntax split into array of strings or null if the syntax did not parse. + string[] GetAttributeInlineDirectorySyntax(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool resultUsedToCreateReference); + + /// + /// Get an integer attribute value and displays an error for an illegal integer value. + /// + /// Source line information about the owner element. + /// The attribute containing the value to get. + /// The minimum legal value. + /// The maximum legal value. + /// The attribute's integer value or a special value if an error occurred during conversion. + int GetAttributeIntegerValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, int minimum, int maximum); + + /// + /// Get a long integral attribute value and displays an error for an illegal long value. + /// + /// Source line information about the owner element. + /// The attribute containing the value to get. + /// The minimum legal value. + /// The maximum legal value. + /// The attribute's long value or a special value if an error occurred during conversion. + long GetAttributeLongValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, long minimum, long maximum); + + /// + /// Gets a long filename value and displays an error for an illegal long filename value. + /// + /// Source line information about the owner element. + /// The attribute containing the value to get. + /// true if wildcards are allowed in the filename. + /// true if relative paths are allowed in the filename. + /// The attribute's long filename value. + string GetAttributeLongFilename(SourceLineNumber sourceLineNumbers, XAttribute attribute, bool allowWildcards = false, bool allowRelative = false); + + /// + /// Gets a version value or possibly a binder variable and displays an error for an illegal version value. + /// + /// Source line information about the owner element. + /// The attribute containing the value to get. + /// The attribute's version value. + string GetAttributeVersionValue(SourceLineNumber sourceLineNumbers, XAttribute attribute); + + /// + /// Gets a yes/no value and displays an error for an illegal yes/no value. + /// + /// Source line information about the owner element. + /// The attribute containing the value to get. + /// The attribute's YesNoType value. + YesNoType GetAttributeYesNoValue(SourceLineNumber sourceLineNumbers, XAttribute attribute); + + /// + /// Gets a yes/no/default value and displays an error for an illegal yes/no/default value. + /// + /// Source line information about the owner element. + /// The attribute containing the value to get. + /// The attribute's YesNoType value. + YesNoDefaultType GetAttributeYesNoDefaultValue(SourceLineNumber sourceLineNumbers, XAttribute attribute); + + /// + /// Gets node's inner text and ensure's it is safe for use in a condition by trimming any extra whitespace. + /// + /// The node to ensure inner text is a condition. + /// The value converted into a safe condition. + string GetConditionInnerText(XElement node); + + /// + /// Get an element's inner text and trims any extra whitespace. + /// + /// The element with inner text to be trimmed. + /// The node's inner text trimmed. + string GetTrimmedInnerText(XElement element); + + /// + /// Verifies that a value is a legal identifier. + /// + /// The value to verify. + /// true if the value is an identifier; false otherwise. + bool IsValidIdentifier(string value); + + /// + /// Verifies if an identifier is a valid loc identifier. + /// + /// Identifier to verify. + /// True if the identifier is a valid loc identifier. + bool IsValidLocIdentifier(string identifier); + + /// + /// Verifies if a filename is a valid long filename. + /// + /// Filename to verify. + /// true if wildcards are allowed in the filename. + /// true if relative paths are allowed in the filename. + /// True if the filename is a valid long filename + bool IsValidLongFilename(string filename, bool allowWildcards = false, bool allowRelative = false); + + /// + /// Verifies if a filename is a valid short filename. + /// + /// Filename to verify. + /// true if wildcards are allowed in the filename. + /// True if the filename is a valid short filename + bool IsValidShortFilename(string filename, bool allowWildcards = false); + + /// + /// Attempts to use an extension to parse the attribute. + /// + /// Element containing attribute to be parsed. + /// Attribute to be parsed. + /// Extra information about the context in which this element is being parsed. + void ParseExtensionAttribute(IEnumerable extensions, Intermediate intermediate, IntermediateSection section, XElement element, XAttribute attribute, IDictionary context = null); + + /// + /// Attempts to use an extension to parse the element. + /// + /// Element containing element to be parsed. + /// Element to be parsed. + /// Extra information about the context in which this element is being parsed. + void ParseExtensionElement(IEnumerable extensions, Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary context = null); + + /// + /// Attempts to use an extension to parse the element, with support for setting component keypath. + /// + /// Element containing element to be parsed. + /// Element to be parsed. + /// Extra information about the context in which this element is being parsed. + ComponentKeyPath ParsePossibleKeyPathExtensionElement(IEnumerable extensions, Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary context); + + /// + /// Process all children of the element looking for extensions and erroring on the unexpected. + /// + /// Element to parse children. + void ParseForExtensionElements(IEnumerable extensions, Intermediate intermediate, IntermediateSection section, XElement element); + + /// + /// Called when the compiler encounters an unexpected attribute. + /// + /// Parent element that found unexpected attribute. + /// Unexpected attribute. + void UnexpectedAttribute(XElement element, XAttribute attribute); + + /// + /// Called when the compiler encounters an unexpected child element. + /// + /// Parent element that found unexpected child. + /// Unexpected child element. + void UnexpectedElement(XElement parentElement, XElement childElement); + } +} -- cgit v1.2.3-55-g6feb