This is an automated email from the ASF dual-hosted git repository.
bamaer pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/hop.git
The following commit(s) were added to refs/heads/main by this push:
new bd48ee75e3 Fix hop import ends with exit code 0 when no import runs
(#9462)
bd48ee75e3 is described below
commit bd48ee75e38f3677c1bdaffde47f7f015d4ab0bc
Author: Lance <[email protected]>
AuthorDate: Fri Nov 13 14:17:15 2026 +0800
Fix hop import ends with exit code 0 when no import runs (#9462)
Signed-off-by: leehaut <[email protected]>
---
.../main/java/org/apache/hop/imp/HopImport.java | 16 ++-
.../org/apache/hop/imp/HopImportExitCodeTest.java | 81 ++++++++++++++
integration-tests/hop_run/hop-import-exit-code.sh | 82 ++++++++++++++
.../hop_run/main-0006-hop-import-exit-code.hwf | 124 +++++++++++++++++++++
4 files changed, 300 insertions(+), 3 deletions(-)
diff --git a/engine/src/main/java/org/apache/hop/imp/HopImport.java
b/engine/src/main/java/org/apache/hop/imp/HopImport.java
index eaaa593f20..04fe67d2e9 100644
--- a/engine/src/main/java/org/apache/hop/imp/HopImport.java
+++ b/engine/src/main/java/org/apache/hop/imp/HopImport.java
@@ -19,6 +19,7 @@ package org.apache.hop.imp;
import java.io.File;
import java.util.Map;
+import java.util.concurrent.Callable;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
@@ -56,7 +57,8 @@ import picocli.CommandLine.ParameterException;
@Setter
@Command(description = "Import metadata", versionProvider =
HopVersionProvider.class)
@HopCommand(id = "import", description = "Import ")
-public class HopImport implements Runnable, IHasHopMetadataProvider,
IHopCommand {
+public class HopImport
+ implements Callable<Integer>, Runnable, IHasHopMetadataProvider,
IHopCommand {
private static final String CONST_IMPORT = "Import is ";
@Option(
@@ -186,6 +188,14 @@ public class HopImport implements Runnable,
IHasHopMetadataProvider, IHopCommand
Hop.addMixinPlugins(cmd, ConfigPlugin.CATEGORY_IMPORT);
}
+ // Callable so picocli (hop.cmd.execute) gets the exit code; a Runnable
always exits 0.
+ // Same contract as main(): 0 = the import finished, 1 = it stopped or
failed.
+ @Override
+ public Integer call() {
+ run();
+ return isFinishedWithoutError() ? 0 : 1;
+ }
+
@Override
public void run() {
try {
@@ -283,8 +293,8 @@ public class HopImport implements Runnable,
IHasHopMetadataProvider, IHopCommand
ExtensionPointHandler.callExtensionPoint(
log, variables, HopExtensionPoint.HopImportEnd.id, this);
- // main() turns this into the process exit code. Without it every
import, successful or not,
- // exited 1 and no script could tell the difference.
+ // call() and main() turn this into the process exit code. Without it
every import,
+ // successful or not, exited 1 and no script could tell the difference.
finishedWithoutError = true;
} catch (Exception e) {
diff --git a/engine/src/test/java/org/apache/hop/imp/HopImportExitCodeTest.java
b/engine/src/test/java/org/apache/hop/imp/HopImportExitCodeTest.java
new file mode 100644
index 0000000000..a653a857be
--- /dev/null
+++ b/engine/src/test/java/org/apache/hop/imp/HopImportExitCodeTest.java
@@ -0,0 +1,81 @@
+/*
+ * 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.hop.imp;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+import org.apache.hop.core.logging.HopLogStore;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import picocli.CommandLine;
+
+/**
+ * {@code hop import} must exit 1 when it stops before importing anything
(#9441).
+ *
+ * <p>{@code hop import} is {@code Hop.main} calling picocli {@code
execute()}. {@link HopImport}
+ * implements {@link java.util.concurrent.Callable} so that return value is
the exit code. A {@link
+ * Runnable} that returns is always exit code 0.
+ */
+class HopImportExitCodeTest {
+
+ @BeforeAll
+ static void initLogging() {
+ HopLogStore.init();
+ }
+
+ @Test
+ void noInputOrOutputFolderShouldExitOne() {
+ assertImportExitsOne();
+ }
+
+ @Test
+ void inputWithoutOutputFolderShouldExitOne() {
+ assertImportExitsOne("-i", "hop-issue-9441/input");
+ }
+
+ @Test
+ void unknownPluginTypeShouldExitOne() {
+ assertImportExitsOne(
+ "-t", "nosuchtype", "-i", "hop-issue-9441/input", "-o",
"hop-issue-9441/output");
+ }
+
+ /**
+ * Same early return {@code hop import} hits, compared with the code {@code
hop-import.bat} would
+ * use.
+ */
+ private static void assertImportExitsOne(String... args) {
+ HopImport hopImport = new HopImport();
+ CommandLine cmd = new CommandLine(hopImport);
+ hopImport.setCmd(cmd);
+
+ int hopCommandExit = cmd.execute(args);
+ int hopImportBatExit = hopImport.isFinishedWithoutError() ? 0 : 1;
+
+ assertFalse(hopImport.isFinishedWithoutError());
+ assertEquals(1, hopImportBatExit);
+ assertEquals(
+ hopImportBatExit,
+ hopCommandExit,
+ "hop import exited "
+ + hopCommandExit
+ + " but hop-import.bat would exit "
+ + hopImportBatExit
+ + " (issue #9441)");
+ }
+}
diff --git a/integration-tests/hop_run/hop-import-exit-code.sh
b/integration-tests/hop_run/hop-import-exit-code.sh
new file mode 100644
index 0000000000..18b2aa5ea7
--- /dev/null
+++ b/integration-tests/hop_run/hop-import-exit-code.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+
+#
+# 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.
+#
+#
+
+# Runs the hop launcher (hop → Hop.main → System.exit) on import commands that
stop before
+# importing anything and expects exit code 1, then on an empty folder and
expects 0 (issue #9441).
+# hop-import.sh already returns 1 from HopImport.main; this checks the hop
import command.
+
+set -u
+
+# The integration-test image only marks *.sh executable. hop sits next to
hop-run.sh.
+BIN="$(dirname "$(command -v hop-run.sh)")"
+HOP="${BIN}/hop"
+HOP_IMPORT="${BIN}/hop-import.sh"
+
+fail() {
+ echo "FAILED: ${1}"
+ if [ -n "${LOG:-}" ] && [ -f "${LOG}" ]; then
+ echo "----- output -----"
+ cat "${LOG}"
+ fi
+ exit 1
+}
+
+# <expected exit code> <launcher> [args...]
+launch() {
+ local expected="${1}"
+ shift
+ local shown="$*"
+ local launcher="${1}"
+ shift
+ LOG="$(mktemp)"
+ echo "${shown}, expecting exit code ${expected}"
+ if [ -x "${launcher}" ]; then
+ "${launcher}" "$@" >"${LOG}" 2>&1
+ else
+ bash "${launcher}" "$@" >"${LOG}" 2>&1
+ fi
+ local code=$?
+ if [ "${code}" -ne "${expected}" ]; then
+ fail "${shown} exited ${code}, expected ${expected}"
+ fi
+ rm -f "${LOG}"
+ LOG=""
+}
+
+[ -f "${HOP}" ] || fail "hop launcher not found next to hop-run.sh"
+[ -f "${HOP_IMPORT}" ] || fail "hop-import.sh not found next to hop-run.sh"
+
+WORK="$(mktemp -d)"
+IN="${WORK}/in"
+OUT="${WORK}/out"
+mkdir -p "${IN}" "${OUT}"
+cleanup() {
+ rm -rf "${WORK}"
+}
+trap cleanup EXIT
+
+launch 1 "${HOP}" import
+launch 1 "${HOP}" import -i "${IN}"
+launch 1 "${HOP}" import -t nosuchtype -i "${IN}" -o "${OUT}"
+launch 1 "${HOP_IMPORT}"
+launch 1 "${HOP}" import -i "${WORK}/does-not-exist" -o "${OUT}"
+launch 0 "${HOP}" import -t kettle -i "${IN}" -o "${OUT}"
+
+echo "hop import exit code is 1 when nothing is imported and 0 when an empty
folder is imported"
diff --git a/integration-tests/hop_run/main-0006-hop-import-exit-code.hwf
b/integration-tests/hop_run/main-0006-hop-import-exit-code.hwf
new file mode 100644
index 0000000000..835fd82e61
--- /dev/null
+++ b/integration-tests/hop_run/main-0006-hop-import-exit-code.hwf
@@ -0,0 +1,124 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+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.
+
+-->
+<workflow>
+ <name>main-0006-hop-import-exit-code</name>
+ <name_sync_with_filename>Y</name_sync_with_filename>
+ <description>hop import exits 1 when nothing is imported and 0 when an empty
folder is imported (issue #9441).</description>
+ <extended_description/>
+ <workflow_version/>
+ <created_user>-</created_user>
+ <created_date>2026/11/13 11:30:00.000</created_date>
+ <modified_user>-</modified_user>
+ <modified_date>2026/11/13 11:30:00.000</modified_date>
+ <parameters>
+ </parameters>
+ <actions>
+ <action>
+ <name>Start</name>
+ <description/>
+ <type>SPECIAL</type>
+ <attributes/>
+ <DayOfMonth>1</DayOfMonth>
+ <doNotWaitOnFirstExecution>N</doNotWaitOnFirstExecution>
+ <hour>12</hour>
+ <intervalMinutes>60</intervalMinutes>
+ <intervalSeconds>0</intervalSeconds>
+ <minutes>0</minutes>
+ <repeat>N</repeat>
+ <schedulerType>0</schedulerType>
+ <weekDay>1</weekDay>
+ <parallel>N</parallel>
+ <xloc>64</xloc>
+ <yloc>96</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>Check exit code</name>
+ <description>Runs hop import for the cases that stop before importing
and expects exit code 1, then an empty folder and expects 0. The script logs
why it failed.</description>
+ <type>SHELL</type>
+ <attributes/>
+ <filename>${PROJECT_HOME}/hop-import-exit-code.sh</filename>
+ <work_directory>${PROJECT_HOME}</work_directory>
+ <arg_from_previous>N</arg_from_previous>
+ <exec_per_row>N</exec_per_row>
+ <set_logfile>N</set_logfile>
+ <logfile/>
+ <set_append_logfile>N</set_append_logfile>
+ <logext/>
+ <add_date>N</add_date>
+ <add_time>N</add_time>
+ <insertScript>N</insertScript>
+ <script/>
+ <loglevel>Basic</loglevel>
+ <parallel>N</parallel>
+ <xloc>288</xloc>
+ <yloc>96</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>Success</name>
+ <description/>
+ <type>SUCCESS</type>
+ <attributes/>
+ <parallel>N</parallel>
+ <xloc>512</xloc>
+ <yloc>96</yloc>
+ <attributes_hac/>
+ </action>
+ <action>
+ <name>Abort</name>
+ <description/>
+ <type>ABORT</type>
+ <attributes/>
+ <always_log_rows>N</always_log_rows>
+ <message>hop import did not return the expected exit code, see the
output of the script above</message>
+ <parallel>N</parallel>
+ <xloc>288</xloc>
+ <yloc>240</yloc>
+ <attributes_hac/>
+ </action>
+ </actions>
+ <hops>
+ <hop>
+ <from>Start</from>
+ <to>Check exit code</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>Y</unconditional>
+ </hop>
+ <hop>
+ <from>Check exit code</from>
+ <to>Success</to>
+ <enabled>Y</enabled>
+ <evaluation>Y</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ <hop>
+ <from>Check exit code</from>
+ <to>Abort</to>
+ <enabled>Y</enabled>
+ <evaluation>N</evaluation>
+ <unconditional>N</unconditional>
+ </hop>
+ </hops>
+ <notepads>
+ </notepads>
+ <attributes/>
+</workflow>