Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/0.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Jun 26, 2018
2 parents e2fb812 + edcc087 commit 96b93c6
Show file tree
Hide file tree
Showing 7 changed files with 1,174 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nuspec/nuget/Cake.Issues.MsBuild.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ See the Project Site for an overview of the whole ecosystem of addins for workin
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright © BBT Software AG and contributors</copyright>
<tags>Cake Script Cake-Issues Cake-IssueProvider CodeAnalysis Linting MsBuild</tags>
<releaseNotes>https://github.com/cake-contrib/Cake.Issues.MsBuild/releases/tag/0.3.0</releaseNotes>
<releaseNotes>https://github.com/cake-contrib/Cake.Issues.MsBuild/releases/tag/0.3.1</releaseNotes>
</metadata>
<files>
<file src="netstandard2.0\Cake.Issues.MsBuild.dll" target="lib\netstandard2.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</PropertyGroup>

<ItemGroup>
<None Remove="Testfiles\FullLog.xml" />
<None Remove="Testfiles\IssueWithFile.xml" />
<None Remove="Testfiles\IssueWithLineZero.xml" />
<None Remove="Testfiles\IssueWithOnlyFileName.xml" />
Expand All @@ -23,6 +24,7 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Testfiles\FullLog.xml" />
<EmbeddedResource Include="Testfiles\IssueWithoutCode.xml" />
<EmbeddedResource Include="Testfiles\IssueWithFile.xml" />
<EmbeddedResource Include="Testfiles\IssueWithLineZero.xml" />
Expand Down
925 changes: 925 additions & 0 deletions src/Cake.Issues.MsBuild.Tests/Testfiles/FullLog.xml

Large diffs are not rendered by default.

191 changes: 191 additions & 0 deletions src/Cake.Issues.MsBuild.Tests/XmlFileLoggerFormatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,190 @@ public void Should_Throw_If_Log_Is_Null()

public sealed class TheReadIssuesMethod
{
[Fact]
public void Should_Read_Full_Log_Correct()
{
// Given
var fixture = new MsBuildIssuesProviderFixture("FullLog.xml");

// When
var issues = fixture.ReadIssues().ToList();

// Then
issues.Count.ShouldBe(19);
CheckIssue(
issues[0],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Class1.cs",
13,
"CS0219",
300,
"Warning",
@"The variable 'foo' is assigned but its value is never used");
CheckIssue(
issues[1],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Class1.cs",
1,
"SA1652",
300,
"Warning",
@"Enable XML documentation output");
CheckIssue(
issues[2],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Class1.cs",
1,
"SA1633",
300,
"Warning",
@"The file header is missing or not located at the top of the file.");
CheckIssue(
issues[3],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Class1.cs",
1,
"SA1200",
300,
"Warning",
@"Using directive must appear within a namespace declaration");
CheckIssue(
issues[4],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Class1.cs",
2,
"SA1200",
300,
"Warning",
@"Using directive must appear within a namespace declaration");
CheckIssue(
issues[5],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Class1.cs",
3,
"SA1200",
300,
"Warning",
@"Using directive must appear within a namespace declaration");
CheckIssue(
issues[6],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Class1.cs",
4,
"SA1200",
300,
"Warning",
@"Using directive must appear within a namespace declaration");
CheckIssue(
issues[7],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Class1.cs",
5,
"SA1200",
300,
"Warning",
@"Using directive must appear within a namespace declaration");
CheckIssue(
issues[8],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
1,
"SA1652",
300,
"Warning",
@"Enable XML documentation output");
CheckIssue(
issues[9],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
1,
"SA1633",
300,
"Warning",
@"The file header is missing or not located at the top of the file.");
CheckIssue(
issues[10],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
5,
"SA1028",
300,
"Warning",
@"Code must not contain trailing whitespace");
CheckIssue(
issues[11],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
17,
"SA1028",
300,
"Warning",
@"Code must not contain trailing whitespace");
CheckIssue(
issues[12],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
18,
"SA1028",
300,
"Warning",
@"Code must not contain trailing whitespace");
CheckIssue(
issues[13],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
28,
"SA1028",
300,
"Warning",
@"Code must not contain trailing whitespace");
CheckIssue(
issues[14],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
32,
"SA1028",
300,
"Warning",
@"Code must not contain trailing whitespace");
CheckIssue(
issues[15],
@"src\ClassLibrary1\ClassLibrary1.csproj",
null,
null,
"CA2210",
300,
"Warning",
@"Microsoft.Design : Sign 'ClassLibrary1.dll' with a strong name key.");
CheckIssue(
issues[16],
@"src\ClassLibrary1\ClassLibrary1.csproj",
null,
null,
"CA1014",
300,
"Warning",
@"Microsoft.Design : Mark 'ClassLibrary1.dll' with CLSCompliant(true) because it exposes externally visible types.");
CheckIssue(
issues[17],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Class1.cs",
12,
"CA1822",
300,
"Warning",
@"Microsoft.Performance : The 'this' parameter (or 'Me' in Visual Basic) of 'Class1.Foo()' is never used. Mark the member as static (or Shared in Visual Basic) or use 'this'/'Me' in the method body or at least one property accessor, if appropriate.");
CheckIssue(
issues[18],
@"src\ClassLibrary1\ClassLibrary1.csproj",
@"src\ClassLibrary1\Class1.cs",
13,
"CA1804",
300,
"Warning",
@"Microsoft.Performance : 'Class1.Foo()' declares a variable, 'foo', of type 'string', which is never used or is only assigned to. Use this variable or remove it.");
}

[Fact]
public void Should_Read_Issue_With_File_Correct()
{
Expand All @@ -37,6 +221,7 @@ public void Should_Read_Issue_With_File_Correct()
var issue = issues.Single();
CheckIssue(
issue,
string.Empty,
@"src\Cake.Issues.MsBuild.Tests\MsBuildIssuesProviderTests.cs",
1311,
"CA2201",
Expand All @@ -59,6 +244,7 @@ public void Should_Read_Issue_With_File_Without_Path_Correct()
var issue = issues.Single();
CheckIssue(
issue,
string.Empty,
@"src\Cake.Issues.MsBuild.Tests\MsBuildIssuesProviderTests.cs",
13,
"CS0219",
Expand All @@ -81,6 +267,7 @@ public void Should_Read_Issue_With_Line_Zero_Correct()
var issue = issues.Single();
CheckIssue(
issue,
@"Cake.Prca.shfbproj",
@"SHFB",
null,
"BE0006",
Expand All @@ -103,6 +290,7 @@ public void Should_Read_Issue_Without_File_Correct()
var issue = issues.Single();
CheckIssue(
issue,
string.Empty,
null,
null,
"CA1711",
Expand All @@ -125,6 +313,7 @@ public void Should_Read_Issue_Without_Code_Correct()
var issue = issues.Single();
CheckIssue(
issue,
string.Empty,
@"src\Cake.Issues.MsBuild.Tests\MsBuildIssuesProviderTests.cs",
21,
null,
Expand All @@ -135,6 +324,7 @@ public void Should_Read_Issue_Without_Code_Correct()

private static void CheckIssue(
IIssue issue,
string project,
string affectedFileRelativePath,
int? line,
string rule,
Expand All @@ -144,6 +334,7 @@ private static void CheckIssue(
{
issue.ProviderType.ShouldBe("Cake.Issues.MsBuild.MsBuildIssuesProvider");
issue.ProviderName.ShouldBe("MSBuild");
issue.Project.ShouldBe(project);

if (issue.AffectedFileRelativePath == null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.28.0" />
<PackageReference Include="Cake.Issues" Version="0.3.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
</ItemGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/Cake.Issues.MsBuild/MsBuildIssuesAliases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static ILogFileFormat MsBuildXmlFileLoggerFormat(
/// var issues =
/// ReadIssues(
/// MsBuildIssuesFromFilePath(
/// @"c:\build\InspectCode.log",
/// @"c:\build\msbuild.xml",
/// MsBuildXmlFileLoggerFormat),
/// @"c:\repo");
/// ]]>
Expand Down Expand Up @@ -211,7 +211,7 @@ public static IIssueProvider MsBuildIssuesFromContent(
/// <![CDATA[
/// var settings =
/// MsBuildIssuesSettings.FromFilePath(
/// @"c:\build\msbuild.log",
/// @"c:\build\msbuild.xml",
/// MsBuildXmlFileLoggerFormat);
///
/// var issues =
Expand Down
52 changes: 52 additions & 0 deletions src/Cake.Issues.MsBuild/XmlFileLoggerFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using Core.Diagnostics;

Expand Down Expand Up @@ -38,6 +39,12 @@ public override IEnumerable<IIssue> ReadIssues(
// Loop through all warning tags.
foreach (var warning in logDocument.Descendants("warning"))
{
// Read affected project from the warning.
if (!TryGetProject(warning, repositorySettings, out string project))
{
continue;
}

// Read affected file from the warning.
if (!this.TryGetFile(warning, repositorySettings, out string fileName))
{
Expand Down Expand Up @@ -68,6 +75,7 @@ public override IEnumerable<IIssue> ReadIssues(
IssueBuilder
.NewIssue(warning.Value, issueProvider)
.WithPriority(IssuePriority.Warning)
.InProject(project)
.InFile(fileName, line)
.OfRule(rule, ruleUrl)
.Create());
Expand Down Expand Up @@ -126,6 +134,50 @@ private static bool TryGetRule(XElement warning, out string rule)
return !string.IsNullOrWhiteSpace(rule);
}

/// <summary>
/// Determines the project for a warning logged in a MsBuild log.
/// </summary>
/// <param name="warning">Warning element from MsBuild log.</param>
/// <param name="repositorySettings">Repository settings to use.</param>
/// <param name="project">Returns project.</param>
/// <returns>True if the project could be parsed.</returns>
private static bool TryGetProject(
XElement warning,
RepositorySettings repositorySettings,
out string project)
{
project = string.Empty;

var projectNode = warning.Ancestors("project").FirstOrDefault();
if (projectNode == null)
{
return true;
}

var projectAttr = projectNode.Attribute("file");
if (projectAttr == null)
{
return true;
}

project = projectAttr.Value;
if (string.IsNullOrWhiteSpace(project))
{
return true;
}

// Make path relative to repository root.
project = project.Substring(repositorySettings.RepositoryRoot.FullPath.Length);

// Remove leading directory separator.
if (project.StartsWith(Path.DirectorySeparatorChar.ToString()))
{
project = project.Substring(1);
}

return true;
}

/// <summary>
/// Reads the affected file path from a warning logged in a MsBuild log.
/// </summary>
Expand Down

0 comments on commit 96b93c6

Please sign in to comment.