Skip to content

Commit

Permalink
Merge pull request #111 from sfoslund/FixingGithubIssues
Browse files Browse the repository at this point in the history
Fixing Issues from manual testing
  • Loading branch information
sfoslund authored Jan 17, 2020
2 parents 56fb651 + 36aa40d commit 6fc40ba
Show file tree
Hide file tree
Showing 31 changed files with 342 additions and 135 deletions.
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
16 changes: 8 additions & 8 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 Down Expand Up @@ -75,5 +70,10 @@ private static 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
72 changes: 31 additions & 41 deletions src/dotnet-core-uninstall/Shared/Commands/ListCommandExec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,18 @@
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()
public static void Execute(IBundleCollector bundleCollector)
{
if (RuntimeInfo.RunningOnWindows)
{
Execute(
RegistryQuery.GetAllInstalledBundles(),
Windows.SupportedBundleTypeConfigs.SupportedBundleTypes);
}
else if (RuntimeInfo.RunningOnOSX)
{
Execute(
FileSystemExplorer.GetAllInstalledBundles(),
MacOs.SupportedBundleTypeConfigs.SupportedBundleTypes);
}
else
{
throw new OperatingSystemNotSupportedException();
}
Execute(
bundleCollector.GetAllInstalledBundles(),
bundleCollector.GetSupportedBundleTypes());
}

private static void Execute(
Expand All @@ -44,36 +29,23 @@ private static void Execute(
Console.WriteLine(RuntimeInfo.RunningOnWindows ? LocalizableStrings.WindowsListCommandOutput : LocalizableStrings.MacListCommandOutput);

var listCommandParseResult = CommandLineConfigs.ListCommand.Parse(Environment.GetCommandLineArgs());

var verbose = listCommandParseResult.CommandResult.GetVerbosityLevel().Equals(VerbosityLevel.Detailed) ||
listCommandParseResult.CommandResult.GetVerbosityLevel().Equals(VerbosityLevel.Diagnostic);
var typeSelection = listCommandParseResult.CommandResult.GetTypeSelection();
var archSelection = listCommandParseResult.CommandResult.GetArchSelection();

var stackView = new StackLayoutView();

var filteredBundlesByArch = bundles.Where(bundle => archSelection.HasFlag(bundle.Arch));

var sortedBundles = GetFilteredBundlesWithRequirements(bundles, supportedBundleTypes, listCommandParseResult);

var stackView = new StackLayoutView();
var footnotes = new List<string>();

foreach (var bundleType in supportedBundleTypes)
foreach ((var bundleType, var filteredBundles) in sortedBundles)
{
if (typeSelection.HasFlag(bundleType.Type))
{
var filteredBundlesByType = bundleType
.Filter(filteredBundlesByArch);

var uninstallMap = VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(filteredBundlesByType);

stackView.Add(new ContentView(bundleType.Header));
stackView.Add(bundleType.GridViewGenerator.Invoke(uninstallMap, verbose));
stackView.Add(new ContentView(string.Empty));
stackView.Add(new ContentView(bundleType.Header));
stackView.Add(bundleType.GridViewGenerator.Invoke(filteredBundles, verbose));
stackView.Add(new ContentView(string.Empty));

footnotes.AddRange(filteredBundlesByType
.Where(bundle => bundle.Version.HasFootnote)
.Select(bundle => bundle.Version.Footnote));
}
footnotes.AddRange(filteredBundles
.Where(bundle => bundle.Key.Version.HasFootnote)
.Select(bundle => bundle.Key.Version.Footnote));
}

foreach (var footnote in footnotes)
Expand All @@ -90,5 +62,23 @@ private static void Execute(
new ConsoleRenderer(new SystemConsole()),
new Region(0, 0, Console.WindowWidth, int.MaxValue));
}

public static Dictionary<BundleTypePrintInfo, Dictionary<Bundle, string>> GetFilteredBundlesWithRequirements(
IEnumerable<Bundle> bundles,
IEnumerable<BundleTypePrintInfo> supportedBundleTypes,
ParseResult parseResult)
{
var uninstallMap = VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(bundles);

var typeSelection = parseResult.CommandResult.GetTypeSelection();
var archSelection = parseResult.CommandResult.GetArchSelection();

var filteredBundlesByArch = bundles.Where(bundle => archSelection.HasFlag(bundle.Arch));

return supportedBundleTypes.Where(type => typeSelection.HasFlag(type.Type))
.Select(type => new KeyValuePair<BundleTypePrintInfo, Dictionary<Bundle, string>>(type,
uninstallMap.Where(pair => type.Filter(filteredBundlesByArch).Contains(pair.Key)).ToDictionary(i => i.Key, i => i.Value)))
.ToDictionary(i => i.Key, i => i.Value);
}
}
}
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 @@ -207,15 +208,15 @@ private static IEnumerable<string> ParseCommandToArgs(string command)
return args;
}

private static bool AskItAndReturnUserAnswer(IDictionary<Bundle, string> bundles)
public static bool AskItAndReturnUserAnswer(IDictionary<Bundle, string> bundles, string userResponse = null)
{
var displayNames = string.Join("\n", bundles.Select(bundle => $" {bundle.Key.DisplayName}"));
Console.Write(string.Format(RuntimeInfo.RunningOnWindows ? LocalizableStrings.WindowsConfirmationPromptOutputFormat :
LocalizableStrings.MacConfirmationPromptOutputFormat, displayNames));

var response = Console.ReadLine().Trim().ToUpper();
var response = userResponse == null ? Console.ReadLine().Trim().ToUpper() : userResponse.ToUpper();

if (response.Equals("Y"))
if (response.Equals("Y") || response.Equals("YES"))
{
return true;
}
Expand All @@ -229,7 +230,7 @@ private static bool AskItAndReturnUserAnswer(IDictionary<Bundle, string> bundles
}
}

private static bool AskWithWarningsForRequiredBundles(IDictionary<Bundle, string> bundles)
public static bool AskWithWarningsForRequiredBundles(IDictionary<Bundle, string> bundles, string userResponse = null)
{
var requiredBundles = bundles.Where(b => !b.Value.Equals(string.Empty));
foreach (var pair in requiredBundles)
Expand All @@ -238,12 +239,12 @@ private static bool AskWithWarningsForRequiredBundles(IDictionary<Bundle, string
Console.Write(string.Format(RuntimeInfo.RunningOnWindows ? LocalizableStrings.WindowsRequiredBundleConfirmationPromptOutputFormat :
LocalizableStrings.MacRequiredBundleConfirmationPromptOutputFormat, pair.Key.DisplayName, pair.Value));
Console.ResetColor();
var response = Console.ReadLine().Trim().ToUpper();
var response = userResponse == null ? Console.ReadLine().Trim().ToUpper() : userResponse.ToUpper();
if (response.Equals("N"))
{
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();
}
}
Loading

0 comments on commit 6fc40ba

Please sign in to comment.