2017-11-27 10:45:43 -08:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Xml.Xsl;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
using Microsoft.DotNet.Configurer;
|
|
|
|
|
using Microsoft.Extensions.EnvironmentAbstractions;
|
|
|
|
|
|
2017-12-04 14:13:24 -08:00
|
|
|
|
namespace Microsoft.DotNet.ShellShim
|
2017-11-27 10:45:43 -08:00
|
|
|
|
{
|
|
|
|
|
internal static class EnvironmentPathFactory
|
|
|
|
|
{
|
|
|
|
|
public static IEnvironmentPath CreateEnvironmentPath(
|
|
|
|
|
bool hasSuperUserAccess = false,
|
|
|
|
|
IEnvironmentProvider environmentProvider = null)
|
|
|
|
|
{
|
|
|
|
|
if (environmentProvider == null)
|
|
|
|
|
{
|
|
|
|
|
environmentProvider = new EnvironmentProvider();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnvironmentPath environmentPath = new DoNothingEnvironmentPath();
|
|
|
|
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
|
{
|
|
|
|
|
environmentPath = new WindowsEnvironmentPath(
|
2018-05-17 12:52:21 -07:00
|
|
|
|
CliFolderPathCalculator.ToolsShimPath,
|
2018-03-23 12:40:58 -07:00
|
|
|
|
Reporter.Output,
|
|
|
|
|
environmentProvider);
|
2017-11-27 10:45:43 -08:00
|
|
|
|
}
|
|
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && hasSuperUserAccess)
|
|
|
|
|
{
|
|
|
|
|
environmentPath = new LinuxEnvironmentPath(
|
2018-05-17 12:52:21 -07:00
|
|
|
|
CliFolderPathCalculator.ToolsShimPathInUnix,
|
2017-11-27 10:45:43 -08:00
|
|
|
|
Reporter.Output,
|
2018-03-23 12:40:58 -07:00
|
|
|
|
environmentProvider,
|
|
|
|
|
new FileWrapper());
|
2017-11-27 10:45:43 -08:00
|
|
|
|
}
|
|
|
|
|
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && hasSuperUserAccess)
|
|
|
|
|
{
|
|
|
|
|
environmentPath = new OSXEnvironmentPath(
|
2018-05-17 12:52:21 -07:00
|
|
|
|
executablePath: CliFolderPathCalculator.ToolsShimPathInUnix,
|
2017-11-27 10:45:43 -08:00
|
|
|
|
reporter: Reporter.Output,
|
|
|
|
|
environmentProvider: environmentProvider,
|
|
|
|
|
fileSystem: new FileWrapper());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return environmentPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IEnvironmentPathInstruction CreateEnvironmentPathInstruction(
|
|
|
|
|
IEnvironmentProvider environmentProvider = null)
|
|
|
|
|
{
|
2018-05-17 12:52:21 -07:00
|
|
|
|
return CreateEnvironmentPath(true, environmentProvider);
|
2017-11-27 10:45:43 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|