Minor code clean up in build task
Rob Mensching committed
Dec 27, 2018 at 11:07 UTC
05c1b41651afced8b3f3629668ef1b32bcc04e6d
1 file changed
+20
-90
src/WixToolset.BuildTasks/DoIt.cs
+20
-90
@@ -135,6 +135,25 @@ namespace WixToolset.BuildTasks
135
}
136
137
private void ExecuteCore(IServiceProvider serviceProvider, IMessageListener listener)
138
+ {
139
+ var commandLineString = this.BuildCommandLine();
140
+
141
+ this.Log.LogMessage(MessageImportance.Normal, "wix.exe " + commandLineString);
142
+
143
+ var messaging = serviceProvider.GetService<IMessaging>();
144
+ messaging.SetListener(listener);
145
+
146
+ var arguments = serviceProvider.GetService<ICommandLineArguments>();
147
+ arguments.Populate(commandLineString);
148
+
149
+ var commandLine = serviceProvider.GetService<ICommandLine>();
150
+ commandLine.ExtensionManager = this.CreateExtensionManagerWithStandardBackends(serviceProvider, messaging, arguments.Extensions);
151
+ commandLine.Arguments = arguments;
152
+ var command = commandLine.ParseStandardCommandLine();
153
+ command?.Execute();
154
+ }
155
+
156
+ private string BuildCommandLine()
157
{
158
var commandLineBuilder = new WixCommandLineBuilder();
159
@@ -164,21 +183,7 @@ namespace WixToolset.BuildTasks
183
commandLineBuilder.AppendTextIfNotWhitespace(this.AdditionalOptions);
184
commandLineBuilder.AppendFileNamesIfNotNull(this.SourceFiles, " ");
185
167
- var commandLineString = commandLineBuilder.ToString();
168
-
169
- this.Log.LogMessage(MessageImportance.Normal, "wix.exe " + commandLineString);
170
-
171
- var messaging = serviceProvider.GetService<IMessaging>();
172
- messaging.SetListener(listener);
173
-
174
- var arguments = serviceProvider.GetService<ICommandLineArguments>();
175
- arguments.Populate(commandLineString);
176
-
177
- var commandLine = serviceProvider.GetService<ICommandLine>();
178
- commandLine.ExtensionManager = this.CreateExtensionManagerWithStandardBackends(serviceProvider, messaging, arguments.Extensions);
179
- commandLine.Arguments = arguments;
180
- var command = commandLine.ParseStandardCommandLine();
181
- command?.Execute();
186
+ return commandLineBuilder.ToString();
187
}
188
189
private IExtensionManager CreateExtensionManagerWithStandardBackends(IServiceProvider serviceProvider, IMessaging messaging, string[] extensions)
@@ -205,11 +210,6 @@ namespace WixToolset.BuildTasks
210
return extensionManager;
211
}
212
208
- private void DisplayMessage(object sender, DisplayEventArgs e)
209
- {
210
- this.Log.LogMessageFromText(e.Message, MessageImportance.Normal);
211
- }
212
-
213
private IEnumerable<string> CalculateBindPathStrings()
214
{
215
if (null != this.BindInputPaths)
@@ -231,76 +231,6 @@ namespace WixToolset.BuildTasks
231
}
232
}
233
234
- ///// <summary>
235
- ///// Builds a command line from options in this task.
236
- ///// </summary>
237
- //protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder)
238
- //{
239
- // base.BuildCommandLine(commandLineBuilder);
240
-
241
- // commandLineBuilder.AppendIfTrue("-p", this.PreprocessToStdOut);
242
- // commandLineBuilder.AppendSwitchIfNotNull("-p", this.PreprocessToFile);
243
- // commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile);
244
- // commandLineBuilder.AppendArrayIfNotNull("-d", this.DefineConstants);
245
- // commandLineBuilder.AppendArrayIfNotNull("-I", this.IncludeSearchPaths);
246
- // commandLineBuilder.AppendIfTrue("-pedantic", this.Pedantic);
247
- // commandLineBuilder.AppendSwitchIfNotNull("-arch ", this.InstallerPlatform);
248
- // commandLineBuilder.AppendExtensions(this.Extensions, this.ExtensionDirectory, this.referencePaths);
249
- // commandLineBuilder.AppendTextIfNotNull(this.AdditionalOptions);
250
-
251
- // // Support per-source-file output by looking at the SourceFiles items to
252
- // // see if there is any "CandleOutput" metadata. If there is, we do our own
253
- // // appending, otherwise we fall back to the built-in "append file names" code.
254
- // // Note also that the wix.targets "Compile" target does *not* automagically
255
- // // fix the "@(CompileObjOutput)" list to include these new output names.
256
- // // If you really want to use this, you're going to have to clone the target
257
- // // in your own .targets file and create the output list yourself.
258
- // bool usePerSourceOutput = false;
259
- // if (this.SourceFiles != null)
260
- // {
261
- // foreach (ITaskItem item in this.SourceFiles)
262
- // {
263
- // if (!String.IsNullOrEmpty(item.GetMetadata("CandleOutput")))
264
- // {
265
- // usePerSourceOutput = true;
266
- // break;
267
- // }
268
- // }
269
- // }
270
-
271
- // if (usePerSourceOutput)
272
- // {
273
- // string[] newSourceNames = new string[this.SourceFiles.Length];
274
- // for (int iSource = 0; iSource < this.SourceFiles.Length; ++iSource)
275
- // {
276
- // ITaskItem item = this.SourceFiles[iSource];
277
- // if (null == item)
278
- // {
279
- // newSourceNames[iSource] = null;
280
- // }
281
- // else
282
- // {
283
- // string output = item.GetMetadata("CandleOutput");
284
-
285
- // if (!String.IsNullOrEmpty(output))
286
- // {
287
- // newSourceNames[iSource] = String.Concat(item.ItemSpec, ";", output);
288
- // }
289
- // else
290
- // {
291
- // newSourceNames[iSource] = item.ItemSpec;
292
- // }
293
- // }
294
- // }
295
-
296
- // commandLineBuilder.AppendFileNamesIfNotNull(newSourceNames, " ");
297
- // }
298
- // else
299
- // {
300
- // commandLineBuilder.AppendFileNamesIfNotNull(this.SourceFiles, " ");
301
- // }
302
- //}
303
-
234
private class MsbuildMessageListener : IMessageListener
235
{
236
public MsbuildMessageListener(TaskLoggingHelper logger, string shortName, string longName)