@@ -52,15 +52,13 @@ public override async Task<int> ExecuteAsync(CommandContext context, Settings se
5252 . GetJavaInstallations ( )
5353 . ConfigureAwait ( false ) ;
5454
55- var selected = AnsiConsole . Prompt (
55+ var newJavaHome = AnsiConsole . Prompt (
5656 new SelectionPrompt < string > ( )
5757 . Title ( "Which java should be set?" )
5858 . PageSize ( 25 )
5959 . MoreChoicesText ( "[grey](Move up and down to reveal more installations)[/]" )
60- . AddChoices ( installations . Select ( x => x . Location ) . ToArray ( ) )
61- ) ;
62-
63- string javaHome = null ;
60+ . AddChoices ( installations . Select ( x => x . Location ) . ToArray ( ) ) ) ;
61+
6462 string javaBin = null ;
6563 await AnsiConsole . Status ( )
6664 . StartAsync ( "Applying..." , async ctx =>
@@ -72,17 +70,17 @@ await AnsiConsole.Status()
7270 ? EnvironmentScope . Machine
7371 : EnvironmentScope . User ;
7472
75- javaHome = await _javaHomeAdapter . GetValue ( EnvironmentScope . Process ) ;
73+ var oldJavaHome = await _javaHomeAdapter . GetValue ( EnvironmentScope . Process ) ;
7674 var paths = ( await _pathAdapter . GetValue ( scope ) ) . ToList ( ) ;
77- if ( ! string . IsNullOrEmpty ( javaHome ) )
75+ if ( ! string . IsNullOrEmpty ( oldJavaHome ) )
7876 {
79- paths = paths . Where ( x => ! x . StartsWith ( javaHome , StringComparison . OrdinalIgnoreCase ) ) . ToList ( ) ;
77+ paths = paths . Where ( x => ! x . StartsWith ( oldJavaHome , StringComparison . OrdinalIgnoreCase ) ) . ToList ( ) ;
8078 }
8179
82- javaBin = Path . Combine ( selected , "bin" ) ;
80+ javaBin = Path . Combine ( newJavaHome , "bin" ) ;
8381 paths . Add ( javaBin ) ;
8482
85- await _javaHomeAdapter . SetValue ( selected , scope ) ;
83+ await _javaHomeAdapter . SetValue ( newJavaHome , scope ) ;
8684 await _pathAdapter . SetValue ( paths , scope ) ;
8785 } ) . ConfigureAwait ( false ) ;
8886
@@ -91,11 +89,11 @@ await AnsiConsole.Status()
9189 switch ( shellType )
9290 {
9391 case ShellType . PowerShell :
94- refreshCommands . Add ( $ "$env:JAVA_HOME=\" { javaHome } \" ") ;
92+ refreshCommands . Add ( $ "$env:JAVA_HOME=\" { newJavaHome } \" ") ;
9593 refreshCommands . Add ( $ "$env:PATH=\" { javaBin } { Path . PathSeparator } $($env:PATH)\" ") ;
9694 break ;
9795 case ShellType . CommandPrompt :
98- refreshCommands . Add ( $ "set \" JAVA_HOME={ javaHome } \" ") ;
96+ refreshCommands . Add ( $ "set \" JAVA_HOME={ newJavaHome } \" ") ;
9997 refreshCommands . Add ( $ "set \" PATH={ javaBin } { Path . PathSeparator } %PATH%\" ") ;
10098 break ;
10199 }
0 commit comments