This is an automated email from the ASF dual-hosted git repository.
tbonelee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new bcb428dde5 [ZEPPELIN-6712] Fix CLI version options and restore
CommandLineUtils
bcb428dde5 is described below
commit bcb428dde5346b0803587292d06839a003bd03f0
Author: Gyeongtae Park <[email protected]>
AuthorDate: Sun Sep 20 20:14:25 2026 +0900
[ZEPPELIN-6712] Fix CLI version options and restore CommandLineUtils
### What is this PR for?
Fix `bin/zeppelin.sh --version` and `bin/zeppelin.sh -v`, which currently
fail with `Unsupported argument.` because the option parser rejects them before
reaching the version-handling code.
Restore `CommandLineUtils` and its unit tests, as `getZeppelinVersion()` in
`bin/common.sh` still references the removed class. Update the script to
recognize both version options, invoke the version command after loading
`common.sh`, and include the options in the usage message.
### What type of PR is it?
Bug Fix
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-6712
### How should this be tested?
The restored `CommandLineUtilsTest` covers `--version`, `-v`, and
invocation without arguments.
Run:
```bash
./mvnw package -pl zeppelin-server --am \
-Dtest=CommandLineUtilsTest \
-Dsurefire.failIfNoSpecifiedTests=false
```
All 3 tests passed with no failures, errors, or skipped tests. The build
succeeded.
Manual validation:
```bash
bin/zeppelin.sh --version
bin/zeppelin.sh -v
bin/zeppelin.sh --config conf --version
```
All three commands printed `0.13.0-SNAPSHOT` and exited successfully
without starting the server in the local development checkout. Bash syntax
validation also passed.
### Questions:
* Do the license files need updating? No.
* Are there breaking changes for older versions? No.
* Does this need documentation? The script's usage message has been updated.
Closes #5488 from ParkGyeongTae/ZEPPELIN-6712.
Signed-off-by: ChanHo Lee <[email protected]>
---
bin/zeppelin.sh | 9 ++-
.../apache/zeppelin/utils/CommandLineUtils.java | 41 ++++++++++
.../zeppelin/utils/CommandLineUtilsTest.java | 91 ++++++++++++++++++++++
3 files changed, 139 insertions(+), 2 deletions(-)
diff --git a/bin/zeppelin.sh b/bin/zeppelin.sh
index d767891db8..244f7e6173 100755
--- a/bin/zeppelin.sh
+++ b/bin/zeppelin.sh
@@ -43,10 +43,11 @@ if [ -f /proc/self/cgroup ] && [ -n "$(command -v getent)"
]; then
fi
function usage() {
- echo "Usage: bin/zeppelin.sh [--config <conf-dir>] [--run <noteId>]"
+ echo "Usage: bin/zeppelin.sh [--config <conf-dir>] [--run <noteId>]
[--version|-v]"
}
POSITIONAL=()
+VERSION_ONLY=false
while [[ $# -gt 0 ]]
do
key="$1"
@@ -61,6 +62,10 @@ do
shift # past argument
shift # past value
;;
+ -v|--version)
+ VERSION_ONLY=true
+ shift
+ ;;
-h|--help)
usage
exit 0
@@ -81,7 +86,7 @@ bin="$(cd "${bin}">/dev/null; pwd)"
check_java_version
-if [ "$1" == "--version" ] || [ "$1" == "-v" ]; then
+if [[ "${VERSION_ONLY}" == true ]]; then
getZeppelinVersion
fi
diff --git
a/zeppelin-server/src/main/java/org/apache/zeppelin/utils/CommandLineUtils.java
b/zeppelin-server/src/main/java/org/apache/zeppelin/utils/CommandLineUtils.java
new file mode 100644
index 0000000000..e1804dca03
--- /dev/null
+++
b/zeppelin-server/src/main/java/org/apache/zeppelin/utils/CommandLineUtils.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.zeppelin.utils;
+
+import java.util.Locale;
+
+import org.apache.zeppelin.util.Util;
+
+/**
+ * Command-line entry point invoked by getZeppelinVersion() in bin/common.sh.
+ */
+public class CommandLineUtils {
+ public static void main(String[] args) {
+ if (args.length == 0) {
+ return;
+ }
+
+ String usage = args[0].toLowerCase(Locale.US);
+ switch (usage) {
+ case "--version":
+ case "-v":
+ System.out.println(Util.getVersion());
+ break;
+ default:
+ }
+ }
+}
diff --git
a/zeppelin-server/src/test/java/org/apache/zeppelin/utils/CommandLineUtilsTest.java
b/zeppelin-server/src/test/java/org/apache/zeppelin/utils/CommandLineUtilsTest.java
new file mode 100644
index 0000000000..5fc07191ab
--- /dev/null
+++
b/zeppelin-server/src/test/java/org/apache/zeppelin/utils/CommandLineUtilsTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.zeppelin.utils;
+
+import org.apache.zeppelin.util.Util;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Test;
+
+import java.io.ByteArrayOutputStream;
+import java.io.PrintStream;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * Unit tests for {@link CommandLineUtils} written in Given-When-Then style.
+ */
+class CommandLineUtilsTest {
+
+ /**
+ * Captures standard output during test execution.
+ */
+ private final ByteArrayOutputStream outContent = new
ByteArrayOutputStream();
+
+ /**
+ * Original System.out kept for restoration.
+ */
+ private final PrintStream originalOut = System.out;
+
+ @AfterEach
+ void restoreStdout() {
+ // Restore the original System.out after each test
+ System.setOut(originalOut);
+ }
+
+ @Test
+ @DisplayName("Given --version flag, when main is executed, then version is
printed")
+ void givenVersionFlag_whenMain_thenPrintsVersion() {
+ // ----- Given -----
+ System.setOut(new PrintStream(outContent));
+ String expected = Util.getVersion(); // whatever the project
returns
+
+ // ----- When -----
+ CommandLineUtils.main(new String[]{"--version"});
+
+ // ----- Then -----
+ assertEquals(expected, outContent.toString().trim());
+ }
+
+ @Test
+ @DisplayName("Given -v flag, when main is executed, then version is
printed")
+ void givenShortVersionFlag_whenMain_thenPrintsVersion() {
+ // ----- Given -----
+ System.setOut(new PrintStream(outContent));
+ String expected = Util.getVersion();
+
+ // ----- When -----
+ CommandLineUtils.main(new String[]{"-v"});
+
+ // ----- Then -----
+ assertEquals(expected, outContent.toString().trim());
+ }
+
+ @Test
+ @DisplayName("Given no arguments, when main is executed, then nothing is
printed")
+ void givenNoArgs_whenMain_thenPrintsNothing() {
+ // ----- Given -----
+ System.setOut(new PrintStream(outContent));
+
+ // ----- When -----
+ CommandLineUtils.main(new String[]{});
+
+ // ----- Then -----
+ assertEquals("", outContent.toString().trim());
+ }
+}