This is an automated email from the ASF dual-hosted git repository.

mattcasters 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 f3820d4efc hop-run gives a parameter its -p value or its default, not 
a same-named variable, fixes #9003 (#9192)
f3820d4efc is described below

commit f3820d4efcee1f5b5af0039393d8d6ee7a9e7887
Author: Bart Maertens <[email protected]>
AuthorDate: Sun Nov 1 14:27:56 2026 +0100

    hop-run gives a parameter its -p value or its default, not a same-named 
variable, fixes #9003 (#9192)
---
 .../modules/ROOT/pages/variables/parameters.adoc   | 16 ++---
 .../main/java/org/apache/hop/run/HopRunBase.java   | 21 ++----
 .../org/apache/hop/run/HopRunParametersTest.java   | 81 ++++++++++++++++++++++
 integration-tests/http/main-0001-http-post.hwf     |  7 +-
 integration-tests/http/main-0002-http-client.hwf   |  7 +-
 integration-tests/http/main-0003-rest-client.hwf   |  7 +-
 .../http/main-0004-webservice-available.hwf        |  7 +-
 integration-tests/http/main-0005-http-action.hwf   |  7 +-
 .../http/main-0007-rest-client-post.hwf            |  7 +-
 .../http/main-0008-rest-client-put.hwf             |  7 +-
 .../http/main-0009-rest-client-delete.hwf          |  7 +-
 .../http/main-0010-rest-client-head.hwf            |  7 +-
 .../http/main-0011-rest-client-options.hwf         |  7 +-
 .../http/main-0012-rest-client-patch.hwf           |  7 +-
 integration-tests/http/main-0013-webservice.hwf    |  5 --
 .../http/main-0014-rest-client-with-proxy.hwf      |  7 +-
 .../http/main-0015-http-client-with-proxy.hwf      |  7 +-
 integration-tests/http/main-0016-post-a-file.hwf   |  5 --
 .../http/main-0051-http-client-proxy-auth.hwf      |  7 +-
 .../http/main-0052-http-client-rest-connection.hwf |  7 +-
 .../http/main-0053-http-post-proxy-auth.hwf        |  7 +-
 21 files changed, 111 insertions(+), 129 deletions(-)

diff --git a/docs/hop-user-manual/modules/ROOT/pages/variables/parameters.adoc 
b/docs/hop-user-manual/modules/ROOT/pages/variables/parameters.adoc
index 29832ce84e..966cac9339 100644
--- a/docs/hop-user-manual/modules/ROOT/pages/variables/parameters.adoc
+++ b/docs/hop-user-manual/modules/ROOT/pages/variables/parameters.adoc
@@ -78,17 +78,17 @@ Wrap a value that contains a comma in double quotes, and 
the whole option in sin
   -p 'INPUT_FILE=/data/orders.csv,COUNTRIES="BE,NL"'
 ----
 
-`hop-run` gives every parameter the first value it finds:
-
-. The value passed with `-p`.
-. The value of a variable with the same name, for example a project or 
environment variable, or a system property passed with `-s`.
-. The default value.
-
-An empty value, like `-p INPUT_FILE=`, gives the parameter its default value, 
even when a variable with the same name exists.
+A parameter gets the value passed with `-p`, or else its default value, like 
in Hop Gui.
+An empty value, like `-p INPUT_FILE=`, also gives it its default value.
+A project or environment variable, or a system property passed with `-s`, with 
the same name as the parameter is not used.
 
 A name passed with `-p` that the pipeline or workflow doesn't declare is set 
as a variable.
 
-NOTE: Unlike Hop Gui, `hop-run` uses a project or environment variable with 
the same name before the default value.
+If a value should come from the project or the environment, don't declare it 
as a parameter: use the variable as `+${NAME}+` directly.
+
+NOTE: Before Hop 2.21, `hop-run` gave a parameter without a `-p` value the 
value of a project or environment variable with the same name, before its 
default value.
+A pipeline or workflow that relied on this gets the default value now.
+Pass the value with `-p`, or remove the parameter so the variable is used.
 
 === From another pipeline or workflow
 
diff --git a/engine/src/main/java/org/apache/hop/run/HopRunBase.java 
b/engine/src/main/java/org/apache/hop/run/HopRunBase.java
index dfcf8d22be..141f7eca44 100644
--- a/engine/src/main/java/org/apache/hop/run/HopRunBase.java
+++ b/engine/src/main/java/org/apache/hop/run/HopRunBase.java
@@ -645,7 +645,11 @@ public abstract class HopRunBase implements Runnable, 
IHasHopMetadataProvider {
 
   /**
    * Configure the variables and parameters in the given configuration on the 
given variable
-   * variables and named parameters
+   * variables and named parameters.
+   *
+   * <p>A declared parameter only gets the value passed with the -p option. 
Without one, activating
+   * the parameters gives it its default, even when the project, environment 
or hop-config has a
+   * variable with the same name. Hop Gui and child executions (#8101) do the 
same (#9003).
    */
   protected void configureParametersAndVariables(
       CommandLine cmd,
@@ -657,20 +661,7 @@ public abstract class HopRunBase implements Runnable, 
IHasHopMetadataProvider {
     //
     variables.setVariables(configuration.getVariablesMap());
 
-    // By default, we use the value from the current variables map:
-    //
-    for (String key : namedParams.listParameters()) {
-      String value = variables.getVariable(key);
-      if (StringUtils.isNotEmpty(value)) {
-        try {
-          namedParams.setParameterValue(key, value);
-        } catch (UnknownParamException e) {
-          throw new ParameterException(cmd, "Unable to set parameter '" + key 
+ "'", e);
-        }
-      }
-    }
-
-    // Possibly override with the parameter values set by the user (-p option)
+    // Set the parameter values set by the user (-p option)
     //
     for (String key : configuration.getParametersMap().keySet()) {
       String value = configuration.getParametersMap().get(key);
diff --git a/engine/src/test/java/org/apache/hop/run/HopRunParametersTest.java 
b/engine/src/test/java/org/apache/hop/run/HopRunParametersTest.java
new file mode 100644
index 0000000000..62c68d1dd6
--- /dev/null
+++ b/engine/src/test/java/org/apache/hop/run/HopRunParametersTest.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.run;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.apache.hop.core.parameters.NamedParameters;
+import org.apache.hop.core.variables.IVariables;
+import org.apache.hop.core.variables.Variables;
+import org.apache.hop.pipeline.PipelineExecutionConfiguration;
+import org.junit.jupiter.api.Test;
+import picocli.CommandLine;
+
+/** A declared parameter gets the -p value or its default, never a same-named 
variable (#9003). */
+class HopRunParametersTest {
+
+  private static final String PARAMETER = "P_2517";
+
+  @Test
+  void sameNamedVariableDoesNotReplaceTheDefault() throws Exception {
+    IVariables variables = run(PARAMETER, "from-project");
+
+    assertEquals("from-default", variables.getVariable(PARAMETER));
+  }
+
+  @Test
+  void commandLineValueReplacesTheDefault() throws Exception {
+    IVariables variables = run(PARAMETER, "from-project", "-p", PARAMETER + 
"=from-command-line");
+
+    assertEquals("from-command-line", variables.getVariable(PARAMETER));
+  }
+
+  @Test
+  void undeclaredNameStaysAVariable() throws Exception {
+    IVariables variables = run("OTHER", "from-project", "-p", 
"OTHER=from-command-line");
+
+    assertEquals("from-command-line", variables.getVariable("OTHER"));
+    assertEquals("from-default", variables.getVariable(PARAMETER));
+  }
+
+  /**
+   * Runs the hop-run parameter handling for a pipeline or workflow that 
declares {@link #PARAMETER}
+   * with a default, where the project already sets variable {@code name}.
+   */
+  private static IVariables run(String name, String value, String... args) 
throws Exception {
+    HopRun hopRun = new HopRun();
+    CommandLine cmd = new CommandLine(hopRun);
+    cmd.parseArgs(args);
+
+    NamedParameters namedParams = new NamedParameters();
+    namedParams.addParameterDefinition(PARAMETER, "from-default", "");
+
+    // Like the engine created by hop-run: initialized from hop-run's own 
variables
+    //
+    IVariables variables = new Variables();
+    variables.initializeFrom(null);
+    variables.setVariable(name, value);
+
+    PipelineExecutionConfiguration configuration = new 
PipelineExecutionConfiguration();
+    hopRun.parseParametersAndVariables(cmd, configuration, namedParams);
+    hopRun.configureParametersAndVariables(cmd, configuration, variables, 
namedParams);
+    namedParams.activateParameters(variables);
+    return variables;
+  }
+}
diff --git a/integration-tests/http/main-0001-http-post.hwf 
b/integration-tests/http/main-0001-http-post.hwf
index 64c88dc67f..2c31aac8e2 100644
--- a/integration-tests/http/main-0001-http-post.hwf
+++ b/integration-tests/http/main-0001-http-post.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0002-http-client.hwf 
b/integration-tests/http/main-0002-http-client.hwf
index 95b630c318..80512375c2 100644
--- a/integration-tests/http/main-0002-http-client.hwf
+++ b/integration-tests/http/main-0002-http-client.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0003-rest-client.hwf 
b/integration-tests/http/main-0003-rest-client.hwf
index 1c9dbd0ac2..1634de25dd 100644
--- a/integration-tests/http/main-0003-rest-client.hwf
+++ b/integration-tests/http/main-0003-rest-client.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0004-webservice-available.hwf 
b/integration-tests/http/main-0004-webservice-available.hwf
index b4e3ad8940..28d64e3f18 100644
--- a/integration-tests/http/main-0004-webservice-available.hwf
+++ b/integration-tests/http/main-0004-webservice-available.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0005-http-action.hwf 
b/integration-tests/http/main-0005-http-action.hwf
index 84a583ea02..8d9ac7f335 100644
--- a/integration-tests/http/main-0005-http-action.hwf
+++ b/integration-tests/http/main-0005-http-action.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/10/02 18:03:21.160</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0007-rest-client-post.hwf 
b/integration-tests/http/main-0007-rest-client-post.hwf
index aadb9c885e..c6166b304e 100644
--- a/integration-tests/http/main-0007-rest-client-post.hwf
+++ b/integration-tests/http/main-0007-rest-client-post.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0008-rest-client-put.hwf 
b/integration-tests/http/main-0008-rest-client-put.hwf
index 76362fa4eb..0cf483f5c6 100644
--- a/integration-tests/http/main-0008-rest-client-put.hwf
+++ b/integration-tests/http/main-0008-rest-client-put.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0009-rest-client-delete.hwf 
b/integration-tests/http/main-0009-rest-client-delete.hwf
index f0f4d757f1..a3bb3935f0 100644
--- a/integration-tests/http/main-0009-rest-client-delete.hwf
+++ b/integration-tests/http/main-0009-rest-client-delete.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0010-rest-client-head.hwf 
b/integration-tests/http/main-0010-rest-client-head.hwf
index c8c9cd13ba..fd3fe3e581 100644
--- a/integration-tests/http/main-0010-rest-client-head.hwf
+++ b/integration-tests/http/main-0010-rest-client-head.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0011-rest-client-options.hwf 
b/integration-tests/http/main-0011-rest-client-options.hwf
index 2c732b04ba..5db3e592af 100644
--- a/integration-tests/http/main-0011-rest-client-options.hwf
+++ b/integration-tests/http/main-0011-rest-client-options.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0012-rest-client-patch.hwf 
b/integration-tests/http/main-0012-rest-client-patch.hwf
index 58a1fc5913..a53ccbb25d 100644
--- a/integration-tests/http/main-0012-rest-client-patch.hwf
+++ b/integration-tests/http/main-0012-rest-client-patch.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0013-webservice.hwf 
b/integration-tests/http/main-0013-webservice.hwf
index c888d79506..4fc44fedb0 100644
--- a/integration-tests/http/main-0013-webservice.hwf
+++ b/integration-tests/http/main-0013-webservice.hwf
@@ -29,11 +29,6 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>CASTLEMOCK_HOSTNAME</name>
-      <default_value>castlemock</default_value>
-      <description/>
-    </parameter>
     <parameter>
       <name>CASTLEMOCK_PROJECT_LOCATION</name>
       <default_value>/tmp/CastleMockProject.xml</default_value>
diff --git a/integration-tests/http/main-0014-rest-client-with-proxy.hwf 
b/integration-tests/http/main-0014-rest-client-with-proxy.hwf
index 3d484d0162..c52e449458 100644
--- a/integration-tests/http/main-0014-rest-client-with-proxy.hwf
+++ b/integration-tests/http/main-0014-rest-client-with-proxy.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0015-http-client-with-proxy.hwf 
b/integration-tests/http/main-0015-http-client-with-proxy.hwf
index b769b10de6..d589bfd347 100644
--- a/integration-tests/http/main-0015-http-client-with-proxy.hwf
+++ b/integration-tests/http/main-0015-http-client-with-proxy.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0016-post-a-file.hwf 
b/integration-tests/http/main-0016-post-a-file.hwf
index 945ed6a43d..47a5a14297 100644
--- a/integration-tests/http/main-0016-post-a-file.hwf
+++ b/integration-tests/http/main-0016-post-a-file.hwf
@@ -29,11 +29,6 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>CASTLEMOCK_HOSTNAME</name>
-      <default_value>castlemock</default_value>
-      <description/>
-    </parameter>
     <parameter>
       <name>CASTLEMOCK_PROJECT_LOCATION</name>
       <default_value>/tmp/CastleMockProject.xml</default_value>
diff --git a/integration-tests/http/main-0051-http-client-proxy-auth.hwf 
b/integration-tests/http/main-0051-http-client-proxy-auth.hwf
index 887d66a6c6..5b06ff7a77 100644
--- a/integration-tests/http/main-0051-http-client-proxy-auth.hwf
+++ b/integration-tests/http/main-0051-http-client-proxy-auth.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0052-http-client-rest-connection.hwf 
b/integration-tests/http/main-0052-http-client-rest-connection.hwf
index 5552a11ec2..91e2719417 100644
--- a/integration-tests/http/main-0052-http-client-rest-connection.hwf
+++ b/integration-tests/http/main-0052-http-client-rest-connection.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>
diff --git a/integration-tests/http/main-0053-http-post-proxy-auth.hwf 
b/integration-tests/http/main-0053-http-post-proxy-auth.hwf
index eff938c6bd..98b302c584 100644
--- a/integration-tests/http/main-0053-http-post-proxy-auth.hwf
+++ b/integration-tests/http/main-0053-http-post-proxy-auth.hwf
@@ -29,12 +29,7 @@ limitations under the License.
   <modified_user>-</modified_user>
   <modified_date>2021/09/27 10:46:50.001</modified_date>
   <parameters>
-    <parameter>
-      <name>HOSTNAME</name>
-      <default_value>localhost</default_value>
-      <description/>
-    </parameter>
-  </parameters>
+    </parameters>
   <actions>
     <action>
       <name>Start</name>

Reply via email to