Skip to content

Commit

Permalink
Merge pull request #7 from augustoproiete/run-as-global-tool-and-fall…
Browse files Browse the repository at this point in the history
…back-logic

Add ability to execute MinVer as global tool and fallback logic
  • Loading branch information
augustoproiete authored Nov 24, 2020
2 parents 5f24795 + 32c404e commit 1885916
Show file tree
Hide file tree
Showing 16 changed files with 939 additions and 245 deletions.
1 change: 1 addition & 0 deletions Cake.MinVer.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArgumentsStyleLiteral/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArgumentsStyleNamedExpression/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArgumentsStyleStringLiteral/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeTrailingCommaInMultilineLists/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CommentTypo/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MarkupAttributeTypo/@EntryIndexedValue">DO_NOT_SHOW</s:String>
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=MarkupTextTypo/@EntryIndexedValue">DO_NOT_SHOW</s:String>
Expand Down
48 changes: 48 additions & 0 deletions src/Cake.MinVer/MinVerGlobalTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections.Generic;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Core.Tooling;

namespace Cake.MinVer
{
internal class MinVerGlobalTool : MinVerToolBase
{
public MinVerGlobalTool(
IFileSystem fileSystem,
ICakeEnvironment environment,
IProcessRunner processRunner,
IToolLocator tools,
ICakeLog log) : base(fileSystem, environment, processRunner, tools, log)
{
}

/// <inheritdoc />
protected override ProcessArgumentBuilder GetArguments(MinVerSettings settings)
{
var command = new ProcessArgumentBuilder();
var args = CreateArgumentBuilder(settings);

if (!args.IsNullOrEmpty())
{
args.CopyTo(command);
}

CakeLog.Verbose("{0} arguments: {1}", GetToolName(), args.RenderSafe());

return command;
}

/// <inheritdoc />
protected override string GetToolName()
{
return "MinVer Global Tool (minver)";
}

/// <inheritdoc />
protected override IEnumerable<string> GetToolExecutableNames()
{
return new [] { "minver", "minver.exe" };
}
}
}
43 changes: 43 additions & 0 deletions src/Cake.MinVer/MinVerLocalTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Core.Tooling;

namespace Cake.MinVer
{
internal class MinVerLocalTool : MinVerToolBase
{
public MinVerLocalTool(
IFileSystem fileSystem,
ICakeEnvironment environment,
IProcessRunner processRunner,
IToolLocator tools,
ICakeLog log) : base(fileSystem, environment, processRunner, tools, log)
{
}

/// <inheritdoc />
protected override ProcessArgumentBuilder GetArguments(MinVerSettings settings)
{
var command = new ProcessArgumentBuilder();
var args = CreateArgumentBuilder(settings);

command.Append("minver");

if (!args.IsNullOrEmpty())
{
args.CopyTo(command);
}

CakeLog.Verbose("{0} arguments: {1}", GetToolName(), args.RenderSafe());

return command;
}

/// <inheritdoc />
protected override string GetToolName()
{
return "MinVer Local Tool (dotnet minver)";
}
}
}
24 changes: 24 additions & 0 deletions src/Cake.MinVer/MinVerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ public class MinVerSettings : DotNetCoreSettings
/// </summary>
public string TagPrefix { get; set; }

/// <summary>
/// By default, MinVer is executed as a local tool first and, in case of error, fallback(*) to global tool
/// Set <see cref="PreferGlobalTool" /> to <see langword="true" /> to execute MinVer as global tool first and,
/// in case of an error, fallback(*) to local tool
///
/// (*) Unless the fallback is disabled via <see cref="NoFallback" />
///
/// Local tool = `dotnet minver`
/// Global tool = `minver`
/// </summary>
public bool PreferGlobalTool { get; set; }

/// <summary>
/// By default, MinVer is executed as a local tool first(*) and, in case of error, fallback to global tool(*)
/// Set <see cref="NoFallback" /> to <see langword="true" /> to disable the fallback in case of an error
///
/// (*) Unless <see cref="PreferGlobalTool" /> is set to <see langword="true" />, in which case MinVer is
/// executed as a global tool first and, in case of an error, fallback to local tool
///
/// Local tool = `dotnet minver`
/// Global tool = `minver`
/// </summary>
public bool NoFallback { get; set; }

/// <summary>
/// Set the verbosity.
/// --verbosity &lt;VERBOSITY&gt;
Expand Down
67 changes: 67 additions & 0 deletions src/Cake.MinVer/MinVerSettingsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel;
using Cake.Core.IO;
using Cake.Core.Tooling;

namespace Cake.MinVer
{
Expand Down Expand Up @@ -152,6 +153,72 @@ public static MinVerSettings WithTagPrefix(this MinVerSettings settings, string
return settings;
}

/// <summary>
/// By default, MinVer is executed as a local tool first and, in case of error, fallback(*) to global tool
/// Set <see cref="MinVerSettings.PreferGlobalTool" /> to <see langword="true" /> to execute MinVer as global tool first and,
/// in case of an error, fallback(*) to local tool
///
/// (*) Unless the fallback is disabled via <see cref="MinVerSettings.NoFallback" />
///
/// Local tool = `dotnet minver`
/// Global tool = `minver`
/// </summary>
/// <param name="settings">The settings.</param>
/// <returns>The <paramref name="settings" /> instance with <see cref="MinVerSettings.Repo" />.</returns>
public static MinVerSettings WithPreferGlobalTool(this MinVerSettings settings)
{
if (settings is null)
{
throw new ArgumentNullException(nameof(settings));
}

settings.PreferGlobalTool = true;

return settings;
}

/// <summary>
/// By default, MinVer is executed as a local tool first(*) and, in case of error, fallback to global tool(*)
/// Set <see cref="MinVerSettings.NoFallback" /> to <see langword="true" /> to disable the fallback in case of an error
///
/// (*) Unless <see cref="MinVerSettings.PreferGlobalTool" /> is set to <see langword="true" />, in which case MinVer is
/// executed as a global tool first and, in case of an error, fallback to local tool
///
/// Local tool = `dotnet minver`
/// Global tool = `minver`
/// </summary>
/// <param name="settings">The settings.</param>
/// <returns>The <paramref name="settings" /> instance with <see cref="MinVerSettings.Repo" />.</returns>
public static MinVerSettings WithNoFallback(this MinVerSettings settings)
{
if (settings is null)
{
throw new ArgumentNullException(nameof(settings));
}

settings.NoFallback = true;

return settings;
}

/// <summary>
/// Set a custom path to the minver.exe file.
/// </summary>
/// <param name="settings">The settings.</param>
/// <param name="toolPath">The custom path to the minver.exe file.</param>
/// <returns>The <paramref name="settings" /> instance with <see cref="ToolSettings.ToolPath" /> set to <paramref name="toolPath" />.</returns>
public static MinVerSettings WithToolPath(this MinVerSettings settings, FilePath toolPath)
{
if (settings is null)
{
throw new ArgumentNullException(nameof(settings));
}

settings.ToolPath = toolPath ?? throw new ArgumentNullException(nameof(toolPath));

return settings;
}

/// <summary>
/// Set the verbosity.
/// --verbosity &lt;VERBOSITY&gt;
Expand Down
Loading

0 comments on commit 1885916

Please sign in to comment.