From 2724cfee4c163f3297ee25edfd2372767cfd4945 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 19 Jul 2018 00:58:00 -0700 Subject: Move tool projects to Tools repo --- src/test/Example.Extension/Data/example.txt | 1 + src/test/Example.Extension/Data/example.wir | Bin 0 -> 534 bytes src/test/Example.Extension/Data/example.wxs | 8 ++ .../Example.Extension/Example.Extension.csproj | 20 +++++ .../Example.Extension/ExampleCompilerExtension.cs | 81 +++++++++++++++++++++ src/test/Example.Extension/ExampleExtensionData.cs | 33 +++++++++ .../Example.Extension/ExampleExtensionFactory.cs | 43 +++++++++++ .../ExamplePreprocessorExtensionAndCommandLine.cs | 50 +++++++++++++ .../Example.Extension/ExampleTableDefinitions.cs | 20 +++++ src/test/Example.Extension/ExampleTuple.cs | 31 ++++++++ .../Example.Extension/ExampleTupleDefinitions.cs | 20 +++++ .../ExampleWindowsInstallerBackendExtension.cs | 32 ++++++++ 12 files changed, 339 insertions(+) create mode 100644 src/test/Example.Extension/Data/example.txt create mode 100644 src/test/Example.Extension/Data/example.wir create mode 100644 src/test/Example.Extension/Data/example.wxs create mode 100644 src/test/Example.Extension/Example.Extension.csproj create mode 100644 src/test/Example.Extension/ExampleCompilerExtension.cs create mode 100644 src/test/Example.Extension/ExampleExtensionData.cs create mode 100644 src/test/Example.Extension/ExampleExtensionFactory.cs create mode 100644 src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs create mode 100644 src/test/Example.Extension/ExampleTableDefinitions.cs create mode 100644 src/test/Example.Extension/ExampleTuple.cs create mode 100644 src/test/Example.Extension/ExampleTupleDefinitions.cs create mode 100644 src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs (limited to 'src/test/Example.Extension') diff --git a/src/test/Example.Extension/Data/example.txt b/src/test/Example.Extension/Data/example.txt new file mode 100644 index 00000000..1b4ffe8a --- /dev/null +++ b/src/test/Example.Extension/Data/example.txt @@ -0,0 +1 @@ +This is example.txt. \ No newline at end of file diff --git a/src/test/Example.Extension/Data/example.wir b/src/test/Example.Extension/Data/example.wir new file mode 100644 index 00000000..674f63fc Binary files /dev/null and b/src/test/Example.Extension/Data/example.wir differ diff --git a/src/test/Example.Extension/Data/example.wxs b/src/test/Example.Extension/Data/example.wxs new file mode 100644 index 00000000..53531e99 --- /dev/null +++ b/src/test/Example.Extension/Data/example.wxs @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/src/test/Example.Extension/Example.Extension.csproj b/src/test/Example.Extension/Example.Extension.csproj new file mode 100644 index 00000000..1dde5044 --- /dev/null +++ b/src/test/Example.Extension/Example.Extension.csproj @@ -0,0 +1,20 @@ + + + + + + netstandard2.0 + false + embedded + + + + + + + + + + + + diff --git a/src/test/Example.Extension/ExampleCompilerExtension.cs b/src/test/Example.Extension/ExampleCompilerExtension.cs new file mode 100644 index 00000000..cd9e1fb9 --- /dev/null +++ b/src/test/Example.Extension/ExampleCompilerExtension.cs @@ -0,0 +1,81 @@ +// 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 Example.Extension +{ + using System; + using System.Collections.Generic; + using System.Xml.Linq; + using WixToolset.Data; + using WixToolset.Extensibility; + + internal class ExampleCompilerExtension : BaseCompilerExtension + { + public override XNamespace Namespace => "http://www.example.com/scheams/v1/wxs"; + + public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary context) + { + var processed = false; + + switch (parentElement.Name.LocalName) + { + case "Component": + switch (element.Name.LocalName) + { + case "Example": + this.ParseExampleElement(intermediate, section, element); + processed = true; + break; + } + break; + } + + if (!processed) + { + base.ParseElement(intermediate, section, parentElement, element, context); + } + } + + private void ParseExampleElement(Intermediate intermediate, IntermediateSection section, XElement element) + { + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element); + Identifier id = null; + string value = null; + + foreach (var attrib in element.Attributes()) + { + if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) + { + switch (attrib.Name.LocalName) + { + case "Id": + id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib); + break; + + case "Value": + value = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib); + break; + + default: + this.ParseHelper.UnexpectedAttribute(element, attrib); + break; + } + } + else + { + this.ParseAttribute(intermediate, section, element, attrib, null); + } + } + + if (null == id) + { + //this.Messaging(WixErrors.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id")); + } + + if (!this.Messaging.EncounteredError) + { + var tuple = this.ParseHelper.CreateRow(section, sourceLineNumbers, "Example", id); + tuple.Set(1, value); + } + } + } +} diff --git a/src/test/Example.Extension/ExampleExtensionData.cs b/src/test/Example.Extension/ExampleExtensionData.cs new file mode 100644 index 00000000..724f9eea --- /dev/null +++ b/src/test/Example.Extension/ExampleExtensionData.cs @@ -0,0 +1,33 @@ +// 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 Example.Extension +{ + using WixToolset.Data; + using WixToolset.Extensibility; + + internal class ExampleExtensionData : IExtensionData + { + public string DefaultCulture => null; + + public Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions) + { + return Intermediate.Load(typeof(ExampleExtensionData).Assembly, "Example.Extension.Data.Example.wir", tupleDefinitions); + } + + public bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition) + { + switch (name) + { + case "Example": + tupleDefinition = ExampleTupleDefinitions.Example; + break; + + default: + tupleDefinition = null; + break; + } + + return tupleDefinition != null; + } + } +} \ No newline at end of file diff --git a/src/test/Example.Extension/ExampleExtensionFactory.cs b/src/test/Example.Extension/ExampleExtensionFactory.cs new file mode 100644 index 00000000..a081b758 --- /dev/null +++ b/src/test/Example.Extension/ExampleExtensionFactory.cs @@ -0,0 +1,43 @@ +// 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 Example.Extension +{ + using System; + using WixToolset.Extensibility; + + public class ExampleExtensionFactory : IExtensionFactory + { + private ExamplePreprocessorExtensionAndCommandLine preprocessorExtension; + + public bool TryCreateExtension(Type extensionType, out object extension) + { + if (extensionType == typeof(IExtensionCommandLine) || extensionType == typeof(IPreprocessorExtension)) + { + if (preprocessorExtension == null) + { + preprocessorExtension = new ExamplePreprocessorExtensionAndCommandLine(); + } + + extension = preprocessorExtension; + } + else if (extensionType == typeof(ICompilerExtension)) + { + extension = new ExampleCompilerExtension(); + } + else if (extensionType == typeof(IExtensionData)) + { + extension = new ExampleExtensionData(); + } + else if (extensionType == typeof(IWindowsInstallerBackendExtension)) + { + extension = new ExampleWindowsInstallerBackendExtension(); + } + else + { + extension = null; + } + + return extension != null; + } + } +} diff --git a/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs b/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs new file mode 100644 index 00000000..6f86e20d --- /dev/null +++ b/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs @@ -0,0 +1,50 @@ +// 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 Example.Extension +{ + using System; + using System.Collections.Generic; + using WixToolset.Extensibility; + using WixToolset.Extensibility.Services; + + internal class ExamplePreprocessorExtensionAndCommandLine : BasePreprocessorExtension, IExtensionCommandLine + { + private string exampleValueFromCommandLine; + + public IEnumerable CommandLineSwitches => throw new NotImplementedException(); + + public ExamplePreprocessorExtensionAndCommandLine() + { + this.Prefixes = new[] { "ex" }; + } + + public void PreParse(ICommandLineContext context) + { + } + + public bool TryParseArgument(IParseCommandLine parseCommandLine, string arg) + { + if (parseCommandLine.IsSwitch(arg) && arg.Substring(1).Equals("example", StringComparison.OrdinalIgnoreCase)) + { + this.exampleValueFromCommandLine = parseCommandLine.GetNextArgumentOrError(arg); + return true; + } + + return false; + } + + public void PostParse() + { + } + + public override string GetVariableValue(string prefix, string name) + { + if (prefix == "ex" && "test".Equals(name, StringComparison.OrdinalIgnoreCase)) + { + return String.IsNullOrWhiteSpace(this.exampleValueFromCommandLine) ? "(null)" : this.exampleValueFromCommandLine; + } + + return null; + } + } +} \ No newline at end of file diff --git a/src/test/Example.Extension/ExampleTableDefinitions.cs b/src/test/Example.Extension/ExampleTableDefinitions.cs new file mode 100644 index 00000000..dbd6491b --- /dev/null +++ b/src/test/Example.Extension/ExampleTableDefinitions.cs @@ -0,0 +1,20 @@ +// 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 Example.Extension +{ + using WixToolset.Data.WindowsInstaller; + + public static class ExampleTableDefinitions + { + public static readonly TableDefinition ExampleTable = new TableDefinition( + "Example", + new[] + { + new ColumnDefinition("Example", ColumnType.String, 72, true, false, ColumnCategory.Identifier), + new ColumnDefinition("Value", ColumnType.String, 0, false, false, ColumnCategory.Formatted), + } + ); + + public static readonly TableDefinition[] All = new[] { ExampleTable }; + } +} diff --git a/src/test/Example.Extension/ExampleTuple.cs b/src/test/Example.Extension/ExampleTuple.cs new file mode 100644 index 00000000..0fc0d82c --- /dev/null +++ b/src/test/Example.Extension/ExampleTuple.cs @@ -0,0 +1,31 @@ +// 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 Example.Extension +{ + using WixToolset.Data; + + public enum ExampleTupleFields + { + Example, + Value, + } + + public class ExampleTuple : IntermediateTuple + { + public ExampleTuple() : base(ExampleTupleDefinitions.Example, null, null) + { + } + + public ExampleTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(ExampleTupleDefinitions.Example, sourceLineNumber, id) + { + } + + public IntermediateField this[ExampleTupleFields index] => this.Fields[(int)index]; + + public string Value + { + get => this.Fields[(int)ExampleTupleFields.Value]?.AsString(); + set => this.Set((int)ExampleTupleFields.Value, value); + } + } +} diff --git a/src/test/Example.Extension/ExampleTupleDefinitions.cs b/src/test/Example.Extension/ExampleTupleDefinitions.cs new file mode 100644 index 00000000..4775b827 --- /dev/null +++ b/src/test/Example.Extension/ExampleTupleDefinitions.cs @@ -0,0 +1,20 @@ +// 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 Example.Extension +{ + using WixToolset.Data; + + public static class ExampleTupleDefinitions + { + public const string ExampleName = "Example"; + + public static readonly IntermediateTupleDefinition Example = new IntermediateTupleDefinition( + ExampleName, + new[] + { + new IntermediateFieldDefinition(nameof(ExampleTupleFields.Example), IntermediateFieldType.String), + new IntermediateFieldDefinition(nameof(ExampleTupleFields.Value), IntermediateFieldType.String), + }, + typeof(ExampleTuple)); + } +} diff --git a/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs b/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs new file mode 100644 index 00000000..f00a5102 --- /dev/null +++ b/src/test/Example.Extension/ExampleWindowsInstallerBackendExtension.cs @@ -0,0 +1,32 @@ +// 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 Example.Extension +{ + using WixToolset.Data; + using WixToolset.Data.WindowsInstaller; + using WixToolset.Extensibility; + + internal class ExampleWindowsInstallerBackendExtension : BaseWindowsInstallerBackendExtension + { + public override bool TryAddTupleToOutput(IntermediateTuple tuple, Output output) + { +#if ALTERNATIVE_TO_USING_HELPER + switch (tuple.Definition.Name) + { + case TupleDefinitions.ExampleName: + { + var table = output.EnsureTable(ExampleTableDefinitions.ExampleTable); + var row = table.CreateRow(tuple.SourceLineNumbers); + row[0] = tuple[0].AsString(); + row[1] = tuple[1].AsString(); + } + return true; + } + + return false; +#else + return this.BackendHelper.TryAddTupleToOutputMatchingTableDefinitions(tuple, output, ExampleTableDefinitions.All); +#endif + } + } +} -- cgit v1.2.3-55-g6feb