From 5ba862bfa618c89a563d555e8ce7b44a904df406 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 6 Dec 2017 11:39:26 -0800 Subject: Add support for loading Intermediates from extensions --- .../Example.Extension/Example.Extension.csproj | 18 ----- .../Example.Extension/ExampleCompilerExtension.cs | 84 ---------------------- src/test/Example.Extension/ExampleExtensionData.cs | 33 --------- .../Example.Extension/ExampleExtensionFactory.cs | 39 ---------- .../ExamplePreprocessorExtensionAndCommandLine.cs | 46 ------------ src/test/Example.Extension/ExampleTuple.cs | 31 -------- src/test/Example.Extension/TupleDefinitions.cs | 18 ----- 7 files changed, 269 deletions(-) delete mode 100644 src/test/Example.Extension/Example.Extension.csproj delete mode 100644 src/test/Example.Extension/ExampleCompilerExtension.cs delete mode 100644 src/test/Example.Extension/ExampleExtensionData.cs delete mode 100644 src/test/Example.Extension/ExampleExtensionFactory.cs delete mode 100644 src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs delete mode 100644 src/test/Example.Extension/ExampleTuple.cs delete mode 100644 src/test/Example.Extension/TupleDefinitions.cs (limited to 'src/test/Example.Extension') diff --git a/src/test/Example.Extension/Example.Extension.csproj b/src/test/Example.Extension/Example.Extension.csproj deleted file mode 100644 index 80c64b25..00000000 --- a/src/test/Example.Extension/Example.Extension.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - netstandard2.0 - false - - - - - - - - - - - diff --git a/src/test/Example.Extension/ExampleCompilerExtension.cs b/src/test/Example.Extension/ExampleCompilerExtension.cs deleted file mode 100644 index 5b20e48f..00000000 --- a/src/test/Example.Extension/ExampleCompilerExtension.cs +++ /dev/null @@ -1,84 +0,0 @@ -// 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 ExampleCompilerExtension() - { - this.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 deleted file mode 100644 index c3cb0473..00000000 --- a/src/test/Example.Extension/ExampleExtensionData.cs +++ /dev/null @@ -1,33 +0,0 @@ -// 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 null; - } - - public bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition) - { - switch (name) - { - case "Example": - tupleDefinition = TupleDefinitions.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 deleted file mode 100644 index b91d06e9..00000000 --- a/src/test/Example.Extension/ExampleExtensionFactory.cs +++ /dev/null @@ -1,39 +0,0 @@ -// 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 - { - extension = null; - } - - return extension != null; - } - } -} diff --git a/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs b/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs deleted file mode 100644 index 53394ea3..00000000 --- a/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs +++ /dev/null @@ -1,46 +0,0 @@ -// 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)) - { - parseCommandLine.GetNextArgumentOrError(ref this.exampleValueFromCommandLine); - return true; - } - - return false; - } - - 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/ExampleTuple.cs b/src/test/Example.Extension/ExampleTuple.cs deleted file mode 100644 index f280a5c8..00000000 --- a/src/test/Example.Extension/ExampleTuple.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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(TupleDefinitions.Example, null, null) - { - } - - public ExampleTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(TupleDefinitions.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/TupleDefinitions.cs b/src/test/Example.Extension/TupleDefinitions.cs deleted file mode 100644 index 2c320fbc..00000000 --- a/src/test/Example.Extension/TupleDefinitions.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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 TupleDefinitions - { - public static readonly IntermediateTupleDefinition Example = new IntermediateTupleDefinition( - "Example", - new[] - { - new IntermediateFieldDefinition(nameof(ExampleTupleFields.Example), IntermediateFieldType.String), - new IntermediateFieldDefinition(nameof(ExampleTupleFields.Value), IntermediateFieldType.String), - }, - typeof(ExampleTuple)); - } -} -- cgit v1.2.3-55-g6feb