Make CliFolderPathCalculator
a static class.
The `CliFolderPathCalculator` class implements no interface and has no instance fields. This commit therefore makes it a static class.
This commit is contained in:
parent
8f8770be8a
commit
3e962bc131
19 changed files with 40 additions and 75 deletions
|
@ -21,7 +21,7 @@ namespace Microsoft.DotNet.Configurer
|
|||
|
||||
private string SentinelPath => Path.Combine(_dotnetUserProfileFolderPath, SENTINEL);
|
||||
|
||||
public AspNetCertificateSentinel(CliFolderPathCalculator cliFallbackFolderPathCalculator) :
|
||||
public AspNetCertificateSentinel() :
|
||||
this(
|
||||
CliFolderPathCalculator.DotnetUserProfileFolderPath,
|
||||
FileSystemWrapper.Default.File,
|
||||
|
|
|
@ -8,16 +8,20 @@ using NuGet.Common;
|
|||
|
||||
namespace Microsoft.DotNet.Configurer
|
||||
{
|
||||
public class CliFolderPathCalculator
|
||||
public static class CliFolderPathCalculator
|
||||
{
|
||||
private const string DotnetProfileDirectoryName = ".dotnet";
|
||||
private const string ToolsShimFolderName = "tools";
|
||||
|
||||
public string CliFallbackFolderPath => Environment.GetEnvironmentVariable("DOTNET_CLI_TEST_FALLBACKFOLDER") ??
|
||||
Path.Combine(new DirectoryInfo(AppContext.BaseDirectory).Parent.FullName, "NuGetFallbackFolder");
|
||||
public string ToolsShimPath => Path.Combine(DotnetUserProfileFolderPath, ToolsShimFolderName);
|
||||
public string ToolsPackagePath => ToolPackageFolderPathCalculator.GetToolPackageFolderPath(ToolsShimPath);
|
||||
public BashPathUnderHomeDirectory ToolsShimPathInUnix
|
||||
public static string CliFallbackFolderPath =>
|
||||
Environment.GetEnvironmentVariable("DOTNET_CLI_TEST_FALLBACKFOLDER") ??
|
||||
Path.Combine(new DirectoryInfo(AppContext.BaseDirectory).Parent.FullName, "NuGetFallbackFolder");
|
||||
|
||||
public static string ToolsShimPath => Path.Combine(DotnetUserProfileFolderPath, ToolsShimFolderName);
|
||||
|
||||
public static string ToolsPackagePath => ToolPackageFolderPathCalculator.GetToolPackageFolderPath(ToolsShimPath);
|
||||
|
||||
public static BashPathUnderHomeDirectory ToolsShimPathInUnix
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -37,7 +41,7 @@ namespace Microsoft.DotNet.Configurer
|
|||
}
|
||||
}
|
||||
|
||||
public string NuGetUserSettingsDirectory =>
|
||||
public static string NuGetUserSettingsDirectory =>
|
||||
NuGetEnvironment.GetFolderPath(NuGetFolderPath.UserSettingsDirectory);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace Microsoft.DotNet.Configurer
|
|||
|
||||
private string SentinelPath => Path.Combine(_dotnetUserProfileFolderPath, SENTINEL);
|
||||
|
||||
public FirstTimeUseNoticeSentinel(CliFolderPathCalculator cliFolderPathCalculator) :
|
||||
public FirstTimeUseNoticeSentinel() :
|
||||
this(
|
||||
CliFolderPathCalculator.DotnetUserProfileFolderPath,
|
||||
FileSystemWrapper.Default.File,
|
||||
|
|
|
@ -17,31 +17,20 @@ namespace Microsoft.DotNet.Configurer
|
|||
|
||||
private readonly INuGetCacheSentinel _nuGetCacheSentinel;
|
||||
|
||||
private readonly CliFolderPathCalculator _cliFolderPathCalculator;
|
||||
|
||||
public NuGetCachePrimer(
|
||||
INuGetPackagesArchiver nugetPackagesArchiver,
|
||||
INuGetCacheSentinel nuGetCacheSentinel,
|
||||
CliFolderPathCalculator cliFolderPathCalculator)
|
||||
: this(nugetPackagesArchiver,
|
||||
nuGetCacheSentinel,
|
||||
cliFolderPathCalculator,
|
||||
FileSystemWrapper.Default.File)
|
||||
public NuGetCachePrimer(INuGetPackagesArchiver nugetPackagesArchiver, INuGetCacheSentinel nuGetCacheSentinel)
|
||||
: this(nugetPackagesArchiver, nuGetCacheSentinel, FileSystemWrapper.Default.File)
|
||||
{
|
||||
}
|
||||
|
||||
internal NuGetCachePrimer(
|
||||
INuGetPackagesArchiver nugetPackagesArchiver,
|
||||
INuGetCacheSentinel nuGetCacheSentinel,
|
||||
CliFolderPathCalculator cliFolderPathCalculator,
|
||||
IFile file)
|
||||
{
|
||||
_nugetPackagesArchiver = nugetPackagesArchiver;
|
||||
|
||||
_nuGetCacheSentinel = nuGetCacheSentinel;
|
||||
|
||||
_cliFolderPathCalculator = cliFolderPathCalculator;
|
||||
|
||||
_file = file;
|
||||
}
|
||||
|
||||
|
@ -52,7 +41,7 @@ namespace Microsoft.DotNet.Configurer
|
|||
return;
|
||||
}
|
||||
|
||||
var nuGetFallbackFolder = _cliFolderPathCalculator.CliFallbackFolderPath;
|
||||
var nuGetFallbackFolder = CliFolderPathCalculator.CliFallbackFolderPath;
|
||||
|
||||
_nugetPackagesArchiver.ExtractArchive(nuGetFallbackFolder);
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ namespace Microsoft.DotNet.Configurer
|
|||
|
||||
private Stream InProgressSentinel { get; set; }
|
||||
|
||||
public NuGetCacheSentinel(CliFolderPathCalculator cliFolderPathCalculator) :
|
||||
this(cliFolderPathCalculator.CliFallbackFolderPath,
|
||||
public NuGetCacheSentinel() :
|
||||
this(CliFolderPathCalculator.CliFallbackFolderPath,
|
||||
FileSystemWrapper.Default.File,
|
||||
FileSystemWrapper.Default.Directory)
|
||||
{
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Microsoft.DotNet.Configurer
|
|||
private readonly IDirectory _directory;
|
||||
private string _dotnetUserProfileFolderPath;
|
||||
|
||||
public UserLevelCacheWriter(CliFolderPathCalculator cliFolderPathCalculator) :
|
||||
public UserLevelCacheWriter() :
|
||||
this(
|
||||
CliFolderPathCalculator.DotnetUserProfileFolderPath,
|
||||
FileSystemWrapper.Default.File,
|
||||
|
|
|
@ -88,15 +88,14 @@ namespace Microsoft.DotNet.Cli
|
|||
var success = true;
|
||||
var command = string.Empty;
|
||||
var lastArg = 0;
|
||||
var cliFallbackFolderPathCalculator = new CliFolderPathCalculator();
|
||||
TopLevelCommandParserResult topLevelCommandParserResult = TopLevelCommandParserResult.Empty;
|
||||
|
||||
using (INuGetCacheSentinel nugetCacheSentinel = new NuGetCacheSentinel(cliFallbackFolderPathCalculator))
|
||||
using (INuGetCacheSentinel nugetCacheSentinel = new NuGetCacheSentinel())
|
||||
using (IFirstTimeUseNoticeSentinel disposableFirstTimeUseNoticeSentinel =
|
||||
new FirstTimeUseNoticeSentinel(cliFallbackFolderPathCalculator))
|
||||
new FirstTimeUseNoticeSentinel())
|
||||
{
|
||||
IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel = disposableFirstTimeUseNoticeSentinel;
|
||||
IAspNetCertificateSentinel aspNetCertificateSentinel = new AspNetCertificateSentinel(cliFallbackFolderPathCalculator);
|
||||
IAspNetCertificateSentinel aspNetCertificateSentinel = new AspNetCertificateSentinel();
|
||||
IFileSentinel toolPathSentinel = new FileSentinel(
|
||||
new FilePath(
|
||||
Path.Combine(
|
||||
|
@ -174,7 +173,6 @@ namespace Microsoft.DotNet.Cli
|
|||
firstTimeUseNoticeSentinel,
|
||||
aspNetCertificateSentinel,
|
||||
toolPathSentinel,
|
||||
cliFallbackFolderPathCalculator,
|
||||
hasSuperUserAccess,
|
||||
dotnetFirstRunConfiguration,
|
||||
environmentProvider);
|
||||
|
@ -241,7 +239,6 @@ namespace Microsoft.DotNet.Cli
|
|||
IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel,
|
||||
IAspNetCertificateSentinel aspNetCertificateSentinel,
|
||||
IFileSentinel toolPathSentinel,
|
||||
CliFolderPathCalculator cliFolderPathCalculator,
|
||||
bool hasSuperUserAccess,
|
||||
DotnetFirstRunConfiguration dotnetFirstRunConfiguration,
|
||||
IEnvironmentProvider environmentProvider)
|
||||
|
@ -249,15 +246,11 @@ namespace Microsoft.DotNet.Cli
|
|||
using (PerfTrace.Current.CaptureTiming())
|
||||
{
|
||||
var nugetPackagesArchiver = new NuGetPackagesArchiver();
|
||||
var environmentPath = EnvironmentPathFactory.CreateEnvironmentPath(
|
||||
cliFolderPathCalculator,
|
||||
hasSuperUserAccess,
|
||||
environmentProvider);
|
||||
var environmentPath = EnvironmentPathFactory.CreateEnvironmentPath(hasSuperUserAccess, environmentProvider);
|
||||
var commandFactory = new DotNetCommandFactory(alwaysRunOutOfProc: true);
|
||||
var nugetCachePrimer = new NuGetCachePrimer(
|
||||
nugetPackagesArchiver,
|
||||
nugetCacheSentinel,
|
||||
cliFolderPathCalculator);
|
||||
nugetCacheSentinel);
|
||||
var aspnetCertificateGenerator = new AspNetCoreCertificateGenerator();
|
||||
var dotnetConfigurer = new DotnetFirstTimeUseConfigurer(
|
||||
nugetCachePrimer,
|
||||
|
@ -268,7 +261,7 @@ namespace Microsoft.DotNet.Cli
|
|||
toolPathSentinel,
|
||||
dotnetFirstRunConfiguration,
|
||||
Reporter.Output,
|
||||
cliFolderPathCalculator.CliFallbackFolderPath,
|
||||
CliFolderPathCalculator.CliFallbackFolderPath,
|
||||
environmentPath);
|
||||
|
||||
dotnetConfigurer.Configure();
|
||||
|
|
|
@ -14,15 +14,9 @@ namespace Microsoft.DotNet.ShellShim
|
|||
internal static class EnvironmentPathFactory
|
||||
{
|
||||
public static IEnvironmentPath CreateEnvironmentPath(
|
||||
CliFolderPathCalculator cliFolderPathCalculator = null,
|
||||
bool hasSuperUserAccess = false,
|
||||
IEnvironmentProvider environmentProvider = null)
|
||||
{
|
||||
if (cliFolderPathCalculator == null)
|
||||
{
|
||||
cliFolderPathCalculator = new CliFolderPathCalculator();
|
||||
}
|
||||
|
||||
if (environmentProvider == null)
|
||||
{
|
||||
environmentProvider = new EnvironmentProvider();
|
||||
|
@ -32,14 +26,14 @@ namespace Microsoft.DotNet.ShellShim
|
|||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
environmentPath = new WindowsEnvironmentPath(
|
||||
cliFolderPathCalculator.ToolsShimPath,
|
||||
CliFolderPathCalculator.ToolsShimPath,
|
||||
Reporter.Output,
|
||||
environmentProvider);
|
||||
}
|
||||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && hasSuperUserAccess)
|
||||
{
|
||||
environmentPath = new LinuxEnvironmentPath(
|
||||
cliFolderPathCalculator.ToolsShimPathInUnix,
|
||||
CliFolderPathCalculator.ToolsShimPathInUnix,
|
||||
Reporter.Output,
|
||||
environmentProvider,
|
||||
new FileWrapper());
|
||||
|
@ -47,7 +41,7 @@ namespace Microsoft.DotNet.ShellShim
|
|||
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && hasSuperUserAccess)
|
||||
{
|
||||
environmentPath = new OSXEnvironmentPath(
|
||||
executablePath: cliFolderPathCalculator.ToolsShimPathInUnix,
|
||||
executablePath: CliFolderPathCalculator.ToolsShimPathInUnix,
|
||||
reporter: Reporter.Output,
|
||||
environmentProvider: environmentProvider,
|
||||
fileSystem: new FileWrapper());
|
||||
|
@ -57,10 +51,9 @@ namespace Microsoft.DotNet.ShellShim
|
|||
}
|
||||
|
||||
public static IEnvironmentPathInstruction CreateEnvironmentPathInstruction(
|
||||
CliFolderPathCalculator cliFolderPathCalculator = null,
|
||||
IEnvironmentProvider environmentProvider = null)
|
||||
{
|
||||
return CreateEnvironmentPath(cliFolderPathCalculator, true, environmentProvider);
|
||||
return CreateEnvironmentPath(true, environmentProvider);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,7 @@ namespace Microsoft.DotNet.ShellShim
|
|||
|
||||
private static DirectoryPath GetShimLocation()
|
||||
{
|
||||
var cliFolderPathCalculator = new CliFolderPathCalculator();
|
||||
return new DirectoryPath(cliFolderPathCalculator.ToolsShimPath);
|
||||
return new DirectoryPath(CliFolderPathCalculator.ToolsShimPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace Microsoft.DotNet.Cli.Telemetry
|
|||
_hasher = hasher ?? Sha256Hasher.Hash;
|
||||
_getMACAddress = getMACAddress ?? MacAddressGetter.GetMacAddress;
|
||||
_dockerContainerDetector = dockerContainerDetector ?? new DockerContainerDetectorForTelemetry();
|
||||
_userLevelCacheWriter = userLevelCacheWriter ?? new UserLevelCacheWriter(new CliFolderPathCalculator());
|
||||
_userLevelCacheWriter = userLevelCacheWriter ?? new UserLevelCacheWriter();
|
||||
}
|
||||
|
||||
private readonly IDockerContainerDetector _dockerContainerDetector;
|
||||
|
|
|
@ -34,8 +34,7 @@ namespace Microsoft.DotNet.ToolPackage
|
|||
|
||||
private static DirectoryPath GetPackageLocation()
|
||||
{
|
||||
var cliFolderPathCalculator = new CliFolderPathCalculator();
|
||||
return new DirectoryPath(cliFolderPathCalculator.ToolsPackagePath);
|
||||
return new DirectoryPath(CliFolderPathCalculator.ToolsPackagePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace Microsoft.DotNet.ToolPackage
|
|||
_store = store ?? throw new ArgumentNullException(nameof(store));
|
||||
_projectRestorer = projectRestorer ?? throw new ArgumentNullException(nameof(projectRestorer));
|
||||
_tempProject = tempProject;
|
||||
_offlineFeed = offlineFeed ?? new DirectoryPath(new CliFolderPathCalculator().CliFallbackFolderPath);
|
||||
_offlineFeed = offlineFeed ?? new DirectoryPath(CliFolderPathCalculator.CliFallbackFolderPath);
|
||||
}
|
||||
|
||||
public IToolPackage InstallPackage(PackageId packageId,
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace Microsoft.DotNet.Tools.MSBuild
|
|||
public sealed class MSBuildLogger : INodeLogger
|
||||
{
|
||||
private readonly IFirstTimeUseNoticeSentinel _sentinel =
|
||||
new FirstTimeUseNoticeSentinel(new CliFolderPathCalculator());
|
||||
new FirstTimeUseNoticeSentinel();
|
||||
private readonly ITelemetry _telemetry;
|
||||
private const string NewEventName = "msbuild";
|
||||
private const string TargetFrameworkTelemetryEventName = "targetframeworkeval";
|
||||
|
|
|
@ -31,8 +31,7 @@ namespace Microsoft.DotNet.Tools.New
|
|||
{
|
||||
var sessionId =
|
||||
Environment.GetEnvironmentVariable(MSBuildForwardingApp.TelemetrySessionIdEnvironmentVariableName);
|
||||
var telemetry =
|
||||
new Telemetry(new FirstTimeUseNoticeSentinel(new CliFolderPathCalculator()), sessionId);
|
||||
var telemetry = new Telemetry(new FirstTimeUseNoticeSentinel(), sessionId);
|
||||
var logger = new TelemetryLogger(null);
|
||||
|
||||
if (telemetry.Enabled)
|
||||
|
|
|
@ -60,8 +60,6 @@ namespace Microsoft.DotNet.Tools.Tool.Install
|
|||
_verbosity = appliedCommand.SingleArgumentOrDefault("verbosity");
|
||||
_toolPath = appliedCommand.SingleArgumentOrDefault("tool-path");
|
||||
|
||||
var cliFolderPathCalculator = new CliFolderPathCalculator();
|
||||
|
||||
_createToolPackageStoreAndInstaller = createToolPackageStoreAndInstaller ?? ToolPackageFactory.CreateToolPackageStoreAndInstaller;
|
||||
|
||||
_environmentPathInstruction = environmentPathInstruction
|
||||
|
|
|
@ -34,8 +34,6 @@ namespace Microsoft.DotNet.Tools.Tool.Uninstall
|
|||
IReporter reporter = null)
|
||||
: base(result)
|
||||
{
|
||||
var pathCalculator = new CliFolderPathCalculator();
|
||||
|
||||
_options = options ?? throw new ArgumentNullException(nameof(options));
|
||||
_reporter = reporter ?? Reporter.Output;
|
||||
_errorReporter = reporter ?? Reporter.Error;
|
||||
|
|
|
@ -26,7 +26,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
|
||||
private Mock<INuGetPackagesArchiver> _nugetPackagesArchiverMock;
|
||||
private Mock<INuGetCacheSentinel> _nugetCacheSentinel;
|
||||
private CliFolderPathCalculator _cliFolderPathCalculator;
|
||||
|
||||
public GivenANuGetCachePrimer()
|
||||
{
|
||||
|
@ -40,12 +39,9 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
|
||||
_nugetCacheSentinel = new Mock<INuGetCacheSentinel>();
|
||||
|
||||
_cliFolderPathCalculator = new CliFolderPathCalculator();
|
||||
|
||||
var nugetCachePrimer = new NuGetCachePrimer(
|
||||
_nugetPackagesArchiverMock.Object,
|
||||
_nugetCacheSentinel.Object,
|
||||
_cliFolderPathCalculator,
|
||||
_fileSystemMock.File);
|
||||
|
||||
nugetCachePrimer.PrimeCache();
|
||||
|
@ -63,7 +59,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
var nugetCachePrimer = new NuGetCachePrimer(
|
||||
nugetPackagesArchiverMock.Object,
|
||||
_nugetCacheSentinel.Object,
|
||||
_cliFolderPathCalculator,
|
||||
fileSystemMock.File);
|
||||
|
||||
nugetCachePrimer.PrimeCache();
|
||||
|
@ -75,7 +70,7 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
public void It_extracts_the_archive_to_the_fallback_folder()
|
||||
{
|
||||
_nugetPackagesArchiverMock.Verify(n =>
|
||||
n.ExtractArchive(_cliFolderPathCalculator.CliFallbackFolderPath),
|
||||
n.ExtractArchive(CliFolderPathCalculator.CliFallbackFolderPath),
|
||||
Times.Exactly(1));
|
||||
}
|
||||
|
||||
|
@ -95,7 +90,6 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
var nugetCachePrimer = new NuGetCachePrimer(
|
||||
nugetPackagesArchiveMock.Object,
|
||||
nugetCacheSentinel.Object,
|
||||
_cliFolderPathCalculator,
|
||||
_fileSystemMock.File);
|
||||
|
||||
Action action = () => nugetCachePrimer.PrimeCache();
|
||||
|
|
|
@ -15,9 +15,8 @@ namespace Microsoft.DotNet.Configurer.UnitTests
|
|||
public void It_does_not_return_same_path_for_tools_package_and_tool_shim()
|
||||
{
|
||||
// shim name will conflict with the folder that is PackageId, if commandName and packageId are the same.
|
||||
var cliFolderPathCalculator = new CliFolderPathCalculator();
|
||||
cliFolderPathCalculator.ToolsPackagePath.Should().NotBe(cliFolderPathCalculator.ToolsShimPath);
|
||||
cliFolderPathCalculator.ToolsPackagePath.Should().NotBe(cliFolderPathCalculator.ToolsShimPathInUnix.Path);
|
||||
CliFolderPathCalculator.ToolsPackagePath.Should().NotBe(CliFolderPathCalculator.ToolsShimPath);
|
||||
CliFolderPathCalculator.ToolsPackagePath.Should().NotBe(CliFolderPathCalculator.ToolsShimPathInUnix.Path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ namespace Microsoft.DotNet.Tests
|
|||
|
||||
File.Exists(profiled).Should().BeTrue();
|
||||
File.ReadAllText(profiled).Should().Be(
|
||||
$"export PATH=\"$PATH:{new CliFolderPathCalculator().ToolsShimPathInUnix.PathWithDollar}\"");
|
||||
$"export PATH=\"$PATH:{CliFolderPathCalculator.ToolsShimPathInUnix.PathWithDollar}\"");
|
||||
}
|
||||
|
||||
[MacOsOnlyFact]
|
||||
|
@ -234,7 +234,7 @@ namespace Microsoft.DotNet.Tests
|
|||
command.ExecuteWithCapturedOutput("internal-reportinstallsuccess test").Should().Pass();
|
||||
|
||||
File.Exists(pathsd).Should().BeTrue();
|
||||
File.ReadAllText(pathsd).Should().Be(new CliFolderPathCalculator().ToolsShimPathInUnix.PathWithTilde);
|
||||
File.ReadAllText(pathsd).Should().Be(CliFolderPathCalculator.ToolsShimPathInUnix.PathWithTilde);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
Loading…
Reference in a new issue