Anubhav Bansal
Anubhav Bansal

Reputation: 87

Usage of jacococli.jar with multiple classfiles

As in most cases my class files are at 2 locations inside tomcat at, lib and classes. Now once .exec file is created I need to pull a report referencing both the locations classes and a few jars in lib, for this I am using the below command

java -jar jacococli.jar report /local/jacoco.exec --html /jacocoReport/html --name MergeCode --classfiles /tomcat/webapps/<app>/WEB-INF/lib/new.jar /tomcat/webapps/<app>/WEB-INF/classes

but it is throwing error, and from the error it looks like it is considering the second location/jar from --classfiles option as an exec file.

[INFO] Loading execution data file /local/jacoco.exec.
[INFO] Loading execution data file /tomcat/webapps/<app>/WEB-INF/classes.
Exception in thread "main" java.io.FileNotFoundException: /tomcat/webapps/<app>/WEB-INF/classes (Is a directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at org.jacoco.cli.internal.core.tools.ExecFileLoader.load(ExecFileLoader.java:71)
at org.jacoco.cli.internal.commands.Report.loadExecutionData(Report.java:98)
at org.jacoco.cli.internal.commands.Report.execute(Report.java:82)
at org.jacoco.cli.internal.Main.execute(Main.java:89)
at org.jacoco.cli.internal.Main.main(Main.java:104)

I have tried moving classes before the jar file, the exception is different

[INFO] Loading execution data file /local/jacoco.exec.
[INFO] Loading execution data file /tomcat/webapps/<app>/WEB-INF/lib/new.jar.
Exception in thread "main" java.io.IOException: Invalid execution data file.
at org.jacoco.cli.internal.core.data.ExecutionDataReader.read(ExecutionDataReader.java:89)
at org.jacoco.cli.internal.core.tools.ExecFileLoader.load(ExecFileLoader.java:59)
at org.jacoco.cli.internal.core.tools.ExecFileLoader.load(ExecFileLoader.java:73)
at org.jacoco.cli.internal.commands.Report.loadExecutionData(Report.java:98)
at org.jacoco.cli.internal.commands.Report.execute(Report.java:82)
at org.jacoco.cli.internal.Main.execute(Main.java:89)
at org.jacoco.cli.internal.Main.main(Main.java:104)

for

java -jar jacococli.jar classinfo /tomcat/webapps/<app>/WEB-INF/lib/new.jar /tomcat/webapps/<app>/WEB-INF/classes /tomcat/webapps/<app>/WEB-INF/lib/new1.jar

multiple files work fine all classes in the classes folder and set of jar files in lib folder are listed,

Documentation at http://www.jacoco.org/jacoco/trunk/doc/cli.html states that --classfiles for report can have multiple files but does not state example or delimiter. I tried with comma, semicolon but it does not work ' '[space] works with classinfo so I am assuming it should work with report also.

Googling also did not result in any examples for jacococli.jar.

Upvotes: 4

Views: 6007

Answers (1)

Godin
Godin

Reputation: 10564

Documentation at http://www.jacoco.org/jacoco/trunk/doc/cli.html states that --classfiles for report can have multiple files

This is wrong - documentation at http://www.jacoco.org/jacoco/trunk/doc/cli.html actually states that

Some parameters can be specified multiple times to provide multiple values.

And

--classfiles <path>

can be specified multiple times literally, i.e.

--classfiles path1 --classfiles path2

When you omit prefix --classfiles, then it is interpreted as

<execfiles>

giving exceptions

Exception in thread "main" java.io.FileNotFoundException: /tomcat/webapps/<app>/WEB-INF/classes (Is a directory)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at org.jacoco.cli.internal.core.tools.ExecFileLoader.load(ExecFileLoader.java:71)

and

Exception in thread "main" java.io.IOException: Invalid execution data file.
at org.jacoco.cli.internal.core.data.ExecutionDataReader.read(ExecutionDataReader.java:89)
at org.jacoco.cli.internal.core.tools.ExecFileLoader.load(ExecFileLoader.java:59)

as expected - as in one case it is not a file and in another case it is not valid exec file.

' '[space] works with classinfo so I am assuming it should work with report also

report and classinfo are two different commands and have different arguments with all the consequences. Space works with classinfo command, because it allows multiple specifications of

<classlocations>

note absence of need to specify prefix in comparison to report command.

Upvotes: 5

Related Questions