From 1463ddf695c92f75481448aa582e4027c6c8e3c2 Mon Sep 17 00:00:00 2001 From: sfoslund Date: Wed, 8 Jan 2020 14:34:15 -0800 Subject: [PATCH 1/5] Fixing asp.net bundle list problems, fixing --version flag --- .../LocalizableStrings.Designer.cs | 2 +- .../LocalizableStrings.resx | 2 +- .../Shared/Commands/UninstallCommandExec.cs | 4 ++-- .../Shared/Configs/CommandLineConfigs.cs | 2 +- .../Shared/Utils/Regexes.cs | 4 +++- .../Windows/RegistryQuery.cs | 24 +++++++++++++++---- .../xlf/LocalizableStrings.cs.xlf | 4 ++-- .../xlf/LocalizableStrings.de.xlf | 4 ++-- .../xlf/LocalizableStrings.es.xlf | 4 ++-- .../xlf/LocalizableStrings.fr.xlf | 4 ++-- .../xlf/LocalizableStrings.it.xlf | 4 ++-- .../xlf/LocalizableStrings.ja.xlf | 4 ++-- .../xlf/LocalizableStrings.ko.xlf | 4 ++-- .../xlf/LocalizableStrings.pl.xlf | 4 ++-- .../xlf/LocalizableStrings.pt-BR.xlf | 4 ++-- .../xlf/LocalizableStrings.ru.xlf | 4 ++-- .../xlf/LocalizableStrings.tr.xlf | 4 ++-- .../xlf/LocalizableStrings.zh-Hans.xlf | 4 ++-- .../xlf/LocalizableStrings.zh-Hant.xlf | 4 ++-- .../IntegrationTests/IntegrationTests.cs | 20 ++++++++++++++++ 20 files changed, 74 insertions(+), 36 deletions(-) create mode 100644 test/dotnet-core-uninstall.Tests/Shared/IntegrationTests/IntegrationTests.cs diff --git a/src/dotnet-core-uninstall/LocalizableStrings.Designer.cs b/src/dotnet-core-uninstall/LocalizableStrings.Designer.cs index 42ee5412..e6487a72 100644 --- a/src/dotnet-core-uninstall/LocalizableStrings.Designer.cs +++ b/src/dotnet-core-uninstall/LocalizableStrings.Designer.cs @@ -79,7 +79,7 @@ internal static string CancelingMessage { } /// - /// Looks up a localized string similar to Allowed values are "Y" and "n".. + /// Looks up a localized string similar to Allowed values are "Y", "YES", and "N".. /// internal static string ConfirmationPromptInvalidExceptionMessage { get { diff --git a/src/dotnet-core-uninstall/LocalizableStrings.resx b/src/dotnet-core-uninstall/LocalizableStrings.resx index 0312b759..f251082e 100644 --- a/src/dotnet-core-uninstall/LocalizableStrings.resx +++ b/src/dotnet-core-uninstall/LocalizableStrings.resx @@ -292,7 +292,7 @@ To avoid breaking Visual Studio or other problems, read https://aka.ms/dotnet-co Do you want to continue? [Y/n] - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". Remove the specified .NET Core SDKs or Runtimes. diff --git a/src/dotnet-core-uninstall/Shared/Commands/UninstallCommandExec.cs b/src/dotnet-core-uninstall/Shared/Commands/UninstallCommandExec.cs index 830932bd..16d70efd 100644 --- a/src/dotnet-core-uninstall/Shared/Commands/UninstallCommandExec.cs +++ b/src/dotnet-core-uninstall/Shared/Commands/UninstallCommandExec.cs @@ -215,7 +215,7 @@ private static bool AskItAndReturnUserAnswer(IDictionary bundles var response = Console.ReadLine().Trim().ToUpper(); - if (response.Equals("Y")) + if (response.Equals("Y") || response.Equals("YES")) { return true; } @@ -243,7 +243,7 @@ private static bool AskWithWarningsForRequiredBundles(IDictionary new UninstallHelpBuilder(context.Console)) .Build(); CommandLineParseResult = UninstallCommandParser.Parse(Environment.GetCommandLineArgs()); diff --git a/src/dotnet-core-uninstall/Shared/Utils/Regexes.cs b/src/dotnet-core-uninstall/Shared/Utils/Regexes.cs index 9dcb3fc1..a73cbbe0 100644 --- a/src/dotnet-core-uninstall/Shared/Utils/Regexes.cs +++ b/src/dotnet-core-uninstall/Shared/Utils/Regexes.cs @@ -97,6 +97,8 @@ internal static class Regexes $@"\\dotnet\-(?<{TypeGroupName}>runtime)\-{_runtimeVersionCachePathRegex}\-win\-{_archRegex.ToString()}\.exe|\\dotnet\-win\-{_archRegex.ToString()}\.{_runtimeVersionCachePathRegex.ToString()}\.exe"); private static readonly Regex _aspNetRuntimeCachePathRegex = new Regex( $@"\\(?<{TypeGroupName}>AspNetCore)\.{_aspNetRuntimeVersionCachePathRegex.ToString()}\.RuntimePackageStore_{_archRegex.ToString()}\.exe|\\(?<{TypeGroupName}>aspnetcore\-runtime)\-{_aspNetRuntimeVersionCachePathRegex.ToString()}\-win\-{_archRegex.ToString()}\.exe"); + private static readonly Regex _aspNetSharedFrameworkCachePathRegex = new Regex( + $@"\\(?<{TypeGroupName}>AspNetCoreSharedFrameworkBundle)-{_archRegex.ToString()}\.exe"); private static readonly Regex _hostingBundleCachePathRegex = new Regex( $@"\\DotNetCore\.({_hostingBundleAuxVersionCachePathRegex.ToString()}_)?{_hostingBundleVersionCachePathRegex.ToString()}\-(?<{TypeGroupName}>WindowsHosting)\.exe|\\dotnetcore\.{_hostingBundleAuxVersionCachePathRegex.ToString()}_{_hostingBundleVersionCachePathRegex.ToString()}\-(?<{TypeGroupName}>windowshosting)\.exe|\\dotnet\-(?<{TypeGroupName}>hosting)\-{_hostingBundleVersionCachePathRegex.ToString()}\-win\.exe"); @@ -107,6 +109,6 @@ internal static class Regexes public static readonly Regex BundleDisplayNameRegex = new Regex( $@"^({_sdkDisplayNameRegex.ToString()}|{_runtimeDisplayNameRegex.ToString()}|{_aspNetRuntimeDisplayNameRegex.ToString()}|{_hostingBundleDisplayNameRegex.ToString()})$"); public static readonly Regex BundleCachePathRegex = new Regex( - $@"({_sdkCachePathRegex.ToString()}|{_runtimeCachePathRegex.ToString()}|{_aspNetRuntimeCachePathRegex.ToString()}|{_hostingBundleCachePathRegex.ToString()})$"); + $@"({_sdkCachePathRegex.ToString()}|{_runtimeCachePathRegex.ToString()}|{_aspNetRuntimeCachePathRegex.ToString()}|{_aspNetSharedFrameworkCachePathRegex.ToString()}|{_hostingBundleCachePathRegex.ToString()})$"); } } diff --git a/src/dotnet-core-uninstall/Windows/RegistryQuery.cs b/src/dotnet-core-uninstall/Windows/RegistryQuery.cs index 5474fd6f..8eeaf812 100644 --- a/src/dotnet-core-uninstall/Windows/RegistryQuery.cs +++ b/src/dotnet-core-uninstall/Windows/RegistryQuery.cs @@ -40,7 +40,9 @@ public static IEnumerable GetAllInstalledBundles() .Where(bundle => IsDotNetCoreBundle(bundle)); var wrappedBundles = bundles - .Select(bundle => WrapRegistryKey(bundle)).ToList(); + .Select(bundle => WrapRegistryKey(bundle)) + .Where(bundle => bundle != null) + .ToList(); return wrappedBundles; } @@ -83,22 +85,36 @@ private static Bundle WrapRegistryKey(RegistryKey registryKey) var uninstallCommand = registryKey.GetValue("QuietUninstallString") as string; var bundleCachePath = registryKey.GetValue("BundleCachePath") as string; - ParseVersionAndArch(displayName, bundleCachePath, out var version, out var arch); + ParseVersionAndArch(registryKey, displayName, bundleCachePath, out var version, out var arch); + + if (version == null) + { + return null; + } return Bundle.From(version, arch, uninstallCommand, displayName); } - private static void ParseVersionAndArch(string displayName, string bundleCachePath, out BundleVersion version, out BundleArch arch) + private static void ParseVersionAndArch(RegistryKey registryKey, string displayName, string bundleCachePath, out BundleVersion version, out BundleArch arch) { var match = Regexes.BundleDisplayNameRegex.Match(displayName); var cachePathMatch = Regexes.BundleCachePathRegex.Match(bundleCachePath); var archString = cachePathMatch.Groups[Regexes.ArchGroupName].Value ?? string.Empty; - var versionString = cachePathMatch.Groups[Regexes.VersionGroupName].Value; + var versionFromCachePath = cachePathMatch.Groups[Regexes.VersionGroupName].Value; + var versionFromRegistry = string.Join('.', (registryKey.GetValue("DisplayVersion") as string).Split('.').Take(3)); + var versionString = string.IsNullOrEmpty(versionFromCachePath) ? versionFromRegistry : versionFromCachePath; var hasAuxVersion = cachePathMatch.Groups[Regexes.AuxVersionGroupName].Success; var footnote = hasAuxVersion ? string.Format(LocalizableStrings.HostingBundleFootnoteFormat, displayName, versionString) : null; + if (string.IsNullOrEmpty(displayName) || string.IsNullOrEmpty(versionString) || string.IsNullOrEmpty(archString)) + { + version = null; + arch = BundleArch.X64 | BundleArch.X86; + return; + } + switch (match.Groups[Regexes.TypeGroupName].Value) { case "SDK": version = new SdkVersion(versionString); break; diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.cs.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.cs.xlf index b06621c3..3c7fb91f 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.cs.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.cs.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.de.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.de.xlf index a3f5e4ae..5a330ee8 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.de.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.de.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.es.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.es.xlf index 184aea80..837a49bc 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.es.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.es.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.fr.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.fr.xlf index 77a6a6bc..23f0a881 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.fr.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.fr.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.it.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.it.xlf index 2e97424e..7a3d508d 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.it.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.it.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.ja.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.ja.xlf index dc4ba0f2..f1d7b7b9 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.ja.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.ja.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.ko.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.ko.xlf index 3dd452b4..2576b369 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.ko.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.ko.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.pl.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.pl.xlf index a7668dad..c9dcdbc9 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.pl.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.pl.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.pt-BR.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.pt-BR.xlf index d691ab03..b6a8306d 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.pt-BR.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.pt-BR.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.ru.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.ru.xlf index 2cc92df9..ab503ee4 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.ru.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.ru.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.tr.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.tr.xlf index 7281cab0..0263e1fa 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.tr.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.tr.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.zh-Hans.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.zh-Hans.xlf index a6c1b832..cb97388f 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.zh-Hans.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.zh-Hans.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/src/dotnet-core-uninstall/xlf/LocalizableStrings.zh-Hant.xlf b/src/dotnet-core-uninstall/xlf/LocalizableStrings.zh-Hant.xlf index 2e22682d..a6fd4528 100644 --- a/src/dotnet-core-uninstall/xlf/LocalizableStrings.zh-Hant.xlf +++ b/src/dotnet-core-uninstall/xlf/LocalizableStrings.zh-Hant.xlf @@ -13,8 +13,8 @@ - Allowed values are "Y" and "n". - Allowed values are "Y" and "n". + Allowed values are "Y", "YES", and "N". + Allowed values are "Y", "YES", and "N". diff --git a/test/dotnet-core-uninstall.Tests/Shared/IntegrationTests/IntegrationTests.cs b/test/dotnet-core-uninstall.Tests/Shared/IntegrationTests/IntegrationTests.cs new file mode 100644 index 00000000..95e19cf5 --- /dev/null +++ b/test/dotnet-core-uninstall.Tests/Shared/IntegrationTests/IntegrationTests.cs @@ -0,0 +1,20 @@ +using System.CommandLine; +using System.CommandLine.Invocation; +using FluentAssertions; +using Microsoft.DotNet.Tools.Uninstall.Shared.Configs; +using Xunit; + +namespace Microsoft.DotNet.Tools.Uninstall.Tests.Shared.VSVersioning +{ + public class IntegrationTests + { + [Fact] + internal void VersionCommandOutputsVersionInfo() + { + var console = new TestConsole(); + var output = CommandLineConfigs.UninstallCommandParser.InvokeAsync(new string[1] { "--version" }, console); + output.Result.Should().Be(0); + console.Out.ToString().Should().Match("*.*.*"); + } + } +} From 50eb01aba2b2e2935c5d9c5e9a3b8761f4fe1660 Mon Sep 17 00:00:00 2001 From: sfoslund Date: Mon, 13 Jan 2020 13:35:27 -0800 Subject: [PATCH 2/5] Adding integration tests, fixing issues with list and dry run requirement filtering --- .../MacOs/FileSystemExplorer.cs | 22 ++-- src/dotnet-core-uninstall/Program.cs | 6 + .../Shared/Commands/CommandBundleFilter.cs | 27 +---- .../Shared/Commands/DryRunCommandExec.cs | 5 +- .../Shared/Commands/ListCommandExec.cs | 43 +++---- .../Shared/Commands/UninstallCommandExec.cs | 5 +- .../Shared/Configs/CommandLineConfigs.cs | 11 +- .../Shared/Utils/IBundleCollector.cs | 13 ++ .../VisualStudioSafeVersionsExtractor.cs | 2 +- .../Windows/RegistryQuery.cs | 27 +++-- .../IntegrationTests/IntegrationTests.cs | 111 +++++++++++++++++- .../Shared/VSVersioning/VSVersionTests.cs | 2 - .../TestUtils/MockRegistryQuery.cs | 41 +++++++ 13 files changed, 234 insertions(+), 81 deletions(-) create mode 100644 src/dotnet-core-uninstall/Shared/Utils/IBundleCollector.cs create mode 100644 test/dotnet-core-uninstall.Tests/TestUtils/MockRegistryQuery.cs diff --git a/src/dotnet-core-uninstall/MacOs/FileSystemExplorer.cs b/src/dotnet-core-uninstall/MacOs/FileSystemExplorer.cs index c41f5526..20cb032d 100644 --- a/src/dotnet-core-uninstall/MacOs/FileSystemExplorer.cs +++ b/src/dotnet-core-uninstall/MacOs/FileSystemExplorer.cs @@ -4,11 +4,11 @@ using System.Linq; using Microsoft.DotNet.Tools.Uninstall.Shared.BundleInfo; using Microsoft.DotNet.Tools.Uninstall.Shared.BundleInfo.Versioning; -using Microsoft.DotNet.Tools.Uninstall.Shared.VSVersioning; +using Microsoft.DotNet.Tools.Uninstall.Shared.Configs; namespace Microsoft.DotNet.Tools.Uninstall.MacOs { - internal static class FileSystemExplorer + internal class FileSystemExplorer : IBundleCollector { private static readonly string DotNetInstallPath = Path.Combine("/", "usr", "local", "share", "dotnet"); private static readonly string DotNetSdkInstallPath = Path.Combine(DotNetInstallPath, "sdk"); @@ -17,12 +17,7 @@ internal static class FileSystemExplorer private static readonly string DotNetAspAppInstallPath = Path.Combine(DotNetInstallPath, "shared", "Microsoft.AspNetCore.App"); private static readonly string DotNetHostFxrInstallPath = Path.Combine(DotNetInstallPath, "host", "fxr"); - public static IEnumerable GetInstalledBundles() - { - return VisualStudioSafeVersionsExtractor.GetUninstallableBundles(GetAllInstalledBundles()); - } - - public static IEnumerable GetAllInstalledBundles() + public virtual IEnumerable GetAllInstalledBundles() { var sdks = GetInstalledBundles(DotNetSdkInstallPath); var runtimes = GetInstalledBundles( @@ -34,7 +29,7 @@ public static IEnumerable GetAllInstalledBundles() return sdks.Concat(runtimes).ToList(); } - private static IEnumerable GetInstalledBundles(params string[] paths) + private IEnumerable GetInstalledBundles(params string[] paths) where TBundleVersion : BundleVersion, IComparable, new() { string bundleTypeString; @@ -55,7 +50,7 @@ private static IEnumerable GetInstalledBundles(params st string.Format(LocalizableStrings.MacOsBundleDisplayNameFormat, bundleTypeString, group.First().Version.ToString()))); } - private static IEnumerable<(TBundleVersion Version, string Path)> GetInstalledVersionsAndUninstallCommands(string path) + private IEnumerable<(TBundleVersion Version, string Path)> GetInstalledVersionsAndUninstallCommands(string path) where TBundleVersion : BundleVersion, IComparable, new() { return Directory.Exists(path) ? @@ -71,9 +66,14 @@ private static IEnumerable GetInstalledBundles(params st new List<(TBundleVersion Version, string Path)>(); } - private static string GetUninstallCommand(IEnumerable paths) + private string GetUninstallCommand(IEnumerable paths) { return string.Join(" ", paths); } + + public IEnumerable GetSupportedBundleTypes() + { + return MacOs.SupportedBundleTypeConfigs.SupportedBundleTypes; + } } } diff --git a/src/dotnet-core-uninstall/Program.cs b/src/dotnet-core-uninstall/Program.cs index 174b1eb0..f358fa9e 100644 --- a/src/dotnet-core-uninstall/Program.cs +++ b/src/dotnet-core-uninstall/Program.cs @@ -3,6 +3,8 @@ using System.CommandLine.Invocation; using Microsoft.DotNet.Tools.Uninstall.Shared.Configs; +using Microsoft.DotNet.Tools.Uninstall.Shared.Exceptions; +using Microsoft.DotNet.Tools.Uninstall.Shared.Utils; namespace Microsoft.DotNet.Tools.Uninstall { @@ -10,6 +12,10 @@ internal class Program { internal static int Main(string[] args) { + if (!(RuntimeInfo.RunningOnOSX || RuntimeInfo.RunningOnWindows)) + { + throw new OperatingSystemNotSupportedException(); + } return CommandLineConfigs.UninstallCommandParser.InvokeAsync(args).Result; } } diff --git a/src/dotnet-core-uninstall/Shared/Commands/CommandBundleFilter.cs b/src/dotnet-core-uninstall/Shared/Commands/CommandBundleFilter.cs index e9673f9e..2bc0884f 100644 --- a/src/dotnet-core-uninstall/Shared/Commands/CommandBundleFilter.cs +++ b/src/dotnet-core-uninstall/Shared/Commands/CommandBundleFilter.cs @@ -3,8 +3,6 @@ using Microsoft.DotNet.Tools.Uninstall.Shared.Configs; using Microsoft.DotNet.Tools.Uninstall.Shared.Exceptions; using Microsoft.DotNet.Tools.Uninstall.Shared.BundleInfo; -using Microsoft.DotNet.Tools.Uninstall.Shared.Utils; -using Microsoft.DotNet.Tools.Uninstall.Windows; using System.Reflection; using Microsoft.DotNet.Tools.Uninstall.MacOs; using System.Linq; @@ -31,23 +29,7 @@ internal static class CommandBundleFilter } }); - private static IEnumerable GetAllBundles() - { - if (RuntimeInfo.RunningOnWindows) - { - return RegistryQuery.GetAllInstalledBundles(); - } - else if (RuntimeInfo.RunningOnOSX) - { - return FileSystemExplorer.GetAllInstalledBundles(); - } - else - { - throw new OperatingSystemNotSupportedException(); - } - } - - public static IEnumerable GetFilteredBundles(IEnumerable bundles, ParseResult parseResult = null) + public static IEnumerable GetFilteredBundles(IEnumerable allBundles, ParseResult parseResult = null) { if (parseResult == null) { @@ -57,6 +39,7 @@ public static IEnumerable GetFilteredBundles(IEnumerable bundles var option = parseResult.CommandResult.GetUninstallMainOption(); var typeSelection = parseResult.CommandResult.GetTypeSelection(); var archSelection = parseResult.CommandResult.GetArchSelection(); + var bundles = allBundles; if (option == null) { @@ -83,7 +66,7 @@ public static IEnumerable GetFilteredBundles(IEnumerable bundles if (parseResult.CommandResult.OptionResult(CommandLineConfigs.ForceOption.Name) == null) { - bundles = FilterRequiredBundles(bundles, parseResult.CommandResult.Tokens); + bundles = FilterRequiredBundles(allBundles, parseResult.CommandResult.Tokens).Intersect(bundles); } if (bundles.Any(bundle => bundle.Version.SemVer >= VisualStudioSafeVersionsExtractor.UpperLimit)) { @@ -92,9 +75,9 @@ public static IEnumerable GetFilteredBundles(IEnumerable bundles return bundles; } - public static IDictionary GetFilteredWithRequirementStrings() + public static IDictionary GetFilteredWithRequirementStrings(IBundleCollector bundleCollector) { - var allBundles = GetAllBundles(); + var allBundles = bundleCollector.GetAllInstalledBundles(); var filteredBundles = GetFilteredBundles(allBundles); return VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(allBundles) .Where(pair => filteredBundles.Contains(pair.Key)) diff --git a/src/dotnet-core-uninstall/Shared/Commands/DryRunCommandExec.cs b/src/dotnet-core-uninstall/Shared/Commands/DryRunCommandExec.cs index dfa97a6c..f93f3fcd 100644 --- a/src/dotnet-core-uninstall/Shared/Commands/DryRunCommandExec.cs +++ b/src/dotnet-core-uninstall/Shared/Commands/DryRunCommandExec.cs @@ -3,16 +3,17 @@ using Microsoft.DotNet.Tools.Uninstall.Shared.BundleInfo; using System.Linq; using Microsoft.DotNet.Tools.Uninstall.Shared.Utils; +using Microsoft.DotNet.Tools.Uninstall.MacOs; namespace Microsoft.DotNet.Tools.Uninstall.Shared.Commands { internal static class DryRunCommandExec { - public static void Execute() + public static void Execute(IBundleCollector bundleCollector) { CommandBundleFilter.HandleVersionOption(); - var filtered = CommandBundleFilter.GetFilteredWithRequirementStrings(); + var filtered = CommandBundleFilter.GetFilteredWithRequirementStrings(bundleCollector); TryIt(filtered); } diff --git a/src/dotnet-core-uninstall/Shared/Commands/ListCommandExec.cs b/src/dotnet-core-uninstall/Shared/Commands/ListCommandExec.cs index d89af425..4653f1b5 100644 --- a/src/dotnet-core-uninstall/Shared/Commands/ListCommandExec.cs +++ b/src/dotnet-core-uninstall/Shared/Commands/ListCommandExec.cs @@ -8,33 +8,25 @@ using Microsoft.DotNet.Tools.Uninstall.Shared.BundleInfo; using Microsoft.DotNet.Tools.Uninstall.Shared.Configs; using Microsoft.DotNet.Tools.Uninstall.Shared.Configs.Verbosity; -using Microsoft.DotNet.Tools.Uninstall.Shared.Exceptions; using Microsoft.DotNet.Tools.Uninstall.Shared.Utils; using Microsoft.DotNet.Tools.Uninstall.Shared.VSVersioning; -using Microsoft.DotNet.Tools.Uninstall.Windows; namespace Microsoft.DotNet.Tools.Uninstall.Shared.Commands { internal static class ListCommandExec { - public static void Execute() + private static IConsole SysConsole; + private static Region Region; + private static string[] Args; + + public static void Execute(IBundleCollector bundleCollector, IConsole console = null, Region region = null, string[] args = null) { - if (RuntimeInfo.RunningOnWindows) - { - Execute( - RegistryQuery.GetAllInstalledBundles(), - Windows.SupportedBundleTypeConfigs.SupportedBundleTypes); - } - else if (RuntimeInfo.RunningOnOSX) - { - Execute( - FileSystemExplorer.GetAllInstalledBundles(), - MacOs.SupportedBundleTypeConfigs.SupportedBundleTypes); - } - else - { - throw new OperatingSystemNotSupportedException(); - } + SysConsole = console == null? new SystemConsole() : console; + Region = region == null? new Region(0, 0, Console.WindowWidth, int.MaxValue) : region; + Args = args == null? Environment.GetCommandLineArgs(): args; + Execute( + bundleCollector.GetAllInstalledBundles(), + bundleCollector.GetSupportedBundleTypes()); } private static void Execute( @@ -43,7 +35,9 @@ private static void Execute( { Console.WriteLine(RuntimeInfo.RunningOnWindows ? LocalizableStrings.WindowsListCommandOutput : LocalizableStrings.MacListCommandOutput); - var listCommandParseResult = CommandLineConfigs.ListCommand.Parse(Environment.GetCommandLineArgs()); + var uninstallMap = VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(bundles); + + var listCommandParseResult = CommandLineConfigs.ListCommand.Parse(Args); var verbose = listCommandParseResult.CommandResult.GetVerbosityLevel().Equals(VerbosityLevel.Detailed) || listCommandParseResult.CommandResult.GetVerbosityLevel().Equals(VerbosityLevel.Diagnostic); @@ -63,11 +57,10 @@ private static void Execute( { var filteredBundlesByType = bundleType .Filter(filteredBundlesByArch); - - var uninstallMap = VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(filteredBundlesByType); + var filteredWithStrings = uninstallMap.Where(pair => filteredBundlesByType.Contains(pair.Key)).ToDictionary(i => i.Key, i => i.Value); stackView.Add(new ContentView(bundleType.Header)); - stackView.Add(bundleType.GridViewGenerator.Invoke(uninstallMap, verbose)); + stackView.Add(bundleType.GridViewGenerator.Invoke(filteredWithStrings, verbose)); stackView.Add(new ContentView(string.Empty)); footnotes.AddRange(filteredBundlesByType @@ -87,8 +80,8 @@ private static void Execute( } stackView.Render( - new ConsoleRenderer(new SystemConsole()), - new Region(0, 0, Console.WindowWidth, int.MaxValue)); + new ConsoleRenderer(SysConsole), + Region); } } } diff --git a/src/dotnet-core-uninstall/Shared/Commands/UninstallCommandExec.cs b/src/dotnet-core-uninstall/Shared/Commands/UninstallCommandExec.cs index 16d70efd..33186ec1 100644 --- a/src/dotnet-core-uninstall/Shared/Commands/UninstallCommandExec.cs +++ b/src/dotnet-core-uninstall/Shared/Commands/UninstallCommandExec.cs @@ -11,6 +11,7 @@ using System.Security.Principal; using System.Runtime.InteropServices; using System.ComponentModel; +using Microsoft.DotNet.Tools.Uninstall.MacOs; namespace Microsoft.DotNet.Tools.Uninstall.Shared.Commands { @@ -26,11 +27,11 @@ private static extern IntPtr CommandLineToArgvW( [MarshalAs(UnmanagedType.LPWStr)] string lpCmdLine, out int pNumArgs); - public static void Execute() + public static void Execute(IBundleCollector bundleCollector) { CommandBundleFilter.HandleVersionOption(); - var filtered = CommandBundleFilter.GetFilteredWithRequirementStrings(); + var filtered = CommandBundleFilter.GetFilteredWithRequirementStrings(bundleCollector); if (CommandLineConfigs.CommandLineParseResult.CommandResult.OptionResult(CommandLineConfigs.YesOption.Name) != null) { diff --git a/src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs b/src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs index 9d66277b..18293a15 100644 --- a/src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs +++ b/src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs @@ -4,11 +4,13 @@ using System.CommandLine.Builder; using System.CommandLine.Invocation; using System.Linq; +using Microsoft.DotNet.Tools.Uninstall.MacOs; using Microsoft.DotNet.Tools.Uninstall.Shared.BundleInfo; using Microsoft.DotNet.Tools.Uninstall.Shared.Commands; using Microsoft.DotNet.Tools.Uninstall.Shared.Configs.Verbosity; using Microsoft.DotNet.Tools.Uninstall.Shared.Exceptions; using Microsoft.DotNet.Tools.Uninstall.Shared.Utils; +using Microsoft.DotNet.Tools.Uninstall.Windows; namespace Microsoft.DotNet.Tools.Uninstall.Shared.Configs { @@ -177,7 +179,7 @@ internal static class CommandLineConfigs { "diag", VerbosityLevel.Diagnostic }, { "diagnostic", VerbosityLevel.Diagnostic } }; - public static readonly ParseResult CommandLineParseResult; + public static ParseResult CommandLineParseResult; public static readonly IEnumerable