Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/MSBuildProjectCreator.UnitTests/BuildOutputTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void Errors(string expectedMessage, string expectedCode)
{
BuildOutput buildOutput = GetProjectLoggerWithEvents(eventSource => { eventSource.OnErrorRaised(expectedMessage, expectedCode); });

BuildErrorEventArgs args = buildOutput.Errors.ShouldHaveSingleItem();
BuildErrorEventArgs args = buildOutput.ErrorEvents.ShouldHaveSingleItem();

args.Message.ShouldBe(expectedMessage);

Expand All @@ -61,20 +61,20 @@ public void MessagesByImportance(MessageImportance importance)

var actualItem = buildOutput.Messages.ShouldHaveSingleItem();

actualItem.Message.ShouldBe(expectedMessage);
actualItem.ShouldBe(expectedMessage);

switch (importance)
{
case MessageImportance.High:
buildOutput.MessagesHighImportance.ShouldHaveSingleItem().ShouldBe(actualItem);
buildOutput.Messages.High.ShouldHaveSingleItem().ShouldBe(actualItem);
break;

case MessageImportance.Normal:
buildOutput.MessagesNormalImportance.ShouldHaveSingleItem().ShouldBe(actualItem);
buildOutput.Messages.Normal.ShouldHaveSingleItem().ShouldBe(actualItem);
break;

case MessageImportance.Low:
buildOutput.MessagesLowImportance.ShouldHaveSingleItem().ShouldBe(actualItem);
buildOutput.Messages.Low.ShouldHaveSingleItem().ShouldBe(actualItem);
break;
}
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public void Warnings(string expectedMessage, string expectedCode)
{
BuildOutput buildOutput = GetProjectLoggerWithEvents(eventSource => { eventSource.OnWarningRaised(expectedMessage, expectedCode); });

BuildWarningEventArgs args = buildOutput.Warnings.ShouldHaveSingleItem();
BuildWarningEventArgs args = buildOutput.WarningEvents.ShouldHaveSingleItem();

args.Message.ShouldBe(expectedMessage);

Expand Down
50 changes: 26 additions & 24 deletions src/MSBuildProjectCreator/BuildOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ public sealed class BuildOutput : ILogger, IDisposable
/// <summary>
/// Stores the errors that were logged.
/// </summary>
private readonly List<BuildErrorEventArgs> _errors = new List<BuildErrorEventArgs>();
private readonly List<BuildErrorEventArgs> _errorEvents = new List<BuildErrorEventArgs>();

/// <summary>
/// Stores the messages that were logged.
/// </summary>
private readonly List<BuildMessageEventArgs> _messages = new List<BuildMessageEventArgs>(50);
private readonly List<BuildMessageEventArgs> _messageEvents = new List<BuildMessageEventArgs>(50);

/// <summary>
/// Stores the results by project.
Expand All @@ -35,7 +35,7 @@ public sealed class BuildOutput : ILogger, IDisposable
/// <summary>
/// Stores the warnings that were logged.
/// </summary>
private readonly List<BuildWarningEventArgs> _warnings = new List<BuildWarningEventArgs>();
private readonly List<BuildWarningEventArgs> _warningEvents = new List<BuildWarningEventArgs>();

/// <summary>
/// Stores all build events.
Expand All @@ -49,6 +49,8 @@ public sealed class BuildOutput : ILogger, IDisposable

private BuildOutput()
{
MessageEvents = new BuildOutputMessageEvents(_messageEvents);
Messages = new BuildOutputMessages(this);
}

/// <summary>
Expand All @@ -57,29 +59,24 @@ private BuildOutput()
public IReadOnlyCollection<BuildEventArgs> AllEvents => _allEvents;

/// <summary>
/// Gets the errors that were logged.
/// Gets the error events that were logged.
/// </summary>
public IReadOnlyCollection<BuildErrorEventArgs> Errors => _errors;
public IReadOnlyCollection<BuildErrorEventArgs> ErrorEvents => _errorEvents;

/// <summary>
/// Gets the messages that were logged.
/// </summary>
public IReadOnlyCollection<BuildMessageEventArgs> Messages => _messages;

/// <summary>
/// Gets the messages that were logged with <see cref="MessageImportance.High"/>.
/// Gets the error messages that were logged.
/// </summary>
public IReadOnlyCollection<BuildMessageEventArgs> MessagesHighImportance => _messages.Where(i => i.Importance == MessageImportance.High).ToList();
public IReadOnlyCollection<string> Errors => _errorEvents.Select(i => i.Message).ToList();

/// <summary>
/// Gets the messages that were logged with <see cref="MessageImportance.Low"/>.
/// Gets the messages that were logged.
/// </summary>
public IReadOnlyCollection<BuildMessageEventArgs> MessagesLowImportance => _messages.Where(i => i.Importance == MessageImportance.Low).ToList();
public BuildOutputMessageEvents MessageEvents { get; }

/// <summary>
/// Gets the messages that were logged with <see cref="MessageImportance.Normal"/>.
/// Gets a <see cref="BuildOutputMessages"/> object that gets the messages from the build.
/// </summary>
public IReadOnlyCollection<BuildMessageEventArgs> MessagesNormalImportance => _messages.Where(i => i.Importance == MessageImportance.Normal).ToList();
public BuildOutputMessages Messages { get; }

/// <inheritdoc cref="ILogger.Parameters"/>
public string Parameters { get; set; }
Expand All @@ -98,9 +95,14 @@ private BuildOutput()
public LoggerVerbosity Verbosity { get; set; }

/// <summary>
/// Gets the warnings that were logged.
/// Gets the warning events that were logged.
/// </summary>
public IReadOnlyCollection<BuildWarningEventArgs> WarningEvents => _warningEvents;

/// <summary>
/// Gets the warning messages that were logged.
/// </summary>
public IReadOnlyCollection<BuildWarningEventArgs> Warnings => _warnings;
public IReadOnlyCollection<string> Warnings => _warningEvents.Select(i => i.Message).ToList();

/// <summary>
/// Creates an instance of the <see cref="BuildOutput"/> class.
Expand All @@ -115,9 +117,9 @@ public static BuildOutput Create()
public void Dispose()
{
_buildFinished = null;
_errors.Clear();
_messages.Clear();
_warnings.Clear();
_errorEvents.Clear();
_messageEvents.Clear();
_warningEvents.Clear();
_allEvents = null;
}

Expand Down Expand Up @@ -212,12 +214,12 @@ private void OnAnyEventRaised(object sender, BuildEventArgs e)

private void OnBuildFinished(object sender, BuildFinishedEventArgs args) => _buildFinished = args;

private void OnErrorRaised(object sender, BuildErrorEventArgs args) => _errors.Add(args);
private void OnErrorRaised(object sender, BuildErrorEventArgs args) => _errorEvents.Add(args);

private void OnMessageRaised(object sender, BuildMessageEventArgs args) => _messages.Add(args);
private void OnMessageRaised(object sender, BuildMessageEventArgs args) => _messageEvents.Add(args);

private void OnProjectFinished(object sender, ProjectFinishedEventArgs e) => _resultsByProject.AddOrUpdate(e.ProjectFile, e.Succeeded, (projectFile, succeeded) => succeeded && e.Succeeded);

private void OnWarningRaised(object sender, BuildWarningEventArgs args) => _warnings.Add(args);
private void OnWarningRaised(object sender, BuildWarningEventArgs args) => _warningEvents.Add(args);
}
}
59 changes: 59 additions & 0 deletions src/MSBuildProjectCreator/BuildOutputMessageEvents.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) Jeff Kluge. All rights reserved.
//
// Licensed under the MIT license.

using Microsoft.Build.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Build.Utilities.ProjectCreation
{
/// <summary>
/// Represents the <see cref="BuildMessageEventArgs"/> that were logged during a build.
/// </summary>
public sealed class BuildOutputMessageEvents : IReadOnlyCollection<BuildMessageEventArgs>
{
private readonly IReadOnlyCollection<BuildMessageEventArgs> _messageEvents;

/// <summary>
/// Initializes a new instance of the <see cref="BuildOutputMessageEvents"/> class.
/// </summary>
/// <param name="messageEvents">A <see cref="IReadOnlyCollection{BuildMessageEventArgs}"/> containing the logged message events.</param>
internal BuildOutputMessageEvents(IReadOnlyCollection<BuildMessageEventArgs> messageEvents)
{
_messageEvents = messageEvents ?? throw new ArgumentNullException(nameof(messageEvents));
}

/// <inheritdoc cref="IReadOnlyCollection{T}.Count"/>
public int Count => _messageEvents.Count;

/// <summary>
/// Gets the <see cref="BuildMessageEventArgs"/> that were logged with <see cref="MessageImportance.High"/>.
/// </summary>
public IReadOnlyCollection<BuildMessageEventArgs> High => _messageEvents.Where(i => i.Importance == MessageImportance.High).ToList();

/// <summary>
/// Gets the <see cref="BuildMessageEventArgs"/> that were logged with <see cref="MessageImportance.Low"/>.
/// </summary>
public IReadOnlyCollection<BuildMessageEventArgs> Low => _messageEvents.Where(i => i.Importance == MessageImportance.Low).ToList();

/// <summary>
/// Gets the <see cref="BuildMessageEventArgs"/> that were logged with <see cref="MessageImportance.Normal"/>.
/// </summary>
public IReadOnlyCollection<BuildMessageEventArgs> Normal => _messageEvents.Where(i => i.Importance == MessageImportance.Normal).ToList();

/// <inheritdoc cref="IEnumerable{T}.GetEnumerator"/>
public IEnumerator<BuildMessageEventArgs> GetEnumerator()
{
return _messageEvents.GetEnumerator();
}

/// <inheritdoc cref="IEnumerable.GetEnumerator"/>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}
59 changes: 59 additions & 0 deletions src/MSBuildProjectCreator/BuildOutputMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) Jeff Kluge. All rights reserved.
//
// Licensed under the MIT license.

using Microsoft.Build.Framework;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.Build.Utilities.ProjectCreation
{
/// <summary>
/// Represents the messages that were logged during a build.
/// </summary>
public sealed class BuildOutputMessages : IReadOnlyCollection<string>
{
private readonly BuildOutput _buildOutput;

/// <summary>
/// Initializes a new instance of the <see cref="BuildOutputMessages"/> class.
/// </summary>
/// <param name="buildOutput">The <see cref="BuildOutput"/> object that has message events.</param>
internal BuildOutputMessages(BuildOutput buildOutput)
{
_buildOutput = buildOutput ?? throw new ArgumentNullException(nameof(buildOutput));
}

/// <inheritdoc cref="IReadOnlyCollection{T}.Count"/>
public int Count => _buildOutput.MessageEvents.Count;

/// <summary>
/// Gets the messages that were logged with <see cref="MessageImportance.High"/>.
/// </summary>
public IReadOnlyCollection<string> High => _buildOutput.MessageEvents.High.Select(i => i.Message).ToList();

/// <summary>
/// Gets the messages that were logged with <see cref="MessageImportance.Low"/>.
/// </summary>
public IReadOnlyCollection<string> Low => _buildOutput.MessageEvents.Low.Select(i => i.Message).ToList();

/// <summary>
/// Gets the messages that were logged with <see cref="MessageImportance.Normal"/>.
/// </summary>
public IReadOnlyCollection<string> Normal => _buildOutput.MessageEvents.Normal.Select(i => i.Message).ToList();

/// <inheritdoc cref="IEnumerable{T}.GetEnumerator"/>
public IEnumerator<string> GetEnumerator()
{
return _buildOutput.MessageEvents.Select(i => i.Message).ToList().GetEnumerator();
}

/// <inheritdoc cref="IEnumerable.GetEnumerator"/>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.0",
"version": "1.1",
"assemblyVersion": "1.0",
"nugetPackageVersion": {
"semVer": 1
Expand Down