Skip to content

Commit e68aafe

Browse files
authored
do not constrain the output of the Groups command in opengrok-groups (#4671)
fixes #4670 Also, do not install Python packages on Linux as the system environment is externally managed
1 parent 252a540 commit e68aafe

File tree

5 files changed

+64
-26
lines changed

5 files changed

+64
-26
lines changed

dev/before_install

-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ if [[ "$RUNNER_OS" == "Linux" ]]; then
2828
# Bitkeeper install failure is not critical, so exit code is not checked.
2929
sudo ./dev/install-bitkeeper.sh
3030

31-
sudo -H ./dev/install-python-packages.sh
32-
if [[ $? != 0 ]]; then
33-
echo "cannot install Python packages"
34-
exit 1
35-
fi
36-
3731
sudo ./dev/install-universal_ctags.sh
3832
if [[ $? != 0 ]]; then
3933
echo "cannot install Universal ctags"

tools/src/main/python/opengrok_tools/groups.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# CDDL HEADER END
1919

2020
#
21-
# Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
21+
# Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
2222
#
2323

2424
import argparse
@@ -51,7 +51,8 @@ def main():
5151
cmd = Java(args.options, classpath=args.jar, java=args.java,
5252
java_opts=args.java_opts, redirect_stderr=False,
5353
main_class='org.opengrok.indexer.configuration.Groups',
54-
logger=logger, doprint=args.doprint)
54+
logger=logger, doprint=args.doprint,
55+
max_line_length=-1, max_lines=-1)
5556
cmd.execute()
5657
ret = cmd.getretcode()
5758
if ret is None or ret != SUCCESS_EXITVAL:

tools/src/main/python/opengrok_tools/utils/command.py

+22-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#
1919

2020
#
21-
# Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
21+
# Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2222
#
2323

2424
import logging
@@ -49,10 +49,13 @@ class Command:
4949
ERRORED = "errored"
5050
TIMEDOUT = "timed out"
5151

52+
MAX_LINE_LENGTH_DEFAULT = 250
53+
MAX_LINES_DEFAULT = 10000
54+
5255
def __init__(self, cmd, args_subst=None, args_append=None, logger=None,
5356
excl_subst=False, work_dir=None, env_vars=None, timeout=None,
5457
redirect_stderr=True, resource_limits=None, doprint=False,
55-
max_line_length=250, max_lines=10000):
58+
max_line_length=None, max_lines=None):
5659

5760
if doprint is None:
5861
doprint = False
@@ -72,8 +75,17 @@ def __init__(self, cmd, args_subst=None, args_append=None, logger=None,
7275
self.doprint = doprint
7376
self.err = None
7477
self.returncode = None
75-
self.max_line_length = int(max_line_length)
76-
self.max_lines = int(max_lines)
78+
79+
# Convert the maximums to integers to avoid exceptions when using them as indexes
80+
# in case they are passed as floats.
81+
if (max_line_length is None):
82+
self.max_line_length = self.MAX_LINE_LENGTH_DEFAULT
83+
else:
84+
self.max_line_length = int(max_line_length)
85+
if (max_lines is None):
86+
self.max_lines = self.MAX_LINES_DEFAULT
87+
else:
88+
self.max_lines = int(max_lines)
7789

7890
self.logger = logger or logging.getLogger(__name__)
7991

@@ -162,7 +174,10 @@ class OutputThread(threading.Thread):
162174
stdout/stderr buffers fill up.
163175
"""
164176

165-
def __init__(self, event, logger, doprint=False, max_line_length=250, max_lines=10000):
177+
def __init__(self, event, logger, doprint=False,
178+
max_line_length=Command.MAX_LINE_LENGTH_DEFAULT,
179+
max_lines=Command.MAX_LINES_DEFAULT):
180+
166181
super(OutputThread, self).__init__()
167182
self.read_fd, self.write_fd = os.pipe()
168183
self.pipe_fobj = os.fdopen(self.read_fd, encoding='utf8')
@@ -195,11 +210,11 @@ def run(self):
195210
line = line.rstrip() # This will remove not only newline but also whitespace.
196211

197212
# Assuming that self.max_line_length is bigger than 3.
198-
if len(line) > self.max_line_length:
213+
if self.max_line_length > 0 and len(line) > self.max_line_length:
199214
line = line[:self.max_line_length] + "..."
200215

201216
# Shorten the list to be one less than the maximum because a line is going to be added.
202-
if len(self.out) >= self.max_lines:
217+
if self.max_lines > 0 and len(self.out) >= self.max_lines:
203218
self.out = self.out[-self.max_lines + 1:]
204219
self.out[0] = "... <truncated>"
205220

tools/src/main/python/opengrok_tools/utils/java.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class Java(Command):
3737

3838
def __init__(self, command, logger=None, main_class=None, java=None,
3939
jar=None, java_opts=None, classpath=None, env_vars=None,
40-
redirect_stderr=True, doprint=False):
40+
redirect_stderr=True, doprint=False,
41+
max_line_length=None, max_lines=None):
4142

4243
if not java:
4344
java = self.FindJava(logger)
@@ -72,7 +73,8 @@ def __init__(self, command, logger=None, main_class=None, java=None,
7273
logger.debug("Java command: {}".format(java_command))
7374

7475
super().__init__(java_command, logger=logger, env_vars=env,
75-
redirect_stderr=redirect_stderr, doprint=doprint)
76+
redirect_stderr=redirect_stderr, doprint=doprint,
77+
max_line_length=max_line_length, max_lines=max_lines)
7678

7779
def FindJava(self, logger):
7880
"""

tools/src/test/python/test_command.py

+35-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#
2121

2222
#
23-
# Copyright (c) 2017, 2023, Oracle and/or its affiliates. All rights reserved.
23+
# Copyright (c) 2017, 2024, Oracle affiliates. All rights reserved.
2424
# Portions Copyright (c) 2020, Krystof Tulinger <[email protected]>
2525
#
2626

@@ -29,6 +29,8 @@
2929
import tempfile
3030
import time
3131

32+
from enum import Enum
33+
3234
import pytest
3335

3436
from conftest import posix_only, system_binary
@@ -181,19 +183,39 @@ def test_stderr():
181183
assert 'root' in "\n".join(cmd.getoutput())
182184

183185

186+
class LongTestMode(Enum):
187+
"""
188+
Enum to parametrize the long output test below.
189+
"""
190+
ORIGINAL = 1
191+
SHORTEN = 2
192+
UNLIMITED = 3
193+
194+
184195
# This test needs the "/bin/cat" command, therefore it is Unix only.
185196
@posix_only
186-
@pytest.mark.parametrize('shorten', [True, False])
187-
def test_long_output(shorten):
197+
@pytest.mark.parametrize("mode", [LongTestMode.SHORTEN, LongTestMode.ORIGINAL, LongTestMode.UNLIMITED])
198+
def test_long_output(mode):
188199
"""
189200
Test that output thread in the Command class captures all the output.
190201
(and also it does not hang the command by filling up the pipe)
191202
203+
Also test the truncation.
204+
192205
By default, stderr is redirected to stdout.
193206
"""
194-
num_lines = 5000
195-
line_length = 1000
196-
# should be enough to fill a pipe
207+
num_lines_orig = 15000
208+
line_length_orig = 1000
209+
210+
# By using different values than the defaults, the modes which set the lengths
211+
# to non-negative/not-None values will verify that non-default values are acted upon.
212+
assert line_length_orig > Command.MAX_LINE_LENGTH_DEFAULT
213+
assert num_lines_orig > Command.MAX_LINES_DEFAULT
214+
215+
num_lines = num_lines_orig
216+
line_length = line_length_orig
217+
218+
# Should be enough to fill a pipe on most systems.
197219
num_bytes = num_lines * (line_length + 1)
198220
with tempfile.NamedTemporaryFile() as file:
199221
for _ in range(num_lines):
@@ -202,21 +224,25 @@ def test_long_output(shorten):
202224
file.flush()
203225
assert os.path.getsize(file.name) == num_bytes
204226

205-
if shorten:
227+
if mode is LongTestMode.SHORTEN:
206228
num_lines //= 2
207229
line_length //= 2
230+
elif mode is LongTestMode.UNLIMITED:
231+
num_lines = -1
232+
line_length = -1
208233
cmd = Command(["/bin/cat", file.name],
209234
max_lines=num_lines, max_line_length=line_length)
210235
cmd.execute()
211236

212237
assert cmd.getstate() == Command.FINISHED
213238
assert cmd.getretcode() == 0
214239
assert cmd.geterroutput() is None
215-
assert len(cmd.getoutput()) == num_lines
216-
if shorten:
240+
if mode is LongTestMode.SHORTEN:
241+
assert len(cmd.getoutput()) == num_lines
217242
# Add 3 for the '...' suffix.
218243
assert all(len(x) <= line_length + 3 for x in cmd.getoutput())
219244
else:
245+
assert len(cmd.getoutput()) == num_lines_orig
220246
assert len("\n".join(cmd.getoutput()) + "\n") == num_bytes
221247

222248

0 commit comments

Comments
 (0)