Skip to content

Commit

Permalink
improve debug server to take args array
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrthomas committed Jul 24, 2023
1 parent 221cd47 commit b962e60
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
4 changes: 4 additions & 0 deletions karate-core/src/main/java/com/intuit/karate/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ public static Main parseKarateOptions(String line) {
String[] args = Command.tokenize(line);
return CommandLine.populateCommand(new Main(), args);
}

public static Main parseKarateArgs(List<String> args) {
return CommandLine.populateCommand(new Main(), args.toArray(new String[args.size()]));
}

// matches ( -X XXX )* (XXX)
private static final Pattern CLI_ARGS = Pattern.compile("(\\s*-{1,2}\\w\\s\\S*\\s*)*(.*)$");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public class DapServerHandler extends SimpleChannelInboundHandler<DapMessage> im
protected final Map<Long, Stack<Map<String, Variable>>> FRAME_VARS = new ConcurrentHashMap();
protected final Map<Long, Entry<String, Variable>> VARIABLES = new ConcurrentHashMap();

private List<String> launchArgs;
private String launchCommand;
private String preStep;

Expand Down Expand Up @@ -262,9 +263,16 @@ private void handleRequest(DapMessage req, ChannelHandlerContext ctx) {
case "launch":
// normally a single feature full path, but can be set with any valid karate.options
// for e.g. "-t @smoke -T 5 classpath:demo.feature"
String karateOptions = StringUtils.trimToEmpty(req.getArgument("karateOptions", String.class));
String feature = StringUtils.trimToEmpty(req.getArgument("feature", String.class));
launchCommand = StringUtils.trimToEmpty(karateOptions + " " + feature);
launchArgs = req.getArgument("karateArgs", List.class);
launchCommand = StringUtils.trimToEmpty(req.getArgument("karateOptions", String.class));
String feature = StringUtils.trimToNull(req.getArgument("feature", String.class));
if (feature != null) {
if (launchArgs != null) {
launchArgs.add(feature);
} else {
launchCommand = launchCommand + " " + feature;
}
}
preStep = StringUtils.trimToNull(req.getArgument("debugPreStep", String.class));
if (preStep != null) {
logger.debug("using pre-step: {}", preStep);
Expand Down Expand Up @@ -413,8 +421,14 @@ public RuntimeHook create() {
}

private void start() {
logger.debug("command line: {}", launchCommand);
Main options = IdeMain.parseIdeCommandLine(launchCommand);
Main options;
if (launchArgs != null) {
logger.debug("command args: {}", launchArgs);
options = Main.parseKarateArgs(launchArgs);
} else {
logger.debug("command line: {}", launchCommand);
options = IdeMain.parseIdeCommandLine(launchCommand);
}
if (runnerThread != null) {
runnerThread.interrupt();
}
Expand Down

0 comments on commit b962e60

Please sign in to comment.