Implement simplified command and improved backend integration
Rob Mensching committed
Jun 13, 2020 at 10:01 UTC
cd6f466549ba8e4b138da4332b0831ab45ca8a2f
8 files changed
+102
-94
src/WixToolset.Core.Burn/WixToolsetCoreServiceProviderExtensions.cs
new
+17
@@ -0,0 +1,17 @@
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 WixToolset.Core.Burn
4
+{
5
+ using WixToolset.Extensibility.Services;
6
+
7
+ public static class WixToolsetCoreServiceProviderExtensions
8
+ {
9
+ public static IWixToolsetCoreServiceProvider AddBundleBackend(this IWixToolsetCoreServiceProvider coreProvider)
10
+ {
11
+ var extensionManager = coreProvider.GetService<IExtensionManager>();
12
+ extensionManager.Add(typeof(BurnExtensionFactory).Assembly);
13
+
14
+ return coreProvider;
15
+ }
16
+ }
17
+}
src/WixToolset.Core.Burn/WixToolsetStandardBackend.cs
deleted
-12
@@ -1,12 +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 WixToolset.Core.Burn
4
-{
5
- /// <summary>
6
- /// Denotes this assembly contains a backend that is considered
7
- /// a standard part of the WiX Toolset.
8
- /// </summary>
9
- public static class WixToolsetStandardBackend
10
- {
11
- }
12
-}
src/WixToolset.Core.ExtensionCache/WixToolsetCoreServiceProviderExtensions.cs
+5
-5
@@ -8,16 +8,16 @@ namespace WixToolset.Core.ExtensionCache
8
9
public static class WixToolsetCoreServiceProviderExtensions
10
{
11
- public static IWixToolsetCoreServiceProvider AddExtensionCacheManager(this IWixToolsetCoreServiceProvider serviceProvider)
11
+ public static IWixToolsetCoreServiceProvider AddExtensionCacheManager(this IWixToolsetCoreServiceProvider coreProvider)
12
{
13
- var extensionManager = serviceProvider.GetService<IExtensionManager>();
13
+ var extensionManager = coreProvider.GetService<IExtensionManager>();
14
extensionManager.Add(typeof(ExtensionCacheManagerExtensionFactory).Assembly);
15
16
- serviceProvider.AddService(CreateExtensionCacheManager);
17
- return serviceProvider;
16
+ coreProvider.AddService(CreateExtensionCacheManager);
17
+ return coreProvider;
18
}
19
20
- private static ExtensionCacheManager CreateExtensionCacheManager(IWixToolsetCoreServiceProvider provider, Dictionary<Type, object> singletons)
20
+ private static ExtensionCacheManager CreateExtensionCacheManager(IWixToolsetCoreServiceProvider coreProvider, Dictionary<Type, object> singletons)
21
{
22
var extensionCacheManager = new ExtensionCacheManager();
23
singletons.Add(typeof(ExtensionCacheManager), extensionCacheManager);
src/WixToolset.Core.TestPackage/WixRunner.cs
+9
-26
@@ -6,6 +6,8 @@ namespace WixToolset.Core.TestPackage
6
using System.Collections.Generic;
7
using System.Threading;
8
using System.Threading.Tasks;
9
+ using WixToolset.Core.Burn;
10
+ using WixToolset.Core.WindowsInstaller;
11
using WixToolset.Data;
12
using WixToolset.Extensibility.Data;
13
using WixToolset.Extensibility.Services;
@@ -26,40 +28,21 @@ namespace WixToolset.Core.TestPackage
28
return new WixRunnerResult { ExitCode = exitCode.Result, Messages = messages.ToArray() };
29
}
30
29
- public static Task<int> Execute(string[] args, IWixToolsetServiceProvider serviceProvider, out List<Message> messages)
31
+ public static Task<int> Execute(string[] args, IWixToolsetCoreServiceProvider coreProvider, out List<Message> messages)
32
{
33
+ coreProvider.AddWindowsInstallerBackend()
34
+ .AddBundleBackend();
35
+
36
var listener = new TestMessageListener();
37
38
messages = listener.Messages;
39
35
- var messaging = serviceProvider.GetService<IMessaging>();
40
+ var messaging = coreProvider.GetService<IMessaging>();
41
messaging.SetListener(listener);
42
38
- var arguments = serviceProvider.GetService<ICommandLineArguments>();
39
- arguments.Populate(args);
40
-
41
- var commandLine = serviceProvider.GetService<ICommandLine>();
42
- commandLine.ExtensionManager = CreateExtensionManagerWithStandardBackends(serviceProvider, arguments.Extensions);
43
- commandLine.Arguments = arguments;
44
- var command = commandLine.ParseStandardCommandLine();
43
+ var commandLine = coreProvider.GetService<ICommandLine>();
44
+ var command = commandLine.CreateCommand(args);
45
return command?.ExecuteAsync(CancellationToken.None) ?? Task.FromResult(1);
46
}
47
-
48
- private static IExtensionManager CreateExtensionManagerWithStandardBackends(IWixToolsetServiceProvider serviceProvider, string[] extensions)
49
- {
50
- var extensionManager = serviceProvider.GetService<IExtensionManager>();
51
-
52
- foreach (var type in new[] { typeof(WixToolset.Core.Burn.WixToolsetStandardBackend), typeof(WixToolset.Core.WindowsInstaller.WixToolsetStandardBackend) })
53
- {
54
- extensionManager.Add(type.Assembly);
55
- }
56
-
57
- foreach (var extension in extensions)
58
- {
59
- extensionManager.Load(extension);
60
- }
61
-
62
- return extensionManager;
63
- }
47
}
48
}
src/WixToolset.Core.WindowsInstaller/ValidatorExtension.cs
+1
-1
@@ -63,7 +63,7 @@ namespace WixToolset.Extensibility
63
{
64
if (this.databaseFile != null)
65
{
66
- this.sourceLineNumbers = new SourceLineNumber(databaseFile);
66
+ this.sourceLineNumbers = new SourceLineNumber(this.databaseFile);
67
}
68
}
69
src/WixToolset.Core.WindowsInstaller/WixToolsetCoreServiceProviderExtensions.cs
new
+17
@@ -0,0 +1,17 @@
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 WixToolset.Core.WindowsInstaller
4
+{
5
+ using WixToolset.Extensibility.Services;
6
+
7
+ public static class WixToolsetCoreServiceProviderExtensions
8
+ {
9
+ public static IWixToolsetCoreServiceProvider AddWindowsInstallerBackend(this IWixToolsetCoreServiceProvider coreProvider)
10
+ {
11
+ var extensionManager = coreProvider.GetService<IExtensionManager>();
12
+ extensionManager.Add(typeof(WindowsInstallerExtensionFactory).Assembly);
13
+
14
+ return coreProvider;
15
+ }
16
+ }
17
+}
src/WixToolset.Core.WindowsInstaller/WixToolsetStandardBackend.cs
deleted
-12
@@ -1,12 +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 WixToolset.Core.WindowsInstaller
4
-{
5
- /// <summary>
6
- /// Denotes this assembly contains a backend that is considered
7
- /// a standard part of the WiX Toolset.
8
- /// </summary>
9
- public static class WixToolsetStandardBackend
10
- {
11
- }
12
-}
src/WixToolset.Core/CommandLine/CommandLine.cs
+53
-38
@@ -21,30 +21,35 @@ namespace WixToolset.Core.CommandLine
21
22
internal class CommandLine : ICommandLine
23
{
24
- public CommandLine(IWixToolsetServiceProvider serviceProvider)
25
- {
26
- this.ServiceProvider = serviceProvider;
27
-
28
- this.Messaging = this.ServiceProvider.GetService<IMessaging>();
29
- }
24
+ public CommandLine(IWixToolsetServiceProvider serviceProvider) => this.ServiceProvider = serviceProvider;
25
26
private IWixToolsetServiceProvider ServiceProvider { get; }
27
33
- private IMessaging Messaging { get; set; }
28
+ public ICommandLineCommand CreateCommand(string[] args)
29
+ {
30
+ var arguments = this.ServiceProvider.GetService<ICommandLineArguments>();
31
+ arguments.Populate(args);
32
35
- public IExtensionManager ExtensionManager { get; set; }
33
+ this.LoadExtensions(arguments.Extensions);
34
37
- public ICommandLineArguments Arguments { get; set; }
35
+ return this.ParseStandardCommandLine(arguments);
36
+ }
37
39
- public static string ExpectedArgument { get; } = "expected argument";
38
+ public ICommandLineCommand CreateCommand(string commandLine)
39
+ {
40
+ var arguments = this.ServiceProvider.GetService<ICommandLineArguments>();
41
+ arguments.Populate(commandLine);
42
41
- public bool ShowHelp { get; private set; }
43
+ this.LoadExtensions(arguments.Extensions);
44
43
- public ICommandLineCommand ParseStandardCommandLine()
45
+ return this.ParseStandardCommandLine(arguments);
46
+ }
47
+
48
+ public ICommandLineCommand ParseStandardCommandLine(ICommandLineArguments arguments)
49
{
50
var context = this.ServiceProvider.GetService<ICommandLineContext>();
46
- context.ExtensionManager = this.ExtensionManager ?? this.ServiceProvider.GetService<IExtensionManager>();
47
- context.Arguments = this.Arguments;
51
+ context.ExtensionManager = this.ServiceProvider.GetService<IExtensionManager>();
52
+ context.Arguments = arguments;
53
54
var command = this.Parse(context);
55
@@ -56,9 +61,19 @@ namespace WixToolset.Core.CommandLine
61
return command;
62
}
63
64
+ private void LoadExtensions(string[] extensions)
65
+ {
66
+ var extensionManager = this.ServiceProvider.GetService<IExtensionManager>();
67
+
68
+ foreach (var extension in extensions)
69
+ {
70
+ extensionManager.Load(extension);
71
+ }
72
+ }
73
+
74
private ICommandLineCommand Parse(ICommandLineContext context)
75
{
61
- var extensions = this.ExtensionManager.GetServices<IExtensionCommandLine>();
76
+ var extensions = context.ExtensionManager.GetServices<IExtensionCommandLine>();
77
78
foreach (var extension in extensions)
79
{
@@ -80,7 +95,7 @@ namespace WixToolset.Core.CommandLine
95
// First argument must be the command or global switch (that creates a command).
96
if (command == null)
97
{
83
- if (!this.TryParseCommand(arg, parser, out command, extensions))
98
+ if (!this.TryParseCommand(arg, parser, extensions, out command))
99
{
100
parser.ErrorArgument = arg;
101
}
@@ -105,8 +120,8 @@ namespace WixToolset.Core.CommandLine
120
121
return command ?? new HelpCommand();
122
}
108
-
109
- private bool TryParseCommand(string arg, ICommandLineParser parser, out ICommandLineCommand command, IEnumerable<IExtensionCommandLine> extensions)
123
+
124
+ private bool TryParseCommand(string arg, ICommandLineParser parser, IEnumerable<IExtensionCommandLine> extensions, out ICommandLineCommand command)
125
{
126
command = null;
127
@@ -115,17 +130,17 @@ namespace WixToolset.Core.CommandLine
130
var parameter = arg.Substring(1);
131
switch (parameter.ToLowerInvariant())
132
{
118
- case "?":
119
- case "h":
120
- case "help":
121
- case "-help":
122
- command = new HelpCommand();
123
- break;
124
-
125
- case "version":
126
- case "-version":
127
- command = new VersionCommand();
128
- break;
133
+ case "?":
134
+ case "h":
135
+ case "help":
136
+ case "-help":
137
+ command = new HelpCommand();
138
+ break;
139
+
140
+ case "version":
141
+ case "-version":
142
+ command = new VersionCommand();
143
+ break;
144
}
145
}
146
else
@@ -134,17 +149,17 @@ namespace WixToolset.Core.CommandLine
149
{
150
switch (commandType)
151
{
137
- case CommandTypes.Build:
138
- command = new BuildCommand(this.ServiceProvider);
139
- break;
152
+ case CommandTypes.Build:
153
+ command = new BuildCommand(this.ServiceProvider);
154
+ break;
155
141
- case CommandTypes.Compile:
142
- command = new CompileCommand(this.ServiceProvider);
143
- break;
156
+ case CommandTypes.Compile:
157
+ command = new CompileCommand(this.ServiceProvider);
158
+ break;
159
145
- case CommandTypes.Decompile:
146
- command = new DecompileCommand(this.ServiceProvider);
147
- break;
160
+ case CommandTypes.Decompile:
161
+ command = new DecompileCommand(this.ServiceProvider);
162
+ break;
163
}
164
}
165
else