From 55eb8bb7fc0b9f174a3e17b8cfa20f30606e9d0a Mon Sep 17 00:00:00 2001 From: William Lee Date: Tue, 30 Jan 2018 15:41:39 -0800 Subject: [PATCH] replace string with FilePath (#8494) --- src/dotnet/ShellShim/IShellShimMaker.cs | 6 ++++-- src/dotnet/ShellShim/ShellShimMaker.cs | 10 ++++------ .../dotnet-install-tool/InstallToolCommand.cs | 2 +- .../Microsoft.DotNet.Cli.Msi.Tests.csproj | 4 ++++ .../ShellShimMakerTests.cs | 10 ++++++---- .../ShellShimMakerMock.cs | 5 +---- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/dotnet/ShellShim/IShellShimMaker.cs b/src/dotnet/ShellShim/IShellShimMaker.cs index 35ff02493..443285ddd 100644 --- a/src/dotnet/ShellShim/IShellShimMaker.cs +++ b/src/dotnet/ShellShim/IShellShimMaker.cs @@ -1,8 +1,10 @@ -namespace Microsoft.DotNet.ShellShim +using Microsoft.Extensions.EnvironmentAbstractions; + +namespace Microsoft.DotNet.ShellShim { public interface IShellShimMaker { - void CreateShim(string packageExecutablePath, string shellCommandName); + void CreateShim(FilePath packageExecutable, string shellCommandName); void EnsureCommandNameUniqueness(string shellCommandName); } } diff --git a/src/dotnet/ShellShim/ShellShimMaker.cs b/src/dotnet/ShellShim/ShellShimMaker.cs index f3247c620..6121cfd2a 100644 --- a/src/dotnet/ShellShim/ShellShimMaker.cs +++ b/src/dotnet/ShellShim/ShellShimMaker.cs @@ -26,13 +26,13 @@ namespace Microsoft.DotNet.ShellShim pathToPlaceShim ?? throw new ArgumentNullException(nameof(pathToPlaceShim)); } - public void CreateShim(string packageExecutablePath, string shellCommandName) + public void CreateShim(FilePath packageExecutable, string shellCommandName) { FilePath shimPath = GetShimPath(shellCommandName); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - CreateConfigFile(shimPath.Value + ".config", entryPoint: packageExecutablePath, runner: "dotnet"); + CreateConfigFile(shimPath.Value + ".config", entryPoint: packageExecutable, runner: "dotnet"); using (var shim = File.Create(shimPath.Value)) using (var exe = typeof(ShellShimMaker).Assembly.GetManifestResourceStream(LauncherExeResourceName)) { @@ -41,8 +41,6 @@ namespace Microsoft.DotNet.ShellShim } else { - var packageExecutable = new FilePath(packageExecutablePath); - var script = new StringBuilder(); script.AppendLine("#!/bin/sh"); script.AppendLine($"dotnet {packageExecutable.ToQuotedString()} \"$@\""); @@ -63,7 +61,7 @@ namespace Microsoft.DotNet.ShellShim } } - internal void CreateConfigFile(string outputPath, string entryPoint, string runner) + internal void CreateConfigFile(string outputPath, FilePath entryPoint, string runner) { XDocument config; using (var resource = typeof(ShellShimMaker).Assembly.GetManifestResourceStream(LauncherConfigResourceName)) @@ -72,7 +70,7 @@ namespace Microsoft.DotNet.ShellShim } var appSettings = config.Descendants("appSettings").First(); - appSettings.Add(new XElement("add", new XAttribute("key", "entryPoint"), new XAttribute("value", entryPoint))); + appSettings.Add(new XElement("add", new XAttribute("key", "entryPoint"), new XAttribute("value", entryPoint.Value))); appSettings.Add(new XElement("add", new XAttribute("key", "runner"), new XAttribute("value", runner ?? string.Empty))); config.Save(outputPath); } diff --git a/src/dotnet/commands/dotnet-install/dotnet-install-tool/InstallToolCommand.cs b/src/dotnet/commands/dotnet-install/dotnet-install-tool/InstallToolCommand.cs index 9138239e4..f3041a12a 100644 --- a/src/dotnet/commands/dotnet-install/dotnet-install-tool/InstallToolCommand.cs +++ b/src/dotnet/commands/dotnet-install/dotnet-install-tool/InstallToolCommand.cs @@ -83,7 +83,7 @@ namespace Microsoft.DotNet.Tools.Install.Tool _shellShimMaker.EnsureCommandNameUniqueness(commandName); _shellShimMaker.CreateShim( - toolConfigurationAndExecutablePath.Executable.Value, + toolConfigurationAndExecutablePath.Executable, commandName); _environmentPathInstruction diff --git a/test/Installer/Microsoft.DotNet.Cli.Msi.Tests/Microsoft.DotNet.Cli.Msi.Tests.csproj b/test/Installer/Microsoft.DotNet.Cli.Msi.Tests/Microsoft.DotNet.Cli.Msi.Tests.csproj index 17220aaf1..28ccae43e 100644 --- a/test/Installer/Microsoft.DotNet.Cli.Msi.Tests/Microsoft.DotNet.Cli.Msi.Tests.csproj +++ b/test/Installer/Microsoft.DotNet.Cli.Msi.Tests/Microsoft.DotNet.Cli.Msi.Tests.csproj @@ -25,4 +25,8 @@ + + + + diff --git a/test/Microsoft.DotNet.ShellShim.Tests/ShellShimMakerTests.cs b/test/Microsoft.DotNet.ShellShim.Tests/ShellShimMakerTests.cs index 804288f3e..956523926 100644 --- a/test/Microsoft.DotNet.ShellShim.Tests/ShellShimMakerTests.cs +++ b/test/Microsoft.DotNet.ShellShim.Tests/ShellShimMakerTests.cs @@ -13,6 +13,7 @@ using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; using Microsoft.DotNet.Tools.Test.Utilities.Mock; using Microsoft.DotNet.Tools.Tests.ComponentMocks; +using Microsoft.Extensions.EnvironmentAbstractions; using Xunit; using Xunit.Abstractions; @@ -31,8 +32,9 @@ namespace Microsoft.DotNet.ShellShim.Tests [InlineData("my_native_app.exe", null)] [InlineData("./my_native_app.js", "nodejs")] [InlineData(@"C:\tools\my_native_app.dll", "dotnet")] - public void GivenAnRunnerOrEntryPointItCanCreateConfig(string entryPoint, string runner) + public void GivenAnRunnerOrEntryPointItCanCreateConfig(string entryPointPath, string runner) { + var entryPoint = new FilePath(entryPointPath); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return; @@ -51,7 +53,7 @@ namespace Microsoft.DotNet.ShellShim.Tests .Should() .Contain(e => e.Attribute("key").Value == "runner" && e.Attribute("value").Value == (runner ?? string.Empty)) .And - .Contain(e => e.Attribute("key").Value == "entryPoint" && e.Attribute("value").Value == entryPoint); + .Contain(e => e.Attribute("key").Value == "entryPoint" && e.Attribute("value").Value == entryPoint.Value); } [Fact] @@ -63,7 +65,7 @@ namespace Microsoft.DotNet.ShellShim.Tests var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName(); shellShimMaker.CreateShim( - outputDll.FullName, + new FilePath(outputDll.FullName), shellCommandName); var stdOut = ExecuteInShell(shellCommandName); @@ -82,7 +84,7 @@ namespace Microsoft.DotNet.ShellShim.Tests var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName(); shellShimMaker.CreateShim( - outputDll.FullName, + new FilePath(outputDll.FullName), shellCommandName); var stdOut = ExecuteInShell(shellCommandName, arguments); diff --git a/test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ShellShimMakerMock.cs b/test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ShellShimMakerMock.cs index 3e19da8db..50d123d09 100644 --- a/test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ShellShimMakerMock.cs +++ b/test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ShellShimMakerMock.cs @@ -23,11 +23,8 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks _fileSystem = fileSystem ?? new FileSystemWrapper(); } - public void CreateShim(string packageExecutablePath, string shellCommandName) + public void CreateShim(FilePath packageExecutable, string shellCommandName) { - var packageExecutable = new FilePath(packageExecutablePath); - - var fakeshim = new FakeShim { Runner = "dotnet",