Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing Issues from manual testing #111

Merged
merged 5 commits into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dotnet-core-uninstall/LocalizableStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/dotnet-core-uninstall/LocalizableStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -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] </value>
</data>
<data name="ConfirmationPromptInvalidExceptionMessage" xml:space="preserve">
<value>Allowed values are "Y" and "n".</value>
<value>Allowed values are "Y", "YES", and "N".</value>
</data>
<data name="RemoveCommandDescription" xml:space="preserve">
<value>Remove the specified .NET Core SDKs or Runtimes.</value>
Expand Down
22 changes: 11 additions & 11 deletions src/dotnet-core-uninstall/MacOs/FileSystemExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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<Bundle> GetInstalledBundles()
{
return VisualStudioSafeVersionsExtractor.GetUninstallableBundles(GetAllInstalledBundles());
}

public static IEnumerable<Bundle> GetAllInstalledBundles()
public virtual IEnumerable<Bundle> GetAllInstalledBundles()
{
var sdks = GetInstalledBundles<SdkVersion>(DotNetSdkInstallPath);
var runtimes = GetInstalledBundles<RuntimeVersion>(
Expand All @@ -34,7 +29,7 @@ public static IEnumerable<Bundle> GetAllInstalledBundles()
return sdks.Concat(runtimes).ToList();
}

private static IEnumerable<Bundle> GetInstalledBundles<TBundleVersion>(params string[] paths)
private IEnumerable<Bundle> GetInstalledBundles<TBundleVersion>(params string[] paths)
where TBundleVersion : BundleVersion, IComparable<TBundleVersion>, new()
{
string bundleTypeString;
Expand All @@ -55,7 +50,7 @@ private static IEnumerable<Bundle> GetInstalledBundles<TBundleVersion>(params st
string.Format(LocalizableStrings.MacOsBundleDisplayNameFormat, bundleTypeString, group.First().Version.ToString())));
}

private static IEnumerable<(TBundleVersion Version, string Path)> GetInstalledVersionsAndUninstallCommands<TBundleVersion>(string path)
private IEnumerable<(TBundleVersion Version, string Path)> GetInstalledVersionsAndUninstallCommands<TBundleVersion>(string path)
where TBundleVersion : BundleVersion, IComparable<TBundleVersion>, new()
{
return Directory.Exists(path) ?
Expand All @@ -71,9 +66,14 @@ private static IEnumerable<Bundle> GetInstalledBundles<TBundleVersion>(params st
new List<(TBundleVersion Version, string Path)>();
}

private static string GetUninstallCommand(IEnumerable<string> paths)
private string GetUninstallCommand(IEnumerable<string> paths)
{
return string.Join(" ", paths);
}

public IEnumerable<BundleTypePrintInfo> GetSupportedBundleTypes()
{
return MacOs.SupportedBundleTypeConfigs.SupportedBundleTypes;
}
}
}
6 changes: 6 additions & 0 deletions src/dotnet-core-uninstall/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@

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
{
internal class Program
{
internal static int Main(string[] args)
{
if (!(RuntimeInfo.RunningOnOSX || RuntimeInfo.RunningOnWindows))
{
throw new OperatingSystemNotSupportedException();
}
return CommandLineConfigs.UninstallCommandParser.InvokeAsync(args).Result;
}
}
Expand Down
27 changes: 5 additions & 22 deletions src/dotnet-core-uninstall/Shared/Commands/CommandBundleFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,23 +29,7 @@ internal static class CommandBundleFilter
}
});

private static IEnumerable<Bundle> GetAllBundles()
{
if (RuntimeInfo.RunningOnWindows)
{
return RegistryQuery.GetAllInstalledBundles();
}
else if (RuntimeInfo.RunningOnOSX)
{
return FileSystemExplorer.GetAllInstalledBundles();
}
else
{
throw new OperatingSystemNotSupportedException();
}
}

public static IEnumerable<Bundle> GetFilteredBundles(IEnumerable<Bundle> bundles, ParseResult parseResult = null)
public static IEnumerable<Bundle> GetFilteredBundles(IEnumerable<Bundle> allBundles, ParseResult parseResult = null)
{
if (parseResult == null)
{
Expand All @@ -57,6 +39,7 @@ public static IEnumerable<Bundle> GetFilteredBundles(IEnumerable<Bundle> bundles
var option = parseResult.CommandResult.GetUninstallMainOption();
var typeSelection = parseResult.CommandResult.GetTypeSelection();
var archSelection = parseResult.CommandResult.GetArchSelection();
var bundles = allBundles;

if (option == null)
{
Expand All @@ -83,7 +66,7 @@ public static IEnumerable<Bundle> GetFilteredBundles(IEnumerable<Bundle> 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))
{
Expand All @@ -92,9 +75,9 @@ public static IEnumerable<Bundle> GetFilteredBundles(IEnumerable<Bundle> bundles
return bundles;
}

public static IDictionary<Bundle, string> GetFilteredWithRequirementStrings()
public static IDictionary<Bundle, string> GetFilteredWithRequirementStrings(IBundleCollector bundleCollector)
{
var allBundles = GetAllBundles();
var allBundles = bundleCollector.GetAllInstalledBundles();
var filteredBundles = GetFilteredBundles(allBundles);
return VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(allBundles)
.Where(pair => filteredBundles.Contains(pair.Key))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
43 changes: 18 additions & 25 deletions src/dotnet-core-uninstall/Shared/Commands/ListCommandExec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
sfoslund marked this conversation as resolved.
Show resolved Hide resolved
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(
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -215,7 +216,7 @@ private static bool AskItAndReturnUserAnswer(IDictionary<Bundle, string> bundles

var response = Console.ReadLine().Trim().ToUpper();

if (response.Equals("Y"))
if (response.Equals("Y") || response.Equals("YES"))
sfoslund marked this conversation as resolved.
Show resolved Hide resolved
{
return true;
}
Expand Down Expand Up @@ -243,7 +244,7 @@ private static bool AskWithWarningsForRequiredBundles(IDictionary<Bundle, string
{
return false ;
}
else if (!response.Equals("Y"))
else if (!(response.Equals("Y") || response.Equals("YES")))
{
throw new ConfirmationPromptInvalidException();
}
Expand Down
13 changes: 8 additions & 5 deletions src/dotnet-core-uninstall/Shared/Configs/CommandLineConfigs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -177,15 +179,14 @@ internal static class CommandLineConfigs
{ "diag", VerbosityLevel.Diagnostic }, { "diagnostic", VerbosityLevel.Diagnostic }
};

public static readonly ParseResult CommandLineParseResult;
public static ParseResult CommandLineParseResult;
public static readonly IEnumerable<Option> RemoveAuxOptions;
public static readonly IEnumerable<Option> DryRunAuxOptions;
public static readonly IEnumerable<Option> WhatIfAuxOptions;
public static readonly IEnumerable<Option> ListAuxOptions;

static CommandLineConfigs()
{
UninstallRootCommand.AddOption(new Option("--version", LocalizableStrings.VersionOptionDescription));
DryRunCommand.AddAlias(WhatIfCommandName);

UninstallRootCommand.AddCommand(ListCommand);
Expand Down Expand Up @@ -226,12 +227,14 @@ static CommandLineConfigs()
}
AssignOptionsToCommand(ListCommand, ListAuxOptions);

ListCommand.Handler = CommandHandler.Create(ExceptionHandler.HandleException(() => ListCommandExec.Execute()));
DryRunCommand.Handler = CommandHandler.Create(ExceptionHandler.HandleException(() => DryRunCommandExec.Execute()));
RemoveCommand.Handler = CommandHandler.Create(ExceptionHandler.HandleException(() => UninstallCommandExec.Execute()));
var bundleCollector = RuntimeInfo.RunningOnWindows ? new RegistryQuery() as IBundleCollector : new FileSystemExplorer() as IBundleCollector;
ListCommand.Handler = CommandHandler.Create(ExceptionHandler.HandleException(() => ListCommandExec.Execute(bundleCollector)));
DryRunCommand.Handler = CommandHandler.Create(ExceptionHandler.HandleException(() => DryRunCommandExec.Execute(bundleCollector)));
RemoveCommand.Handler = CommandHandler.Create(ExceptionHandler.HandleException(() => UninstallCommandExec.Execute(bundleCollector)));

UninstallCommandParser = new CommandLineBuilder(UninstallRootCommand)
.UseDefaults()
.UseVersionOption()
.UseHelpBuilder(context => new UninstallHelpBuilder(context.Console))
.Build();
CommandLineParseResult = UninstallCommandParser.Parse(Environment.GetCommandLineArgs());
Expand Down
13 changes: 13 additions & 0 deletions src/dotnet-core-uninstall/Shared/Utils/IBundleCollector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using Microsoft.DotNet.Tools.Uninstall.Shared.BundleInfo;
using Microsoft.DotNet.Tools.Uninstall.Shared.Configs;

namespace Microsoft.DotNet.Tools.Uninstall.MacOs
{
internal interface IBundleCollector
{
public IEnumerable<Bundle> GetAllInstalledBundles();

public IEnumerable<BundleTypePrintInfo> GetSupportedBundleTypes();
}
}
4 changes: 3 additions & 1 deletion src/dotnet-core-uninstall/Shared/Utils/Regexes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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()})$");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static Dictionary<Bundle, string> GetReasonRequiredStrings(IEnumerable<Bu
}

return requirementStringResults
.OrderByDescending(pair => pair.bundle)
.OrderByDescending(pair => pair.bundle.DisplayName)
.ToDictionary(i => i.bundle, i => i.Item2);
}
}
Expand Down
Loading