Skip to content

Commit c340be7

Browse files
rakillenrobertpatrick
authored andcommitted
Only use JLine with Java 1.8.0 and higher
1 parent 3275bd2 commit c340be7

File tree

2 files changed

+32
-16
lines changed

2 files changed

+32
-16
lines changed

core/src/main/python/wlsdeploy/tool/modelhelp/model_help_interactive_printer.py

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
"""
2-
Copyright (c) 2020, 2023, Oracle and/or its affiliates.
2+
Copyright (c) 2020, 2024, Oracle and/or its affiliates.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
55
import re
6+
import sys
67

7-
from org.jline.terminal import TerminalBuilder
8-
from org.jline.reader import LineReaderBuilder
9-
from org.jline.reader.impl.completer import StringsCompleter
108
from oracle.weblogic.deploy.util import CLAException
119

12-
# Jython tools don't require sys.path modification
1310
from wlsdeploy.exception import exception_helper
1411
from wlsdeploy.tool.modelhelp.model_help_printer import ModelHelpPrinter
1512
from wlsdeploy.tool.modelhelp.model_help_utils import ControlOptions
1613
from wlsdeploy.tool.modelhelp.model_help_utils import PathOptions
17-
from wlsdeploy.util.exit_code import ExitCode
1814
from wlsdeploy.util import model
15+
from wlsdeploy.util import string_utils
16+
from wlsdeploy.util.exit_code import ExitCode
1917

2018
_class_name = 'ModelHelpInteractivePrinter'
2119
SIMPLE_COMMAND_REGEX = re.compile(r'^top$|^(cd|ls|cat)(?:\s+(\.\.(?:/[a-zA-Z0-9#.]+)*/?))?$')
@@ -43,13 +41,23 @@ def interactive_help_main_loop(self):
4341
self._output_buffer.add_output()
4442
self._output_buffer.add_message('WLSDPLY-10119', model_path)
4543

46-
completer = StringsCompleter(['cat', 'cd', 'ls', 'top', 'exit'])
47-
terminal = TerminalBuilder.terminal()
48-
reader = LineReaderBuilder.builder().terminal(terminal).completer(completer).build()
44+
# JLine requires Java 1.8.0
45+
reader = None
46+
if string_utils.is_java_version_or_above('1.8.0'):
47+
from org.jline.terminal import TerminalBuilder
48+
from org.jline.reader import LineReaderBuilder
49+
from org.jline.reader.impl.completer import StringsCompleter
50+
51+
completer = StringsCompleter(['cat', 'cd', 'ls', 'top', 'exit'])
52+
terminal = TerminalBuilder.terminal()
53+
reader = LineReaderBuilder.builder().terminal(terminal).completer(completer).build()
54+
4955
while True:
5056
if command_str == 'exit':
5157
break
52-
reader.getHistory().add(command_str)
58+
59+
if reader:
60+
reader.getHistory().add(command_str)
5361

5462
# the "process command" prints the help (or error) for the command_str
5563
# plus appends a new path to the history if the str specifies a successful directory change
@@ -280,13 +288,21 @@ def _add_message(self, key, *args, **kwargs):
280288

281289
def _interactive_help_prompt(model_path, reader):
282290
"""
283-
Gets the next command from stdin or a file.
291+
Gets the next command from stdin or using JLine.
284292
:param model_path: a current model path
285-
:param reader: JLine reader
286-
:param printer: a model help printer
293+
:param reader: JLine reader, or None if JLine not supported
287294
:return: returns when user types 'exit'
288295
"""
289-
command_str = reader.readLine('[%s] --> ' % model_path)
296+
prompt = '[%s] --> ' % model_path
297+
298+
if reader:
299+
command_str = reader.readLine(prompt)
300+
else:
301+
# prompt using sys.stdout.write to avoid newline
302+
sys.stdout.write(prompt)
303+
sys.stdout.flush()
304+
command_str = raw_input('') # get command from stdin
305+
290306
command_str = ' '.join(command_str.split()) # remove extra white-space
291307
return command_str
292308

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
3-
Copyright (c) 2017, 2023, Oracle and/or its affiliates.
3+
Copyright (c) 2017, 2024, Oracle and/or its affiliates.
44
Licensed under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl.
55
-->
66
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -45,7 +45,7 @@
4545
<slf4j.version>2.0.13</slf4j.version>
4646
<jzlib.version>1.1.3</jzlib.version>
4747
<asn.one.version>0.6.0</asn.one.version>
48-
<jline.version>3.25.1</jline.version>
48+
<jline.version>3.26.1</jline.version>
4949
<jansi.version>2.4.1</jansi.version>
5050
<junit.version>5.10.2</junit.version>
5151
<wdt.scm.repo.url>${env.WDT_SCM_REPO_URL}</wdt.scm.repo.url>

0 commit comments

Comments
 (0)