Skip to content

Commit

Permalink
CAMEL-21567: camel-jbang - Debug command should accept options from run
Browse files Browse the repository at this point in the history
  • Loading branch information
davsclaus committed Dec 22, 2024
1 parent a2eff02 commit 0c15919
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.camel.main.KameletMain;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ReflectionHelper;
import org.apache.camel.util.StringHelper;
import org.apache.camel.util.TimeUtils;
import org.apache.camel.util.URISupport;
Expand Down Expand Up @@ -220,7 +219,7 @@ private void doRead(Console c, AtomicBoolean quit) {
logUpdated.set(true);
}
}
sendDebugCommand(spawnPid, "step", null);
sendDebugCommand(spawnPid, "step", line, null);
}
// user have pressed ENTER so continue
waitForUser.set(false);
Expand Down Expand Up @@ -266,7 +265,8 @@ protected int runDebug(KameletMain main) throws Exception {
}

private void removeDebugOnlyOptions(List<String> cmds) {
ReflectionHelper.doWithFields(Debug.class, fc -> cmds.removeIf(c -> {
// 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);
Expand Down Expand Up @@ -309,7 +309,7 @@ protected int doWatch() {
return 0;
}

private void sendDebugCommand(long pid, String command, String breakpoint) {
private void sendDebugCommand(long pid, String command, String argument, String breakpoint) {
// ensure output file is deleted before executing action
File outputFile = getOutputFile(Long.toString(pid));
FileUtil.deleteFile(outputFile);
Expand All @@ -319,6 +319,14 @@ private void sendDebugCommand(long pid, String command, String breakpoint) {
if (command != null) {
root.put("command", command);
}
if (argument != null && !argument.isBlank()) {
if ("i".equals(argument)) {
argument = "into";
} else if ("o".equals(argument)) {
argument = "over";
}
root.put("argument", argument);
}
if (breakpoint != null) {
root.put("breakpoint", breakpoint);
}
Expand Down Expand Up @@ -471,7 +479,7 @@ private void printDebugStatus(long pid, StringWriter buffer) {
}
}

String msg = " Breakpoint suspended. Press ENTER to continue.";
String msg = " Breakpoint suspended. Press ENTER to continue (i = step into (default), o = step over).";
if (loggingColor) {
AnsiConsole.out().println(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a(msg).reset());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -28,6 +29,7 @@
import org.apache.camel.catalog.CamelCatalog;
import org.apache.camel.catalog.DefaultCamelCatalog;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.ReflectionHelper;
import org.apache.camel.util.StringHelper;
import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
Expand Down Expand Up @@ -191,4 +193,15 @@ public static boolean isInCamelCatalog(String artifactId) {
}
return false;
}

public static void doWithFields(Class<?> clazz, ReflectionHelper.FieldCallback fc) throws IllegalArgumentException {
Field[] fields = clazz.getDeclaredFields();
for (Field field : fields) {
try {
fc.doWith(field);
} catch (IllegalAccessException ex) {
// ignore
}
}
}
}

0 comments on commit 0c15919

Please sign in to comment.