I am attempting to instrument wars with Cobertura 1.9.4.1. For this, I use the following ant task, which is invoked using the maven-antrun-plugin:
<target name="instrumentEar">
<cobertura-instrument todir="${module}/target/${ear.dir}">
<includeclasses regex="nl.*" />
<fileset dir="${module}/target/${ear.dir}">
<include name="**/*.war"/>
</fileset>
</cobertura-instrument>
</target>
Upon execution the output is:
[INFO] --- maven-antrun-plugin:1.3:run (instrument) @ my-ear ---
[INFO] Executing tasks
instrumentEar:
[cobertura-instrument] Cobertura 1.9.4.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-instrument] Instrumenting 2 files to D:\workspace\my-ear\target\my-ear-1.0.0-SNAPSHOT
[cobertura-instrument] Cobertura: Error closing output stream.
[cobertura-instrument] java.util.zip.ZipException: ZIP file must have at least one entry
[cobertura-instrument] at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:304)
[cobertura-instrument] at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:146)
[cobertura-instrument] at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:321)
[cobertura-instrument] at net.sourceforge.cobertura.util.IOUtil.closeOutputStream(IOUtil.java:165)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.addInstrumentationToArchive(Main.java:319)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:488)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.main(Main.java:514)
[cobertura-instrument] Cobertura: Error closing output stream.
[cobertura-instrument] java.util.zip.ZipException: ZIP file must have at least one entry
[cobertura-instrument] at java.util.zip.ZipOutputStream.finish(ZipOutputStream.java:304)
[cobertura-instrument] at java.util.zip.DeflaterOutputStream.close(DeflaterOutputStream.java:146)
[cobertura-instrument] at java.util.zip.ZipOutputStream.close(ZipOutputStream.java:321)
[cobertura-instrument] at net.sourceforge.cobertura.util.IOUtil.closeOutputStream(IOUtil.java:165)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.addInstrumentationToArchive(Main.java:319)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:488)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.Main.main(Main.java:514)
[cobertura-instrument] Cobertura: Saved information on 0 classes.
[cobertura-instrument] Instrument time: 67ms
It seems ant is unable to read the wars that have been created by maven. I can remember from a long time ago I had problems with the java zip implementation and used the one from ant. Could it be something similar is happening here, but reversed?
This thread suggests this should work, but some people recommend extracting the wars first before instrumenting.
Has anybody had any success with the ant task (cobertura-instrument) to instrument wars in place?