replace string with FilePath (#8494)
This commit is contained in:
parent
8649a5c6c2
commit
55eb8bb7fc
6 changed files with 20 additions and 17 deletions
|
@ -1,8 +1,10 @@
|
||||||
namespace Microsoft.DotNet.ShellShim
|
using Microsoft.Extensions.EnvironmentAbstractions;
|
||||||
|
|
||||||
|
namespace Microsoft.DotNet.ShellShim
|
||||||
{
|
{
|
||||||
public interface IShellShimMaker
|
public interface IShellShimMaker
|
||||||
{
|
{
|
||||||
void CreateShim(string packageExecutablePath, string shellCommandName);
|
void CreateShim(FilePath packageExecutable, string shellCommandName);
|
||||||
void EnsureCommandNameUniqueness(string shellCommandName);
|
void EnsureCommandNameUniqueness(string shellCommandName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,13 @@ namespace Microsoft.DotNet.ShellShim
|
||||||
pathToPlaceShim ?? throw new ArgumentNullException(nameof(pathToPlaceShim));
|
pathToPlaceShim ?? throw new ArgumentNullException(nameof(pathToPlaceShim));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CreateShim(string packageExecutablePath, string shellCommandName)
|
public void CreateShim(FilePath packageExecutable, string shellCommandName)
|
||||||
{
|
{
|
||||||
FilePath shimPath = GetShimPath(shellCommandName);
|
FilePath shimPath = GetShimPath(shellCommandName);
|
||||||
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
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 shim = File.Create(shimPath.Value))
|
||||||
using (var exe = typeof(ShellShimMaker).Assembly.GetManifestResourceStream(LauncherExeResourceName))
|
using (var exe = typeof(ShellShimMaker).Assembly.GetManifestResourceStream(LauncherExeResourceName))
|
||||||
{
|
{
|
||||||
|
@ -41,8 +41,6 @@ namespace Microsoft.DotNet.ShellShim
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var packageExecutable = new FilePath(packageExecutablePath);
|
|
||||||
|
|
||||||
var script = new StringBuilder();
|
var script = new StringBuilder();
|
||||||
script.AppendLine("#!/bin/sh");
|
script.AppendLine("#!/bin/sh");
|
||||||
script.AppendLine($"dotnet {packageExecutable.ToQuotedString()} \"$@\"");
|
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;
|
XDocument config;
|
||||||
using (var resource = typeof(ShellShimMaker).Assembly.GetManifestResourceStream(LauncherConfigResourceName))
|
using (var resource = typeof(ShellShimMaker).Assembly.GetManifestResourceStream(LauncherConfigResourceName))
|
||||||
|
@ -72,7 +70,7 @@ namespace Microsoft.DotNet.ShellShim
|
||||||
}
|
}
|
||||||
|
|
||||||
var appSettings = config.Descendants("appSettings").First();
|
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)));
|
appSettings.Add(new XElement("add", new XAttribute("key", "runner"), new XAttribute("value", runner ?? string.Empty)));
|
||||||
config.Save(outputPath);
|
config.Save(outputPath);
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,7 @@ namespace Microsoft.DotNet.Tools.Install.Tool
|
||||||
_shellShimMaker.EnsureCommandNameUniqueness(commandName);
|
_shellShimMaker.EnsureCommandNameUniqueness(commandName);
|
||||||
|
|
||||||
_shellShimMaker.CreateShim(
|
_shellShimMaker.CreateShim(
|
||||||
toolConfigurationAndExecutablePath.Executable.Value,
|
toolConfigurationAndExecutablePath.Executable,
|
||||||
commandName);
|
commandName);
|
||||||
|
|
||||||
_environmentPathInstruction
|
_environmentPathInstruction
|
||||||
|
|
|
@ -25,4 +25,8 @@
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -13,6 +13,7 @@ using Microsoft.DotNet.TestFramework;
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities.Mock;
|
using Microsoft.DotNet.Tools.Test.Utilities.Mock;
|
||||||
using Microsoft.DotNet.Tools.Tests.ComponentMocks;
|
using Microsoft.DotNet.Tools.Tests.ComponentMocks;
|
||||||
|
using Microsoft.Extensions.EnvironmentAbstractions;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
@ -31,8 +32,9 @@ namespace Microsoft.DotNet.ShellShim.Tests
|
||||||
[InlineData("my_native_app.exe", null)]
|
[InlineData("my_native_app.exe", null)]
|
||||||
[InlineData("./my_native_app.js", "nodejs")]
|
[InlineData("./my_native_app.js", "nodejs")]
|
||||||
[InlineData(@"C:\tools\my_native_app.dll", "dotnet")]
|
[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))
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -51,7 +53,7 @@ namespace Microsoft.DotNet.ShellShim.Tests
|
||||||
.Should()
|
.Should()
|
||||||
.Contain(e => e.Attribute("key").Value == "runner" && e.Attribute("value").Value == (runner ?? string.Empty))
|
.Contain(e => e.Attribute("key").Value == "runner" && e.Attribute("value").Value == (runner ?? string.Empty))
|
||||||
.And
|
.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]
|
[Fact]
|
||||||
|
@ -63,7 +65,7 @@ namespace Microsoft.DotNet.ShellShim.Tests
|
||||||
var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();
|
var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();
|
||||||
|
|
||||||
shellShimMaker.CreateShim(
|
shellShimMaker.CreateShim(
|
||||||
outputDll.FullName,
|
new FilePath(outputDll.FullName),
|
||||||
shellCommandName);
|
shellCommandName);
|
||||||
var stdOut = ExecuteInShell(shellCommandName);
|
var stdOut = ExecuteInShell(shellCommandName);
|
||||||
|
|
||||||
|
@ -82,7 +84,7 @@ namespace Microsoft.DotNet.ShellShim.Tests
|
||||||
var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();
|
var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();
|
||||||
|
|
||||||
shellShimMaker.CreateShim(
|
shellShimMaker.CreateShim(
|
||||||
outputDll.FullName,
|
new FilePath(outputDll.FullName),
|
||||||
shellCommandName);
|
shellCommandName);
|
||||||
|
|
||||||
var stdOut = ExecuteInShell(shellCommandName, arguments);
|
var stdOut = ExecuteInShell(shellCommandName, arguments);
|
||||||
|
|
|
@ -23,11 +23,8 @@ namespace Microsoft.DotNet.Tools.Tests.ComponentMocks
|
||||||
_fileSystem = fileSystem ?? new FileSystemWrapper();
|
_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
|
var fakeshim = new FakeShim
|
||||||
{
|
{
|
||||||
Runner = "dotnet",
|
Runner = "dotnet",
|
||||||
|
|
Loading…
Add table
Reference in a new issue