Skip to content

Commit

Permalink
[GR-47829] No more default choice for fetch-jdk
Browse files Browse the repository at this point in the history
PullRequest: mx/1652
  • Loading branch information
zapster committed Aug 10, 2023
2 parents 5e967b7 + ef1fdd4 commit f7b5b9b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
2 changes: 1 addition & 1 deletion mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18590,7 +18590,7 @@ def alarm_handler(signum, frame):
abort(1, killsig=signal.SIGINT)

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("6.39.2") # LayoutDirDistribution does proper needsRebuild check
version = VersionSpec("6.40.0") # not more default choice for mx fetch-jdk

_mx_start_datetime = datetime.utcnow()
_last_timestamp = _mx_start_datetime
Expand Down
29 changes: 12 additions & 17 deletions mx_fetchjdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,10 @@ def _parse_args(args):
if jdk_id is not None:
settings["jdk-binary"] = _get_jdk_binary_or_abort(jdk_binaries, jdk_id)
else:
settings["jdk-binary"] = _choose_jdk_binary(jdk_binaries, is_quiet())
if is_quiet():
parser.print_usage()
mx.abort('A <jdk-id> must be provided in quiet mode.')
settings["jdk-binary"] = _choose_jdk_binary(jdk_binaries)

if args.alias is not None:
if args.alias == "-":
Expand Down Expand Up @@ -469,20 +472,11 @@ def _get_extracted_jdk_archive_root_folder(extracted_archive_path):
return root_folders[0]


def _choose_jdk_binary(jdk_binaries, quiet=False):
if quiet:
return _get_jdk_binary_or_abort(jdk_binaries, _DEFAULT_JDK_ID)

def _choose_jdk_binary(jdk_binaries):
index = 1
default_choice = 1
choices = sorted(jdk_binaries.items())
for jdk_id, jdk_binary in choices:
if jdk_id == _DEFAULT_JDK_ID:
default_choice = index
default = "*"
else:
default = " "
prefix = f'[{index}]{default}'
prefix = f'[{index}]'

print(f"{prefix:5} {jdk_id.ljust(25)} | {jdk_binary.selector()}")
index += 1
Expand All @@ -495,9 +489,11 @@ def _choose_jdk_binary(jdk_binaries, quiet=False):
choice = ""

if choice == "":
index = default_choice - 1
else:
raise IndexError('<empty>')
try:
index = int(choice) - 1
except ValueError:
raise IndexError(choice)

if index < 0:
raise IndexError(choice)
Expand All @@ -514,9 +510,8 @@ def _choose_jdk_binary(jdk_binaries, quiet=False):
return choices[index][1]
except (NameError, IndexError) as e:
mx.warn(f"Invalid selection: {e}")


_DEFAULT_JDK_ID = "labsjdk-ce-20"
except EOFError:
mx.abort(1)


class _JdkBinary(object):
Expand Down

0 comments on commit f7b5b9b

Please sign in to comment.