Integrate JaCoCo "on-the-fly" in new URLClassLoader instances

50 views
Skip to first unread message

sorm...@gmail.com

unread,
Dec 14, 2018, 8:16:06 AM12/14/18
to JaCoCo and EclEmma Users
Hi JaCoCo team,

I'm writing a JUnit 5 support library that isolates main/test/others classes into dedicated class loaders. The first client of that library will be a Maven Plugin similar to Surefire. As I want to support "code coverage" early I'm thinking about ways how to enable this feature using JaCoCo.

At the moment, the new Maven Plugin executes tests "in-process" -- meaning the JaCoCo agent has already to be on the Maven boot class-path. Right?

Is there another way to get coverage data from a running process? Am I missing a/the point completely?

Cheers,
Christian

Marc Hoffmann

unread,
Dec 14, 2018, 8:51:12 AM12/14/18
to jac...@googlegroups.com
Hi Christian,

you might try offline instrumentation for the class files.

If you’re adding your own class loaders you might also consider doing on-the-fly instrumentation within your class loaders. See our API example “CoreTutorial”: https://www.jacoco.org/jacoco/trunk/doc/api.html

Regards,
-marc


--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/8eba6bfd-51bc-44a6-8197-c46694a61767%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sorm...@gmail.com

unread,
Dec 14, 2018, 9:34:46 AM12/14/18
to JaCoCo and EclEmma Users
On Friday, December 14, 2018 at 2:51:12 PM UTC+1, Marc R. Hoffmann wrote:
> Hi Christian,
>
>
> you might try offline instrumentation for the class files.
>
>
> If you’re adding your own class loaders you might also consider doing on-the-fly instrumentation within your class loaders. See our API example “CoreTutorial”: https://www.jacoco.org/jacoco/trunk/doc/api.html


Thanks for the quick reply, Marc!

And yes, that's exactly what I was looking for. Awesome.

Will report back when the integration is done. If you're interested in the progress, here is the tracking issue: https://github.com/sormuras/junit-platform-maven-plugin/issues/18

Cheers,
Christian

Evgeny Mandrikov

unread,
Dec 14, 2018, 10:28:48 AM12/14/18
to JaCoCo and EclEmma Users
While you can do what Marc proposed,
recommended way of JaCoCo usage/integration - is agent,
mainly because of its simplicity in understanding by end-users,
especially compared to ClassLoaders.

Moreover

On Friday, December 14, 2018 at 2:16:06 PM UTC+1, sorm...@gmail.com wrote:

At the moment, the new Maven Plugin executes tests "in-process" --


IMO execution of tests inside of Maven process is a bad idea in general.
Not only agents can't be used, but also impossible to specify any other JVM options without affecting Maven - think about "-Xmx", "-D", etc.
So my advice will be to support out-of-Maven-process execution early. After that support of JaCoCo IMO will be much simpler to develop and maintain for you, and most importantly simpler to understand for end-users who are already familiar with usage of JaCoCo with maven-surefire-plugin.

Marc Hoffmann

unread,
Dec 14, 2018, 12:01:03 PM12/14/18
to jac...@googlegroups.com
I agree with Evgeny. There is another important requirement in many build setups:

You might want to use a different JDK for running your tests (e.g. when running your test suites against latest JDKs).

Cheers,
-marc



--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.

sorm...@gmail.com

unread,
Dec 15, 2018, 7:34:48 AM12/15/18
to JaCoCo and EclEmma Users
On Friday, December 14, 2018 at 6:01:03 PM UTC+1, Marc R. Hoffmann wrote:
> I agree with Evgeny. There is another important requirement in many build setups:
>
>
> You might want to use a different JDK for running your tests (e.g. when running your test suites against latest JDKs).
>


Thanks to both of you for mentioning those valid points. The new plugin will of course have a "fork option" that allows using jacoco et al like we are used to. Actually, the new plugin implementation started by calling the `junit-platform-console` program as an external process. I will re-introduce this mode later.

My question was related to the non-forked mode -- which will support jacoco soon with no user-interaction needed, because it is impossible.

sorm...@gmail.com

unread,
Dec 15, 2018, 11:44:12 AM12/15/18
to JaCoCo and EclEmma Users
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages