Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 55eb8bb

Browse files
author
William Lee
authored
replace string with FilePath (#8494)
1 parent 8649a5c commit 55eb8bb

File tree

6 files changed

+20
-17
lines changed

6 files changed

+20
-17
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
namespace Microsoft.DotNet.ShellShim
1+
using Microsoft.Extensions.EnvironmentAbstractions;
2+
3+
namespace Microsoft.DotNet.ShellShim
24
{
35
public interface IShellShimMaker
46
{
5-
void CreateShim(string packageExecutablePath, string shellCommandName);
7+
void CreateShim(FilePath packageExecutable, string shellCommandName);
68
void EnsureCommandNameUniqueness(string shellCommandName);
79
}
810
}

src/dotnet/ShellShim/ShellShimMaker.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public ShellShimMaker(string pathToPlaceShim)
2626
pathToPlaceShim ?? throw new ArgumentNullException(nameof(pathToPlaceShim));
2727
}
2828

29-
public void CreateShim(string packageExecutablePath, string shellCommandName)
29+
public void CreateShim(FilePath packageExecutable, string shellCommandName)
3030
{
3131
FilePath shimPath = GetShimPath(shellCommandName);
3232

3333
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
3434
{
35-
CreateConfigFile(shimPath.Value + ".config", entryPoint: packageExecutablePath, runner: "dotnet");
35+
CreateConfigFile(shimPath.Value + ".config", entryPoint: packageExecutable, runner: "dotnet");
3636
using (var shim = File.Create(shimPath.Value))
3737
using (var exe = typeof(ShellShimMaker).Assembly.GetManifestResourceStream(LauncherExeResourceName))
3838
{
@@ -41,8 +41,6 @@ public void CreateShim(string packageExecutablePath, string shellCommandName)
4141
}
4242
else
4343
{
44-
var packageExecutable = new FilePath(packageExecutablePath);
45-
4644
var script = new StringBuilder();
4745
script.AppendLine("#!/bin/sh");
4846
script.AppendLine($"dotnet {packageExecutable.ToQuotedString()} \"$@\"");
@@ -63,7 +61,7 @@ public void EnsureCommandNameUniqueness(string shellCommandName)
6361
}
6462
}
6563

66-
internal void CreateConfigFile(string outputPath, string entryPoint, string runner)
64+
internal void CreateConfigFile(string outputPath, FilePath entryPoint, string runner)
6765
{
6866
XDocument config;
6967
using (var resource = typeof(ShellShimMaker).Assembly.GetManifestResourceStream(LauncherConfigResourceName))
@@ -72,7 +70,7 @@ internal void CreateConfigFile(string outputPath, string entryPoint, string runn
7270
}
7371

7472
var appSettings = config.Descendants("appSettings").First();
75-
appSettings.Add(new XElement("add", new XAttribute("key", "entryPoint"), new XAttribute("value", entryPoint)));
73+
appSettings.Add(new XElement("add", new XAttribute("key", "entryPoint"), new XAttribute("value", entryPoint.Value)));
7674
appSettings.Add(new XElement("add", new XAttribute("key", "runner"), new XAttribute("value", runner ?? string.Empty)));
7775
config.Save(outputPath);
7876
}

src/dotnet/commands/dotnet-install/dotnet-install-tool/InstallToolCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public override int Execute()
8383
_shellShimMaker.EnsureCommandNameUniqueness(commandName);
8484

8585
_shellShimMaker.CreateShim(
86-
toolConfigurationAndExecutablePath.Executable.Value,
86+
toolConfigurationAndExecutablePath.Executable,
8787
commandName);
8888

8989
_environmentPathInstruction

test/Installer/Microsoft.DotNet.Cli.Msi.Tests/Microsoft.DotNet.Cli.Msi.Tests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@
2525
<Reference Include="System" />
2626
<Reference Include="Microsoft.CSharp" />
2727
</ItemGroup>
28+
29+
<ItemGroup>
30+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
31+
</ItemGroup>
2832
</Project>

test/Microsoft.DotNet.ShellShim.Tests/ShellShimMakerTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Microsoft.DotNet.Tools.Test.Utilities;
1414
using Microsoft.DotNet.Tools.Test.Utilities.Mock;
1515
using Microsoft.DotNet.Tools.Tests.ComponentMocks;
16+
using Microsoft.Extensions.EnvironmentAbstractions;
1617
using Xunit;
1718
using Xunit.Abstractions;
1819

@@ -31,8 +32,9 @@ public ShellShimMakerTests(ITestOutputHelper output)
3132
[InlineData("my_native_app.exe", null)]
3233
[InlineData("./my_native_app.js", "nodejs")]
3334
[InlineData(@"C:\tools\my_native_app.dll", "dotnet")]
34-
public void GivenAnRunnerOrEntryPointItCanCreateConfig(string entryPoint, string runner)
35+
public void GivenAnRunnerOrEntryPointItCanCreateConfig(string entryPointPath, string runner)
3536
{
37+
var entryPoint = new FilePath(entryPointPath);
3638
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
3739
return;
3840

@@ -51,7 +53,7 @@ public void GivenAnRunnerOrEntryPointItCanCreateConfig(string entryPoint, string
5153
.Should()
5254
.Contain(e => e.Attribute("key").Value == "runner" && e.Attribute("value").Value == (runner ?? string.Empty))
5355
.And
54-
.Contain(e => e.Attribute("key").Value == "entryPoint" && e.Attribute("value").Value == entryPoint);
56+
.Contain(e => e.Attribute("key").Value == "entryPoint" && e.Attribute("value").Value == entryPoint.Value);
5557
}
5658

5759
[Fact]
@@ -63,7 +65,7 @@ public void GivenAnExecutablePathItCanGenerateShimFile()
6365
var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();
6466

6567
shellShimMaker.CreateShim(
66-
outputDll.FullName,
68+
new FilePath(outputDll.FullName),
6769
shellCommandName);
6870
var stdOut = ExecuteInShell(shellCommandName);
6971

@@ -82,7 +84,7 @@ public void GivenAShimItPassesThroughArguments(string arguments, string[] expect
8284
var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();
8385

8486
shellShimMaker.CreateShim(
85-
outputDll.FullName,
87+
new FilePath(outputDll.FullName),
8688
shellCommandName);
8789

8890
var stdOut = ExecuteInShell(shellCommandName, arguments);

test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ShellShimMakerMock.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,8 @@ public ShellShimMakerMock(string pathToPlaceShim, IFileSystem fileSystem = null)
2323
_fileSystem = fileSystem ?? new FileSystemWrapper();
2424
}
2525

26-
public void CreateShim(string packageExecutablePath, string shellCommandName)
26+
public void CreateShim(FilePath packageExecutable, string shellCommandName)
2727
{
28-
var packageExecutable = new FilePath(packageExecutablePath);
29-
30-
3128
var fakeshim = new FakeShim
3229
{
3330
Runner = "dotnet",

0 commit comments

Comments
 (0)