-
Notifications
You must be signed in to change notification settings - Fork 392
Fix cobertura Jenkins reporter + source link support #614
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
Changes from 10 commits
a6e0687
84c0aff
5b4e316
45075e1
ef7d0b0
a50f143
28e038c
a8198b6
83cae50
26e4959
7ffb1de
ab54646
529437f
595194f
761662b
bc24dd4
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 |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Globalization; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Runtime.InteropServices; | ||
|
||
| using System.Text; | ||
| using System.Xml.Linq; | ||
|
|
||
|
|
@@ -30,7 +32,8 @@ public string Report(CoverageResult result) | |
| coverage.Add(new XAttribute("timestamp", (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds)); | ||
|
|
||
| XElement sources = new XElement("sources"); | ||
| sources.Add(new XElement("source", string.Empty)); | ||
| var rootDirs = GetRootDirs(result.Modules, result.IsSourceLinkUsed).ToList(); | ||
| rootDirs.ForEach(x => sources.Add(new XElement("source", x))); | ||
|
|
||
| XElement packages = new XElement("packages"); | ||
| foreach (var module in result.Modules) | ||
|
|
@@ -48,7 +51,7 @@ public string Report(CoverageResult result) | |
| { | ||
| XElement @class = new XElement("class"); | ||
| @class.Add(new XAttribute("name", cls.Key)); | ||
| @class.Add(new XAttribute("filename", document.Key)); | ||
| @class.Add(new XAttribute("filename", GetRelativePathFromBase(rootDirs, document.Key, result.IsSourceLinkUsed))); | ||
| @class.Add(new XAttribute("line-rate", (summary.CalculateLineCoverage(cls.Value).Percent / 100).ToString(CultureInfo.InvariantCulture))); | ||
| @class.Add(new XAttribute("branch-rate", (summary.CalculateBranchCoverage(cls.Value).Percent / 100).ToString(CultureInfo.InvariantCulture))); | ||
| @class.Add(new XAttribute("complexity", summary.CalculateCyclomaticComplexity(cls.Value))); | ||
|
|
@@ -129,5 +132,37 @@ public string Report(CoverageResult result) | |
|
|
||
| return Encoding.UTF8.GetString(stream.ToArray()); | ||
| } | ||
|
|
||
| private static IEnumerable<string> GetRootDirs(Modules modules, bool isSourceLinkUsed) | ||
|
||
| { | ||
| if (isSourceLinkUsed) return new[] { string.Empty }; | ||
|
|
||
| List<string> sources = new List<string>(); | ||
|
|
||
| foreach (var module in modules) | ||
| { | ||
|
|
||
| sources.AddRange( | ||
| module.Value.Select(d => Path.GetDirectoryName(d.Key))); | ||
| } | ||
|
|
||
| sources = sources.Distinct().ToList(); | ||
| return sources.Select(Directory.GetDirectoryRoot).Distinct(); | ||
| } | ||
|
|
||
| private static string GetRelativePathFromBase(IEnumerable<string> basePaths, string path, bool isSourceLinkUsed) | ||
|
||
| { | ||
| if (isSourceLinkUsed) return path; | ||
|
|
||
| string relativePath = path; | ||
| basePaths.ToList().ForEach(basePath => | ||
| { | ||
| if (path.StartsWith(basePath)) | ||
| { | ||
| relativePath = path.Substring(basePath.Length); | ||
|
||
| } | ||
| }); | ||
| return relativePath; | ||
| } | ||
| } | ||
| } | ||
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.
nit: I prefer to maintain switch name
UseSourceLinkThere 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.
Done