Skip to content
This repository was archived by the owner on Mar 1, 2021. It is now read-only.

Commit 06d6a06

Browse files
committed
(maint) Refactoring
- Change name of project to Cake.DotNetTool.Module - Switch to using tools folder by default - Can switch to using Global using pre-processor
1 parent c4fc05c commit 06d6a06

17 files changed

+124
-95
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,3 +280,6 @@ BuildArtifacts/
280280

281281
# Testing
282282
test/tools/Modules/*.dll
283+
284+
.store
285+
dotnet-octo

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Cake.DotNet.Module
1+
# Cake.DotNetTool.Module
22

3-
Cake.DotNet.Module is a Module for Cake, which extends it with a new IPackageInstaller for installing tools using the dotnet cli.
3+
Cake.DotNetTool.Module is a Module for Cake, which extends it with a new IPackageInstaller for installing tools using the dotnet cli.
44

55
[![License](http://img.shields.io/:license-mit-blue.svg)](http://cake-contrib.mit-license.org)

Source/Cake.DotNet.Module.Tests/Cake.DotNet.Module.Tests.csproj renamed to Source/Cake.DotNetTool.Module.Tests/Cake.DotNetTool.Module.Tests.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<PackageReference Include="Cake.Core" Version="0.28.0">
8+
<PackageReference Include="Cake.Core" Version="0.30.0">
99
<PrivateAssets>all</PrivateAssets>
1010
</PackageReference>
11-
<PackageReference Include="Cake.Testing" Version="0.28.0">
11+
<PackageReference Include="Cake.Testing" Version="0.30.0">
1212
<PrivateAssets>all</PrivateAssets>
1313
</PackageReference>
1414
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" />
@@ -18,7 +18,7 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<ProjectReference Include="..\Cake.DotNet.Module\Cake.DotNet.Module.csproj" />
21+
<ProjectReference Include="..\Cake.DotNetTool.Module\Cake.DotNetTool.Module.csproj" />
2222
</ItemGroup>
2323

2424
</Project>

Source/Cake.DotNet.Module.Tests/DotNetPackageInstallerFixture.cs renamed to Source/Cake.DotNetTool.Module.Tests/DotNetToolPackageInstallerFixture.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
using NSubstitute;
88
using System.Collections.Generic;
99

10-
namespace Cake.DotNet.Module.Tests
10+
namespace Cake.DotNetTool.Module.Tests
1111
{
1212
/// <summary>
13-
/// Fixture used for testing DotNetPackageInstaller
13+
/// Fixture used for testing DotNetToolPackageInstaller
1414
/// </summary>
15-
internal sealed class DotNetPackageInstallerFixture
15+
internal sealed class DotNetToolPackageInstallerFixture
1616
{
1717
public ICakeEnvironment Environment { get; set; }
1818
public IFileSystem FileSystem { get; set; }
1919
public IProcessRunner ProcessRunner { get; set; }
20-
public IDotNetContentResolver ContentResolver { get; set; }
20+
public IDotNetToolContentResolver ContentResolver { get; set; }
2121
public ICakeLog Log { get; set; }
2222

2323
public PackageReference Package { get; set; }
@@ -27,14 +27,14 @@ internal sealed class DotNetPackageInstallerFixture
2727
public ICakeConfiguration Config { get; set; }
2828

2929
/// <summary>
30-
/// Initializes a new instance of the <see cref="DotNetPackageInstallerFixture"/> class.
30+
/// Initializes a new instance of the <see cref="DotNetToolPackageInstallerFixture"/> class.
3131
/// </summary>
32-
internal DotNetPackageInstallerFixture()
32+
internal DotNetToolPackageInstallerFixture()
3333
{
3434
Environment = FakeEnvironment.CreateUnixEnvironment();
3535
FileSystem = new FakeFileSystem(Environment);
3636
ProcessRunner = Substitute.For<IProcessRunner>();
37-
ContentResolver = Substitute.For<IDotNetContentResolver>();
37+
ContentResolver = Substitute.For<IDotNetToolContentResolver>();
3838
Log = new FakeLog();
3939
Config = Substitute.For<ICakeConfiguration>();
4040
Package = new PackageReference("dotnet:?package=windirstat");
@@ -45,10 +45,10 @@ internal DotNetPackageInstallerFixture()
4545
/// <summary>
4646
/// Create the installer.
4747
/// </summary>
48-
/// <returns>The DotNet package installer.</returns>
49-
internal DotNetPackageInstaller CreateInstaller()
48+
/// <returns>The dotnet Tool package installer.</returns>
49+
internal DotNetToolPackageInstaller CreateInstaller()
5050
{
51-
return new DotNetPackageInstaller(Environment, ProcessRunner, Log, ContentResolver, Config, FileSystem);
51+
return new DotNetToolPackageInstaller(Environment, ProcessRunner, Log, ContentResolver, Config, FileSystem);
5252
}
5353

5454
/// <summary>DotNetPackageInstallerFixture

Source/Cake.DotNet.Module.Tests/DotNetPackageInstallerTests.cs renamed to Source/Cake.DotNetTool.Module.Tests/DotNetToolPackageInstallerTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
using System.Collections.Generic;
77
using Xunit;
88

9-
namespace Cake.DotNet.Module.Tests
9+
namespace Cake.DotNetTool.Module.Tests
1010
{
1111
/// <summary>
12-
/// DotNetPackageInstaller unit tests
12+
/// DotNetToolPackageInstaller unit tests
1313
/// </summary>
14-
public sealed class DotNetPackageInstallerTests
14+
public sealed class DotNetToolPackageInstallerTests
1515
{
1616
public sealed class TheConstructor
1717
{
1818
[Fact]
1919
public void Should_Throw_If_Environment_Is_Null()
2020
{
2121
// Given
22-
var fixture = new DotNetPackageInstallerFixture();
22+
var fixture = new DotNetToolPackageInstallerFixture();
2323
fixture.Environment = null;
2424

2525
// When
@@ -34,7 +34,7 @@ public void Should_Throw_If_Environment_Is_Null()
3434
public void Should_Throw_If_Process_Runner_Is_Null()
3535
{
3636
// Given
37-
var fixture = new DotNetPackageInstallerFixture();
37+
var fixture = new DotNetToolPackageInstallerFixture();
3838
fixture.ProcessRunner = null;
3939

4040
// When
@@ -49,7 +49,7 @@ public void Should_Throw_If_Process_Runner_Is_Null()
4949
public void Should_Throw_If_Content_Resolver_Is_Null()
5050
{
5151
// Given
52-
var fixture = new DotNetPackageInstallerFixture();
52+
var fixture = new DotNetToolPackageInstallerFixture();
5353
fixture.ContentResolver = null;
5454

5555
// When
@@ -64,7 +64,7 @@ public void Should_Throw_If_Content_Resolver_Is_Null()
6464
public void Should_Throw_If_Log_Is_Null()
6565
{
6666
// Given
67-
var fixture = new DotNetPackageInstallerFixture();
67+
var fixture = new DotNetToolPackageInstallerFixture();
6868
fixture.Log = null;
6969

7070
// When
@@ -81,7 +81,7 @@ public sealed class TheCanInstallMethod
8181
public void Should_Throw_If_URI_Is_Null()
8282
{
8383
// Given
84-
var fixture = new DotNetPackageInstallerFixture();
84+
var fixture = new DotNetToolPackageInstallerFixture();
8585
fixture.Package = null;
8686

8787
// When
@@ -96,7 +96,7 @@ public void Should_Throw_If_URI_Is_Null()
9696
public void Should_Be_Able_To_Install_If_Scheme_Is_Correct()
9797
{
9898
// Given
99-
var fixture = new DotNetPackageInstallerFixture();
99+
var fixture = new DotNetToolPackageInstallerFixture();
100100
fixture.Package = new PackageReference("dotnet:?package=Octopus.DotNet.Cli");
101101

102102
// When
@@ -110,7 +110,7 @@ public void Should_Be_Able_To_Install_If_Scheme_Is_Correct()
110110
public void Should_Not_Be_Able_To_Install_If_Scheme_Is_Incorrect()
111111
{
112112
// Given
113-
var fixture = new DotNetPackageInstallerFixture();
113+
var fixture = new DotNetToolPackageInstallerFixture();
114114
fixture.Package = new PackageReference("homebrew:?package=windirstat");
115115

116116
// When
@@ -127,7 +127,7 @@ public sealed class TheInstallMethod
127127
public void Should_Throw_If_Uri_Is_Null()
128128
{
129129
// Given
130-
var fixture = new DotNetPackageInstallerFixture();
130+
var fixture = new DotNetToolPackageInstallerFixture();
131131
fixture.Package = null;
132132

133133
// When
@@ -142,7 +142,7 @@ public void Should_Throw_If_Uri_Is_Null()
142142
public void Should_Throw_If_Install_Path_Is_Null()
143143
{
144144
// Given
145-
var fixture = new DotNetPackageInstallerFixture();
145+
var fixture = new DotNetToolPackageInstallerFixture();
146146
fixture.InstallPath = null;
147147

148148
// When
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
44
VisualStudioVersion = 14.0.25420.1
55
MinimumVisualStudioVersion = 10.0.40219.1
6-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.DotNet.Module", "Cake.DotNet.Module\Cake.DotNet.Module.csproj", "{666C4FA1-0963-4836-9E54-89FBBE4C9381}"
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.DotNetTool.Module", "Cake.DotNetTool.Module\Cake.DotNetTool.Module.csproj", "{666C4FA1-0963-4836-9E54-89FBBE4C9381}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.DotNet.Module.Tests", "Cake.DotNet.Module.Tests\Cake.DotNet.Module.Tests.csproj", "{1A12838D-0FD6-448E-834F-23927CF9D91E}"
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cake.DotNetTool.Module.Tests", "Cake.DotNetTool.Module.Tests\Cake.DotNetTool.Module.Tests.csproj", "{1A12838D-0FD6-448E-834F-23927CF9D91E}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
File renamed without changes.

Source/Cake.DotNet.Module/Cake.DotNet.Module.csproj renamed to Source/Cake.DotNetTool.Module/Cake.DotNetTool.Module.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
<GenerateDocumentationFile>true</GenerateDocumentationFile>
55
</PropertyGroup>
66
<PropertyGroup>
7-
<CodeAnalysisRuleSet>Cake.DotNet.Module.ruleset</CodeAnalysisRuleSet>
7+
<CodeAnalysisRuleSet>Cake.DotNetTool.Module.ruleset</CodeAnalysisRuleSet>
88
</PropertyGroup>
99
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
1010
<DefineConstants>TRACE;DEBUG;NETSTANDARD</DefineConstants>
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Cake.Core" Version="0.28.0" PrivateAssets="All" />
14+
<PackageReference Include="Cake.Core" Version="0.30.0" PrivateAssets="All" />
1515
</ItemGroup>
1616

1717
</Project>

Source/Cake.DotNet.Module/Cake.DotNet.Module.ruleset renamed to Source/Cake.DotNetTool.Module/Cake.DotNetTool.Module.ruleset

File renamed without changes.

Source/Cake.DotNet.Module/DotNetContentResolver.cs renamed to Source/Cake.DotNetTool.Module/DotNetToolContentResolver.cs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,67 +2,76 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using Cake.Core;
5+
using Cake.Core.Configuration;
56
using Cake.Core.Diagnostics;
67
using Cake.Core.IO;
78
using Cake.Core.Packaging;
89

9-
namespace Cake.DotNet.Module
10+
namespace Cake.DotNetTool.Module
1011
{
1112
/// <summary>
12-
/// Locates and lists contents of DotNet Packages.
13+
/// Locates and lists contents of dotnet Tool Packages.
1314
/// </summary>
14-
public class DotNetContentResolver : IDotNetContentResolver
15+
public class DotNetToolContentResolver : IDotNetToolContentResolver
1516
{
1617
private readonly IFileSystem _fileSystem;
1718
private readonly ICakeEnvironment _environment;
1819
private readonly IGlobber _globber;
1920
private readonly ICakeLog _log;
2021

22+
private readonly ICakeConfiguration _config;
23+
2124
/// <summary>
22-
/// Initializes a new instance of the <see cref="DotNetContentResolver"/> class.
25+
/// Initializes a new instance of the <see cref="DotNetToolContentResolver"/> class.
2326
/// </summary>
2427
/// <param name="fileSystem">The file system.</param>
2528
/// <param name="environment">The environment.</param>
2629
/// <param name="globber">The Globber.</param>
2730
/// <param name="log">The Log</param>
28-
public DotNetContentResolver(
31+
/// <param name="config">the configuration</param>
32+
public DotNetToolContentResolver(
2933
IFileSystem fileSystem,
3034
ICakeEnvironment environment,
3135
IGlobber globber,
32-
ICakeLog log)
36+
ICakeLog log,
37+
ICakeConfiguration config)
3338
{
3439
_fileSystem = fileSystem;
3540
_environment = environment;
3641
_globber = globber;
3742
_log = log;
43+
_config = config;
3844
}
3945

4046
/// <summary>
41-
/// Collects all the files for the given DotNet Package.
47+
/// Collects all the files for the given dotnet Tool Package.
4248
/// </summary>
43-
/// <param name="package">The DotNet Package.</param>
44-
/// <param name="type">The type of DotNet Package.</param>
49+
/// <param name="package">The dotnet Tool Package.</param>
50+
/// <param name="type">The type of dotnet Tool Package.</param>
4551
/// <returns>All the files for the Package.</returns>
4652
public IReadOnlyCollection<IFile> GetFiles(PackageReference package, PackageType type)
4753
{
4854
if (type == PackageType.Addin)
4955
{
50-
throw new InvalidOperationException("DotNet Module does not support Addins'");
56+
throw new InvalidOperationException("DotNetTool Module does not support Addins'");
5157
}
5258

5359
if (type == PackageType.Tool)
5460
{
55-
if(package.Parameters.ContainsKey("toolpath"))
56-
{
57-
return GetToolFiles(new DirectoryPath(package.Parameters["toolpath"].First()), package);
58-
}
59-
else if(_environment.Platform.IsUnix())
61+
if(package.Parameters.ContainsKey("global"))
6062
{
61-
return GetToolFiles(new DirectoryPath(_environment.GetEnvironmentVariable("HOME")).Combine(".dotnet/tools"), package);
63+
if(_environment.Platform.IsUnix())
64+
{
65+
return GetToolFiles(new DirectoryPath(_environment.GetEnvironmentVariable("HOME")).Combine(".dotnet/tools"), package);
66+
}
67+
else
68+
{
69+
return GetToolFiles(new DirectoryPath(_environment.GetEnvironmentVariable("USERPROFILE")).Combine(".dotnet/tools"), package);
70+
}
6271
}
6372
else
6473
{
65-
return GetToolFiles(new DirectoryPath(_environment.GetEnvironmentVariable("USERPROFILE")).Combine(".dotnet/tools"), package);
74+
return GetToolFiles(_config.GetToolPath(_environment.WorkingDirectory, _environment), package);
6675
}
6776
}
6877

0 commit comments

Comments
 (0)