Skip to content

Commit

Permalink
Add NuGet provider in Frosting
Browse files Browse the repository at this point in the history
This will make it possible to install NuGet tools in Frosting.
I also cleaned up the code a bit to make it possible to initialize
a NuGet module without providing a Cake configuration.

Closes #2933
  • Loading branch information
patriksvensson committed Nov 6, 2020
1 parent 94eab0d commit daf0142
Show file tree
Hide file tree
Showing 24 changed files with 354 additions and 494 deletions.
1 change: 1 addition & 0 deletions src/Cake.Frosting/Cake.Frosting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<ItemGroup>
<ProjectReference Include="..\Cake.Core\Cake.Core.csproj" />
<ProjectReference Include="..\Cake.Common\Cake.Common.csproj" />
<ProjectReference Include="..\Cake.NuGet\Cake.NuGet.csproj" />
</ItemGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
2 changes: 2 additions & 0 deletions src/Cake.Frosting/CakeHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Cake.Core.Modules;
using Cake.Frosting.Internal;
using Cake.Frosting.Internal.Composition;
using Cake.NuGet;

namespace Cake.Frosting
{
Expand Down Expand Up @@ -52,6 +53,7 @@ public ICakeHost Build()
var registrar = new CakeServices();
registrar.RegisterModule(new CoreModule());
registrar.RegisterModule(new Module());
registrar.RegisterModule(new NuGetModule());
var container = registrar.Build();

// Add custom registrations to the container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
// 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 System.Collections.Generic;
using Cake.Core;
using Cake.Core.IO;
using Cake.Core.Packaging;
using Cake.Core.Polyfill;

namespace Cake.NuGet.Tests.Fixtures
Expand Down
3 changes: 1 addition & 2 deletions src/Cake.NuGet.Tests/Fixtures/NuGetContentResolverFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System.Collections.Generic;
using System.Runtime.Versioning;
using Cake.Core.Diagnostics;
using Cake.Core.IO;
using Cake.Core.Packaging;
using Cake.Core.Polyfill;
Expand Down Expand Up @@ -51,7 +50,7 @@ public void CreateNonCLRAssembly(FilePath path)

public IReadOnlyCollection<IFile> GetFiles()
{
var resolver = new NuGetContentResolver(FileSystem, Environment, Globber, Log);
var resolver = new NuGetContentResolver(FileSystem, Environment, Globber);
return resolver.GetFiles(Path, Package, PackageType);
}

Expand Down
6 changes: 1 addition & 5 deletions src/Cake.NuGet.Tests/Fixtures/NuGetModuleFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

using System;
using Cake.Core.Composition;
using Cake.Core.Configuration;
using Cake.Testing;
using NSubstitute;

namespace Cake.NuGet.Tests.Fixtures
Expand All @@ -14,13 +12,11 @@ internal sealed class NuGetModuleFixture<T>
{
public ICakeContainerRegistrar Registrar { get; }
public ICakeRegistrationBuilder Builder { get; }
public FakeConfiguration Configuration { get; }

public NuGetModuleFixture()
{
Registrar = Substitute.For<ICakeContainerRegistrar>();
Builder = Substitute.For<ICakeRegistrationBuilder>();
Configuration = new FakeConfiguration();

Registrar.RegisterType<T>().Returns(Builder);
Builder.As(Arg.Any<Type>()).Returns(Builder);
Expand All @@ -31,7 +27,7 @@ public NuGetModuleFixture()

public NuGetModule CreateModule()
{
return new NuGetModule(Configuration);
return new NuGetModule();
}
}
}
23 changes: 18 additions & 5 deletions src/Cake.NuGet.Tests/Fixtures/NuGetPackageInstallerFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if !NETCORE
using System.Collections.Generic;
using Cake.Core;
using Cake.Core.Configuration;
Expand All @@ -15,7 +14,16 @@

namespace Cake.NuGet.Tests.Fixtures
{
internal sealed class NuGetPackageInstallerFixture
internal sealed class OutOfProcessFixture : NuGetPackageInstallerFixture
{
public OutOfProcessFixture()
: base()
{
Config?.GetValue(Constants.NuGet.UseInProcessClient).Returns(bool.FalseString);
}
}

internal abstract class NuGetPackageInstallerFixture
{
public ICakeEnvironment Environment { get; set; }
public FakeFileSystem FileSystem { get; set; }
Expand All @@ -30,6 +38,9 @@ internal sealed class NuGetPackageInstallerFixture

public ICakeConfiguration Config { get; set; }

public InProcessInstaller InProc { get; set; }
public OutOfProcessInstaller OutProc { get; set; }

public NuGetPackageInstallerFixture()
{
Environment = FakeEnvironment.CreateUnixEnvironment();
Expand All @@ -48,6 +59,9 @@ public NuGetPackageInstallerFixture()
ProcessRunner = Substitute.For<IProcessRunner>();
ProcessRunner.When(p => p.Start(Arg.Any<FilePath>(), Arg.Any<ProcessSettings>()))
.Do(info => FileSystem.CreateDirectory(InstallPath.Combine(Package.Package.ToLowerInvariant()).Combine(Package.Package)));

InProc = new InProcessInstaller(FileSystem, Environment, ContentResolver, Log, Config);
OutProc = new OutOfProcessInstaller(FileSystem, Environment, ProcessRunner, ToolResolver, ContentResolver, Log, Config);
}

public void InstallPackageAtSpecifiedPath(DirectoryPath path)
Expand All @@ -58,7 +72,7 @@ public void InstallPackageAtSpecifiedPath(DirectoryPath path)

public NuGetPackageInstaller CreateInstaller()
{
return new NuGetPackageInstaller(FileSystem, Environment, ProcessRunner, ToolResolver, ContentResolver, Log, Config);
return new NuGetPackageInstaller(Config, InProc, OutProc);
}

public IReadOnlyCollection<IFile> Install()
Expand All @@ -73,5 +87,4 @@ public bool CanInstall()
return installer.CanInstall(Package, PackageType);
}
}
}
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// 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 System.Collections.Generic;
using Cake.Core;
using Cake.Core.IO;
using Cake.Core.Packaging;
using Cake.Core.Polyfill;
Expand Down
6 changes: 0 additions & 6 deletions src/Cake.NuGet.Tests/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@
// 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.Reflection;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Cake.NuGet.Tests")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
Expand Down
1 change: 0 additions & 1 deletion src/Cake.NuGet.Tests/Unit/NuGetContentResolverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Cake.NuGet.Tests.Fixtures;
using Cake.Testing;
using Cake.Testing.Xunit;
using NSubstitute;
using Xunit;

namespace Cake.NuGet.Tests.Unit
Expand Down
2 changes: 0 additions & 2 deletions src/Cake.NuGet.Tests/Unit/NuGetLoadDirectiveProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
// 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.Diagnostics;
using Cake.Core.Packaging;
using Cake.NuGet.Tests.Fixtures;
using Cake.Testing.Xunit;
using Xunit;

namespace Cake.NuGet.Tests.Unit
Expand Down
42 changes: 0 additions & 42 deletions src/Cake.NuGet.Tests/Unit/NuGetModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public void Should_Register_The_NuGet_Load_Directive_Provider_When_Using_In_Proc
{
// Given
var fixture = new NuGetModuleFixture<NuGetLoadDirectiveProvider>();
fixture.Configuration.SetValue(Constants.NuGet.UseInProcessClient, bool.TrueString);
var module = fixture.CreateModule();

// When
Expand All @@ -65,29 +64,11 @@ public void Should_Register_The_NuGet_Load_Directive_Provider_When_Using_In_Proc
fixture.Builder.Received(1).Singleton();
}

[RuntimeFact(TestRuntime.CoreClr)]
public void Should_Not_Register_The_NuGet_Load_Directive_Provider_When_Not_Using_In_Process_Client()
{
// Given
var fixture = new NuGetModuleFixture<NuGetLoadDirectiveProvider>();
fixture.Configuration.SetValue(Constants.NuGet.UseInProcessClient, bool.FalseString);
var module = fixture.CreateModule();

// When
module.Register(fixture.Registrar);

// Then
fixture.Registrar.Received(0).RegisterType<NuGetLoadDirectiveProvider>();
fixture.Builder.Received(0).As<ILoadDirectiveProvider>();
fixture.Builder.Received(0).Singleton();
}

[Fact]
public void Should_Register_The_NuGet_Package_Installer()
{
// Given
var fixture = new NuGetModuleFixture<NuGetPackageInstaller>();
fixture.Configuration.SetValue(Constants.NuGet.UseInProcessClient, bool.FalseString);
var module = fixture.CreateModule();

// When
Expand All @@ -99,29 +80,6 @@ public void Should_Register_The_NuGet_Package_Installer()
fixture.Builder.Received(1).As<IPackageInstaller>();
fixture.Builder.Received(1).Singleton();
}

[Theory]
[InlineData(true)]
[InlineData(null)]
public void Should_Register_The_In_Process_NuGet_Package_Installer_If_Set_In_Configuration(bool? config)
{
// Given
var fixture = new NuGetModuleFixture<Install.NuGetPackageInstaller>();
if (config.HasValue)
{
fixture.Configuration.SetValue(Constants.NuGet.UseInProcessClient, config.Value ? bool.TrueString : bool.FalseString);
}
var module = fixture.CreateModule();

// When
module.Register(fixture.Registrar);

// Then
fixture.Registrar.Received(1).RegisterType<Install.NuGetPackageInstaller>();
fixture.Builder.Received(1).As<INuGetPackageInstaller>();
fixture.Builder.Received(1).As<IPackageInstaller>();
fixture.Builder.Received(1).Singleton();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
// 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 System.Collections.Generic;
using System.Linq;
using Cake.Core.Configuration;
using Cake.Core.Packaging;
using Cake.NuGet.Install;
using Cake.NuGet.Tests.Stubs;
using NSubstitute;
using NuGet.Configuration;
Expand Down
Loading

0 comments on commit daf0142

Please sign in to comment.