aboutsummaryrefslogtreecommitdiff
path: root/src/test/TestData
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-12-06 11:39:26 -0800
committerRob Mensching <rob@firegiant.com>2017-12-06 11:40:03 -0800
commit5ba862bfa618c89a563d555e8ce7b44a904df406 (patch)
treecc2655422be3eec1f200efcbc0e562349c229274 /src/test/TestData
parente53afb01c6e01bb9e6521fa77d31e575abc73f9c (diff)
downloadwix-5ba862bfa618c89a563d555e8ce7b44a904df406.tar.gz
wix-5ba862bfa618c89a563d555e8ce7b44a904df406.tar.bz2
wix-5ba862bfa618c89a563d555e8ce7b44a904df406.zip
Add support for loading Intermediates from extensions
Diffstat (limited to 'src/test/TestData')
-rw-r--r--src/test/TestData/Example.Extension/Data/example.txt1
-rw-r--r--src/test/TestData/Example.Extension/Data/example.wirbin0 -> 534 bytes
-rw-r--r--src/test/TestData/Example.Extension/Data/example.wxs8
-rw-r--r--src/test/TestData/Example.Extension/Example.Extension.csproj22
-rw-r--r--src/test/TestData/Example.Extension/ExampleCompilerExtension.cs84
-rw-r--r--src/test/TestData/Example.Extension/ExampleExtensionData.cs33
-rw-r--r--src/test/TestData/Example.Extension/ExampleExtensionFactory.cs39
-rw-r--r--src/test/TestData/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs46
-rw-r--r--src/test/TestData/Example.Extension/ExampleTuple.cs31
-rw-r--r--src/test/TestData/Example.Extension/TupleDefinitions.cs18
10 files changed, 282 insertions, 0 deletions
diff --git a/src/test/TestData/Example.Extension/Data/example.txt b/src/test/TestData/Example.Extension/Data/example.txt
new file mode 100644
index 00000000..1b4ffe8a
--- /dev/null
+++ b/src/test/TestData/Example.Extension/Data/example.txt
@@ -0,0 +1 @@
This is example.txt. \ No newline at end of file
diff --git a/src/test/TestData/Example.Extension/Data/example.wir b/src/test/TestData/Example.Extension/Data/example.wir
new file mode 100644
index 00000000..674f63fc
--- /dev/null
+++ b/src/test/TestData/Example.Extension/Data/example.wir
Binary files differ
diff --git a/src/test/TestData/Example.Extension/Data/example.wxs b/src/test/TestData/Example.Extension/Data/example.wxs
new file mode 100644
index 00000000..53531e99
--- /dev/null
+++ b/src/test/TestData/Example.Extension/Data/example.wxs
@@ -0,0 +1,8 @@
1<?xml version='1.0'?>
2<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3 <Fragment>
4 <Property Id="PropertyFromExampleWir" Value="FromWir" />
5
6 <Binary Id="BinFromWir" SourceFile="example.txt" />
7 </Fragment>
8</Wix>
diff --git a/src/test/TestData/Example.Extension/Example.Extension.csproj b/src/test/TestData/Example.Extension/Example.Extension.csproj
new file mode 100644
index 00000000..d04ce553
--- /dev/null
+++ b/src/test/TestData/Example.Extension/Example.Extension.csproj
@@ -0,0 +1,22 @@
1<?xml version="1.0" encoding="utf-8"?>
2<!-- 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. -->
3
4<Project Sdk="Microsoft.NET.Sdk">
5 <PropertyGroup>
6 <TargetFramework>netstandard2.0</TargetFramework>
7 <IsPackable>false</IsPackable>
8 </PropertyGroup>
9
10 <ItemGroup>
11 <EmbeddedResource Include="Data\Example.wir" />
12 </ItemGroup>
13
14 <ItemGroup>
15 <ProjectReference Include="$(WixToolsetRootFolder)\Data\src\WixToolset.Data\WixToolset.Data.csproj" Condition=" '$(Configuration)' == 'Debug' And Exists('$(WixToolsetRootFolder)\Data\src\WixToolset.Data\WixToolset.Data.csproj') " />
16 <PackageReference Include="WixToolset.Data" Version="4.0.*" Condition=" '$(Configuration)' == 'Release' Or !Exists('$(WixToolsetRootFolder)\Data\src\WixToolset.Data\WixToolset.Data.csproj') " />
17
18 <ProjectReference Include="$(WixToolsetRootFolder)\Extensibility\src\WixToolset.Extensibility\WixToolset.Extensibility.csproj" Condition=" '$(Configuration)' == 'Debug' And Exists('$(WixToolsetRootFolder)\Extensibility\src\WixToolset.Extensibility\WixToolset.Extensibility.csproj') " />
19 <PackageReference Include="WixToolset.Extensibility" Version="4.0.*" Condition=" '$(Configuration)' == 'Release' Or !Exists('$(WixToolsetRootFolder)\Extensibility\src\WixToolset.Extensibility\WixToolset.Extensibility.csproj') " />
20 </ItemGroup>
21
22</Project>
diff --git a/src/test/TestData/Example.Extension/ExampleCompilerExtension.cs b/src/test/TestData/Example.Extension/ExampleCompilerExtension.cs
new file mode 100644
index 00000000..5b20e48f
--- /dev/null
+++ b/src/test/TestData/Example.Extension/ExampleCompilerExtension.cs
@@ -0,0 +1,84 @@
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 Example.Extension
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Xml.Linq;
8 using WixToolset.Data;
9 using WixToolset.Extensibility;
10
11 internal class ExampleCompilerExtension : BaseCompilerExtension
12 {
13 public ExampleCompilerExtension()
14 {
15 this.Namespace = "http://www.example.com/scheams/v1/wxs";
16 }
17
18 public override void ParseElement(Intermediate intermediate, IntermediateSection section, XElement parentElement, XElement element, IDictionary<string, string> context)
19 {
20 var processed = false;
21
22 switch (parentElement.Name.LocalName)
23 {
24 case "Component":
25 switch (element.Name.LocalName)
26 {
27 case "Example":
28 this.ParseExampleElement(intermediate, section, element);
29 processed = true;
30 break;
31 }
32 break;
33 }
34
35 if (!processed)
36 {
37 base.ParseElement(intermediate, section, parentElement, element, context);
38 }
39 }
40
41 private void ParseExampleElement(Intermediate intermediate, IntermediateSection section, XElement element)
42 {
43 var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(element);
44 Identifier id = null;
45 string value = null;
46
47 foreach (var attrib in element.Attributes())
48 {
49 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
50 {
51 switch (attrib.Name.LocalName)
52 {
53 case "Id":
54 id = this.ParseHelper.GetAttributeIdentifier(sourceLineNumbers, attrib);
55 break;
56
57 case "Value":
58 value = this.ParseHelper.GetAttributeValue(sourceLineNumbers, attrib);
59 break;
60
61 default:
62 this.ParseHelper.UnexpectedAttribute(element, attrib);
63 break;
64 }
65 }
66 else
67 {
68 this.ParseAttribute(intermediate, section, element, attrib, null);
69 }
70 }
71
72 if (null == id)
73 {
74 //this.Messaging(WixErrors.ExpectedAttribute(sourceLineNumbers, element.Name.LocalName, "Id"));
75 }
76
77 if (!this.Messaging.EncounteredError)
78 {
79 var tuple = this.ParseHelper.CreateRow(section, sourceLineNumbers, "Example", id);
80 tuple.Set(1, value);
81 }
82 }
83 }
84}
diff --git a/src/test/TestData/Example.Extension/ExampleExtensionData.cs b/src/test/TestData/Example.Extension/ExampleExtensionData.cs
new file mode 100644
index 00000000..6b179ea6
--- /dev/null
+++ b/src/test/TestData/Example.Extension/ExampleExtensionData.cs
@@ -0,0 +1,33 @@
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 Example.Extension
4{
5 using WixToolset.Data;
6 using WixToolset.Extensibility;
7
8 internal class ExampleExtensionData : IExtensionData
9 {
10 public string DefaultCulture => null;
11
12 public Intermediate GetLibrary(ITupleDefinitionCreator tupleDefinitions)
13 {
14 return Intermediate.Load(typeof(ExampleExtensionData).Assembly, "Example.Extension.Data.Example.wir", tupleDefinitions);
15 }
16
17 public bool TryGetTupleDefinitionByName(string name, out IntermediateTupleDefinition tupleDefinition)
18 {
19 switch (name)
20 {
21 case "Example":
22 tupleDefinition = TupleDefinitions.Example;
23 break;
24
25 default:
26 tupleDefinition = null;
27 break;
28 }
29
30 return tupleDefinition != null;
31 }
32 }
33} \ No newline at end of file
diff --git a/src/test/TestData/Example.Extension/ExampleExtensionFactory.cs b/src/test/TestData/Example.Extension/ExampleExtensionFactory.cs
new file mode 100644
index 00000000..b91d06e9
--- /dev/null
+++ b/src/test/TestData/Example.Extension/ExampleExtensionFactory.cs
@@ -0,0 +1,39 @@
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 Example.Extension
4{
5 using System;
6 using WixToolset.Extensibility;
7
8 public class ExampleExtensionFactory : IExtensionFactory
9 {
10 private ExamplePreprocessorExtensionAndCommandLine preprocessorExtension;
11
12 public bool TryCreateExtension(Type extensionType, out object extension)
13 {
14 if (extensionType == typeof(IExtensionCommandLine) || extensionType == typeof(IPreprocessorExtension))
15 {
16 if (preprocessorExtension == null)
17 {
18 preprocessorExtension = new ExamplePreprocessorExtensionAndCommandLine();
19 }
20
21 extension = preprocessorExtension;
22 }
23 else if (extensionType == typeof(ICompilerExtension))
24 {
25 extension = new ExampleCompilerExtension();
26 }
27 else if (extensionType == typeof(IExtensionData))
28 {
29 extension = new ExampleExtensionData();
30 }
31 else
32 {
33 extension = null;
34 }
35
36 return extension != null;
37 }
38 }
39}
diff --git a/src/test/TestData/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs b/src/test/TestData/Example.Extension/ExamplePreprocessorExtensionAndCommandLine.cs
new file mode 100644
index 00000000..53394ea3
--- /dev/null
+++ b/src/test/TestData/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
3namespace 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/TestData/Example.Extension/ExampleTuple.cs b/src/test/TestData/Example.Extension/ExampleTuple.cs
new file mode 100644
index 00000000..f280a5c8
--- /dev/null
+++ b/src/test/TestData/Example.Extension/ExampleTuple.cs
@@ -0,0 +1,31 @@
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 Example.Extension
4{
5 using WixToolset.Data;
6
7 public enum ExampleTupleFields
8 {
9 Example,
10 Value,
11 }
12
13 public class ExampleTuple : IntermediateTuple
14 {
15 public ExampleTuple() : base(TupleDefinitions.Example, null, null)
16 {
17 }
18
19 public ExampleTuple(SourceLineNumber sourceLineNumber, Identifier id = null) : base(TupleDefinitions.Example, sourceLineNumber, id)
20 {
21 }
22
23 public IntermediateField this[ExampleTupleFields index] => this.Fields[(int)index];
24
25 public string Value
26 {
27 get => this.Fields[(int)ExampleTupleFields.Value]?.AsString();
28 set => this.Set((int)ExampleTupleFields.Value, value);
29 }
30 }
31}
diff --git a/src/test/TestData/Example.Extension/TupleDefinitions.cs b/src/test/TestData/Example.Extension/TupleDefinitions.cs
new file mode 100644
index 00000000..2c320fbc
--- /dev/null
+++ b/src/test/TestData/Example.Extension/TupleDefinitions.cs
@@ -0,0 +1,18 @@
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 Example.Extension
4{
5 using WixToolset.Data;
6
7 public static class TupleDefinitions
8 {
9 public static readonly IntermediateTupleDefinition Example = new IntermediateTupleDefinition(
10 "Example",
11 new[]
12 {
13 new IntermediateFieldDefinition(nameof(ExampleTupleFields.Example), IntermediateFieldType.String),
14 new IntermediateFieldDefinition(nameof(ExampleTupleFields.Value), IntermediateFieldType.String),
15 },
16 typeof(ExampleTuple));
17 }
18}