-
-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH703: Add FileLogger switches to MSBuild Runner #1215
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -802,6 +802,69 @@ public void Should_Append_Logger_To_Process_Arguments() | |
Assert.Equal("/v:normal /target:Build /logger:B,A;C /logger:E,D /logger:F " + | ||
"\"/Working/src/Solution.sln\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Append_FileLogger_To_Process_Arguments() | ||
{ | ||
// Given | ||
var fixture = new MSBuildRunnerFixture(false); | ||
fixture.Settings.AddFileLogger(new MSBuildFileLogger { AppendToLogFile = false, Encoding = "E", HideVerboseItemAndPropertyList = false, LogFile = "A", MSBuildFileLoggerOutput = MSBuildFileLoggerOutput.All, PerformanceSummaryEnabled = false, ShowCommandLine = false, ShowEventId = false, ShowTimestamp = false, SummaryDisabled = false, Verbosity = Verbosity.Diagnostic }); | ||
|
||
fixture.Settings.AddFileLogger(new MSBuildFileLogger { AppendToLogFile = true, HideVerboseItemAndPropertyList = true, MSBuildFileLoggerOutput = MSBuildFileLoggerOutput.ErrorsOnly, PerformanceSummaryEnabled = true, ShowCommandLine = true, ShowEventId = true, ShowTimestamp = true, SummaryDisabled = true, Verbosity = Verbosity.Minimal }); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break. |
||
fixture.Settings.AddFileLogger(new MSBuildFileLogger { MSBuildFileLoggerOutput = MSBuildFileLoggerOutput.WarningsOnly, Verbosity = Verbosity.Normal }); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break. |
||
fixture.Settings.AddFileLogger(new MSBuildFileLogger { Verbosity = Verbosity.Quiet }); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break. |
||
fixture.Settings.AddFileLogger(new MSBuildFileLogger { Verbosity = Verbosity.Verbose }); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break. |
||
fixture.Settings.AddFileLogger(new MSBuildFileLogger { }); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break. |
||
fixture.Settings.AddFileLogger(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
// Then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add line break. |
||
Assert.Equal(@"/v:normal /target:Build /fl /flp:logfile=A;Encoding=E;Verbosity=Diagnostic /fl1 /flp1:Append;PerformanceSummary;NoSummary;ErrorsOnly;NoItemAndPropertyList;ShowCommandLine;ShowTimestamp;ShowEventId;Verbosity=Minimal /fl2 /flp2:WarningsOnly;Verbosity=Normal /fl3 /flp3:Verbosity=Quiet /fl4 /flp4:Verbosity=Verbose /fl5 /fl6 ""/Working/src/Solution.sln""", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Append_Default_FileLogger_To_Process_Arguments() | ||
{ | ||
// Given | ||
var fixture = new MSBuildRunnerFixture(false); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break. |
||
fixture.Settings.AddFileLogger(); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
// Then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add line break. |
||
Assert.Equal(@"/v:normal /target:Build /fl ""/Working/src/Solution.sln""", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Throw_Exception_For_Too_Many_FileLoggers() | ||
{ | ||
// Given | ||
var fixture = new MSBuildRunnerFixture(false); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break. |
||
fixture.Settings.AddFileLogger(); | ||
fixture.Settings.AddFileLogger(); | ||
fixture.Settings.AddFileLogger(); | ||
fixture.Settings.AddFileLogger(); | ||
fixture.Settings.AddFileLogger(); | ||
fixture.Settings.AddFileLogger(); | ||
fixture.Settings.AddFileLogger(); | ||
fixture.Settings.AddFileLogger(); | ||
fixture.Settings.AddFileLogger(); | ||
fixture.Settings.AddFileLogger(); | ||
fixture.Settings.AddFileLogger(); | ||
|
||
// When | ||
var ex = Assert.Throws<System.InvalidOperationException>(() => fixture.Run()); | ||
// Then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add line break. |
||
Assert.Equal(@"Too Many FileLoggers", ex.Message); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Cake.Core.Diagnostics; | ||
|
||
namespace Cake.Common.Tools.MSBuild | ||
{ | ||
/// <summary> | ||
/// Contains settings for specifying a MSBuild file logger. | ||
/// </summary> | ||
public class MSBuildFileLogger | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="MSBuildFileLogger"/> class. | ||
/// </summary> | ||
public MSBuildFileLogger() | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether PerformanceSummary will Show the time that’s spent in tasks, targets, and projects. | ||
/// </summary> | ||
public bool PerformanceSummaryEnabled { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether Summary will Show the error and warning summary at the end. | ||
/// </summary> | ||
public bool SummaryDisabled { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets show ErrorsOnly, WarningsOnly, or All | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing period. |
||
/// </summary> | ||
public MSBuildFileLoggerOutput MSBuildFileLoggerOutput { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether NoItemAndPropertyList will be set to Don't show the list of items and properties that would appear at the start of each project build if the verbosity level is set to diagnostic. | ||
/// </summary> | ||
public bool HideVerboseItemAndPropertyList { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether ShowCommandLine. Show TaskCommandLineEvent messages. | ||
/// </summary> | ||
public bool ShowCommandLine { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether ShowTimestamp. Show the timestamp as a prefix to any message. | ||
/// </summary> | ||
public bool ShowTimestamp { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether ShowEventId. Show the event ID for each started event, finished event, and message. | ||
/// </summary> | ||
public bool ShowEventId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets Verbosity. Override the /verbosity setting for this logger. | ||
/// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break. |
||
/// specify the following verbosity levels: q[uiet], m[inimal], n[ormal], v[erbose] (detailed), and diag[nostic]. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
/// </summary> | ||
public Verbosity? Verbosity { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets LogFile. The path to the log file into which the build log is written. | ||
/// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break. |
||
/// an empty string will use msbuild.log | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence should begin with a capital letter and end with a period. |
||
/// </summary> | ||
public string LogFile { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets a value indicating whether the build log is appended to the log file or overwrites it. When true, the build log is appended to the log file. | ||
/// </summary> | ||
public bool AppendToLogFile { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets Specifies the encoding for the file (for example, UTF-8, Unicode, or ASCII). | ||
/// </summary> | ||
public string Encoding { get; set; } | ||
|
||
/// <summary> | ||
/// process the file logger config and return parameters as a string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence should begin with a capital letter and end with a period. |
||
/// </summary> | ||
/// <returns>The parameters separated by semi-colons.</returns> | ||
public string GetParameters() | ||
{ | ||
var parameters = new List<string>(); | ||
parameters.Add(!string.IsNullOrWhiteSpace(LogFile) ? $"logfile={LogFile}" : null); | ||
parameters.Add(!string.IsNullOrWhiteSpace(Encoding) ? $"Encoding={Encoding}" : null); | ||
parameters.Add(AppendToLogFile ? "Append" : null); | ||
parameters.Add(PerformanceSummaryEnabled ? "PerformanceSummary" : null); | ||
parameters.Add(SummaryDisabled ? "NoSummary" : null); | ||
parameters.Add(MSBuildFileLoggerOutput == MSBuildFileLoggerOutput.ErrorsOnly ? "ErrorsOnly" : null); | ||
parameters.Add(MSBuildFileLoggerOutput == MSBuildFileLoggerOutput.WarningsOnly ? "WarningsOnly" : null); | ||
parameters.Add(HideVerboseItemAndPropertyList ? "NoItemAndPropertyList" : null); | ||
parameters.Add(ShowCommandLine ? "ShowCommandLine" : null); | ||
parameters.Add(ShowTimestamp ? "ShowTimestamp" : null); | ||
parameters.Add(ShowEventId ? "ShowEventId" : null); | ||
parameters.Add(Verbosity != null ? $"Verbosity={Verbosity.Value.ToString()}" : null); | ||
|
||
return string.Join(";", parameters.Where(p => p != null)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace Cake.Common.Tools.MSBuild | ||
{ | ||
/// <summary> | ||
/// the type of file logger output to generate | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence should begin with a capital letter and end with a period. |
||
/// </summary> | ||
public enum MSBuildFileLoggerOutput | ||
{ | ||
/// <summary> | ||
/// show errors and warnings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence should begin with a capital letter and end with a period. |
||
/// </summary> | ||
All = 0, | ||
|
||
/// <summary> | ||
/// show errors only | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence should begin with a capital letter and end with a period. |
||
/// </summary> | ||
ErrorsOnly = 1, | ||
|
||
/// <summary> | ||
/// show warnings only | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence should begin with a capital letter and end with a period. |
||
/// </summary> | ||
WarningsOnly = 2, | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,12 +111,44 @@ private ProcessArgumentBuilder GetArguments(FilePath solution, MSBuildSettings s | |
} | ||
} | ||
|
||
// Got any file loggers? | ||
if (settings.FileLoggers.Count > 0) | ||
{ | ||
var arguments = settings.FileLoggers.Select((logger, indx) => | ||
{ | ||
return GetLoggerArgument(indx, logger); | ||
}); | ||
|
||
foreach (var argument in arguments) | ||
{ | ||
builder.Append(argument); | ||
} | ||
} | ||
|
||
// Add the solution as the last parameter. | ||
builder.AppendQuoted(solution.MakeAbsolute(_environment).FullPath); | ||
|
||
return builder; | ||
} | ||
|
||
private static string GetLoggerArgument(int indx, MSBuildFileLogger logger) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{ | ||
if (indx >= 10) | ||
{ | ||
throw new InvalidOperationException("Too Many FileLoggers"); | ||
} | ||
|
||
var cntr = indx == 0 ? string.Empty : indx.ToString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
var argument = $"/fl{cntr}"; | ||
|
||
var parameters = logger.GetParameters(); | ||
if (!string.IsNullOrWhiteSpace(parameters)) | ||
{ | ||
argument = $"{argument} /flp{cntr}:{parameters}"; | ||
} | ||
return argument; | ||
} | ||
|
||
private static string GetLoggerArgument(MSBuildLogger logger) | ||
{ | ||
string argument = "/logger:"; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,5 +200,50 @@ public static MSBuildSettings WithLogger(this MSBuildSettings settings, string l | |
}); | ||
return settings; | ||
} | ||
|
||
/// <summary> | ||
/// Adds a file logger. | ||
/// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break. |
||
/// each file logger will be declared in the order added | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence should begin with a capital letter and end with a period. |
||
/// the first file logger will match up to the /fl parameter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence should begin with a capital letter and end with a period. |
||
/// the next nine (max) file loggers will match up to the /fl1 through /fl9 respectively | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence should begin with a capital letter and end with a period. |
||
/// </summary> | ||
/// <param name="settings">The settings.</param> | ||
/// <param name="fileLoggerParameters">Parameters to be passed to the logger.</param> | ||
/// <returns>The same <see cref="MSBuildSettings"/> instance so that multiple calls can be chained.</returns> | ||
public static MSBuildSettings AddFileLogger(this MSBuildSettings settings, MSBuildFileLogger fileLoggerParameters) | ||
{ | ||
if (settings == null) | ||
{ | ||
throw new ArgumentNullException(nameof(settings)); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break. |
||
if (fileLoggerParameters == null) | ||
{ | ||
throw new ArgumentNullException(nameof(fileLoggerParameters)); | ||
} | ||
settings.FileLoggers.Add(fileLoggerParameters); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add line break. |
||
return settings; | ||
} | ||
|
||
/// <summary> | ||
/// Adds a file logger with all the default settings. | ||
/// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove line break. |
||
/// each file logger will be declared in the order added | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence should begin with a capital letter and end with a period. |
||
/// the first file logger will match up to the /fl parameter | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence should begin with a capital letter and end with a period. |
||
/// the next nine (max) file loggers will match up to the /fl1 through /fl9 respectively | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sentence should begin with a capital letter and end with a period. |
||
/// </summary> | ||
/// <param name="settings">The settings.</param> | ||
/// <returns>The same <see cref="MSBuildSettings"/> instance so that multiple calls can be chained.</returns> | ||
public static MSBuildSettings AddFileLogger(this MSBuildSettings settings) | ||
{ | ||
if (settings == null) | ||
{ | ||
throw new ArgumentNullException(nameof(settings)); | ||
} | ||
|
||
settings.FileLoggers.Add(new MSBuildFileLogger()); | ||
return settings; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove line break.