Skip to content

Commit 8b72e22

Browse files
committed
Change autoscan default name to Java major version
1 parent df3c1d8 commit 8b72e22

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/jenv-autoscan.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function Invoke-AutoScan {
4747

4848
# Ask user if java.exe should be added to the list
4949
foreach ($java in $javaExecutables) {
50-
$version = Get-JavaVersion $java
50+
$version = Get-JavaMajorVersion $java
5151
switch (Open-Prompt "JEnv autoscan" ("Found java.exe at {0}. Default name is: '{1}'. Do you want to add it to the list?" -f $java, $version) "Yes", "No", "Rename" ("This will add {0} with alias '{1}' to JEnv" -f $java, $version), ("Skip {0}" -f $java), "Change the default name" 1) {
5252
0 {
5353
Invoke-Add $config $false $version ($java -replace "\\bin\\java\.exe$", "")

src/util.psm1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,16 @@ function Get-JavaVersion {
2222
$version = (Get-Command $javaexe | Select-Object -ExpandProperty Version).toString()
2323
$version = $version -replace "(?>\.0)*(?!.+)", "" # Remove trailing zeros
2424
return $version
25+
}
26+
27+
function Get-JavaMajorVersion {
28+
param (
29+
[Parameter(Mandatory = $true)][string]$javaexe
30+
)
31+
$version = Get-JavaVersion $javaexe
32+
$endIndex = $version.IndexOf(".")
33+
if ($version.StartsWith("1.")) {
34+
$endIndex = $version.IndexOf(".", $endIndex + 1)
35+
}
36+
return $version.Substring(0, $endIndex)
2537
}

0 commit comments

Comments
 (0)