Skip to content

Commit

Permalink
Merge pull request #407 from dnestoro/dnestoro/EnableMetadataCopyWhen…
Browse files Browse the repository at this point in the history
…AgentIsEnabledFromCMD

Enable metadata copy when agent is enabled from cmd
  • Loading branch information
dnestoro committed Mar 8, 2023
2 parents b339e41 + 83f2ea3 commit 199ce20
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctio
when:
// Run Maven in debug mode (-X) in order to capture the command line arguments
// used to launch Surefire with the agent.
mvnDebug '-Pnative', 'test', '-DskipNativeTests'
mvnDebug '-Pnative', 'test', '-Dagent=true', '-DskipNativeTests'

then:
// Agent is used with Surefire
Expand All @@ -81,10 +81,10 @@ class JavaApplicationWithAgentFunctionalTest extends AbstractGraalVMMavenFunctio
def "test agent with metadata copy task"() {
given:
withSample("java-application-with-reflection")
mvn'-Pnative', '-DskipNativeBuild=true', 'package', 'exec:exec@java-agent'
mvn'-Pnative', '-DskipNativeBuild=true', 'package', '-Dagent=true', 'exec:exec@java-agent'

when:
mvn'-Pnative', '-DskipNativeTests', 'native:metadata-copy'
mvn'-Pnative', '-DskipNativeTests', '-Dagent=true', 'native:metadata-copy'

then:
buildSucceeded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*/
package org.graalvm.buildtools.maven;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
Expand Down Expand Up @@ -75,9 +76,12 @@ public class MetadataCopyMojo extends AbstractMergeAgentFilesMojo {
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;

@Parameter(defaultValue = "${session}", readonly = true)
private MavenSession session;

@Override
public void execute() throws MojoExecutionException {
if (agentConfiguration != null && agentConfiguration.isEnabled()) {
if (agentConfiguration != null && (agentConfiguration.isEnabled() || agentIsEnabledFromCmd())) {
// in direct mode user is fully responsible for agent configuration, and we will not execute anything besides line that user provided
if (agentConfiguration.getDefaultMode().equalsIgnoreCase("direct")) {
logger.info("You are running agent in direct mode. Skipping both merge and metadata copy tasks.");
Expand Down Expand Up @@ -215,4 +219,16 @@ private List<String> getListDiff(List<String> list1, List<String> list2) {
return diff;
}

private boolean agentIsEnabledFromCmd() {
if (session == null) {
return false;
}

if (session.getSystemProperties().getProperty("agent") == null) {
return false;
}

return session.getSystemProperties().getProperty("agent").equalsIgnoreCase("true");
}

}
1 change: 0 additions & 1 deletion samples/java-application-with-reflection/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@
<configuration>
<!-- end::native-plugin-agent-options[] -->
<agent>
<enabled>true</enabled>
<defaultMode>Standard</defaultMode>
<options>
<builtinCallerFilter>true</builtinCallerFilter>
Expand Down

0 comments on commit 199ce20

Please sign in to comment.