Skip to content

KNOX-3278: Update JLine to 3.30.6 - #1181

Merged
bonampak merged 51 commits into
apache:masterfrom
bonampak:KNOX-3278
Aug 19, 2026
Merged

KNOX-3278: Update JLine to 3.30.6#1181
bonampak merged 51 commits into
apache:masterfrom
bonampak:KNOX-3278

Conversation

@bonampak

@bonampak bonampak commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

KNOX-3278 - Update jline to 3.30.6

What changes were proposed in this pull request?

Update groovy to 5.0.4, jline to 3.30.6, jna to 5.18.1, aspectj to 1.9.25.1 and rest-assured to 6.0.0.
Rewrote gateway-shell using JLine 3 and Groovy 5. As

How was this patch tested?

Ran example tests and all repl commands (ExampleWebHdfsLs.groovy and ExampleManagerResourceDeployment.groovy both in REPL with :load and as knoxshell.sh arguments. Both work as expected.)

Build:

mvn -Prelease,package clean install -am -pl gateway-shell,gateway-shell-release

Setup:

  • Unzip the target/3.0.0-SNAPSHOT/knoxshell-3.0.0-SNAPSHOT.zip to a directory.
  • For datasource testing, copied the Postgres JDBC driver postgresql-42.7.10.jar to knoxshell-3.0.0-SNAPSHOT/lib/
  • Change localhost in the samples groovy scripts to your cluster:
export KNOX_GATEWAY_HOST="example-knox-gateway-host"
export KNOX_GATEWAY_PORT="8443"

sed -i -e "s/localhost/${KNOX_GATEWAY_HOST}/g" samples/Example*.groovy
  • Build the gateway truststore in your home directory:
./bin/knoxshell.sh buildTrustStore "https://${KNOX_GATEWAY_HOST}:${KNOX_GATEWAY_PORT}"

Tests

Logging

./bin/knoxshell.sh -e "org.apache.logging.log4j.LogManager.getLogger('test').error('hello from knoxshell')"
cat ./logs/knoxshell.log
2026-08-18T13:08:47,990 ERROR test (IndyInterface.java:fromCache(344)) - hello from knoxshell

Datasources command

Prerequisites:

  • copied postgresql-42.7.10.jar to knoxshell-3.0.0-SNAPSHOT/lib
  • created a local postgres db with docker.
./bin/knoxshell.sh
Apache Knox Shell
Type ':help' (':h' or '?') for help, ':exit' or ':quit' (':x' or ':q') to quit.
knox> :ds add ds-postgres jdbc:postgresql://localhost:15432/knoxshell_test_db org.postgresql.Driver basic
Knox DataSources
+----------------+--------------------------------------------------------+--------------------------+--------------+
|      Name      |                     Connect String                     |          Driver          |  Authn Type  |
+----------------+--------------------------------------------------------+--------------------------+--------------+
|  ds-postgres   |  jdbc:postgresql://localhost:15432/knoxshell_test_db   |  org.postgresql.Driver   |    basic     |
+----------------+--------------------------------------------------------+--------------------------+--------------+

knox> :ds select ds-postgres
Knox DataSource Selected
+----------------+--------------------------------------------------------+--------------------------+--------------+
|      Name      |                     Connect String                     |          Driver          |  Authn Type  |
+----------------+--------------------------------------------------------+--------------------------+--------------+
|  ds-postgres   |  jdbc:postgresql://localhost:15432/knoxshell_test_db   |  org.postgresql.Driver   |    basic     |
+----------------+--------------------------------------------------------+--------------------------+--------------+

knox> :sql

(insert query to popup)

SELECT 1 as one;
+--------+
|  one   |
+--------+
|   1    |
+--------+

fs command

knox> :fs mount https://${KNOX_GATEWAY_HOST}:${KNOX_GATEWAY_PORT}/gateway/sandbox myfs
(enter username and password in pop-up dialog window)
https://${KNOX_GATEWAY_HOST}:${KNOX_GATEWAY_PORT}/gateway/sandbox mounted as myfs


knox> :fs mounts
+----------------+--------------------------------------------------------------------------------+
|  Mount Point   |                                  Topology URL                                  |
+----------------+--------------------------------------------------------------------------------+
|      myfs      |  https://${KNOX_GATEWAY_HOST}:${KNOX_GATEWAY_PORT}/gateway/sandbox             |
+----------------+--------------------------------------------------------------------------------+


:fs ls /myfs/tmp/

knox> :fs ls /myfs/tmp/
/tmp/
+--------------+----------+--------------+----------+----------------------------------+--------------------------------------------+
|  permission  |  owner   |    group     |  length  |             modtime              |                    name                    |
+--------------+----------+--------------+----------+----------------------------------+--------------------------------------------+
|      0       |   hdfs   |  supergroup  |    0     |  Tue Aug 18 15:35:25 CEST 2026   |  .file                                    |
+--------------+----------+--------------+----------+----------------------------------+--------------------------------------------+


knox> :fs put /tmp/testing/example-file.txt /myfs/tmp/example-file.txt
Successfully put: /tmp/testing/example-file.txt to: /myfs/tmp/example-file.txt

knox> :fs ls /myfs/tmp/
/tmp/
+--------------+----------+--------------+----------+----------------------------------+--------------------------------------------+
|  permission  |  owner   |    group     |  length  |             modtime              |                    name                    |
+--------------+----------+--------------+----------+----------------------------------+--------------------------------------------+
|      0       |   hdfs   |  supergroup  |    0     |  Tue Aug 18 15:43:25 CEST 2026   |              .file                         |
|     755      |   tom    |  supergroup  |    14    |  Tue Aug 18 15:41:16 CEST 2026   |              example-file.txt              |
+--------------+----------+--------------+----------+----------------------------------+--------------------------------------------+

knox> :fs cat /myfs/tmp/example-file.txt
demo

Invoking groovy scripts with knoxshell

./bin/knoxshell.sh samples/ExampleWebHdfsLs.groovy
Enter username: tom
Enter password:
[tmp, user]
./bin/knoxshell.sh samples/ExampleManagerListResources.groovy
Enter username: tom
Enter password:
Provider Configurations
  • manager
  • admin
  • knoxsso
Descriptors
...
./bin/knoxshell.sh samples/ExampleManagerResourceDeployment.groovy
Enter username: tom
Enter password:

Existing Provider Configurations
  • kerberos-providers
  • manager.groovy
...
  • ExampleWebHdfsPutGet.groovy
    Prerequisite: hdfs home directory for your user exists on the cluster.
kinit -kt <keytab> <hdfs-kerberos-principal>
hdfs dfs -mkdir -p /user/tom
hdfs dfs -chown tom:tom /user/tom
./bin/knoxshell.sh samples/ExampleWebHdfsPutGet.groovy

Enter username: tom
Enter password:
*********************************************************************
KnoxShell README
*********************************************************************
Client Details
...

On the cluster, verified the put was successful:

hdfs dfs -ls /user/tom/example
Found 1 items
-rwxrwxrwx   2 tom tom       1452 2026-08-18 13:10 /user/tom/example/README

Legacy Groovysh commands

Commands skipped (not applicable to CLI/JLine3 architecture and current feature set):
:display, :inspect, :edit, :record, :alias, :set, :register, :doc, :grab

Also not implemented:
:save / :s — dump session history/buffer to a file
:history (jline3 history file will be in ~/.knoxshell_history)

Implemented:

:import, :show, :load, :purge (also for old :clear)

Tested filenames with spaces:

./bin/knoxshell.sh "samples/Example WebHdfs Ls.groovy"
./bin/knoxshell.sh samples/Example\ WebHdfs\ Ls.groovy

inside the shell, only the quoted one works:

knox> . "samples/Example WebHdfs Ls.groovy"
knox> . samples/Example\ WebHdfs\ Ls.groovy
Failed to load 'samples/Example': File not found: testing/knoxshell/knoxshell-3.0.0-SNAPSHOT/samples/Example
Failed to load 'WebHdfs': File not found: testing/knoxshell/knoxshell-3.0.0-SNAPSHOT/WebHdfs
Failed to load 'Ls.groovy': File not found: testing/knoxshell/knoxshell-3.0.0-SNAPSHOT/Ls.groovy
knox>

Integration Tests

There is another ticket for adding integration tests:
KNOX-3280 Add integration tests for KnoxShell and KnoxCLI

UI changes

None

@github-actions

github-actions Bot commented Mar 20, 2026

Copy link
Copy Markdown

Test Results

46 tests   46 ✅  6s ⏱️
 3 suites   0 💤
 3 files     0 ❌

Results for commit 9230a8a.

♻️ This comment has been updated with latest results.

<excludes>
<exclude>schema/**</exclude>
<exclude>**/*.ldif</exclude>
<exclude>META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat</exclude>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we use maven-shade-plugin:3.4.1 and org.apache.logging.log4j:log4j-transform-maven-shade-plugin-extensions, this can be fixed by adding
<transformer implementation="org.apache.logging.log4j.maven.plugins.shade.transformer.Log4j2PluginCacheFileTransformer"/>
Otherwise the Log4j2Plugins.dat will be overwritten by our plugins and will not contain the ones shipped by log4j2.

@bonampak
bonampak marked this pull request as ready for review April 15, 2026 16:22
@bonampak
bonampak requested a review from pzampino April 17, 2026 13:52
checkJava
buildAppJavaOpts
$JAVA "${APP_JAVA_OPTS[@]}" -Dlog4j.configurationFile=conf/knoxshell-log4j2.xml -javaagent:"$APP_BIN_DIR"/../lib/aspectjweaver.jar -cp "$APP_JAR":lib/* org.apache.knox.gateway.shell.Shell "$@" || exit 1
$JAVA "${APP_JAVA_OPTS[@]}" -Dlog4j.configurationFile=conf/knoxshell-log4j2.xml -javaagent:"$APP_BIN_DIR"/../lib/aspectjweaver.jar -cp "$APP_JAR":lib/* -cp "$APP_JAR":lib/* org.apache.knox.gateway.launcher.Launcher "$@" || exit 1

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change from shell.Shell to launcher.Launcher?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept Launcher and removed the duplicate classpath option.

It's because our logging configuration is referring to sys:launcher.dir and sys:launcher.name.
The shaded jar is also using Launcher as main class.

Either we specify these properties in the launcher script or we use Launcher.

Otherwise the log file will not be created:

./bin/knoxshell.sh -e "org.apache.logging.log4j.LogManager.getLogger('test').error('hello from knoxshell')"

main ERROR Unable to create file ${sys:launcher.dir}/../logs/${sys:launcher.name}.log java.io.IOException: No such file or directory at java.base/java.io.UnixFileSystem.createFileExclusively(Native Method) at java.base/java.io.File.createNewFile(File.java:1043) at org.apache.logging.log4j.core.appender.rolling.RollingFileManager.lambda$getFileManager$0(RollingFileManager.java:315)

There are currently classloader issues if we would use -jar and we place extra jars, for example database driver jars in the lib folder. So the -cp flag is needed in that case and -jar cannot be used (the shaded jar does not specify a classpath in its manifest). I'll create a separate issue to use launcher and be consistent with other modules.

KnoxLoginDialog dlg = new KnoxLoginDialog();
dlg.collect();
return dlg;
LineReader reader = LineReaderBuilder.builder()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be a re-implementation of the credential collector logic in the name of the JLine upgrade? Is it necessary for the dependency upgrade?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's not necessary. Reverted back to KnoxLoginDialog.

@smolnar82
smolnar82 self-requested a review August 19, 2026 12:17
@moresandeep
moresandeep self-requested a review August 19, 2026 13:47

@moresandeep moresandeep left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @bonampak! Looks good

@bonampak
bonampak merged commit 114af08 into apache:master Aug 19, 2026
2 checks passed
Raghav-Mah3shwari pushed a commit to Raghav-Mah3shwari/Apache-knox that referenced this pull request Aug 23, 2026
* KNOX-3278: Update jline.version to 3.25.1.

* KNOX-3278: Update groovy to 5.0.4 and jline to 3.30.6, plus jna to 5.18.1.

* KNOX-3278: refactor commands and REPL shell.

* KNOX-3278: fix checkstyle errors and logging configuration in maven-shade-plugin and knoxshell-log4j. Update aspectj for JDK 17.

* KNOX-3278: Fix forbiddenapis check: use Locale.ROOT in printf.

* KNOX-3278: Fix KnoxShellTableCallHistoryTest shouldRollbackToValidPreviousStep

* KNOX-3278: Removing comments and unused methods

* KNOX-3278: Fix missing newlines at end of file.

* KNOX-3278: Restoring SelectCommand to use Swing JTextArea for multiline edits.

* KNOX-3278: Removing KnoxLoginDialog (JLine3 supports password input).

* KNOX-3278: Correcting undeclared jline module dependencies.

* KNOX-3278: Correcting pmd findings.

* KNOX-3278: Update rest-assured to 6.0.0 (needed for Groovy 5)

* KNOX-3278: command completion pt1

* KNOX-3278: command completion pt2

* KNOX-3278: correct checkstyle errors

* KNOX-3278: correct undeclared jline module dependencies.

* KNOX-3278: cleanup DataSourceCommand completer.

* KNOX-3278: add :x and :q as exit commands.

* KNOX-3278: add '?' as help command alias.

* KNOX-3278: import, load and show commands added.

* KNOX-3278: purge command added.

* KNOX-3278: Correcting load command and alias.

* KNOX-3278: Adding completer for ShowCommand.

* KNOX-3278: Correct checkstyle error on shortcut handling

* KNOX-3278: Renaming SimpleCommandRegistry to KnoxShellCommandRegistry and cleaning up command handling. Overriding name() so that tab completion after semicolon does not show the name of the command registry.

* KNOX-3278: No need to exclude Log4j2Plugins.dat from the shaded knoxhsell jar.

* KNOX-3278: correcting knoxshell.sh to use -jar instead of main class (to use Launcher taken from knoxshell.jar manifest main class)

* KNOX-3278: excluding Log4j2Plugins.dat from the shaded knoxhsell jar and making knoxshell-log4j2.xml consistent with other log4j2 configurations.

* KNOX-3278: get rid of useless warning javax.* types are not being woven

* KNOX-3278: fix log4j2 WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.

* KNOX-3278: Fix purge command, simplify import and show commands.

* KNOX-3278: Fix ImportCommand and add support for static imports.

* KNOX-3278: Catch Throwable similarly to legacy GroovySh.

* KNOX-3278: Make LoadCommand handle multi-file loading as in legacy GroovySh 4.

* KNOX-3278: wrap GroovyEngine completer into SafeCompleter to handle unexpected exceptions.

* KNOX-3278: correct knoxshell.sh to use launcher and correctly load classes from the lib directory.

* KNOX-3278: fix no endline at end of file.

* KNOX-3278: refactor Shell.java pt1

* KNOX-3278: refactor Shell.java pt2

* KNOX-3238: review findings: keep Launcher because of logging and remove duplicate classpath argument.

* KNOX-3278: review findings: Restore KnoxLoginDialog for credential collection logic.

* KNOX-3278: review findings: Revert LoginCommand to use KnoxLoginDialog.

Reverts LoginCommand.execute() to use KnoxLoginDialog for credential collection
instead of JLine3 terminal prompts, restoring the Swing GUI popup dialog behavior.

This maintains consistency with the `:login` command behavior from before KNOX-3278 refactoring, as documented in the original pre-refactor version.

* KNOX-3278: review findings: Replace inline FQN with import

* KNOX-3278: review findings: revert trailing newlines in files that would otherwise not be changed.

* KNOX-3278: review findings: remove override for KnoxShellCommandRegistry.name()

* KNOX-3278: correcting load command to parse filenames with spaces as well

* KNOX-3278: correcting Groovy 5 extension module registration.

* KNOX-3278: Ctrl+C continues back to the prompt; Ctrl+D exits the shell.

* KNOX-3278: review findings: revert trailing newlines in files that would otherwise not be changed.

* KNOX-3278: review findings: fix purge command javadoc and help.
bonampak added a commit that referenced this pull request Aug 28, 2026
* KNOX-3278: Update jline.version to 3.25.1.

* KNOX-3278: Update groovy to 5.0.4 and jline to 3.30.6, plus jna to 5.18.1.

* KNOX-3278: refactor commands and REPL shell.

* KNOX-3278: fix checkstyle errors and logging configuration in maven-shade-plugin and knoxshell-log4j. Update aspectj for JDK 17.

* KNOX-3278: Fix forbiddenapis check: use Locale.ROOT in printf.

* KNOX-3278: Fix KnoxShellTableCallHistoryTest shouldRollbackToValidPreviousStep

* KNOX-3278: Removing comments and unused methods

* KNOX-3278: Fix missing newlines at end of file.

* KNOX-3278: Restoring SelectCommand to use Swing JTextArea for multiline edits.

* KNOX-3278: Removing KnoxLoginDialog (JLine3 supports password input).

* KNOX-3278: Correcting undeclared jline module dependencies.

* KNOX-3278: Correcting pmd findings.

* KNOX-3278: Update rest-assured to 6.0.0 (needed for Groovy 5)

* KNOX-3278: command completion pt1

* KNOX-3278: command completion pt2

* KNOX-3278: correct checkstyle errors

* KNOX-3278: correct undeclared jline module dependencies.

* KNOX-3278: cleanup DataSourceCommand completer.

* KNOX-3278: add :x and :q as exit commands.

* KNOX-3278: add '?' as help command alias.

* KNOX-3278: import, load and show commands added.

* KNOX-3278: purge command added.

* KNOX-3278: Correcting load command and alias.

* KNOX-3278: Adding completer for ShowCommand.

* KNOX-3278: Correct checkstyle error on shortcut handling

* KNOX-3278: Renaming SimpleCommandRegistry to KnoxShellCommandRegistry and cleaning up command handling. Overriding name() so that tab completion after semicolon does not show the name of the command registry.

* KNOX-3278: No need to exclude Log4j2Plugins.dat from the shaded knoxhsell jar.

* KNOX-3278: correcting knoxshell.sh to use -jar instead of main class (to use Launcher taken from knoxshell.jar manifest main class)

* KNOX-3278: excluding Log4j2Plugins.dat from the shaded knoxhsell jar and making knoxshell-log4j2.xml consistent with other log4j2 configurations.

* KNOX-3278: get rid of useless warning javax.* types are not being woven

* KNOX-3278: fix log4j2 WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.

* KNOX-3278: Fix purge command, simplify import and show commands.

* KNOX-3278: Fix ImportCommand and add support for static imports.

* KNOX-3278: Catch Throwable similarly to legacy GroovySh.

* KNOX-3278: Make LoadCommand handle multi-file loading as in legacy GroovySh 4.

* KNOX-3278: wrap GroovyEngine completer into SafeCompleter to handle unexpected exceptions.

* KNOX-3278: correct knoxshell.sh to use launcher and correctly load classes from the lib directory.

* KNOX-3278: fix no endline at end of file.

* KNOX-3278: refactor Shell.java pt1

* KNOX-3278: refactor Shell.java pt2

* KNOX-3238: review findings: keep Launcher because of logging and remove duplicate classpath argument.

* KNOX-3278: review findings: Restore KnoxLoginDialog for credential collection logic.

* KNOX-3278: review findings: Revert LoginCommand to use KnoxLoginDialog.

Reverts LoginCommand.execute() to use KnoxLoginDialog for credential collection
instead of JLine3 terminal prompts, restoring the Swing GUI popup dialog behavior.

This maintains consistency with the `:login` command behavior from before KNOX-3278 refactoring, as documented in the original pre-refactor version.

* KNOX-3278: review findings: Replace inline FQN with import

* KNOX-3278: review findings: revert trailing newlines in files that would otherwise not be changed.

* KNOX-3278: review findings: remove override for KnoxShellCommandRegistry.name()

* KNOX-3278: correcting load command to parse filenames with spaces as well

* KNOX-3278: correcting Groovy 5 extension module registration.

* KNOX-3278: Ctrl+C continues back to the prompt; Ctrl+D exits the shell.

* KNOX-3278: review findings: revert trailing newlines in files that would otherwise not be changed.

* KNOX-3278: review findings: fix purge command javadoc and help.

(cherry picked from commit 114af08)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants