Jacoco is not highlighting the source code - even after adding the debug info

2,157 views
Skip to first unread message

Sabyasachi Mishra

unread,
Jan 23, 2018, 8:01:02 AM1/23/18
to JaCoCo and EclEmma Users
HI Team,

I am trying to compute code coverage for a build hosted in tomcat. I am following the below steps.


1.     Added Java agent with Jacocoagent.jar in tomcat.conf file under JAVA_OPTS 

javaagent:/opt/jacoco/lib/jacocoagent.jar=destfile=/opt/jacoco/Result/jacoco.exec,classdumpdir=/opt/jacoco/Result/classes,append=false,includes=*


2.     Started Tomcat.

3.     Ran tests.

4.     After tests are complete stoped the tomcat in order to generate the .exec file.


5.     Keep class files which I wanted to instrument in one place along with the exec file.

6.     Now ran the report generation command 


java -jar Path/jacococli.jar report Path/jacoco.exec --classfiles Path/classes --html Path/Report --name jacocoReport --sourcefiles Path/src/main/java


Now I am able to generate HTML report. But not able to see the highlighted source code. But from the report I can see the functions under the classes.


For adding debugging info to the class I have added below code to maven's pom.xml


<plugin>

<groupId>org.apache.maven.plugins</groupId>

<artifactId>maven-compiler-plugin</artifactId>

<configuration>

<source>1.8</source>

<target>1.8</target>

<debug>true</debug>

        <debuglevel>lines</debuglevel>

</configuration>

</plugin>


Can anyone please tell me what I am missing or what I am doing wrong.

Thanks in advance.

Regards,
Sabyasachi Mishra 

Marc Hoffmann

unread,
Jan 23, 2018, 8:27:01 AM1/23/18
to jac...@googlegroups.com

Hi,

does your generated HTML report show a column called "Lines"? If not, the class files do not contain debug information.

Regards,
-marc

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/9d440a15-f2d2-49c3-91b8-2af73b0d6700%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

Sabyasachi Mishra

unread,
Jan 23, 2018, 10:46:39 AM1/23/18
to JaCoCo and EclEmma Users
Hi Marc,
My HTML report shows a column called lines. Attaching the screenshot.


Thanks and Regards,
Sabyasachi Mishra
Screen Shot 2018-01-23 at 9.14.05 PM.png

Marc Hoffmann

unread,
Jan 23, 2018, 11:22:57 AM1/23/18
to jac...@googlegroups.com

Ok, this means your class files are compiled with debug information.

Did you double check that your source files are available at the location you provided?

  --sourcefiles Path/src/main/java

Note that this path needs to point to the parent folder of the Java package hierarchy. E.g. if you have a class com.example.Foo the source file has to be in this folder:

  Path/src/main/java/com/example/Foo.java

If this check is positive can you please share one of your class file?

Thanks,
-marc

Screen Shot 2018-01-23 at 9.14.05 PM.png

Sabyasachi Mishra

unread,
Jan 24, 2018, 3:05:51 AM1/24/18
to JaCoCo and EclEmma Users
Hi Marc,
This check is positive. But I still can't generate report with highlighted source code.
Sorry I cannot share any class files.
Can you please suggest any alternate approach?

Thanks and Regards,
Sabyasachi Mishra

Evgeny Mandrikov

unread,
Jan 24, 2018, 3:54:03 AM1/24/18
to JaCoCo and EclEmma Users
Hi,

According to your first post you have "<debuglevel>lines</debuglevel>" , which I believe translates into "javac -glines" , so that it will preserve line numbers in class files, but not names of source files, because last one requires "javac -glines,source" or "javac -g" - see https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html
Therefore either set "<debuglevel>lines,source</debuglevel>", or completely remove "<debuglevel>", last case together with "<debug>true</debug>" is equivalent to "javac -g" i.e. all debug information will be included.

Sabyasachi Mishra

unread,
Jan 24, 2018, 9:57:39 AM1/24/18
to JaCoCo and EclEmma Users
Hi Evgeny,
I have made changes to pom.xml as suggested. But still I am not able to see highlighted source code. Instead I can only see function.

Changes in POM:

 <plugin>

                                <groupId>org.apache.maven.plugins</groupId>

                                <artifactId>maven-compiler-plugin</artifactId>

                                <configuration>

                                        <source>1.8</source>

                                        <target>1.8</target>

                                        <debug>true</debug>

                                </configuration>

                        </plugin>

Attaching the screenshots of report.

Regards,
Sabyasachi Mishra 
Screen Shot 2018-01-24 at 8.23.45 PM.png
Screen Shot 2018-01-24 at 8.24.08 PM.png

Evgeny Mandrikov

unread,
Jan 24, 2018, 10:50:58 AM1/24/18
to JaCoCo and EclEmma Users
First make sure that you did clean build and classes were really recompiled after your change.

Then lets verify that your changes do actually change result of compilation - execute javap on BuyerViewGenerator (class from your screenshot) as:

javap -v -p classes/package/name/of/BuyerViewGenerator.class

If you see occurrences

Compiled from "BuyerViewGenerator.java"

and

LineNumberTable

Then indeed this class file contains required debug information.

After that make sure that

classes/package/name/of/BuyerViewGenerator.class

has corresponding source file in a correct place

src/main/java/package/name/of/BuyerViewGenerator.java

After that make sure that you re-run your tests and regenerated jacoco.exec , because otherwise generation of report produces warning

[WARN] For report generation the same class files must be used as at runtime.

and such classes are not linked with their sources. Rephrasing a bit - make sure that you don't have warnings during generation of report.
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Sabyasachi Mishra

unread,
Feb 12, 2018, 1:00:29 AM2/12/18
to JaCoCo and EclEmma Users
Hi Evgeny,
I have tried that. I am still getting stuck at the same point. 

So I made a poc. sharing all the steps and code with you. In the poc I am still getting stuck at the same point.

1. Created a war file. put the war file in the webapps directory of tomcat.
2. Then added the jacoco agent in tomcat in catalena.sh file in under JAVA_OPTS.

-javaagent:/Users/sabyasachi/Documents/JacocoJars/jacocoagent.jar=output=file,destfile=/Users/sabyasachi/Documents/jacoco.exec,dumponexit=true,includes=*,classdumpdir=/Users/sabyasachi/Documents/cla,append=false


3.  Then started the server.
4. Created a small selenium webdriver suite and ran against the website.
5. After the tests are completed I have stopped the tomcat server.
6. Jacoco.exec file is generated.
7. Then I ran the following command to generate the report.

java -jar /Users/sabyasachi/Documents/JacocoJars/jacococli.jar report /Users/sabyasachi/Documents/jacoco.exec --classfiles /Users/sabyasachi/Documents/MathTest.class --html /Users/sabyasachi/Desktop/Rep1 --name jacocoReport --sourcefiles /Users/sabyasachi/Documents/MathTest.java


8. But still I am not able to generate the highlighted source code.

I am sharing the code war file and report.
Can you please look into this and tell me what I am doing wrong.

Thanks and Regards,
Sabyasachi Mishra

Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Marc Hoffmann

unread,
Feb 12, 2018, 1:22:58 AM2/12/18
to jac...@googlegroups.com

Hi Sabyasachi,

one problem is with your parameter

--sourcefiles /Users/sabyasachi/Documents/MathTest.java

Please specify a directory here, which is the root of your java package structure. See FAQ:

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.

Regards,
-marc

Sabyasachi Mishra

unread,
Feb 12, 2018, 4:32:49 AM2/12/18
to JaCoCo and EclEmma Users
Hi Mark,
I ran this command also.

java -jar /Users/sabyasachi/Documents/JacocoJars/jacococli.jar report /Users/sabyasachi/Documents/jacoco.exec --classfiles /Users/sabyasachi/eclipse-workspace5/JACPOC/build/classes/com/math/pkg/MathTest.class --html /Users/sabyasachi/Desktop/Rep1 --name jacocoReport --sourcefiles /Users/sabyasachi/eclipse-workspace5/JACPOC/src/com/math/pkg/MathTest.java

still same.

Thanks and regards,
Sabyasachi Mishra
Screen Shot 2018-02-12 at 3.01.53 PM.png
Message has been deleted
Message has been deleted

Sabyasachi Mishra

unread,
Feb 20, 2018, 1:18:12 PM2/20/18
to JaCoCo and EclEmma Users
Hi Mark/Evegeny,
below is the entire code, test code and Report in github link. Please look into it and let me know what i am missing.


Thanks in advance.

Thanks and Regards,
Sabyasachi Mishra

Marc Hoffmann

unread,
Feb 20, 2018, 2:05:07 PM2/20/18
to jac...@googlegroups.com

As I said before: Your --sourcefiles parameter is wrong. Instead of

    --sourcefiles /Users/sabyasachi/eclipse-workspace5/JACPOC/src/com/math/pkg/MathTest.java

specify

    --sourcefiles /Users/sabyasachi/eclipse-workspace5/JACPOC/src/

It has to be the root folder of your Java package hierarchy. Anything else will simply not work.

Regards,
-marc

Sabyasachi Mishra

unread,
Feb 21, 2018, 11:29:14 AM2/21/18
to JaCoCo and EclEmma Users
Thank you very much Mark,
This worked.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages