gradle-clover-plugin
gradle-clover-plugin copied to clipboard
Steps for generating instrumented war using gradle clover plugin
Hi ,
I am using gradle clover plugin to in to instrument the source coed and .I am able to instrument the classes successfully and got the coverage report. I wanted to build the war from instrumented classes and deploy the war ,have to collect the coverage.
For eg. we can generate instrumented war/jar from maven & clover combination
Is it possible to do?
Could you please help?
Thanks, Chithra
Support for creating JAR/WAR files with instrumented code has been added as explained here: Project Properties
This should be used in conjunction with code that sets up an integration test that uses the instrumented WAR file perhaps with GRetty plugin to run and collect coverage. The property cloverInstrumentedJar
can be used by your build.gradle script to control when this test is executed since you would not want the instrumented JAR file to be used in the production environment.
Your integration tests would need to setup the location of the clover.db using the system properties supported by Clover. The result would be an updated clover.db file that could then used in the clover report. I have not tried that myself but the logic supports the operations required. Ideally the clover report task will pick up the database recordings and add them to the resulting report.
You may need to add the flushpolicy
and flushinterval
configuration values in the clover closure to configure these appropriately.
Thanks Alex.It worked
Hello @bkchithra1 / @Alex-Vol ,
I am a newbie in code coverage and gradle. I need your help in generating instrumented WAR for my project. I have few queries:
- I am using the below terminal command to generate instrumented WAR. Is this correct?
gradle -PcloverInstrumentedJar clean build
I use gradle clean build
to create normal WAR.
-
Does instrumented WAR get created at the same location with the same name as of normal WAR?
-
Is there any way to be sure that instrumented WAR created like clover will be printed in logs?
Thanks in advance.
- Yes, that command line creates the instrumented WAR
- Yes, no attempt is made to create the war with a different name. You should be able to make this yourself using the conditional I use to control clover in your war task configuration
war {
if (project.hasProperty('cloverInstrumentedJar')) {
baseName = baseName + '-instr'
}
}
This will create the war file with the name
- Same approach could be used to signal the war creation is instrumented.
war {
doFirst {
if (project.hasProperty('cloverInstrumentedJar')) {
println "INFO: Creating Clover instrumented WAR"
}
}
}
Thank you very much @Alex-Vol for the quick response. I can see logs of instrumented war creation now. I am deploying the same war on local tomcat with property
-Dclover.initstring.basedir=/home/user/workspace/project/build/.clover
to update .db files at runtime.
I can see below logs while war deployment which might mean that instrumented war being deployed on tomcat
018-02-01 17:48:14,937 [9053935] INFO - over.idea.build.CloverCompiler - CLOVER: COMPILATION IN EXTERNAL BUILD PROCESS HAS FINISHED
But I don't see any clover logs in tomcat logs during integration tests execution and .db files do not update. My integration tests are in the different repository. Please let me know if you see any problem with the setup.
Also, please share how to set flushpolicy
and flushinterval
values in the clover closure. Does below format correct?
clover{
flushpolicy=interval
}
Regards, Shanky
Does tomcat process run with user identity that can write to files in /home/user/workspace/project/build/.clover
?
The format for the configuration is this:
clover {
flushpolicy = 'interval'
}
I do not expect any clover logs generated by the instrumented war file. I would expect when operations are performed that use the code they result in updates to the clover.db files. I have not attempted running with instrumented war files so I cannot confirm what you should expect.
Hi @Alex-Vol ,
Yes, you were right. tomcat
user had no rights to write at the project location. This I found in the logs after deploying instrumented WAR directly on tomcat. Previously, I was deploying via Intellij and no logs were coming for permission denied. Also, I am able to see clover logs in server logs by passing below VM arguments to tomcat:
-Dclover.logging.level=debug
Now the problem is aggregate report is not showing coverage done by integration tests. I am following the below steps. Please help. Thanks.
- I have provided same submodule location where unit tests db files are created. I can see new db files gets created when integration tests are executed. Same gets printed in the logs as well,
[flushed per-test recording (/home/user/workspace/prime-tracking/pilot-tracking/pilot-tracking-engine/build/.clover/clover.db-test1r8dacv75zui7_1v_1di977_jdd8p6lo.s) ] [flushed per-test recording (/home/user/workspace/prime-tracking/pilot-tracking/pilot-tracking-engine/build/.clover/clover.db-test1r8dacv75zui7_1v_8py5lk_jdd8p6lo.s) ]
Writing global coverage file /home/user/workspace/prime-tracking/pilot-tracking/pilot-tracking-engine/build/.clover/clover.db-test8py5lk_jdd7iogiWriting global coverage file /home/user/workspace/prime-tracking/pilot-tracking/pilot-tracking-engine/build/.clover/clover.db-test1di977_jdd7rdyq Writing global coverage file /home/user/workspace/prime-tracking/pilot-tracking/pilot-tracking-engine/build/.clover/clover.db-testumozz6_jdd7iqkq
- Then I am executing
gradle cloverAggregateReports
. But no changes are reflected in the report. clover.db-test file does not update. Could this be an issue?
clover is set up in the build.gradle of root project.
This may require some extra functionality from the plugin unless you can make this work with a single DB file in a new Gradle integration test harness. The plugin will only aggregate databases generated by a Gradle test task. To get this working you would need to setup Tomcat as a test harness invoked by the gradle build during an integration test. You would need to configure the Tomcat process to write a specific clover.db file and not this one per test file.
If you use -Dclover.initstring=/home/user/workspace/project/build/.clover/clover.db
the Tomcat engine should consolidate the database into a single file which is what the plugin expects. Even this is not exactly right, in my opinion this would work if there was a specific integration test and you configured the plugin to expect the same clover.db file as the one generated by Tomcat.
I know others have succeeded to make this work, I suspect you need to spend some more time with it to have it finished. I do not have time to research the details now, so I would not want you to wait for me.
Hi @Alex-Vol ,
Thank you for providing the details and for all your help to reach this point. Yes, I will try to figure it out. Meanwhile, if you get the time please develop this feature.
Shall I raise the feature request?
Regards, Shanky