From 1842c5174006df98e52c6e37e120285d8f08e2be Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 3 Aug 2020 14:15:55 +0000 Subject: [PATCH 01/15] Bump xunit.runner.visualstudio from 2.4.2 to 2.4.3 in /src Bumps [xunit.runner.visualstudio](https://github.com/xunit/visualstudio.xunit) from 2.4.2 to 2.4.3. - [Release notes](https://github.com/xunit/visualstudio.xunit/releases) - [Commits](https://github.com/xunit/visualstudio.xunit/compare/v2.4.2...v2.4.3) Signed-off-by: dependabot-preview[bot] --- src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj b/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj index a372a36..407ebd2 100644 --- a/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj +++ b/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj @@ -48,7 +48,7 @@ - + From df47393f95e2b89e61cabc8494075b4c482d80d1 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Thu, 6 Aug 2020 12:23:53 +0000 Subject: [PATCH 02/15] Bump Microsoft.NET.Test.Sdk from 16.6.1 to 16.7.0 in /src Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 16.6.1 to 16.7.0. - [Release notes](https://github.com/microsoft/vstest/releases) - [Commits](https://github.com/microsoft/vstest/compare/v16.6.1...v16.7.0) Signed-off-by: dependabot-preview[bot] --- src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj b/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj index 407ebd2..eae864e 100644 --- a/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj +++ b/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj @@ -40,7 +40,7 @@ - + From 3416f82623a5b56248087033b8e73bb081122688 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2020 19:18:00 +0000 Subject: [PATCH 03/15] Bump Microsoft.NET.Test.Sdk from 16.7.0 to 16.7.1 in /src Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 16.7.0 to 16.7.1. - [Release notes](https://github.com/microsoft/vstest/releases) - [Commits](https://github.com/microsoft/vstest/compare/v16.7.0...v16.7.1) Signed-off-by: dependabot-preview[bot] --- src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj b/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj index afbac44..79e44ed 100644 --- a/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj +++ b/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj @@ -40,7 +40,7 @@ - + From 2ff964167f9815448e683a81070751abd74a8eb4 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Sat, 22 Aug 2020 22:31:14 +0000 Subject: [PATCH 04/15] Bump Microsoft.CodeAnalysis.FxCopAnalyzers from 3.0.0 to 3.3.0 in /src Bumps [Microsoft.CodeAnalysis.FxCopAnalyzers](https://github.com/dotnet/roslyn-analyzers) from 3.0.0 to 3.3.0. - [Release notes](https://github.com/dotnet/roslyn-analyzers/releases) - [Changelog](https://github.com/dotnet/roslyn-analyzers/blob/master/PostReleaseActivities.md) - [Commits](https://github.com/dotnet/roslyn-analyzers/compare/v3.0.0...v3.3.0) Signed-off-by: dependabot-preview[bot] --- src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj b/src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj index 8aa395a..1281692 100644 --- a/src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj +++ b/src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj @@ -27,7 +27,7 @@ - + From d52d2f97f368901765d2e9225daa6886912d1eae Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Sun, 23 Aug 2020 11:01:27 +0200 Subject: [PATCH 05/15] Update code owners to use a single team --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 44482aa..8482f26 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,3 +1,3 @@ # These owners will be the default owners for everything in the repo and # will be requested for review when someone opens a pull request. -* @cake-contrib/team-bbt @x-jokay \ No newline at end of file +* @cake-contrib/team-cake-issues \ No newline at end of file From 8c4cff76ec6b46756ab05dd8e9d9b9804d4c3070 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Sun, 23 Aug 2020 11:02:55 +0200 Subject: [PATCH 06/15] Disable publishing to MyGet --- recipe.cake | 1 + 1 file changed, 1 insertion(+) diff --git a/recipe.cake b/recipe.cake index 8de517f..2bac329 100644 --- a/recipe.cake +++ b/recipe.cake @@ -11,6 +11,7 @@ BuildParameters.SetParameters( repositoryName: "Cake.Issues.MsBuild", appVeyorAccountName: "cakecontrib", shouldGenerateDocumentation: false, + shouldPublishMyGet: false, shouldRunCodecov: false, shouldRunGitVersion: true); From ef4f17b7cc5adc2bbbdb5b5e837cd61148a7cc46 Mon Sep 17 00:00:00 2001 From: Christoffer Hoel Date: Tue, 22 Sep 2020 10:56:16 +0200 Subject: [PATCH 07/15] (GH-201) Support parsing of errors in MsBuildXmlFileLoggerFormat --- .../Cake.Issues.MsBuild.Tests.csproj | 26 +-------- .../XmlFileLoggerLogFileFormatTests.cs | 56 +++++++++++++++++++ .../IssueWithBothWarningAndErrors.xml | 5 ++ .../IssueWithError.xml | 4 ++ .../XmlFileLoggerLogFileFormat.cs | 25 +++++---- 5 files changed, 83 insertions(+), 33 deletions(-) create mode 100644 src/Cake.Issues.MsBuild.Tests/Testfiles/XmlFileLoggerLogFileFormat/IssueWithBothWarningAndErrors.xml create mode 100644 src/Cake.Issues.MsBuild.Tests/Testfiles/XmlFileLoggerLogFileFormat/IssueWithError.xml diff --git a/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj b/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj index 79e44ed..4b7f17e 100644 --- a/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj +++ b/src/Cake.Issues.MsBuild.Tests/Cake.Issues.MsBuild.Tests.csproj @@ -15,28 +15,12 @@ - - - - - - - - - - + - - - - - - - - - + + @@ -55,8 +39,4 @@ - - - - diff --git a/src/Cake.Issues.MsBuild.Tests/LogFileFormat/XmlFileLoggerLogFileFormatTests.cs b/src/Cake.Issues.MsBuild.Tests/LogFileFormat/XmlFileLoggerLogFileFormatTests.cs index e5892b8..92577a4 100644 --- a/src/Cake.Issues.MsBuild.Tests/LogFileFormat/XmlFileLoggerLogFileFormatTests.cs +++ b/src/Cake.Issues.MsBuild.Tests/LogFileFormat/XmlFileLoggerLogFileFormatTests.cs @@ -402,6 +402,62 @@ public void Should_Read_Issue_With_Absolute_FileName_And_Without_Task() } } } + + [Fact] + public void Should_Read_Errors() + { + // Given + var fixture = new MsBuildIssuesProviderFixture("IssueWithError.xml"); + + // When + var issues = fixture.ReadIssues().ToList(); + + // Then + issues.Count.ShouldBe(1); + IssueChecker.Check( + issues[0], + IssueBuilder.NewIssue( + @"'ConfigurationManager.GetSortedConfigFiles(String)': not all code paths return a value", + "Cake.Issues.MsBuild.MsBuildIssuesProvider", + "MSBuild") + .InProjectOfName(string.Empty) + .InFile(@"src\Cake.Issues.MsBuild.Tests\MsBuildIssuesProviderTests.cs", 1311) + .OfRule("CS0161", null) + .WithPriority(IssuePriority.Error)); + } + + [Fact] + public void Should_Read_Both_Warnings_And_Errors() + { + // Given + var fixture = new MsBuildIssuesProviderFixture("IssueWithBothWarningAndErrors.xml"); + + // When + var issues = fixture.ReadIssues().ToList(); + + // Then + issues.Count.ShouldBe(2); + IssueChecker.Check( + issues[0], + IssueBuilder.NewIssue( + @"Microsoft.Usage : 'ConfigurationManager.GetSortedConfigFiles(String)' creates an exception of type 'ApplicationException', an exception type that is not sufficiently specific and should never be raised by user code. If this exception instance might be thrown, use a different exception type.", + "Cake.Issues.MsBuild.MsBuildIssuesProvider", + "MSBuild") + .InProjectOfName(string.Empty) + .InFile(@"src\Cake.Issues.MsBuild.Tests\MsBuildIssuesProviderTests.cs", 1311) + .OfRule("CA2201", new Uri("https://www.google.com/search?q=\"CA2201:\"+site:docs.microsoft.com")) + .WithPriority(IssuePriority.Warning)); + IssueChecker.Check( + issues[1], + IssueBuilder.NewIssue( + @"'ConfigurationManager.GetSortedConfigFiles(String)': not all code paths return a value", + "Cake.Issues.MsBuild.MsBuildIssuesProvider", + "MSBuild") + .InProjectOfName(string.Empty) + .InFile(@"src\Cake.Issues.MsBuild.Tests\MsBuildIssuesProviderTests.cs", 1311) + .OfRule("CS0161", null) + .WithPriority(IssuePriority.Error)); + } } } } diff --git a/src/Cake.Issues.MsBuild.Tests/Testfiles/XmlFileLoggerLogFileFormat/IssueWithBothWarningAndErrors.xml b/src/Cake.Issues.MsBuild.Tests/Testfiles/XmlFileLoggerLogFileFormat/IssueWithBothWarningAndErrors.xml new file mode 100644 index 0000000..06ae933 --- /dev/null +++ b/src/Cake.Issues.MsBuild.Tests/Testfiles/XmlFileLoggerLogFileFormat/IssueWithBothWarningAndErrors.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/Cake.Issues.MsBuild.Tests/Testfiles/XmlFileLoggerLogFileFormat/IssueWithError.xml b/src/Cake.Issues.MsBuild.Tests/Testfiles/XmlFileLoggerLogFileFormat/IssueWithError.xml new file mode 100644 index 0000000..610acdc --- /dev/null +++ b/src/Cake.Issues.MsBuild.Tests/Testfiles/XmlFileLoggerLogFileFormat/IssueWithError.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/Cake.Issues.MsBuild/LogFileFormat/XmlFileLoggerLogFileFormat.cs b/src/Cake.Issues.MsBuild/LogFileFormat/XmlFileLoggerLogFileFormat.cs index 798103b..f0da8ee 100644 --- a/src/Cake.Issues.MsBuild/LogFileFormat/XmlFileLoggerLogFileFormat.cs +++ b/src/Cake.Issues.MsBuild/LogFileFormat/XmlFileLoggerLogFileFormat.cs @@ -44,41 +44,44 @@ public override IEnumerable ReadIssues( var filtered = string.Concat(raw.Where(c => !char.IsControl(c))); var logDocument = XDocument.Parse(filtered); - // Loop through all warning tags. - foreach (var warning in logDocument.Descendants("warning")) + // Loop through all warning and error tags. + var elements = new List(logDocument.Descendants("warning")); + elements.AddRange(logDocument.Descendants("error")); + + foreach (var element in elements) { // Ignore warnings without a message. - if (string.IsNullOrWhiteSpace(warning.Value)) + if (string.IsNullOrWhiteSpace(element.Value)) { continue; } // Read affected project from the warning. - if (!this.TryGetProject(warning, repositorySettings, out string projectFileRelativePath)) + if (!this.TryGetProject(element, repositorySettings, out string projectFileRelativePath)) { continue; } // Read affected file from the warning. - if (!this.TryGetFile(warning, repositorySettings, out string fileName)) + if (!this.TryGetFile(element, repositorySettings, out string fileName)) { continue; } // Read affected line from the warning. - if (!TryGetLine(warning, out var line)) + if (!TryGetLine(element, out var line)) { continue; } // Read affected column from the warning. - if (!TryGetColumn(warning, out var column)) + if (!TryGetColumn(element, out var column)) { continue; } // Read rule code from the warning. - if (!TryGetRule(warning, out string rule)) + if (!TryGetRule(element, out string rule)) { continue; } @@ -90,11 +93,13 @@ public override IEnumerable ReadIssues( ruleUrl = MsBuildRuleUrlResolver.Instance.ResolveRuleUrl(rule); } + var priority = element.Name.LocalName == "error" ? IssuePriority.Error : IssuePriority.Warning; + // Build issue. result.Add( IssueBuilder - .NewIssue(warning.Value, issueProvider) - .WithPriority(IssuePriority.Warning) + .NewIssue(element.Value, issueProvider) + .WithPriority(priority) .InProject(projectFileRelativePath, System.IO.Path.GetFileNameWithoutExtension(projectFileRelativePath)) .InFile(fileName, line, column) .OfRule(rule, ruleUrl) From 296627b30cfc496256fb48732c57ed1e3e34eb55 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Wed, 23 Sep 2020 07:59:09 +0000 Subject: [PATCH 08/15] Bump MSBuild.StructuredLogger from 2.1.133 to 2.1.176 in /src Bumps [MSBuild.StructuredLogger](https://github.com/KirillOsenkov/MSBuildStructuredLog) from 2.1.133 to 2.1.176. - [Release notes](https://github.com/KirillOsenkov/MSBuildStructuredLog/releases) - [Commits](https://github.com/KirillOsenkov/MSBuildStructuredLog/commits) Signed-off-by: dependabot-preview[bot] --- src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj b/src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj index 1281692..8bb61c6 100644 --- a/src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj +++ b/src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj @@ -28,7 +28,7 @@ - + From 46d4ea2942f18f03e8877e76215e82061c923938 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Wed, 23 Sep 2020 14:55:18 +0200 Subject: [PATCH 09/15] Revert "Bump MSBuild.StructuredLogger from 2.1.133 to 2.1.176 in /src" This reverts commit 296627b30cfc496256fb48732c57ed1e3e34eb55. --- src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj b/src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj index 8bb61c6..1281692 100644 --- a/src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj +++ b/src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj @@ -28,7 +28,7 @@ - + From de3c2c7eaa9c02c1a5f67eb75bd0d72b6f63f062 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Sun, 18 Oct 2020 22:58:45 +0200 Subject: [PATCH 10/15] (GH-201) Update documentation for reading errors --- docs/features.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/features.md b/docs/features.md index c6cff68..702e4ce 100644 --- a/docs/features.md +++ b/docs/features.md @@ -7,7 +7,7 @@ The [Cake.Issues.MsBuild addin] provides the following features. # Basic features -* Reads warnings from MSBuild log files. +* Reads errors and warnings from MSBuild log files. * Provides URLs for all code analysis (`CA*`) and StyleCop (`SA*`) warnings. * Support for custom URL resolving using the [MsBuildAddRuleUrlResolver] alias. @@ -35,8 +35,8 @@ The [Cake.Issues.MsBuild addin] provides the following features. | | `IIssue.MessageText` | | | | `IIssue.MessageHtml` | | | | `IIssue.MessageMarkdown` | | -| | `IIssue.Priority` | Always [IssuePriority.Warning] | -| | `IIssue.PriorityName` | Always `Warning` | +| | `IIssue.Priority` | | +| | `IIssue.PriorityName` | | | | `IIssue.Rule` | | | | `IIssue.RuleUrl` | For code analysis (`CA*`) and StyleCop (`SA*`) warnings. Support for additional rules can be added through a custom [MsBuildAddRuleUrlResolver] | From a7df6e38d8a130c348c43b70a0600bb0ddab7d35 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Sun, 18 Oct 2020 23:50:36 +0200 Subject: [PATCH 11/15] (GH-201) Support parsing of errors in BinaryLogFileFormat --- .../LogFileFormat/BinaryLogFileFormat.cs | 228 ++++++++++-------- 1 file changed, 134 insertions(+), 94 deletions(-) diff --git a/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs b/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs index bad304e..0cf870d 100644 --- a/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs +++ b/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs @@ -43,168 +43,208 @@ public override IEnumerable ReadIssues( { var buildEventArgs = record.Args; - if (buildEventArgs is BuildWarningEventArgs buildWarning) + IIssue issue = null; + if (buildEventArgs is BuildErrorEventArgs buildError) { - // Ignore warnings without a message. - if (string.IsNullOrWhiteSpace(buildWarning.Message)) - { - continue; - } - - var projectFileRelativePath = this.GetProject(buildWarning, repositorySettings); - - // Read affected file from the warning. - if (!this.TryGetFile(buildWarning, repositorySettings, out string fileName)) - { - continue; - } - - var line = GetLine(buildWarning); - var endLine = GetEndLine(buildWarning); - var column = GetColumn(buildWarning); - var endColumn = GetEndColumn(buildWarning); - var rule = buildWarning.Code; - - // Determine rule URL. - Uri ruleUrl = null; - if (!string.IsNullOrWhiteSpace(rule)) - { - ruleUrl = MsBuildRuleUrlResolver.Instance.ResolveRuleUrl(rule); - } - - // Build issue. - result.Add( - IssueBuilder - .NewIssue(buildWarning.Message, issueProvider) - .WithPriority(IssuePriority.Warning) - .InProject(projectFileRelativePath, System.IO.Path.GetFileNameWithoutExtension(projectFileRelativePath)) - .InFile(fileName, line, endLine, column, endColumn) - .OfRule(rule, ruleUrl) - .Create()); + issue = this.GetIssue(buildError, issueProvider, repositorySettings); } + else if (buildEventArgs is BuildWarningEventArgs buildWarning) + { + issue = this.GetIssue(buildWarning, issueProvider, repositorySettings); + } + + if (issue == null) + { + continue; + } + + result.Add(issue); } return result; } /// - /// Reads the affected line from a warning logged in a MsBuild log. + /// Returns the column based on the value from a MsBuild log. /// - /// Warning element from MsBuild log. - /// Line number or null if warning is not related to a file. - private static int? GetLine(BuildWarningEventArgs warning) + /// Raw value from MsBuild log. + /// Column number or null if warning is not related to a file. + private static int? GetColumn(int column) { - var line = warning.LineNumber; - - // Convert negative line numbers or line number 0 to null - if (line <= 0) + // Convert negative column numbers or column number 0 to null + if (column <= 0) { return null; } - return line; + return column; } /// - /// Reads the end of line range from a warning logged in a MsBuild log. + /// Returns the line based on the value from a MsBuild log. /// - /// Warning element from MsBuild log. - /// End of line range or null if warning is not related to a file. - private static int? GetEndLine(BuildWarningEventArgs warning) + /// Raw value from MsBuild log. + /// Line number or null if warning is not related to a file. + private static int? GetLine(int line) { - var endLine = warning.EndLineNumber; - // Convert negative line numbers or line number 0 to null - if (endLine <= 0) + if (line <= 0) { return null; } - return endLine; + return line; } /// - /// Reads the affected column from a warning logged in a MsBuild log. + /// Returns an issue for a build error. /// - /// Warning element from MsBuild log. - /// Column number or null if warning is not related to a file. - private static int? GetColumn(BuildWarningEventArgs warning) + /// Error for which the issue should be returned. + /// Issue provider instance. + /// Repository settings to use. + /// Issue instance or null, if the could not be parsed. + private IIssue GetIssue( + BuildErrorEventArgs buildError, + MsBuildIssuesProvider issueProvider, + IRepositorySettings repositorySettings) { - var column = warning.ColumnNumber; - - // Convert negative column numbers or column number 0 to null - if (column <= 0) - { - return null; - } + return + this.GetIssue( + buildError.Message, + buildError.ProjectFile, + buildError.File, + buildError.LineNumber, + buildError.EndLineNumber, + buildError.ColumnNumber, + buildError.EndColumnNumber, + buildError.Code, + issueProvider, + repositorySettings); + } - return column; + /// + /// Returns an issue for a build warning. + /// + /// Warning for which the issue should be returned. + /// Issue provider instance. + /// Repository settings to use. + /// Issue instance or null, if the could not be parsed. + private IIssue GetIssue( + BuildWarningEventArgs buildWarning, + MsBuildIssuesProvider issueProvider, + IRepositorySettings repositorySettings) + { + return + this.GetIssue( + buildWarning.Message, + buildWarning.ProjectFile, + buildWarning.File, + buildWarning.LineNumber, + buildWarning.EndLineNumber, + buildWarning.ColumnNumber, + buildWarning.EndColumnNumber, + buildWarning.Code, + issueProvider, + repositorySettings); } /// - /// Reads the end of column range from a warning logged in a MsBuild log. + /// Returns an issue for values from an MsBuild log. /// - /// Warning element from MsBuild log. - /// End of column range or null if warning is not related to a file. - private static int? GetEndColumn(BuildWarningEventArgs warning) + /// Issue provider instance. + /// Repository settings to use. + /// Issue instance or null, if the values could not be parsed. + private IIssue GetIssue( + string message, + string projectFile, + string file, + int lineNumber, + int endLineNumber, + int columnNumber, + int endColumnNumber, + string code, + MsBuildIssuesProvider issueProvider, + IRepositorySettings repositorySettings) { - var endColumn = warning.EndColumnNumber; + // Ignore warnings without a message. + if (string.IsNullOrWhiteSpace(message)) + { + return null; + } - // Convert negative column numbers or column number 0 to null - if (endColumn <= 0) + var projectFileRelativePath = this.GetProject(projectFile, repositorySettings); + + // Read affected file from the warning. + var (result, fileName) = this.TryGetFile(file, projectFile, repositorySettings); + if (!result) { return null; } - return endColumn; + var line = GetLine(lineNumber); + var endLine = GetLine(endLineNumber); + var column = GetColumn(columnNumber); + var endColumn = GetColumn(endColumnNumber); + var rule = code; + + // Determine rule URL. + Uri ruleUrl = null; + if (!string.IsNullOrWhiteSpace(rule)) + { + ruleUrl = MsBuildRuleUrlResolver.Instance.ResolveRuleUrl(rule); + } + + // Build issue. + return + IssueBuilder + .NewIssue(message, issueProvider) + .WithPriority(IssuePriority.Warning) + .InProject(projectFileRelativePath, System.IO.Path.GetFileNameWithoutExtension(projectFileRelativePath)) + .InFile(fileName, line, endLine, column, endColumn) + .OfRule(rule, ruleUrl) + .Create(); } /// - /// Determines the project for a warning logged in a MsBuild log. + /// Determines the project from a value in a MsBuild log. /// - /// Warning element from the MsBuild log. + /// Raw value from the MsBuild log. /// Repository settings to use. /// Relative path to the project. private string GetProject( - BuildWarningEventArgs warning, + string project, IRepositorySettings repositorySettings) { - var project = warning.ProjectFile; - // Validate project path and make relative to repository root. return this.ValidateFilePath(project, repositorySettings).FilePath; } /// - /// Reads the affected file path from a warning logged in a MsBuild log. + /// Reads the affected file path from a value in a MsBuild log. /// - /// Warning element from MsBuild log. + /// Raw value for file path from MsBuild log. + /// Raw value for project path from the MsBuild log. /// Repository settings to use. - /// Returns the full path to the affected file. - /// True if the file path could be parsed. - private bool TryGetFile( - BuildWarningEventArgs warning, - IRepositorySettings repositorySettings, - out string fileName) + /// True if the file path could be parsed and the full path to the affected file. + private (bool successful, string fileName) TryGetFile( + string fileName, + string project, + IRepositorySettings repositorySettings) { - fileName = warning.File; - if (string.IsNullOrWhiteSpace(fileName)) { - return true; + return (true, fileName); } // If not absolute path, combine with file path from project file. if (!fileName.IsFullPath()) { - var projectDirectory = System.IO.Path.GetDirectoryName(warning.ProjectFile); + var projectDirectory = System.IO.Path.GetDirectoryName(project); fileName = System.IO.Path.Combine(projectDirectory, fileName); } // Validate file path and make relative to repository root. - bool result; - (result, fileName) = this.ValidateFilePath(fileName, repositorySettings); - return result; + return this.ValidateFilePath(fileName, repositorySettings); } } } From 30dfc389d7e6047673969e28caa3a4680514e8ce Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Mon, 19 Oct 2020 21:48:03 +0200 Subject: [PATCH 12/15] Fix naming of arguments and comments --- .../LogFileFormat/BinaryLogFileFormat.cs | 8 +-- .../XmlFileLoggerLogFileFormat.cs | 54 +++++++++---------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs b/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs index 0cf870d..76d7da3 100644 --- a/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs +++ b/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs @@ -68,7 +68,7 @@ public override IEnumerable ReadIssues( /// Returns the column based on the value from a MsBuild log. /// /// Raw value from MsBuild log. - /// Column number or null if warning is not related to a file. + /// Column number or null if warning or error is not related to a file. private static int? GetColumn(int column) { // Convert negative column numbers or column number 0 to null @@ -84,7 +84,7 @@ public override IEnumerable ReadIssues( /// Returns the line based on the value from a MsBuild log. /// /// Raw value from MsBuild log. - /// Line number or null if warning is not related to a file. + /// Line number or null if warning or error is not related to a file. private static int? GetLine(int line) { // Convert negative line numbers or line number 0 to null @@ -166,7 +166,7 @@ private IIssue GetIssue( MsBuildIssuesProvider issueProvider, IRepositorySettings repositorySettings) { - // Ignore warnings without a message. + // Ignore warnings or errors without a message. if (string.IsNullOrWhiteSpace(message)) { return null; @@ -174,7 +174,7 @@ private IIssue GetIssue( var projectFileRelativePath = this.GetProject(projectFile, repositorySettings); - // Read affected file from the warning. + // Read affected file from the warning or error. var (result, fileName) = this.TryGetFile(file, projectFile, repositorySettings); if (!result) { diff --git a/src/Cake.Issues.MsBuild/LogFileFormat/XmlFileLoggerLogFileFormat.cs b/src/Cake.Issues.MsBuild/LogFileFormat/XmlFileLoggerLogFileFormat.cs index f0da8ee..cd0a808 100644 --- a/src/Cake.Issues.MsBuild/LogFileFormat/XmlFileLoggerLogFileFormat.cs +++ b/src/Cake.Issues.MsBuild/LogFileFormat/XmlFileLoggerLogFileFormat.cs @@ -50,37 +50,37 @@ public override IEnumerable ReadIssues( foreach (var element in elements) { - // Ignore warnings without a message. + // Ignore warnings or errors without a message. if (string.IsNullOrWhiteSpace(element.Value)) { continue; } - // Read affected project from the warning. + // Read affected project from the warning or error. if (!this.TryGetProject(element, repositorySettings, out string projectFileRelativePath)) { continue; } - // Read affected file from the warning. + // Read affected file from the warning or error. if (!this.TryGetFile(element, repositorySettings, out string fileName)) { continue; } - // Read affected line from the warning. + // Read affected line from the warning or error. if (!TryGetLine(element, out var line)) { continue; } - // Read affected column from the warning. + // Read affected column from the warning or error. if (!TryGetColumn(element, out var column)) { continue; } - // Read rule code from the warning. + // Read rule code from the warning or error. if (!TryGetRule(element, out string rule)) { continue; @@ -110,16 +110,16 @@ public override IEnumerable ReadIssues( } /// - /// Reads the affected line from a warning logged in a MsBuild log. + /// Reads the affected line from a warning or error logged in a MsBuild log. /// - /// Warning element from MsBuild log. + /// Warning or error element from MsBuild log. /// Returns line. /// True if the line could be parsed. - private static bool TryGetLine(XElement warning, out int? line) + private static bool TryGetLine(XElement element, out int? line) { line = null; - var lineAttr = warning.Attribute("line"); + var lineAttr = element.Attribute("line"); var lineValue = lineAttr?.Value; if (string.IsNullOrWhiteSpace(lineValue)) @@ -139,16 +139,16 @@ private static bool TryGetLine(XElement warning, out int? line) } /// - /// Reads the affected column from a warning logged in a MsBuild log. + /// Reads the affected column from a warning or error logged in a MsBuild log. /// - /// Warning element from MsBuild log. + /// Warning or error element from MsBuild log. /// Returns column. /// True if the column could be parsed. - private static bool TryGetColumn(XElement warning, out int? column) + private static bool TryGetColumn(XElement element, out int? column) { column = null; - var columnAttr = warning.Attribute("column"); + var columnAttr = element.Attribute("column"); var columnValue = columnAttr?.Value; if (string.IsNullOrWhiteSpace(columnValue)) @@ -168,14 +168,14 @@ private static bool TryGetColumn(XElement warning, out int? column) } /// - /// Reads the rule code from a warning logged in a MsBuild log. + /// Reads the rule code from a warning or error logged in a MsBuild log. /// - /// Warning element from MsBuild log. + /// Warning or error element from MsBuild log. /// Returns the code of the rule. /// True if the rule code could be parsed. - private static bool TryGetRule(XElement warning, out string rule) + private static bool TryGetRule(XElement error, out string rule) { - var codeAttr = warning.Attribute("code"); + var codeAttr = error.Attribute("code"); if (codeAttr == null) { rule = null; @@ -187,20 +187,20 @@ private static bool TryGetRule(XElement warning, out string rule) } /// - /// Determines the project for a warning logged in a MsBuild log. + /// Determines the project for a warning or error logged in a MsBuild log. /// - /// Warning element from MsBuild log. + /// Warning or error element from MsBuild log. /// Repository settings to use. /// Returns project. /// True if the project could be parsed. private bool TryGetProject( - XElement warning, + XElement element, IRepositorySettings repositorySettings, out string project) { project = string.Empty; - var projectNode = warning.Ancestors("project").FirstOrDefault(); + var projectNode = element.Ancestors("project").FirstOrDefault(); if (projectNode == null) { return true; @@ -225,20 +225,20 @@ private bool TryGetProject( } /// - /// Reads the affected file path from a warning logged in a MsBuild log. + /// Reads the affected file path from a warning or error logged in a MsBuild log. /// - /// Warning element from MsBuild log. + /// Warning or error element from MsBuild log. /// Repository settings to use. /// Returns the full path to the affected file. /// True if the file path could be parsed. private bool TryGetFile( - XElement warning, + XElement element, IRepositorySettings repositorySettings, out string fileName) { fileName = string.Empty; - var fileAttr = warning.Attribute("file"); + var fileAttr = element.Attribute("file"); if (fileAttr == null) { return true; @@ -253,7 +253,7 @@ private bool TryGetFile( // If not absolute path, combine with file path from compile task. if (!fileName.IsFullPath()) { - var parentFileAttr = warning.Parent?.Attribute("file"); + var parentFileAttr = element.Parent?.Attribute("file"); if (parentFileAttr != null) { var compileTaskDirectory = System.IO.Path.GetDirectoryName(parentFileAttr.Value); From 5bb5dabf4889fba4c630ae8c5649fc1b9ecfe00f Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Mon, 19 Oct 2020 22:27:29 +0200 Subject: [PATCH 13/15] Add missing XML comments --- .../LogFileFormat/BinaryLogFileFormat.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs b/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs index 76d7da3..49decbe 100644 --- a/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs +++ b/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs @@ -151,6 +151,14 @@ private IIssue GetIssue( /// /// Returns an issue for values from an MsBuild log. /// + /// Raw value from the MsBuild log containing the message. + /// Raw value from the MsBuild log containing the project file. + /// Raw value from the MsBuild log containing the file. + /// Raw value from the MsBuild log containing the line number. + /// Raw value from the MsBuild log containing the end of the line range. + /// Raw value from the MsBuild log containing the column. + /// Raw value from the MsBuild log containing the end of the column range. + /// Raw value from the MsBuild log containing the rule. /// Issue provider instance. /// Repository settings to use. /// Issue instance or null, if the values could not be parsed. From 22932141a8df0ece64f4858898f206fcd748ca46 Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Mon, 19 Oct 2020 22:29:51 +0200 Subject: [PATCH 14/15] Use correct issue priority for errors in bin logs --- .../LogFileFormat/BinaryLogFileFormat.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs b/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs index 49decbe..72c323c 100644 --- a/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs +++ b/src/Cake.Issues.MsBuild/LogFileFormat/BinaryLogFileFormat.cs @@ -110,6 +110,7 @@ private IIssue GetIssue( { return this.GetIssue( + IssuePriority.Error, buildError.Message, buildError.ProjectFile, buildError.File, @@ -136,6 +137,7 @@ private IIssue GetIssue( { return this.GetIssue( + IssuePriority.Warning, buildWarning.Message, buildWarning.ProjectFile, buildWarning.File, @@ -151,6 +153,7 @@ private IIssue GetIssue( /// /// Returns an issue for values from an MsBuild log. /// + /// Priority of the issue. /// Raw value from the MsBuild log containing the message. /// Raw value from the MsBuild log containing the project file. /// Raw value from the MsBuild log containing the file. @@ -163,6 +166,7 @@ private IIssue GetIssue( /// Repository settings to use. /// Issue instance or null, if the values could not be parsed. private IIssue GetIssue( + IssuePriority priority, string message, string projectFile, string file, @@ -206,7 +210,7 @@ private IIssue GetIssue( return IssueBuilder .NewIssue(message, issueProvider) - .WithPriority(IssuePriority.Warning) + .WithPriority(priority) .InProject(projectFileRelativePath, System.IO.Path.GetFileNameWithoutExtension(projectFileRelativePath)) .InFile(fileName, line, endLine, column, endColumn) .OfRule(rule, ruleUrl) From 08ed83f2f645cbbc3a2b3e070b97895debbc64bf Mon Sep 17 00:00:00 2001 From: Pascal Berger Date: Tue, 20 Oct 2020 20:33:50 +0200 Subject: [PATCH 15/15] Update release notes link --- nuspec/nuget/Cake.Issues.MsBuild.nuspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nuspec/nuget/Cake.Issues.MsBuild.nuspec b/nuspec/nuget/Cake.Issues.MsBuild.nuspec index 24f8dbc..25940d5 100644 --- a/nuspec/nuget/Cake.Issues.MsBuild.nuspec +++ b/nuspec/nuget/Cake.Issues.MsBuild.nuspec @@ -24,7 +24,7 @@ See the Project Site for an overview of the whole ecosystem of addins for workin Copyright © BBT Software AG and contributors Cake Script Cake-Issues Cake-IssueProvider CodeAnalysis Linting MsBuild - https://github.com/cake-contrib/Cake.Issues.MsBuild/releases/tag/0.9.0 + https://github.com/cake-contrib/Cake.Issues.MsBuild/releases/tag/0.9.1