Skip to content

GH2685/2903: Integrate Cake.DotNetTool.Module #3207

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

Merged
merged 35 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
72dea26
(cake-contrib/Cake.DotNetTool.Module#1) Basic Implementation
gep13 Sep 27, 2018
bb21f52
(cake-contrib/Cake.DotNetTool.Module maint) Refactoring
gep13 Sep 30, 2018
ab2691a
(cake-contrib/Cake.DotNetTool.Module maint) Corrected logging levels
gep13 Oct 12, 2018
b85a946
(cake-contrib/Cake.DotNetTool.Module maint) Added installation of Mod…
gep13 Oct 12, 2018
490553a
(cake-contrib/Cake.DotNetTool.Module build) Switching to 0.29.0 to te…
gep13 Oct 12, 2018
f8b819e
(cake-contrib/Cake.DotNetTool.Module build) Reset changes made for te…
gep13 Oct 14, 2018
d123b7e
(cake-contrib/Cake.DotNetTool.Module) Bump Cake to 0.33.0
gitfool Apr 8, 2019
067f692
(cake-contrib/Cake.DotNetTool.Module) Bump test dependencies
gitfool Apr 8, 2019
8cce8c9
(cake-contrib/Cake.DotNetTool.Module) Add fact attribute
gitfool Apr 8, 2019
59cfd68
(cake-contrib/Cake.DotNetTool.Module#9) Fix iconUrl
Jericho Apr 30, 2019
ccee23f
(cake-contrib/Cake.DotNetTool.Module build) Update nuspec metadata
gep13 May 9, 2019
0e70881
(cake-contrib/Cake.DotNetTool.Module build) Add DebugType
gep13 May 9, 2019
d6815de
(cake-contrib/Cake.DotNetTool.Module#11) Add .git to end of repo URL
gep13 Sep 6, 2019
add767b
(cake-contrib/Cake.DotNetTool.Module maint) Fix line endings
gep13 Nov 25, 2019
617170a
(cake-contrib/Cake.DotNetTool.Module) Added support for '--ignore-fai…
prochnowc Nov 15, 2019
c96f167
(cake-contrib/Cake.DotNetTool.Module) Fixed typo in dotnet '--configf…
prochnowc Nov 15, 2019
638f991
(cake-contrib/Cake.DotNetTool.Module#2) Allow changing of requested t…
gep13 Nov 25, 2019
101fffb
(cake-contrib/Cake.DotNetTool.Module#28) Update to use Cake.Recipe 2.2.0
gep13 Feb 19, 2021
9b881b3
(cake-contrib/Cake.DotNetTool.Module#29) Enable deterministic builds
gep13 Feb 19, 2021
e4efaec
(cake-contrib/Cake.DotNetTool.Module#29) Include symbols
gep13 Feb 19, 2021
393fa22
(cake-contrib/Cake.DotNetTool.Module#29) Remove DebugType
gep13 Feb 19, 2021
fdb4a56
(cake-contrib/Cake.DotNetTool.Module maint) Fix copyright
gep13 Feb 19, 2021
0b4a5ad
(cake-contrib/Cake.DotNetTool.Module#30) Add CakeContrib.Guidelines p…
gep13 Feb 19, 2021
bcdcb2c
(cake-contrib/Cake.DotNetTool.Module#31) Include pdb in nupkg
gep13 Feb 19, 2021
a9235f5
(cake-contrib/Cake.DotNetTool.Module#33) Update TargetFrameworks
gep13 Feb 19, 2021
5cc0e2d
(cake-contrib/Cake.DotNetTool.Module#23): Update Cake.DotNetTool.Modu…
augustoproiete Feb 8, 2021
1d00c8f
(cake-contrib/Cake.DotNetTool.Module#34) Cross compile for .NET 5
gep13 Feb 20, 2021
716feb9
(cake-contrib/Cake.DotNetTool.Module#40) Only target one framework
gep13 Feb 22, 2021
bf5ac4c
(GH-2685) Move Cake.DotNetTool.Module into Cake repository
devlead Feb 27, 2021
d145f2d
(GH-2685) Cake.DotNetTool.Module->Cake code standard
devlead Feb 27, 2021
eab8d17
(GH-2685) Cake.DotNetTool.Module add DNF license header
devlead Feb 27, 2021
66e650c
(GH-2685) Use Cake.DotNetTool.Module in Scripting&Frosting
devlead Feb 27, 2021
6fcf7b8
(GH-2685) Added Cake.DotNetTool.Module integration tests
devlead Feb 27, 2021
54fe9a7
(GH-2685) Clean up Unit tests
devlead Feb 27, 2021
90df47a
(GH-2685) Push Cake.DotNetTool.Module package
devlead Feb 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build/parameters.cake
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public class BuildParameters
"Cake.Tool",
"Cake.Frosting",
"Cake.Frosting.Template",
"Cake.Cli"
"Cake.Cli",
"Cake.DotNetTool.Module"
},
new [] { "cake.portable" });

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>Cake.DotNetTool.Module.Tests</AssemblyName>
<TargetFrameworks>net461;netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<IsCakeTestProject>true</IsCakeTestProject>
</PropertyGroup>
<!-- Import shared functionality -->
<Import Project="..\Shared.msbuild" />
<!-- Project references -->
<ItemGroup>
<ProjectReference Include="..\Cake.Core\Cake.Core.csproj" />
<ProjectReference Include="..\Cake.DotNetTool.Module\Cake.DotNetTool.Module.csproj" />
<ProjectReference Include="..\Cake.Testing\Cake.Testing.csproj" />
<ProjectReference Include="..\Cake.Testing.Xunit\Cake.Testing.Xunit.csproj" />
</ItemGroup>
<!-- Global packages -->
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
<PackageReference Include="NSubstitute" Version="4.2.2" />
<PackageReference Include="Castle.Core" Version="4.4.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System.Collections.Generic;
using Cake.Core;
using Cake.Core.Configuration;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Core.Packaging;
using Cake.Testing;
using NSubstitute;

namespace Cake.DotNetTool.Module.Tests
{
/// <summary>
/// Fixture used for testing DotNetToolPackageInstaller
/// </summary>
internal sealed class DotNetToolPackageInstallerFixture
{
public ICakeEnvironment Environment { get; set; }
public IFileSystem FileSystem { get; set; }
public IProcessRunner ProcessRunner { get; set; }
public IDotNetToolContentResolver ContentResolver { get; set; }
public ICakeLog Log { get; set; }

public PackageReference Package { get; set; }
public PackageType PackageType { get; set; }
public DirectoryPath InstallPath { get; set; }

public ICakeConfiguration Config { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="DotNetToolPackageInstallerFixture"/> class.
/// </summary>
internal DotNetToolPackageInstallerFixture()
{
Environment = FakeEnvironment.CreateUnixEnvironment();
FileSystem = new FakeFileSystem(Environment);
ProcessRunner = Substitute.For<IProcessRunner>();
ContentResolver = Substitute.For<IDotNetToolContentResolver>();
Log = new FakeLog();
Config = Substitute.For<ICakeConfiguration>();
Package = new PackageReference("dotnet:?package=windirstat");
PackageType = PackageType.Addin;
InstallPath = new DirectoryPath("./dotnet");
}

/// <summary>
/// Create the installer.
/// </summary>
/// <returns>The dotnet Tool package installer.</returns>
internal DotNetToolPackageInstaller CreateInstaller()
{
return new DotNetToolPackageInstaller(Environment, ProcessRunner, Log, ContentResolver, Config, FileSystem);
}

/// <summary>DotNetPackageInstallerFixture
/// Installs the specified resource at the given location.
/// </summary>
/// <returns>The installed files.</returns>
internal IReadOnlyCollection<IFile> Install()
{
var installer = CreateInstaller();
return installer.Install(Package, PackageType, InstallPath);
}

/// <summary>
/// Determines whether this instance can install the specified resource.
/// </summary>
/// <returns><c>true</c> if this installer can install the specified resource; otherwise <c>false</c>.</returns>
internal bool CanInstall()
{
var installer = CreateInstaller();
return installer.CanInstall(Package, PackageType);
}
}
}
154 changes: 154 additions & 0 deletions src/Cake.DotNetTool.Module.Tests/DotNetToolPackageInstallerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
using System;
using Cake.Core.Packaging;
using Xunit;

namespace Cake.DotNetTool.Module.Tests
{
/// <summary>
/// DotNetToolPackageInstaller unit tests
/// </summary>
public sealed class DotNetToolPackageInstallerTests
{
public sealed class TheConstructor
{
[Fact]
public void Should_Throw_If_Environment_Is_Null()
{
// Given
var fixture = new DotNetToolPackageInstallerFixture();
fixture.Environment = null;

// When
var result = Record.Exception(() => fixture.CreateInstaller());

// Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("environment", ((ArgumentNullException)result).ParamName);
}

[Fact]
public void Should_Throw_If_Process_Runner_Is_Null()
{
// Given
var fixture = new DotNetToolPackageInstallerFixture();
fixture.ProcessRunner = null;

// When
var result = Record.Exception(() => fixture.CreateInstaller());

// Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("processRunner", ((ArgumentNullException)result).ParamName);
}

[Fact]
public void Should_Throw_If_Content_Resolver_Is_Null()
{
// Given
var fixture = new DotNetToolPackageInstallerFixture();
fixture.ContentResolver = null;

// When
var result = Record.Exception(() => fixture.CreateInstaller());

// Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("contentResolver", ((ArgumentNullException)result).ParamName);
}

[Fact]
public void Should_Throw_If_Log_Is_Null()
{
// Given
var fixture = new DotNetToolPackageInstallerFixture();
fixture.Log = null;

// When
var result = Record.Exception(() => fixture.CreateInstaller());

// Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("log", ((ArgumentNullException)result).ParamName);
}
}

public sealed class TheCanInstallMethod
{
[Fact]
public void Should_Throw_If_URI_Is_Null()
{
// Given
var fixture = new DotNetToolPackageInstallerFixture();
fixture.Package = null;

// When
var result = Record.Exception(() => fixture.CanInstall());

// Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("package", ((ArgumentNullException)result).ParamName);
}

[Fact]
public void Should_Be_Able_To_Install_If_Scheme_Is_Correct()
{
// Given
var fixture = new DotNetToolPackageInstallerFixture();
fixture.Package = new PackageReference("dotnet:?package=Octopus.DotNet.Cli");

// When
var result = fixture.CanInstall();

// Then
Assert.True(result);
}

[Fact]
public void Should_Not_Be_Able_To_Install_If_Scheme_Is_Incorrect()
{
// Given
var fixture = new DotNetToolPackageInstallerFixture();
fixture.Package = new PackageReference("homebrew:?package=windirstat");

// When
var result = fixture.CanInstall();

// Then
Assert.False(result);
}
}

public sealed class TheInstallMethod
{
[Fact]
public void Should_Throw_If_Uri_Is_Null()
{
// Given
var fixture = new DotNetToolPackageInstallerFixture();
fixture.Package = null;

// When
var result = Record.Exception(() => fixture.Install());

// Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("package", ((ArgumentNullException)result).ParamName);
}

[Fact]
public void Should_Throw_If_Install_Path_Is_Null()
{
// Given
var fixture = new DotNetToolPackageInstallerFixture();
fixture.InstallPath = null;

// When
var result = Record.Exception(() => fixture.Install());

// Then
Assert.IsType<ArgumentNullException>(result);
Assert.Equal("path", ((ArgumentNullException)result).ParamName);
}
}
}
}
27 changes: 27 additions & 0 deletions src/Cake.DotNetTool.Module/Cake.DotNetTool.Module.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
 <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Cake.DotNetTool.Module</AssemblyName>
<TargetFrameworks>net461;netstandard2.0;net5.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>Cake.DotNetTool.Module.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<DefineConstants>TRACE;DEBUG;NETSTANDARD</DefineConstants>
</PropertyGroup>

<PropertyGroup>
<Description>Cake Module that extends Cake with ability to install tools using dotnet cli.</Description>
</PropertyGroup>

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

</Project>
78 changes: 78 additions & 0 deletions src/Cake.DotNetTool.Module/Cake.DotNetTool.Module.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Microsoft Managed Recommended Rules" Description="These rules focus on the most critical problems in your code, including potential security holes, application crashes, and other important logic and design errors. It is recommended to include this rule set in any custom rule set you create for your projects." ToolsVersion="10.0">
<Localization ResourceAssembly="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.dll" ResourceBaseName="Microsoft.VisualStudio.CodeAnalysis.RuleSets.Strings.Localized">
<Name Resource="MinimumRecommendedRules_Name" />
<Description Resource="MinimumRecommendedRules_Description" />
</Localization>
<Rules AnalyzerId="Microsoft.Analyzers.ManagedCodeAnalysis" RuleNamespace="Microsoft.Rules.Managed">
<Rule Id="CA1001" Action="Warning" />
<Rule Id="CA1009" Action="Warning" />
<Rule Id="CA1016" Action="Warning" />
<Rule Id="CA1033" Action="Warning" />
<Rule Id="CA1049" Action="Warning" />
<Rule Id="CA1060" Action="Warning" />
<Rule Id="CA1061" Action="Warning" />
<Rule Id="CA1063" Action="Warning" />
<Rule Id="CA1065" Action="Warning" />
<Rule Id="CA1301" Action="Warning" />
<Rule Id="CA1400" Action="Warning" />
<Rule Id="CA1401" Action="Warning" />
<Rule Id="CA1403" Action="Warning" />
<Rule Id="CA1404" Action="Warning" />
<Rule Id="CA1405" Action="Warning" />
<Rule Id="CA1410" Action="Warning" />
<Rule Id="CA1415" Action="Warning" />
<Rule Id="CA1821" Action="Warning" />
<Rule Id="CA1900" Action="Warning" />
<Rule Id="CA1901" Action="Warning" />
<Rule Id="CA2002" Action="Warning" />
<Rule Id="CA2100" Action="Warning" />
<Rule Id="CA2101" Action="Warning" />
<Rule Id="CA2108" Action="Warning" />
<Rule Id="CA2111" Action="Warning" />
<Rule Id="CA2112" Action="Warning" />
<Rule Id="CA2114" Action="Warning" />
<Rule Id="CA2116" Action="Warning" />
<Rule Id="CA2117" Action="Warning" />
<Rule Id="CA2122" Action="Warning" />
<Rule Id="CA2123" Action="Warning" />
<Rule Id="CA2124" Action="Warning" />
<Rule Id="CA2126" Action="Warning" />
<Rule Id="CA2131" Action="Warning" />
<Rule Id="CA2132" Action="Warning" />
<Rule Id="CA2133" Action="Warning" />
<Rule Id="CA2134" Action="Warning" />
<Rule Id="CA2137" Action="Warning" />
<Rule Id="CA2138" Action="Warning" />
<Rule Id="CA2140" Action="Warning" />
<Rule Id="CA2141" Action="Warning" />
<Rule Id="CA2146" Action="Warning" />
<Rule Id="CA2147" Action="Warning" />
<Rule Id="CA2149" Action="Warning" />
<Rule Id="CA2200" Action="Warning" />
<Rule Id="CA2202" Action="Warning" />
<Rule Id="CA2207" Action="Warning" />
<Rule Id="CA2212" Action="Warning" />
<Rule Id="CA2213" Action="Warning" />
<Rule Id="CA2214" Action="Warning" />
<Rule Id="CA2216" Action="Warning" />
<Rule Id="CA2220" Action="Warning" />
<Rule Id="CA2229" Action="Warning" />
<Rule Id="CA2231" Action="Warning" />
<Rule Id="CA2232" Action="Warning" />
<Rule Id="CA2235" Action="Warning" />
<Rule Id="CA2236" Action="Warning" />
<Rule Id="CA2237" Action="Warning" />
<Rule Id="CA2238" Action="Warning" />
<Rule Id="CA2240" Action="Warning" />
<Rule Id="CA2241" Action="Warning" />
<Rule Id="CA2242" Action="Warning" />
</Rules>
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1200" Action="None" />
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1309" Action="None" />
<Rule Id="SA1633" Action="None" />
<Rule Id="SA1600" Action="Warning" />
</Rules>
</RuleSet>
Loading