-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tom Staijen
committed
Nov 9, 2016
1 parent
bcf0a8f
commit 8b49592
Showing
7 changed files
with
185 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Cake.Sonar | ||
{ | ||
[AttributeUsage(AttributeTargets.Property)] | ||
public class ArgumentAttribute : Attribute | ||
{ | ||
public string Name { get; set; } | ||
|
||
public ArgumentAttribute(string name) | ||
{ | ||
Name = name; | ||
} | ||
|
||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace Cake.Sonar | ||
{ | ||
public class SonarBeginSettings | ||
{ | ||
[Argument("/d:sonar.host.url=")] | ||
public string Url { get; set; } | ||
|
||
[Argument("/d:sonar.login=")] | ||
public string Login { get; set; } | ||
|
||
[Argument("/d:sonar.password=")] | ||
public string Password { get; set; } | ||
|
||
[Argument("/k:")] | ||
public string Key { get; set; } | ||
|
||
[Argument("/n:")] | ||
public string Name { get; set; } | ||
|
||
[Argument("/d:sonar.branch=")] | ||
public string Branch { get; set; } | ||
|
||
[Argument("/v:")] | ||
public string Version{ get; set; } | ||
|
||
[Argument("/d:sonar.cs.nunit.reportsPaths=")] | ||
public string NUnitReportsPath { get; set; } | ||
|
||
[Argument("/d:sonar.cs.dotcover.reportsPaths=")] | ||
public string DotCoverReportsPath { get; set; } | ||
|
||
public bool Verbose { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System.Linq; | ||
using System.Reflection; | ||
using Cake.Core; | ||
using Cake.Core.Diagnostics; | ||
using Cake.Core.IO; | ||
|
||
namespace Cake.Sonar | ||
{ | ||
public class SonarCake | ||
{ | ||
private readonly ICakeContext _context; | ||
private readonly ICakeLog _log; | ||
private readonly IProcessRunner _runner; | ||
|
||
public SonarCake(ICakeContext context) | ||
{ | ||
_context = context; | ||
_log = _context.Log; | ||
_runner = _context.ProcessRunner; | ||
} | ||
|
||
public static string ToolPath = "Tools/MSBuild.SonarQube.Runner.Tool/tools/MSBuild.SonarQube.Runner.exe"; | ||
|
||
public void Begin(SonarBeginSettings settings) | ||
{ | ||
var arguments = new ProcessArgumentBuilder(); | ||
arguments.Append("begin"); | ||
|
||
AppendArguments(settings, arguments); | ||
|
||
_log.Information(arguments.Render()); | ||
|
||
var proces = _runner.Start(ToolPath, new ProcessSettings() | ||
{ | ||
Arguments = arguments | ||
}); | ||
|
||
if (settings.Verbose) | ||
arguments.Append("/d:sonar.verbuse=true"); | ||
|
||
proces.WaitForExit(); | ||
var exitCode = proces.GetExitCode(); | ||
_log.Information($"Exitcode {exitCode}"); | ||
} | ||
|
||
public void End(SonarEndSettings settings) | ||
{ | ||
var arguments = new ProcessArgumentBuilder(); | ||
arguments.Append("end"); | ||
|
||
AppendArguments(settings, arguments); | ||
|
||
_log.Information(arguments.Render()); | ||
|
||
var proces = _runner.Start(ToolPath, new ProcessSettings() | ||
{ | ||
Arguments = arguments | ||
}); | ||
|
||
proces.WaitForExit(); | ||
var exitCode = proces.GetExitCode(); | ||
_log.Information($"Exitcode {exitCode}"); | ||
} | ||
|
||
public void AppendArguments(object s, ProcessArgumentBuilder builder) | ||
{ | ||
foreach (var pi in s.GetType().GetProperties()) | ||
{ | ||
var attr = pi.GetCustomAttributes<ArgumentAttribute>().FirstOrDefault(); | ||
if (attr != null) | ||
{ | ||
var value = pi.GetValue(s); | ||
if( value != null ) | ||
builder.Append($"{attr.Name}{pi.GetValue(s)}"); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System; | ||
using Cake.Core; | ||
using Cake.Core.Annotations; | ||
|
||
namespace Cake.Sonar | ||
{ | ||
[CakeAliasCategory("Sonar")] | ||
public static class SonarCakeAliases | ||
{ | ||
[CakeMethodAlias] | ||
public static void SonarBegin(this ICakeContext context, SonarBeginSettings settings) | ||
{ | ||
new SonarCake(context).Begin(settings); | ||
} | ||
|
||
[CakeMethodAlias] | ||
public static void SonarEnd(this ICakeContext context, SonarEndSettings settings) | ||
{ | ||
new SonarCake(context).End(settings); | ||
} | ||
|
||
[CakeMethodAlias] | ||
public static void Sonar(this ICakeContext context, Action<ICakeContext> action, SonarBeginSettings settings) | ||
{ | ||
var cake = new SonarCake(context); | ||
cake.Begin(settings); | ||
action(context); | ||
cake.End(new SonarEndSettings() | ||
{ | ||
Login = settings.Login, | ||
Password = settings.Password | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace Cake.Sonar | ||
{ | ||
public class SonarEndSettings | ||
{ | ||
|
||
[Argument("/d:sonar.login=")] | ||
public string Login { get; set; } | ||
|
||
[Argument("/d:sonar.password=")] | ||
public string Password { get; set; } | ||
} | ||
} |