Skip to content

Commit

Permalink
Bring Frosting up to speed
Browse files Browse the repository at this point in the history
Contains some unavoidable breaking changes.
  • Loading branch information
patriksvensson authored and devlead committed Dec 7, 2020
1 parent ce4895b commit a1cbb58
Show file tree
Hide file tree
Showing 172 changed files with 2,612 additions and 4,411 deletions.
25 changes: 25 additions & 0 deletions src/Cake.Cli/Cake.Cli.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.Cli</AssemblyName>
<TargetFrameworks>netstandard2.0;net5.0</TargetFrameworks>
<OutputType>Library</OutputType>
<PlatformTarget>AnyCpu</PlatformTarget>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<!-- Package specific metadata -->
<PropertyGroup>
<Description>The Cake CLI library.</Description>
</PropertyGroup>

<!-- Import shared functionality -->
<Import Project="..\Shared.msbuild" />
<ItemGroup>
<ProjectReference Include="..\Cake.Core\Cake.Core.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Autofac" Version="6.0.0" />
<PackageReference Include="Spectre.Cli" Version="0.46.0" />
</ItemGroup>
</Project>
79 changes: 79 additions & 0 deletions src/Cake.Cli/Features/InfoFeature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using Cake.Core;

namespace Cake.Cli
{
/// <summary>
/// Represents a feature that writes information about Cake to the console.
/// </summary>
public interface ICakeInfoFeature
{
/// <summary>
/// Runs the feature.
/// </summary>
/// <param name="console">The console to write to.</param>
void Run(IConsole console);
}

/// <summary>
/// Writes information about Cake to the console.
/// </summary>
public sealed class InfoFeature : ICakeInfoFeature
{
private readonly IVersionResolver _resolver;

/// <summary>
/// Initializes a new instance of the <see cref="InfoFeature"/> class.
/// </summary>
/// <param name="resolver">The version resolver.</param>
public InfoFeature(IVersionResolver resolver)
{
_resolver = resolver;
}

/// <inheritdoc/>
public void Run(IConsole console)
{
var version = _resolver.GetVersion();
var product = _resolver.GetProductVersion();

console.WriteLine();
console.WriteLine(@" +## #;;'");
console.WriteLine(@" #;;# .+;;;;+,");
console.WriteLine(@" '+;;#;,+';;;;;'#.");
console.WriteLine(@" ++'''';;;;;;;;;;# ;#;");
console.WriteLine(@" ##';;;;++'+#;;;;;'. `#:");
console.WriteLine(@" ;# '+'';;;;;;;;;'#` #.");
console.WriteLine(@" `#, .'++;;;;;':..........#");
console.WriteLine(@" '+ `.........';;;;':.........#");
console.WriteLine(@" #..................+;;;;;':........#");
console.WriteLine(@" #..................#';;;;;'+''''''.#");
console.WriteLine(@" #.......,:;''''''''##';;;;;'+'''''#,");
console.WriteLine(@" #''''''''''''''''''###';;;;;;+''''#");
console.WriteLine(@" #''''''''''''''''''####';;;;;;#'''#");
console.WriteLine(@" #''''''''''''''''''#####';;;;;;#''#");
console.WriteLine(@" #''''''''''''''''''######';;;;;;#'#");
console.WriteLine(@" #''''''''''''''''''#######';;;;;;##");
console.WriteLine(@" #''''''''''''''''''########';;;;;;#");
console.WriteLine(@" #''''''''''''++####+;#######';;;;;;#");
console.WriteLine(@" #+####':,` ,#####';;;;;;'");
console.WriteLine(@" +##'''''+.");

console.ForegroundColor = System.ConsoleColor.Yellow;
console.WriteLine(@" ___ _ ___ _ _ _ ");
console.WriteLine(@" / __\__ _| | _____ / __\_ _(_) | __| |");
console.WriteLine(@" / / / _` | |/ / _ \/__\// | | | | |/ _` |");
console.WriteLine(@"/ /___ (_| | < __/ \/ \ |_| | | | (_| |");
console.WriteLine(@"\____/\__,_|_|\_\___\_____/\__,_|_|_|\__,_|");
console.ResetColor();

console.WriteLine();
console.WriteLine(@"Version: {0}", version);
console.WriteLine(@"Details: {0}", string.Join("\n ", product.Split('/')));
console.WriteLine();
}
}
}
49 changes: 49 additions & 0 deletions src/Cake.Cli/Features/VersionFeature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using Cake.Core;

namespace Cake.Cli
{
/// <summary>
/// Represents a feature that writes the Cake version to the console.
/// </summary>
public interface ICakeVersionFeature
{
/// <summary>
/// Writes the Cake version to the console.
/// </summary>
/// <param name="console">The console to write to.</param>
void Run(IConsole console);
}

/// <summary>
/// Writes the Cake version to the console.
/// </summary>
public sealed class VersionFeature : ICakeVersionFeature
{
private readonly IVersionResolver _resolver;

/// <summary>
/// Initializes a new instance of the <see cref="VersionFeature"/> class.
/// </summary>
/// <param name="resolver">The version resolver.</param>
public VersionFeature(IVersionResolver resolver)
{
_resolver = resolver;
}

/// <inheritdoc/>
public void Run(IConsole console)
{
if (console is null)
{
throw new ArgumentNullException(nameof(console));
}

console.WriteLine(_resolver.GetVersion());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,37 @@
// See the LICENSE file in the project root for more information.

using System.Diagnostics;
using System.Reflection;

namespace Cake.Features.Introspection
namespace Cake.Cli
{
/// <summary>
/// Represents a version resolver.
/// </summary>
public interface IVersionResolver
{
/// <summary>
/// Gets the version.
/// </summary>
/// <returns>The version.</returns>
string GetVersion();

/// <summary>
/// Gets the product version.
/// </summary>
/// <returns>The product version.</returns>
string GetProductVersion();
}

/// <summary>
/// The Cake version resolver.
/// </summary>
public sealed class VersionResolver : IVersionResolver
{
/// <inheritdoc/>
public string GetVersion()
{
var assembly = typeof(Program).Assembly;
var assembly = Assembly.GetEntryAssembly();
var version = FileVersionInfo.GetVersionInfo(assembly.Location).Comments;

if (string.IsNullOrWhiteSpace(version))
Expand All @@ -27,9 +44,10 @@ public string GetVersion()
return version;
}

/// <inheritdoc/>
public string GetProductVersion()
{
var assembly = typeof(Program).Assembly;
var assembly = Assembly.GetEntryAssembly();
var version = FileVersionInfo.GetVersionInfo(assembly.Location).ProductVersion;

if (string.IsNullOrWhiteSpace(version))
Expand Down
82 changes: 82 additions & 0 deletions src/Cake.Cli/Hosts/BuildScriptHost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using Cake.Core;
using Cake.Core.Diagnostics;
using Cake.Core.Scripting;

namespace Cake.Cli
{
/// <summary>
/// The script host used to execute Cake scripts.
/// </summary>
public sealed class BuildScriptHost : BuildScriptHost<ICakeContext>
{
/// <summary>
/// Initializes a new instance of the <see cref="BuildScriptHost"/> class.
/// </summary>
/// <param name="engine">The engine.</param>
/// <param name="executionStrategy">The execution strategy.</param>
/// <param name="context">The context.</param>
/// <param name="reportPrinter">The report printer.</param>
/// <param name="log">The log.</param>
public BuildScriptHost(
ICakeEngine engine,
IExecutionStrategy executionStrategy,
ICakeContext context,
ICakeReportPrinter reportPrinter,
ICakeLog log) : base(engine, executionStrategy, context, reportPrinter, log)
{
}
}

/// <summary>
/// The script host used to execute Cake scripts.
/// </summary>
/// <typeparam name="TContext">The context type.</typeparam>
public class BuildScriptHost<TContext> : ScriptHost
where TContext : ICakeContext
{
private readonly ICakeReportPrinter _reportPrinter;
private readonly ICakeLog _log;
private readonly IExecutionStrategy _executionStrategy;
private readonly TContext _context;

/// <summary>
/// Initializes a new instance of the <see cref="BuildScriptHost{TContext}"/> class.
/// </summary>
/// <param name="engine">The engine.</param>
/// <param name="executionStrategy">The execution strategy.</param>
/// <param name="context">The context.</param>
/// <param name="reportPrinter">The report printer.</param>
/// <param name="log">The log.</param>
public BuildScriptHost(
ICakeEngine engine,
IExecutionStrategy executionStrategy,
TContext context,
ICakeReportPrinter reportPrinter,
ICakeLog log) : base(engine, context)
{
_executionStrategy = executionStrategy;
_context = context;
_reportPrinter = reportPrinter;
_log = log;
}

/// <inheritdoc/>
public override async Task<CakeReport> RunTargetAsync(string target)
{
Settings.SetTarget(target);

var report = await Engine.RunTargetAsync(_context, _executionStrategy, Settings).ConfigureAwait(false);
if (report != null && !report.IsEmpty)
{
_reportPrinter.Write(report);
}

return report;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
using Cake.Core;
using Cake.Core.Scripting;

namespace Cake.Features.Building.Hosts
namespace Cake.Cli
{
/// <summary>
/// The script host used for showing task descriptions.
/// </summary>
public sealed class DescriptionScriptHost : ScriptHost
public class DescriptionScriptHost : ScriptHost
{
private readonly IConsole _console;
private readonly Dictionary<string, string> _descriptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Cake.Core;
using Cake.Core.Diagnostics;

namespace Cake.Features.Building.Hosts
namespace Cake.Cli
{
internal sealed class DryRunExecutionStrategy : IExecutionStrategy
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,41 @@
using Cake.Core.Diagnostics;
using Cake.Core.Scripting;

namespace Cake.Features.Building.Hosts
namespace Cake.Cli
{
/// <summary>
/// The script host used to dry run Cake scripts.
/// </summary>
public sealed class DryRunScriptHost : ScriptHost
public sealed class DryRunScriptHost : DryRunScriptHost<ICakeContext>
{
private readonly ICakeLog _log;

/// <summary>
/// Initializes a new instance of the <see cref="DryRunScriptHost"/> class.
/// </summary>
/// <param name="engine">The engine.</param>
/// <param name="context">The context.</param>
/// <param name="log">The log.</param>
public DryRunScriptHost(ICakeEngine engine, ICakeContext context, ICakeLog log)
: base(engine, context, log)
{
}
}

/// <summary>
/// The script host used to dry run Cake scripts.
/// </summary>
/// <typeparam name="TContext">The context.</typeparam>
public class DryRunScriptHost<TContext> : ScriptHost
where TContext : ICakeContext
{
private readonly ICakeLog _log;

/// <summary>
/// Initializes a new instance of the <see cref="DryRunScriptHost{TContext}"/> class.
/// </summary>
/// <param name="engine">The engine.</param>
/// <param name="context">The context.</param>
/// <param name="log">The log.</param>
public DryRunScriptHost(ICakeEngine engine, TContext context, ICakeLog log)
: base(engine, context)
{
_log = log ?? throw new ArgumentNullException(nameof(log));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Cake.Core.Graph;
using Cake.Core.Scripting;

namespace Cake.Features.Building.Hosts
namespace Cake.Cli
{
/// <summary>
/// The script host used for showing task descriptions.
Expand Down
Loading

0 comments on commit a1cbb58

Please sign in to comment.