diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-12-02 00:46:11 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-12-02 00:46:11 -0800 |
| commit | 95f2f4425b900374c7d7b583ae810b096121b3c4 (patch) | |
| tree | 0ede0972e849bdc2c57e9535e31fbdd0df113f8d /src/test | |
| parent | 720c4a0db1a2fb2aa3e08e5c99d5198873e448ba (diff) | |
| download | wix-95f2f4425b900374c7d7b583ae810b096121b3c4.tar.gz wix-95f2f4425b900374c7d7b583ae810b096121b3c4.tar.bz2 wix-95f2f4425b900374c7d7b583ae810b096121b3c4.zip | |
Implement support for IExtensionCommandLine and IPreprocessorExtension
Diffstat (limited to 'src/test')
5 files changed, 100 insertions, 57 deletions
diff --git a/src/test/Example.Extension/ExampleExtensionFactory.cs b/src/test/Example.Extension/ExampleExtensionFactory.cs index 9539ee85..b91d06e9 100644 --- a/src/test/Example.Extension/ExampleExtensionFactory.cs +++ b/src/test/Example.Extension/ExampleExtensionFactory.cs | |||
| @@ -7,11 +7,18 @@ namespace Example.Extension | |||
| 7 | 7 | ||
| 8 | public class ExampleExtensionFactory : IExtensionFactory | 8 | public class ExampleExtensionFactory : IExtensionFactory |
| 9 | { | 9 | { |
| 10 | private ExamplePreprocessorExtensionAndCommandLine preprocessorExtension; | ||
| 11 | |||
| 10 | public bool TryCreateExtension(Type extensionType, out object extension) | 12 | public bool TryCreateExtension(Type extensionType, out object extension) |
| 11 | { | 13 | { |
| 12 | if (extensionType == typeof(IPreprocessorExtension)) | 14 | if (extensionType == typeof(IExtensionCommandLine) || extensionType == typeof(IPreprocessorExtension)) |
| 13 | { | 15 | { |
| 14 | extension = new ExamplePreprocessorExtension(); | 16 | if (preprocessorExtension == null) |
| 17 | { | ||
| 18 | preprocessorExtension = new ExamplePreprocessorExtensionAndCommandLine(); | ||
| 19 | } | ||
| 20 | |||
| 21 | extension = preprocessorExtension; | ||
| 15 | } | 22 | } |
| 16 | else if (extensionType == typeof(ICompilerExtension)) | 23 | else if (extensionType == typeof(ICompilerExtension)) |
| 17 | { | 24 | { |
diff --git a/src/test/Example.Extension/ExamplePreprocessorExtension.cs b/src/test/Example.Extension/ExamplePreprocessorExtension.cs deleted file mode 100644 index c16c8b5a..00000000 --- a/src/test/Example.Extension/ExamplePreprocessorExtension.cs +++ /dev/null | |||
| @@ -1,55 +0,0 @@ | |||
| 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 | |||
| 3 | namespace Example.Extension | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Xml.Linq; | ||
| 7 | using WixToolset.Data; | ||
| 8 | using WixToolset.Extensibility; | ||
| 9 | |||
| 10 | internal class ExamplePreprocessorExtension : IPreprocessorExtension | ||
| 11 | { | ||
| 12 | public ExamplePreprocessorExtension() | ||
| 13 | { | ||
| 14 | } | ||
| 15 | |||
| 16 | public IPreprocessorCore Core { get => throw new NotImplementedException(); set => throw new NotImplementedException(); } | ||
| 17 | |||
| 18 | public string[] Prefixes => throw new NotImplementedException(); | ||
| 19 | |||
| 20 | public string EvaluateFunction(string prefix, string function, string[] args) | ||
| 21 | { | ||
| 22 | throw new NotImplementedException(); | ||
| 23 | } | ||
| 24 | |||
| 25 | public void Finish() | ||
| 26 | { | ||
| 27 | throw new NotImplementedException(); | ||
| 28 | } | ||
| 29 | |||
| 30 | public string GetVariableValue(string prefix, string name) | ||
| 31 | { | ||
| 32 | throw new NotImplementedException(); | ||
| 33 | } | ||
| 34 | |||
| 35 | public void Initialize() | ||
| 36 | { | ||
| 37 | throw new NotImplementedException(); | ||
| 38 | } | ||
| 39 | |||
| 40 | public void PreprocessDocument(XDocument document) | ||
| 41 | { | ||
| 42 | throw new NotImplementedException(); | ||
| 43 | } | ||
| 44 | |||
| 45 | public string PreprocessParameter(string name) | ||
| 46 | { | ||
| 47 | throw new NotImplementedException(); | ||
| 48 | } | ||
| 49 | |||
| 50 | public bool ProcessPragma(SourceLineNumber sourceLineNumbers, string prefix, string pragma, string args, XContainer parent) | ||
| 51 | { | ||
| 52 | throw new NotImplementedException(); | ||
| 53 | } | ||
| 54 | } | ||
| 55 | } \ No newline at end of file | ||
diff --git a/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs b/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs new file mode 100644 index 00000000..53394ea3 --- /dev/null +++ b/src/test/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs | |||
| @@ -0,0 +1,46 @@ | |||
| 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 | |||
| 3 | namespace Example.Extension | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using WixToolset.Extensibility; | ||
| 8 | using WixToolset.Extensibility.Services; | ||
| 9 | |||
| 10 | internal class ExamplePreprocessorExtensionAndCommandLine : BasePreprocessorExtension, IExtensionCommandLine | ||
| 11 | { | ||
| 12 | private string exampleValueFromCommandLine; | ||
| 13 | |||
| 14 | public IEnumerable<ExtensionCommandLineSwitch> CommandLineSwitches => throw new NotImplementedException(); | ||
| 15 | |||
| 16 | public ExamplePreprocessorExtensionAndCommandLine() | ||
| 17 | { | ||
| 18 | this.Prefixes = new[] { "ex" }; | ||
| 19 | } | ||
| 20 | |||
| 21 | public void PreParse(ICommandLineContext context) | ||
| 22 | { | ||
| 23 | } | ||
| 24 | |||
| 25 | public bool TryParseArgument(IParseCommandLine parseCommandLine, string arg) | ||
| 26 | { | ||
| 27 | if (parseCommandLine.IsSwitch(arg) && arg.Substring(1).Equals("example", StringComparison.OrdinalIgnoreCase)) | ||
| 28 | { | ||
| 29 | parseCommandLine.GetNextArgumentOrError(ref this.exampleValueFromCommandLine); | ||
| 30 | return true; | ||
| 31 | } | ||
| 32 | |||
| 33 | return false; | ||
| 34 | } | ||
| 35 | |||
| 36 | public override string GetVariableValue(string prefix, string name) | ||
| 37 | { | ||
| 38 | if (prefix == "ex" && "test".Equals(name, StringComparison.OrdinalIgnoreCase)) | ||
| 39 | { | ||
| 40 | return String.IsNullOrWhiteSpace(this.exampleValueFromCommandLine) ? "(null)" : this.exampleValueFromCommandLine; | ||
| 41 | } | ||
| 42 | |||
| 43 | return null; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } \ No newline at end of file | ||
diff --git a/src/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs b/src/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs index 5181c748..6acf3472 100644 --- a/src/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/ExtensionFixture.cs | |||
| @@ -56,5 +56,48 @@ namespace WixToolsetTest.CoreIntegration | |||
| 56 | Assert.Equal("Bar", example[1].AsString()); | 56 | Assert.Equal("Bar", example[1].AsString()); |
| 57 | } | 57 | } |
| 58 | } | 58 | } |
| 59 | |||
| 60 | [Fact] | ||
| 61 | public void CanParseCommandLineWithExtension() | ||
| 62 | { | ||
| 63 | var folder = TestData.Get(@"TestData\ExampleExtension"); | ||
| 64 | var extensionPath = Path.GetFullPath(new Uri(typeof(ExampleExtensionFactory).Assembly.CodeBase).LocalPath); | ||
| 65 | |||
| 66 | using (var fs = new DisposableFileSystem()) | ||
| 67 | { | ||
| 68 | var intermediateFolder = fs.GetFolder(); | ||
| 69 | |||
| 70 | var program = new Program(); | ||
| 71 | var result = program.Run(new WixToolsetServiceProvider(), new[] | ||
| 72 | { | ||
| 73 | "build", | ||
| 74 | Path.Combine(folder, "Package.wxs"), | ||
| 75 | Path.Combine(folder, "PackageComponents.wxs"), | ||
| 76 | "-loc", Path.Combine(folder, "Package.en-us.wxl"), | ||
| 77 | "-ext", extensionPath, | ||
| 78 | "-bindpath", Path.Combine(folder, "data"), | ||
| 79 | "-intermediateFolder", intermediateFolder, | ||
| 80 | "-example", "test", | ||
| 81 | "-o", Path.Combine(intermediateFolder, @"bin\extest.msi") | ||
| 82 | }); | ||
| 83 | |||
| 84 | Assert.Equal(0, result); | ||
| 85 | |||
| 86 | Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\extest.msi"))); | ||
| 87 | Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\extest.wixpdb"))); | ||
| 88 | Assert.True(File.Exists(Path.Combine(intermediateFolder, @"bin\MsiPackage\example.txt"))); | ||
| 89 | |||
| 90 | var intermediate = Intermediate.Load(Path.Combine(intermediateFolder, @"bin\extest.wir")); | ||
| 91 | var section = intermediate.Sections.Single(); | ||
| 92 | |||
| 93 | var wixFile = section.Tuples.OfType<WixFileTuple>().Single(); | ||
| 94 | Assert.Equal(Path.Combine(folder, @"data\example.txt"), wixFile[WixFileTupleFields.Source].AsPath().Path); | ||
| 95 | Assert.Equal(@"example.txt", wixFile[WixFileTupleFields.Source].PreviousValue.AsPath().Path); | ||
| 96 | |||
| 97 | var property = section.Tuples.OfType<PropertyTuple>().Where(p => p.Id.Id == "ExampleProperty").Single(); | ||
| 98 | Assert.Equal("ExampleProperty", property.Property); | ||
| 99 | Assert.Equal("test", property.Value); | ||
| 100 | } | ||
| 101 | } | ||
| 59 | } | 102 | } |
| 60 | } | 103 | } |
diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/ExampleExtension/Package.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/ExampleExtension/Package.wxs index cdc323ec..9fd42214 100644 --- a/src/test/WixToolsetTest.CoreIntegration/TestData/ExampleExtension/Package.wxs +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/ExampleExtension/Package.wxs | |||
| @@ -6,6 +6,8 @@ | |||
| 6 | <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" /> | 6 | <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" /> |
| 7 | <MediaTemplate /> | 7 | <MediaTemplate /> |
| 8 | 8 | ||
| 9 | <Property Id="ExampleProperty" Value="$(ex.Test)" /> | ||
| 10 | |||
| 9 | <Feature Id="ProductFeature" Title="!(loc.FeatureTitle)"> | 11 | <Feature Id="ProductFeature" Title="!(loc.FeatureTitle)"> |
| 10 | <ComponentGroupRef Id="ProductComponents" /> | 12 | <ComponentGroupRef Id="ProductComponents" /> |
| 11 | </Feature> | 13 | </Feature> |
