Skip to content

Commit

Permalink
Merge pull request #31 from nils-a/release/0.2.1
Browse files Browse the repository at this point in the history
release/0.2.1
  • Loading branch information
nils-a authored Jun 23, 2021
2 parents 6bf0b80 + 7debd08 commit f5afa8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/JavaVersionSwitcher/Adapters/StorageAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class StorageAdapter : IStorageAdapter
public string ConfigurationFilePath => GetPath("settings.xml");

/// <inheritdoc cref="IStorageAdapter.JavaInstallationCacheFilePath"/>
public string JavaInstallationCacheFilePath => GetPath("");
public string JavaInstallationCacheFilePath => GetPath("installations.xml");

private string GetPath(string fileName)
{
Expand Down
22 changes: 10 additions & 12 deletions src/JavaVersionSwitcher/Commands/SwitchVersionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,13 @@ public override async Task<int> ExecuteAsync(CommandContext context, Settings se
.GetJavaInstallations()
.ConfigureAwait(false);

var selected = AnsiConsole.Prompt(
var newJavaHome = AnsiConsole.Prompt(
new SelectionPrompt<string>()
.Title("Which java should be set?")
.PageSize(25)
.MoreChoicesText("[grey](Move up and down to reveal more installations)[/]")
.AddChoices(installations.Select(x => x.Location).ToArray())
);

string javaHome = null;
.AddChoices(installations.Select(x => x.Location).ToArray()));

string javaBin = null;
await AnsiConsole.Status()
.StartAsync("Applying...", async ctx =>
Expand All @@ -72,17 +70,17 @@ await AnsiConsole.Status()
? EnvironmentScope.Machine
: EnvironmentScope.User;

javaHome = await _javaHomeAdapter.GetValue(EnvironmentScope.Process);
var oldJavaHome = await _javaHomeAdapter.GetValue(EnvironmentScope.Process);
var paths = (await _pathAdapter.GetValue(scope)).ToList();
if (!string.IsNullOrEmpty(javaHome))
if (!string.IsNullOrEmpty(oldJavaHome))
{
paths = paths.Where(x => !x.StartsWith(javaHome,StringComparison.OrdinalIgnoreCase)).ToList();
paths = paths.Where(x => !x.StartsWith(oldJavaHome,StringComparison.OrdinalIgnoreCase)).ToList();
}

javaBin = Path.Combine(selected, "bin");
javaBin = Path.Combine(newJavaHome, "bin");
paths.Add(javaBin);

await _javaHomeAdapter.SetValue(selected, scope);
await _javaHomeAdapter.SetValue(newJavaHome, scope);
await _pathAdapter.SetValue(paths, scope);
}).ConfigureAwait(false);

Expand All @@ -91,11 +89,11 @@ await AnsiConsole.Status()
switch (shellType)
{
case ShellType.PowerShell:
refreshCommands.Add($"$env:JAVA_HOME=\"{javaHome}\"");
refreshCommands.Add($"$env:JAVA_HOME=\"{newJavaHome}\"");
refreshCommands.Add($"$env:PATH=\"{javaBin}{Path.PathSeparator}$($env:PATH)\"");
break;
case ShellType.CommandPrompt:
refreshCommands.Add($"set \"JAVA_HOME={javaHome}\"");
refreshCommands.Add($"set \"JAVA_HOME={newJavaHome}\"");
refreshCommands.Add($"set \"PATH={javaBin}{Path.PathSeparator}%PATH%\"");
break;
}
Expand Down

0 comments on commit f5afa8e

Please sign in to comment.