This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 2a4465f27142 CAMEL-26930: camel-jbang - camel debug passes the run
options on to camel run (#29931)
2a4465f27142 is described below
commit 2a4465f271425ee61d59e217fcda7e6a2e6393af
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 14 19:27:41 2026 +0100
CAMEL-26930: camel-jbang - camel debug passes the run options on to camel
run (#29931)
camel debug removed every argument that started with the name of a field of
Debug,
such as --source-dir=... for the field source, and left the value of an
option given
with a space, such as --breakpoint tick, which camel run then took as a
file. The
options of camel debug are now removed by their exact names, with their
values.
CAMEL-26930: camel-jbang - shorter sentences in the Javadoc of
Debug.withoutDebugOnlyOptions
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../camel/dsl/jbang/core/commands/Debug.java | 44 ++++++++++++++----
.../jbang/core/commands/DebugRunArgumentsTest.java | 53 ++++++++++++++++++++++
2 files changed, 89 insertions(+), 8 deletions(-)
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Debug.java
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Debug.java
index dc7b8372b83b..05f9ce95647d 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Debug.java
+++
b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Debug.java
@@ -25,13 +25,16 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringWriter;
+import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
@@ -591,7 +594,7 @@ public class Debug extends Run {
cmds = BackgroundWait.withoutBackgroundOptions(cmds);
// remove args from debug that are not supported by run
- removeDebugOnlyOptions(cmds);
+ cmds = withoutDebugOnlyOptions(cmds);
// enable light-weight debugger (not camel-debug JAR that is for
IDEA/VSCode tooling with remote JMX)
cmds.add("--prop=camel.debug.enabled=true");
@@ -622,13 +625,38 @@ public class Debug extends Run {
return 0;
}
- private void removeDebugOnlyOptions(List<String> cmds) {
- // only check Debug.class (not super classes)
- RunHelper.doWithFields(Debug.class, fc -> cmds.removeIf(c -> {
- String n1 = "--" + fc.getName();
- String n2 = "--" + StringHelper.camelCaseToDash(fc.getName());
- return c.startsWith(n1) || c.startsWith(n2);
- }));
+ /**
+ * The arguments for camel run: without the options that only camel debug
has. Each goes by its exact name, with its
+ * value (--breakpoint=tick, or --breakpoint tick).
+ * <p>
+ * CAMEL-26930: any argument that started with the name of a field went,
such as --source-dir=... for the field
+ * source. The value of --breakpoint tick stayed, and camel run took it
for a file.
+ */
+ static List<String> withoutDebugOnlyOptions(List<String> args) {
+ // only the options of Debug (not of its super classes), and whether
they take a value
+ Map<String, Boolean> options = new HashMap<>();
+ for (Field field : Debug.class.getDeclaredFields()) {
+ Option option = field.getAnnotation(Option.class);
+ if (option != null) {
+ options.put("--" + option.name(), option.hasValue());
+ for (String alias : option.aliases()) {
+ options.put("--" + alias, option.hasValue());
+ }
+ }
+ }
+ List<String> answer = new ArrayList<>(args.size());
+ for (int i = 0; i < args.size(); i++) {
+ String arg = args.get(i);
+ int eq = arg.indexOf('=');
+ Boolean hasValue = options.get(eq > 0 ? arg.substring(0, eq) :
arg);
+ if (hasValue == null) {
+ answer.add(arg);
+ } else if (eq < 0 && hasValue && i + 1 < args.size() &&
!args.get(i + 1).startsWith("-")) {
+ // its value
+ i++;
+ }
+ }
+ return answer;
}
protected int doWatch() {
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DebugRunArgumentsTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DebugRunArgumentsTest.java
new file mode 100644
index 000000000000..935c3be515ba
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DebugRunArgumentsTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.camel.dsl.jbang.core.commands;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The arguments of the camel run that camel debug starts: before, every
argument that started with the name of a field
+ * of Debug was removed, and the value of an option given with a space was
left as a file (CAMEL-26930).
+ */
+class DebugRunArgumentsTest {
+
+ @Test
+ void theRunOptionsStay() {
+ // the field source of Debug removed --source-dir=...
+ assertThat(Debug.withoutDebugOnlyOptions(List.of("run",
"--source-dir=src", "--source", "route.yaml")))
+ .containsExactly("run", "--source-dir=src", "route.yaml");
+ }
+
+ @Test
+ void theDebugOptionsGoWithTheirValues() {
+ assertThat(Debug.withoutDebugOnlyOptions(List.of("run",
"--breakpoint", "tick", "--log-lines=5", "route.yaml",
+ "--show-headers", "--port=8081")))
+ .containsExactly("run", "route.yaml", "--port=8081");
+ assertThat(Debug.withoutDebugOnlyOptions(List.of("run",
"--breakpoint=tick", "route.yaml")))
+ .containsExactly("run", "route.yaml");
+ }
+
+ @Test
+ void aFlagDoesNotTakeTheNextArgument() {
+ // --pretty has no value: route.yaml after it is the file of the run
+ assertThat(Debug.withoutDebugOnlyOptions(List.of("run", "--pretty",
"route.yaml")))
+ .containsExactly("run", "route.yaml");
+ }
+}