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
Community showcase
Posted Tuesday in United States

Topic Tuesday: What's your favorite topic?

Good morning All, Our goal is to get you into the habit of while enjoying your favorite morning drink you are checking the NOVA "space" for topics and comments. Your input is really needed and...

69 views 4 0
View post

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