It is actually easier than that, there is no need to use system
properties. You can pass a parameter to an agent's 'premain' and
'agentmain' methods, which have signatures

public static void premain(
  String commandLineOptions,
  Instrumentation instr
)

public static void agentmain(
  String commandLineOptions,
  Instrumentation instr
)

Simply pass the information after '=' in

-javaagent:/path/to/myagent.jar=whatever

If 'whatever' is a simple string or something you want to further parse
and break down into key-value pairs or so, is totally up to you. I.e.
something like

<argLine>
  ${myJavaAgent}=${project.groupId}:${project.artifactId}
</argLine>

would be just fine.

-- 
Alexander Kriegisch
https://scrum-master.de


John Patrick schrieb am 30.03.2022 19:34 (GMT +07:00):

> I would do this via a profile, default value and surefire config, so
> something like;
> 
> <profiles>
>   <profile>
>     <id>withJavaAgent</id>
>     <properties>
>       <myJavaAgent>-javaagent:C:\JARS\agent.jar</myJavaAgent>
>     </properties>
>   </profile>
> </profiles>
> <properties>
>   <myJavaAgent></myJavaAgent>
> </properties>
> <plugin>
>   <artifactId>maven-surefire-plugin</artifactId>
>   <configuration>
>     <argLine>${myJavaAgent}
> -DtheGroup=${project.groupId} -DtheArtifact=${project.artifactId}</argLine>
>   </configuration>
> </plugin>
> 
> Then if you want to override on the command line it's; mvn test
> -DmyJavaAgent="-javaagent:C:\JARS\agent.jar"
> Or; mvn test -PwithJavaAgent
> 
> John
> 
> 
> On Wed, 30 Mar 2022 at 06:45, Laurian Angelescu <angelescu.laur...@gmail.com>
> wrote:
> 
>> I am working on a Java agent that instruments test suites and the code
>> under test. The agent runs by invoking the following command on the command
>> line:
>>
>> mvn test -DargLine="-javaagent:C:\JARS\agent.jar"
>>
>> The apache surefire plugin takes care of running the tests and pushing the
>> -DargLine argument to the test JVM.
>>
>> But for hierarchical projects, I believe multiple JVMs are instantiated,
>> one for each child package configured with pom.xml, as *mvn test *is
>> recusively invoked downstream. I would like to keep track of each such
>> child by capturing in mid-flight the group id, artifact id and version if
>> it's available and passing this information into the agent.
>>
>> Is there a way to accomplish this data capture? Assume JUnit test suites.
>>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org

Reply via email to