Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion native-maven-plugin/docs/functional/tracing-agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ the destination. Application agent runs are attached to the `exec-maven-plugin`
the native plugin's `<agentExecutionId>` configuration value; the default execution ID is
`java-agent` so existing POMs keep working. Generated test-agent arguments derived from project paths
must remain a single JVM argument when passed through Maven test runners, including when those paths
contain spaces.
contain spaces. When adding that argument, Maven must preserve the test runner's existing `argLine`
options.
When Maven configures an instrumented test or application execution, normal build
output must report the Maven-managed agent output directory so users can find collected metadata
without debug logging, aligning with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,13 @@ static String quoteAgentArgumentForArgLine(String agentArgument) {
return agentArgument;
}

static String appendAgentArgument(String existingArgLine, String agentArgument) {
String quotedAgentArgument = quoteAgentArgumentForArgLine(agentArgument);
return existingArgLine == null || existingArgLine.isBlank()
? quotedAgentArgument
: existingArgLine + " " + quotedAgentArgument;
}

static String agentOutputDirectoryFor(String baseDir, Context context) {
return (baseDir + "/native/agent-output/" + context).replace('/', File.separatorChar);
}
Expand Down Expand Up @@ -248,11 +255,10 @@ private static boolean configureAgentForPlugin(Plugin plugin, String agentArgume
Xpp3Dom systemPropertyVariables = findOrAppend(configuration, SYSTEM_PROPERTY_VARIABLES);
Xpp3Dom agent = findOrAppend(systemPropertyVariables, NATIVEIMAGE_IMAGECODE);
agent.setValue("agent");
Xpp3Dom argLine = new Xpp3Dom("argLine");
Xpp3Dom argLine = findOrAppend(configuration, "argLine");
// Surefire/Failsafe parse argLine as one command-line string.
// Keep spaced output paths as one JVM argument. §FS-tracing-agent.3.
argLine.setValue(quoteAgentArgumentForArgLine(agentArgument));
configuration.addChild(argLine);
// Preserve user-supplied JVM options while keeping spaced output paths as one argument. §FS-tracing-agent.3.
argLine.setValue(appendAgentArgument(argLine.getValue(), agentArgument));
findOrAppend(configuration, "jvm").setValue(getGraalvmJava());
});
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,15 @@ class NativeExtensionTest extends Specification {
NativeExtension.quoteAgentArgumentForArgLine(agentArgument) == agentArgument
}

def "appends the test agent argument to an existing test runner argLine"() {
given:
def agentArgument = "-agentlib:native-image-agent=config-output-dir=target/native/agent-output/test"

expect:
NativeExtension.appendAgentArgument("-javaagent:existing-agent.jar", agentArgument) ==
"-javaagent:existing-agent.jar " + agentArgument
}

private static Plugin plugin(String artifactId) {
def plugin = new Plugin()
plugin.artifactId = artifactId
Expand Down