-
-
Notifications
You must be signed in to change notification settings - Fork 731
/
NuGetPackageInstaller.cs
62 lines (53 loc) · 1.99 KB
/
NuGetPackageInstaller.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Collections.Generic;
using Cake.Core.Configuration;
using Cake.Core.IO;
using Cake.Core.Packaging;
namespace Cake.NuGet
{
internal sealed class NuGetPackageInstaller : INuGetPackageInstaller
{
private readonly bool _useInProcessClient;
private readonly InProcessInstaller _inProc;
private readonly OutOfProcessInstaller _outProc;
public NuGetPackageInstaller(
ICakeConfiguration configuration,
InProcessInstaller inProc,
OutOfProcessInstaller outProc)
{
if (configuration is null)
{
throw new ArgumentNullException(nameof(configuration));
}
_useInProcessClient = UseInProcessClient(configuration);
_inProc = inProc ?? throw new ArgumentNullException(nameof(inProc));
_outProc = outProc ?? throw new ArgumentNullException(nameof(outProc));
}
private bool UseInProcessClient(ICakeConfiguration configuration)
{
var useInProcessClientString = configuration.GetValue(Constants.NuGet.UseInProcessClient) ?? bool.TrueString;
if (!bool.TryParse(useInProcessClientString, out bool useInProcessClient))
{
// If there is no explicit preference, use the in process client.
return true;
}
return useInProcessClient;
}
public bool CanInstall(PackageReference package, PackageType type)
{
if (_useInProcessClient)
{
return _inProc.CanInstall(package, type);
}
return _outProc.CanInstall(package, type);
}
public IReadOnlyCollection<IFile> Install(PackageReference package, PackageType type, DirectoryPath path)
{
if (_useInProcessClient)
{
return _inProc.Install(package, type, path);
}
return _outProc.Install(package, type, path);
}
}
}