How to use jococo ant task with already compiled/build java code ?

1,142 views
Skip to first unread message

kta...@gmail.com

unread,
Jul 15, 2014, 3:47:00 AM7/15/14
to jac...@googlegroups.com
Hi guys ,
I am new to java and this plugin :)

I am having the complete build/compiled java code with me for swtbot tests. Now i want to see what all code/features has been covered from these tests. So tried to use the ant tasks of jacoco mentioned at

http://www.eclemma.org/jacoco/trunk/doc/ant.html

and referenced
http://www.eclemma.org/jacoco/trunk/doc/examples/build/build.xml too.


when i am giving the report target as

<target name="report" depends="suite">
<!-- Step 3: Create coverage report -->
<jacoco:report>

<!-- This task needs the collected execution data and ... -->
<executiondata>
<file file="${result.exec.file}" />
</executiondata>

<!-- the class files and optional source files ... -->
<structure name="JaCoCo report">
<classfiles>
<fileset dir="${result.classes.dir}" />
</classfiles>

</structure>

<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}" />
<csv destfile="${result.report.dir}/report.csv" />
<xml destfile="${result.report.dir}/report.xml" />
</jacoco:report>
</target>


and coverage as

<jacoco:coverage destfile="${result.exec.file}">
<java fork="true" dir="." timeout="${timeout}" jvm="${jvm}" logError="true" classname="org.eclipse.core.launcher.Main" output="${junit-report-output}/${classname}.txt">
<classpath>
<fileset dir="${eclipse-home}/plugins">
<include name="org.eclipse.equinox.launcher_*.jar" />
</fileset>
</classpath>
<arg line="${launcher-arg-line}" />
<jvmarg line="${jvm-arg-line}" />
<sysproperty key="PLUGIN_PATH" value="${plugin-path}" />
</java>
</jacoco:coverage>

where ${result.classes.dir} (i.e. ${eclipse-home}/plugins) points to my already compiled code directory containing many .class and .jar under different folders.

.exec and index.html and .session.html files are getting generated but result is not correct and command prompt it shows
BUILD FAILED : Error while creating report.

. It is not listing all the classes and .sessions.html lists many classes but with no links to direct to that class and see the executed methods .

And when i run the EclEmma eclipse plugin from eclipse and run and see the result there then that it is working absolutely fine.

So i am just wandering what is missing in case of ant tasks ?

Marc R. Hoffmann

unread,
Jul 15, 2014, 4:01:20 AM7/15/14
to jac...@googlegroups.com
What is the full error message please?

Best regards,
-marc

kta...@gmail.com

unread,
Jul 15, 2014, 4:46:03 AM7/15/14
to jac...@googlegroups.com
plz see the last line of the logs...line 64 is <jacoco:report> tag mentioned earlier...

C:\Xars_client\run\Xplorer>ant -f run_test.xml run -Declipse_home=C:\Xars_client
\run\xplorer\eclipse -Dtest-classname=com.tensilica.xbot.importexport.tests.Expo
rtProjectsTest -Dtest-pluginname=com.tensilica.xbot.importexport.tests -Declipse
-rundir= C:\Xars_client\run\xplorer\eclipse -Dtemp-workspace=C:\workspace_ws -Do
s=win32 -Dlog4j_output=c:\xars_client\run\logs -Dxbotdir=C:\Xars_client\run\xplo
rer\eclipse\plugins -DwaitForEarlyStartup=true -Dws=win32 -DpluginCustomization=
S:\winWS\er_r.ini -Dproject_dir="D:\Work\PerforceDepot\eagle_nest_ktayal\p4root\
other\xideregress\projects" -Dlocalroot=C:\Xars_client\xen_dev\
Buildfile: C:\Xars_client\run\Xplorer\run_test.xml

suite:

init:

swtbot-test:

java-test:
[echo] ======================================
[echo] Running swtbot junit tests in com.tensilica.xbot.importexport.tests.
ExportProjectsTest
[echo] Command line args are -application org.eclipse.swtbot.eclipse.ju
nit4.headless.swtbottestapplication -product com.tensilica.xide.xplorer_ce
-testApplication org.eclipse.ui.ide.workbench -data C:\workspace_ws forma
tter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,C:\Xar
s_client\run\xplorer\eclipse/com.tensilica.xbot.importexport.tests.ExportProject
sTest.xml formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResul
tFormatter -testPluginName com.tensilica.xbot.importexport.tests -classNam
e com.tensilica.xbot.importexport.tests.ExportProjectsTest -os win32 -ws w
in32 -arch x86 -consoleLog -debug -showLocation -pluginCustomization
S:/winWS/er_r.ini --discover ${extraXXargs}
[echo] JVM args are -Dxbot.pluginsdir=C:\Xars_client\run\xplorer\eclipse\pl
ugins -Dtools_dir=${toolsdir} -Dtools=${tools} -Dproject_dir=D:\Work\Perfor
ceDepot\eagle_nest_ktayal\p4root\other\xideregress\projects -Dtie_dir=${tiedir}
-Dtest_count=1 -Dtemp_dir=${tempdir} -Dlocalroot=C:\Xars_client\xen_dev\
-Dorg.eclipse.ui.testsWaitForEarlyStartup=true -Dlog4j_output=c:\xars_cli
ent\run\logs
[echo] JUnit Result File: C:\Xars_client\run\xplorer\eclipse/results/com.te
nsilica.xbot.importexport.tests.ExportProjectsTest.xml.
[echo] Console output File: C:\Xars_client\run\xplorer\eclipse/results/com.
tensilica.xbot.importexport.tests.ExportProjectsTest.txt.
[echo] ======================================
[jacoco:coverage] Enhancing java with coverage
[echo] ======================================
[echo] If you see errors above please see the file C:\Xars_client\run\xplor
er\eclipse/results/com.tensilica.xbot.importexport.tests.ExportProjectsTest.txt
for more information.
[echo] Errors are generally caused by missing or incorrect dependencies.
[echo] ======================================

collect-results:
[move] Warning: C:\Xars_client\run\xplorer\eclipse\screenshots does not exi
st.
[xslt] Transforming into C:\Xars_client\run\xplorer\eclipse\results
[xslt] Processing C:\Xars_client\run\xplorer\eclipse\results\com.tensilica.
xbot.importexport.tests.ExportProjectsTest.xml to C:\Xars_client\run\xplorer\ecl
ipse\results\com.tensilica.xbot.importexport.tests.ExportProjectsTest.html
[xslt] Loading stylesheet C:\Xars_client\run\xplorer\eclipse\plugins\org.ec
lipse.swtbot.eclipse.junit4.headless_2.0.5.20111003_1754-3676ac8-dev-e36\JUNIT.X
SL

report:
[jacoco:report] Loading execution data file C:\Xars_client\run\jacoco_results\ja
coco.exec

BUILD FAILED
C:\Xars_client\run\Xplorer\run_test.xml:64: Error while creating report

Total time: 1 minute 27 seconds

Marc R. Hoffmann

unread,
Jul 15, 2014, 11:37:12 AM7/15/14
to jac...@googlegroups.com
Hm, no useful information here. Can you please run your Ant build with
the -debug option to get more output about the problem?

Ths,
-marc
2rf

kunal tayal

unread,
Jul 16, 2014, 1:48:17 AM7/16/14
to jac...@googlegroups.com
Hi Marc


found out the issue...

changed the <classfiles> element from

<classfiles>
<fileset dir="${result.classes.dir}" >
</classfiles>


to 
                              <classfiles>
<fileset dir="${result.classes.dir}" >
 <include name="com.xyz.xide*.jar"/>
 <include name="com.xyz.xide*/**/*.class"/>
 <include name="com.xyz.xbot*/**/*.class"/>
</fileset>
</classfiles>


without <include> it was not able to take the  .class and .jar files recursively directly from dir ${result.classes.dir}.


Any ways thanks for your time !

-kunal


--
You received this message because you are subscribed to a topic in the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jacoco/AqidzHPR4f8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jacoco+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kunal tayal

unread,
Jul 16, 2014, 5:16:49 AM7/16/14
to jac...@googlegroups.com
Hi marc,

now its not getting the link to source files

<classfiles>
<fileset dir="C:\Xars_client\run\Xplorer\eclipse\plugins\com.xyz.xbot.importexport.tests_4.5.0.201407111823\com\xyz\xbot\importexport\tests" >
</fileset>
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="C:\Xars_client\run\Xplorer\eclipse\plugins\com.xyz.xbot.importexport.tests_4.5.0.201407111823\com\xyz\xbot\importexport\tests">
</fileset>
</sourcefiles>


"C:\Xars_client\run\Xplorer\eclipse\plugins\com.xyz.xbot.importexport.tests_4.5.0.201407111823\com\xyz\xbot\importexport\tests" contains both java and class files. but in report m not linked to source files.


Can u tell me whats going on ?


i tried include *.java too...that is also not working ..

Marc R. Hoffmann

unread,
Jul 22, 2014, 1:32:18 AM7/22/14
to jac...@googlegroups.com
We have an FAQ item for this problem: http://www.eclemma.org/jacoco/trunk/doc/faq.html

-marc

Why does the coverage report not show highlighted source code?

Make sure the following prerequisites are fulfilled to get source code highlighting in JaCoCo coverage reports:

  • Class files must be compiled with debug information to contain line numbers.
  • Source files must be properly supplied at report generation time. I.e. specified source folders must be the direct parent of the folders that define the Java packages.
To unsubscribe from this group and all its topics, send an email to jacoco+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
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.

kunal tayal

unread,
Jul 22, 2014, 1:57:33 AM7/22/14
to jac...@googlegroups.com
Hi marc,

yah i somehow resolved the issue same day..

problem was : --"specified source folders must be the direct parent of the folders that define the Java packages"  

thanks

kunal tayal

unread,
Jul 24, 2014, 4:05:28 AM7/24/14
to jac...@googlegroups.com
Hi marc,

I got some eclipse plugins in folders and some in jars. Jacoco  is nicely taking the source from the folders but not including the source from jars ..

                                     <dirset dir="${src.dir}/" > 
<include name="com.xyz.xbot*/src"/>
<include name="com.xyz.xide*/src"/>
<include name="org.eclipse.cdt*/src"/>
<include name="com.xyz.xbot*.jar/src"/>
<include name="com.xyz.xide*.jar/src"/>
<include name="org.eclipse.cdt*.jar/src"/>
</dirset>


it is perfectly working for <include name="com.xyz.xbot*/src"/>
<include name="com.xyz.xide*/src"/>
<include name="org.eclipse.cdt*/src"/>


but not including the source in jar files....
<include name="com.xyz.xbot*.jar/src"/>
<include name="com.xyz.xide*.jar/src"/>
<include name="org.eclipse.cdt*.jar/src"/>


what could be the reason...?

kunal tayal

unread,
Jul 24, 2014, 8:32:23 AM7/24/14
to jac...@googlegroups.com
moreover if my .java files packages are directly under the .jars then 
 <archives>
<zips> 
<fileset dir="${src.dir}">
<include name="com.xyz.xbot*.jar"/>
<include name="com.xyz.xide*.jar"/>
<include name="org.xyz.cdt*.jar"/>
</fileset>
</zips>
</archives> 

this also works.


but if the packages are under .jars/src  then 

 <archives>
<zips> 
<fileset dir="${src.dir}">
<include name="com.xyz.xbot*.jar/src"/>
<include name="com.xyz.xide*.jar/src"/>
<include name="org.xyz.cdt*.jar/src"/>
</fileset>
</zips>
</archives> 

doesn't work..


whats the mistake i am doing..?

Marc R. Hoffmann

unread,
Aug 7, 2014, 12:21:25 AM8/7/14
to jac...@googlegroups.com
Hi Kunal,

the JaCoCo Ant task does not support providing ZIP (Jar) files for the source code. Also your include

  <include name="com.xyz.xide*.jar/src"/>

will probably not match with any file.

The only chance to fix this is to either unzip the JARs first or try to use zipfilesets instead of the dirset:

  <zipfileset src="com.xyz.xide.jar" prefix="src"/>

But I haven't tried the latter myself.

Cheers,
-marc
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages