Clover instrumented classes generated in wrong directory

I have the following ant configuration. I am trying to get the instrumented classes separate from the actual compiled classes. I still see the instrumented classes in the destdir of javac target instead of the desdir of clover-instr. Please help.

<target name="with.clover">
      <clover-setup initstring="${clover.db}" />
      <clover-instr destdir="${build.dir}/clover/instrumented-classes" srcdir="${app.dir}/src" initstring="${clover.db}" />
    </target>
    <target name="compile" depends="with.clover">
        <javac destdir="${webinf.dir}/classes" srcdir="${app.dir}/src" debug="true" sourcepath="">
            <classpath refid="app.classpath" />
            <include name="**/*.java" />
        </javac>
    </target>

3 answers

I think the problem here is that you're not compiling the instrumented source but the non-instrumented one.

destdir - The directory into which Clover will write an instrumented copy of the source code.

So try that one:

<target name="with.clover">
<clover-setup initstring="${clover.db}" />
<clover-instr destdir="${build.dir}/clover/instrumented-classes" srcdir="${app.dir}/src" initstring="${clover.db}" />
</target>
<target name="compile" depends="with.clover">
<javac destdir="${webinf.dir}/classes" srcdir="${build.dir}/clover/instrumented-classes" debug="true" sourcepath="">
<classpath refid="app.classpath" />
<include name="**/*.java" />
</javac>
</target>

tried that and I'm getting the following error

[clover] Double instrumentation detected: C:\EclipseWorkspaces\ScaleDataProvider.java appears to have already been instrumented by Clover.
[clover] ** Error(s) occurred and the instrumentation process can't continue.

BUILD FAILED

Why do you call clover-instr ? This should not be required as clover-setup replaces the standart javac and when you call javac your classes will actually get instrumented.

So I think you need to either remove clover-setup or clover-instr.

<target name="with.clover">
      <clover-setup initstring="${clover.db}" />
  </target>
    <target name="compile" depends="with.clover">
        <javac destdir="${build.dir}/clover/instrumented-classes" srcdir="${app.dir}/src" debug="true" sourcepath="">
            <classpath refid="app.classpath" />
            <include name="**/*.java" />
        </javac>
    </target>

Do you need to have a non-instrumented classes on one place and instrumented on another ? In that case you should call javac to compile without instrumentation before calling clover-setup I think and then after clover-setup is called again call javac to compile with instrumentation.


here is the build script.

	<path id="instrument.build.classpath">
           .....
 <pathelement path="${clover.jar}"/> </path> <path id="test.classpath"> <path refid="instrument.build.classpath" />
.... </path> <target name="with.clover"> <clover-setup initstring="${clover.db}" /> </target> <target name="instrument" depends="prepare,with.clover" > <javac destdir="${instrument.dest.dir}" srcdir="${src.base.dir}/src" debug="true" sourcepath=""> <classpath refid="instrument.build.classpath" /> <include name="com/app/**/*.java" /> </javac> </target> <target name="clean"> <clover-clean initstring="${clover.db}" /> </target> <target name="prepare" depends="clean"> <mkdir dir="${test.classes.dir}" /> </target> <target name="testCompile" depends="instrument" description="Compiles the test classes from ${test.src.dir} to ${test.classes.dir}"> <javac srcdir="${test.src.dir}" destdir="${test.classes.dir}" includeantruntime="false" deprecation="on" debug="on" debuglevel="lines,vars,source" verbose="true" compiler="modern" encoding="latin1" > <classpath refid="test.classpath" /> </javac> </target> <target name="test" depends="testCompile"> <taskdef name="testng" classpath="${testng.jar}" classname="org.testng.TestNGAntTask" /> <testng haltOnfailure="true" listeners="com.app.common.TestListener" outputdir="${test.output.dir}" classpathref="test.classpath"> <xmlfileset dir="${test.classes.dir}/testsuite" includes="unittestng.xml" /> </testng> <!-- Run clover coverage report in html format --> <clover-html-report outdir="${coverage.results.dir}" title="Clover Report" initstring="${clover.db}" /> </target>

I separated the compilation for non-instrumented and instrumented classes. I do see the classes being instumented and clover.db getting created, but when I run the tests, I don't see the coverage files getting generated which is resulting in zero coverage.

[clover-html-report] Loading coverage database from: 'C:\EclipseWorkspaces\build\testng\build\clover\db\clover.db'
[clover-html-report] No coverage recordings found. No report will be generated.

tried that and I'm getting the following error

[clover] Processing files at 1.7 source level.
[clover] Double instrumentation detected: C:\EclipseWorkspaces\ScaleDataProvider.java appears to have already been instrumented by Clover.
[clover] ** Error(s) occurred and the instrumentation process can't continue.

BUILD FAILED

found the problem. had to move the instrumented classes to be first in the classpath.

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Friday in Off-topic

Friday Fun: Riddle me this

Happy Friday, Funmakers! We had a Community Team offsite in Austin this week, and my mind feels primed for thinkin' from all the brainstorming we did!  So, this week's Friday Fun thread w...

121 views 14 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you