Skip to content

Commit

Permalink
feat: Update behavior of debug flag
Browse files Browse the repository at this point in the history
Match behavior of debug options to appmap-java and the maven plugin
  • Loading branch information
kgilpin committed Aug 6, 2021
1 parent 9286a9f commit d6e9019
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/main/java/com/appland/appmap/AgentCommandLineLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
*/
public class AgentCommandLineLoader implements CommandLineArgumentProvider, Named {

static final String DEFAULT_CONFIG_FILE = "appmap.yml";

private static final Logger LOGGER = Logging.getLogger(CommandLineArgumentProvider.class);
private static final List<String> DEBUG_FLAGS = Arrays.asList("hooks", "locals", "http");
private static final List<String> DEBUG_FLAGS = Arrays.asList("debug", "hooks", "locals", "http");

private final AppMapPluginExtension appmap;

Expand Down Expand Up @@ -55,7 +57,7 @@ public List<String> getAsJvmArg() {
+ appmap.getConfigFile().get().getAsFile().getPath());
}
if (appmap.shouldSkip()) {
LOGGER.warn("AppMap task was executed but but is disable, skip property set to " + appmap
LOGGER.warn("AppMap task was executed but but is disabled, 'skip' property set to " + appmap
.shouldSkip());
return new ArrayList<>();
} else {
Expand All @@ -66,8 +68,11 @@ public List<String> getAsJvmArg() {

List<String> argumentLn = new ArrayList<>();
argumentLn.add(javaAgentArg);
argumentLn.add("-Dappmap.config.file=" + appmap.getConfigFile().get().toString());
argumentLn.add("-Dappmap.output.directory=" + appmap.getOutputDirectory().get().toString());

if ( appmap.getConfigFile().isPresent() ) {
argumentLn.add("-Dappmap.config.file=" + appmap.getConfigFile().get());
}
argumentLn.add("-Dappmap.output.directory=" + appmap.getOutputDirectory().get());
argumentLn.add("-Dappmap.event.valueSize=" + appmap.getEventValueSize());
argumentLn.addAll(buildDebugParams());
LOGGER.lifecycle("Arguments line set to " + Joiner.on(",").join(argumentLn));
Expand All @@ -80,14 +85,23 @@ private List<String> buildDebugParams() {
if (appmap.getDebug() != null && !appmap.getDebug().isEmpty()) {
final List<String> debugTokens = new ArrayList<>(
Arrays.asList(appmap.getDebug().split("[,|\\s]")));

boolean hasDebug = false;
for (String token : debugTokens) {
if (DEBUG_FLAGS.contains(token)) {
debugArgs.add("-Dappmap.debug." + token);
hasDebug = true;
if (token.equals("debug")) {
debugArgs.add("-Dappmap.debug");
} else {
debugArgs.add("-Dappmap.debug." + token);
}
}
}
debugArgs.add(0, "-Dappmap.debug");
debugArgs.add(0, "-Dappmap.debug.file=" + StringEscapeUtils
.escapeJava(format("%s", appmap.getDebugFile())));

if (hasDebug) {
debugArgs.add(0, "-Dappmap.debug.file=" + StringEscapeUtils
.escapeJava(format("%s", appmap.getDebugFile())));
}
}
return debugArgs;
}
Expand Down

0 comments on commit d6e9019

Please sign in to comment.