From 13219fafa9b669f5b1fd83e8bcd45e39dcd13c7f Mon Sep 17 00:00:00 2001 From: Nate McMaster Date: Tue, 21 Mar 2017 16:55:42 -0700 Subject: [PATCH] Remove code that moved into CommandLineUtils --- DotNetTools.sln | 7 -- shared/ArgumentEscaper.cs | 107 ------------------ shared/DotNetMuxer.cs | 56 --------- .../DotNetWatcher.cs | 3 +- .../Internal/MsBuildFileSetFactory.cs | 3 +- .../Internal/ProcessRunner.cs | 1 + .../Internal/ProjectIdResolver.cs | 2 +- .../AwaitableProcess.cs | 4 +- ...otNet.Watcher.Tools.FunctionalTests.csproj | 1 + .../Scenario/ProjectToolScenario.cs | 2 +- .../Scenario/WatchableApp.cs | 2 +- .../ConsoleReporterTests.cs | 0 .../ArgumentEscaperTests.cs | 23 ---- .../Microsoft.Extensions.Tools.Tests.csproj | 20 ---- 14 files changed, 11 insertions(+), 220 deletions(-) delete mode 100644 shared/ArgumentEscaper.cs delete mode 100644 shared/DotNetMuxer.cs rename test/{Microsoft.Extensions.Tools.Tests => Microsoft.DotNet.Watcher.Tools.Tests}/ConsoleReporterTests.cs (100%) delete mode 100644 test/Microsoft.Extensions.Tools.Tests/ArgumentEscaperTests.cs delete mode 100644 test/Microsoft.Extensions.Tools.Tests/Microsoft.Extensions.Tools.Tests.csproj diff --git a/DotNetTools.sln b/DotNetTools.sln index 8b681184c6..e788eb2226 100644 --- a/DotNetTools.sln +++ b/DotNetTools.sln @@ -24,8 +24,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.Watcher.To EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Caching.SqlConfig.Tools", "src\Microsoft.Extensions.Caching.SqlConfig.Tools\Microsoft.Extensions.Caching.SqlConfig.Tools.csproj", "{53F3B53D-303A-4DAA-9C38-4F55195FA5B9}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Extensions.Tools.Tests", "test\Microsoft.Extensions.Tools.Tests\Microsoft.Extensions.Tools.Tests.csproj", "{9295E811-FF0F-E40A-2F9A-0B2C4EBC22AD}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -56,10 +54,6 @@ Global {53F3B53D-303A-4DAA-9C38-4F55195FA5B9}.Debug|Any CPU.Build.0 = Debug|Any CPU {53F3B53D-303A-4DAA-9C38-4F55195FA5B9}.Release|Any CPU.ActiveCfg = Release|Any CPU {53F3B53D-303A-4DAA-9C38-4F55195FA5B9}.Release|Any CPU.Build.0 = Release|Any CPU - {9295E811-FF0F-E40A-2F9A-0B2C4EBC22AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9295E811-FF0F-E40A-2F9A-0B2C4EBC22AD}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9295E811-FF0F-E40A-2F9A-0B2C4EBC22AD}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9295E811-FF0F-E40A-2F9A-0B2C4EBC22AD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -71,6 +65,5 @@ Global {7B331122-83B1-4F08-A119-DC846959844C} = {F5B382BC-258F-46E1-AC3D-10E5CCD55134} {8A2E6961-6B12-4A8E-8215-3E7301D52EAC} = {F5B382BC-258F-46E1-AC3D-10E5CCD55134} {53F3B53D-303A-4DAA-9C38-4F55195FA5B9} = {66517987-2A5A-4330-B130-207039378FD4} - {9295E811-FF0F-E40A-2F9A-0B2C4EBC22AD} = {F5B382BC-258F-46E1-AC3D-10E5CCD55134} EndGlobalSection EndGlobal diff --git a/shared/ArgumentEscaper.cs b/shared/ArgumentEscaper.cs deleted file mode 100644 index 91d8ef3086..0000000000 --- a/shared/ArgumentEscaper.cs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace Microsoft.Extensions.Tools.Internal -{ - public static class ArgumentEscaper - { - /// - /// Undo the processing which took place to create string[] args in Main, so that the next process will - /// receive the same string[] args. - /// - /// - /// See https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/ - /// - /// - /// - public static string EscapeAndConcatenate(IEnumerable args) - => string.Join(" ", args.Select(EscapeSingleArg)); - - private static string EscapeSingleArg(string arg) - { - var sb = new StringBuilder(); - - var needsQuotes = ShouldSurroundWithQuotes(arg); - var isQuoted = needsQuotes || IsSurroundedWithQuotes(arg); - - if (needsQuotes) - { - sb.Append('"'); - } - - for (int i = 0; i < arg.Length; ++i) - { - var backslashes = 0; - - // Consume all backslashes - while (i < arg.Length && arg[i] == '\\') - { - backslashes++; - i++; - } - - if (i == arg.Length && isQuoted) - { - // Escape any backslashes at the end of the arg when the argument is also quoted. - // This ensures the outside quote is interpreted as an argument delimiter - sb.Append('\\', 2 * backslashes); - } - else if (i == arg.Length) - { - // At then end of the arg, which isn't quoted, - // just add the backslashes, no need to escape - sb.Append('\\', backslashes); - } - else if (arg[i] == '"') - { - // Escape any preceding backslashes and the quote - sb.Append('\\', (2 * backslashes) + 1); - sb.Append('"'); - } - else - { - // Output any consumed backslashes and the character - sb.Append('\\', backslashes); - sb.Append(arg[i]); - } - } - - if (needsQuotes) - { - sb.Append('"'); - } - - return sb.ToString(); - } - - private static bool ShouldSurroundWithQuotes(string argument) - { - // Don't quote already quoted strings - if (IsSurroundedWithQuotes(argument)) - { - return false; - } - - // Only quote if whitespace exists in the string - return ContainsWhitespace(argument); - } - - private static bool IsSurroundedWithQuotes(string argument) - { - if (argument.Length <= 1) - { - return false; - } - - return argument[0] == '"' && argument[argument.Length - 1] == '"'; - } - - private static bool ContainsWhitespace(string argument) - => argument.IndexOfAny(new [] { ' ', '\t', '\n' }) >= 0; - } -} \ No newline at end of file diff --git a/shared/DotNetMuxer.cs b/shared/DotNetMuxer.cs deleted file mode 100644 index 56e627f192..0000000000 --- a/shared/DotNetMuxer.cs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using System.IO; -using System.Runtime.InteropServices; - -namespace Microsoft.Extensions.Tools.Internal -{ - public static class DotNetMuxer - { - private const string MuxerName = "dotnet"; - - static DotNetMuxer() - { - MuxerPath = TryFindMuxerPath(); - } - - public static string MuxerPath { get; } - - public static string MuxerPathOrDefault() - => MuxerPath ?? MuxerName; - - private static string TryFindMuxerPath() - { - var fileName = MuxerName; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - fileName += ".exe"; - } - - var fxDepsFile = AppContext.GetData("FX_DEPS_FILE") as string; - - if (string.IsNullOrEmpty(fxDepsFile)) - { - return null; - } - - var muxerDir = new FileInfo(fxDepsFile) // Microsoft.NETCore.App.deps.json - .Directory? // (version) - .Parent? // Microsoft.NETCore.App - .Parent? // shared - .Parent; // DOTNET_HOME - - if (muxerDir == null) - { - return null; - } - - var muxer = Path.Combine(muxerDir.FullName, fileName); - return File.Exists(muxer) - ? muxer - : null; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.Watcher.Tools/DotNetWatcher.cs b/src/Microsoft.DotNet.Watcher.Tools/DotNetWatcher.cs index fb324de797..66a213a043 100644 --- a/src/Microsoft.DotNet.Watcher.Tools/DotNetWatcher.cs +++ b/src/Microsoft.DotNet.Watcher.Tools/DotNetWatcher.cs @@ -1,10 +1,11 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading; using System.Threading.Tasks; using Microsoft.DotNet.Watcher.Internal; +using Microsoft.Extensions.CommandLineUtils; using Microsoft.Extensions.Tools.Internal; namespace Microsoft.DotNet.Watcher diff --git a/src/Microsoft.DotNet.Watcher.Tools/Internal/MsBuildFileSetFactory.cs b/src/Microsoft.DotNet.Watcher.Tools/Internal/MsBuildFileSetFactory.cs index 1a7e900845..a9fd44cece 100644 --- a/src/Microsoft.DotNet.Watcher.Tools/Internal/MsBuildFileSetFactory.cs +++ b/src/Microsoft.DotNet.Watcher.Tools/Internal/MsBuildFileSetFactory.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -9,6 +9,7 @@ using System.Linq; using System.Reflection; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.CommandLineUtils; using Microsoft.Extensions.Tools.Internal; namespace Microsoft.DotNet.Watcher.Internal diff --git a/src/Microsoft.DotNet.Watcher.Tools/Internal/ProcessRunner.cs b/src/Microsoft.DotNet.Watcher.Tools/Internal/ProcessRunner.cs index 592c657675..c866b6db14 100644 --- a/src/Microsoft.DotNet.Watcher.Tools/Internal/ProcessRunner.cs +++ b/src/Microsoft.DotNet.Watcher.Tools/Internal/ProcessRunner.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.CommandLineUtils; using Microsoft.Extensions.Internal; using Microsoft.Extensions.Tools.Internal; diff --git a/src/Microsoft.Extensions.SecretManager.Tools/Internal/ProjectIdResolver.cs b/src/Microsoft.Extensions.SecretManager.Tools/Internal/ProjectIdResolver.cs index afea6d7a58..83fdde4463 100644 --- a/src/Microsoft.Extensions.SecretManager.Tools/Internal/ProjectIdResolver.cs +++ b/src/Microsoft.Extensions.SecretManager.Tools/Internal/ProjectIdResolver.cs @@ -2,10 +2,10 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; +using Microsoft.Extensions.CommandLineUtils; using Microsoft.Extensions.Tools.Internal; namespace Microsoft.Extensions.SecretManager.Tools.Internal diff --git a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/AwaitableProcess.cs b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/AwaitableProcess.cs index 11583832d0..4834125ebe 100644 --- a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/AwaitableProcess.cs +++ b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/AwaitableProcess.cs @@ -1,4 +1,4 @@ -// Copyright (c) .NET Foundation. All rights reserved. +// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; @@ -10,7 +10,7 @@ using System.Threading; using System.Threading.Tasks; using System.Threading.Tasks.Dataflow; using Microsoft.Extensions.Internal; -using Microsoft.Extensions.Tools.Internal; +using Microsoft.Extensions.CommandLineUtils; using Xunit.Abstractions; namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests diff --git a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Microsoft.DotNet.Watcher.Tools.FunctionalTests.csproj b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Microsoft.DotNet.Watcher.Tools.FunctionalTests.csproj index 4141169368..7e562aba0d 100644 --- a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Microsoft.DotNet.Watcher.Tools.FunctionalTests.csproj +++ b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Microsoft.DotNet.Watcher.Tools.FunctionalTests.csproj @@ -22,6 +22,7 @@ + diff --git a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Scenario/ProjectToolScenario.cs b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Scenario/ProjectToolScenario.cs index 1b0f62c7de..5c96f03bfb 100644 --- a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Scenario/ProjectToolScenario.cs +++ b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Scenario/ProjectToolScenario.cs @@ -1,13 +1,13 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.Extensions.Tools.Internal; using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Threading; +using Microsoft.Extensions.CommandLineUtils; using Xunit.Abstractions; namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests diff --git a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Scenario/WatchableApp.cs b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Scenario/WatchableApp.cs index 271a2832e4..3fdb1872e3 100644 --- a/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Scenario/WatchableApp.cs +++ b/test/Microsoft.DotNet.Watcher.Tools.FunctionalTests/Scenario/WatchableApp.cs @@ -7,7 +7,7 @@ using System.IO; using System.Linq; using System.Runtime.CompilerServices; using System.Threading.Tasks; -using Microsoft.Extensions.Tools.Internal; +using Microsoft.Extensions.CommandLineUtils; using Xunit.Abstractions; namespace Microsoft.DotNet.Watcher.Tools.FunctionalTests diff --git a/test/Microsoft.Extensions.Tools.Tests/ConsoleReporterTests.cs b/test/Microsoft.DotNet.Watcher.Tools.Tests/ConsoleReporterTests.cs similarity index 100% rename from test/Microsoft.Extensions.Tools.Tests/ConsoleReporterTests.cs rename to test/Microsoft.DotNet.Watcher.Tools.Tests/ConsoleReporterTests.cs diff --git a/test/Microsoft.Extensions.Tools.Tests/ArgumentEscaperTests.cs b/test/Microsoft.Extensions.Tools.Tests/ArgumentEscaperTests.cs deleted file mode 100644 index 78119021d9..0000000000 --- a/test/Microsoft.Extensions.Tools.Tests/ArgumentEscaperTests.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.Extensions.Tools.Internal; -using Xunit; - -namespace Microsoft.Extensions.Tools.Tests -{ - public class ArgumentEscaperTests - { - [Theory] - [InlineData(new[] { "one", "two", "three" }, "one two three")] - [InlineData(new[] { "line1\nline2", "word1\tword2" }, "\"line1\nline2\" \"word1\tword2\"")] - [InlineData(new[] { "with spaces" }, "\"with spaces\"")] - [InlineData(new[] { @"with\backslash" }, @"with\backslash")] - [InlineData(new[] { @"""quotedwith\backslash""" }, @"\""quotedwith\backslash\""")] - [InlineData(new[] { @"C:\Users\" }, @"C:\Users\")] - [InlineData(new[] { @"C:\Program Files\dotnet\" }, @"""C:\Program Files\dotnet\\""")] - [InlineData(new[] { @"backslash\""preceedingquote" }, @"backslash\\\""preceedingquote")] - public void EscapesArguments(string[] args, string expected) - => Assert.Equal(expected, ArgumentEscaper.EscapeAndConcatenate(args)); - } -} \ No newline at end of file diff --git a/test/Microsoft.Extensions.Tools.Tests/Microsoft.Extensions.Tools.Tests.csproj b/test/Microsoft.Extensions.Tools.Tests/Microsoft.Extensions.Tools.Tests.csproj deleted file mode 100644 index 8d6d2ad328..0000000000 --- a/test/Microsoft.Extensions.Tools.Tests/Microsoft.Extensions.Tools.Tests.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - netcoreapp1.1 - - - - - - - - - - - - - -