How to run a .jar file instrumented in windows using clover-ant in linux ?

Sagar Vysyaraju May 17, 2017

Hi All,

I have instrumented a sample java program in windows, using clover-ant and was able to get the coverage info when running the .jar file using commandline.

Query : How to run an instrumented build in Linux.

Plan A : I tried using the same build which we instrumented in windows and tried runnning the same in linux environment by using the same clover.jar and same coverage.db file. (This didnt work out because the clover.jar path in windows cant be matched to any similar path in linux, similarly the same issue with initstring)

Plan B : Installed ant in the linux environment, copied the same java project in to linux machine, modified the build.xml to the expected paths of clover.jar present in the linux machine. When trying to run the .jar file I am seeing the below error :

/home/sv186037/Desktop/code_coverage/CloverInstrumentBuild/build/jar/CIB.jar: line 1: $'PK\003\004': command not found
/home/sv186037/Desktop/code_coverage/CloverInstrumentBuild/build/jar/CIB.jar: line 2: $'\bS#\261J': command not found
/home/sv186037/Desktop/code_coverage/CloverInstrumentBuild/build/jar/CIB.jar: line 3: syntax error near unexpected token `)'
/home/sv186037/Desktop/code_coverage/CloverInstrumentBuild/build/jar/CIB.jar: line 3:R#�J�C8�s�META-INF/MANIFEST.MFM�1�0
�H��Gb%����fb��X���T����� �����)�ٛhM%Ɂ���v�κ<�&�p���?��D��oW��pU`(���G0
�l�Ƶ˛bZ)\f0`�PK'

2 comments

Grzegorz Lewandowski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 18, 2017

General rule of thumb should be

  1.  Instrument code with Clover
  2. Compile instrumented code with making sure code clover.jar is in the classpath
  3. Move instrumented JAR along with Clover database to a second machine (it doesn't matter if you're moving it from Windows to Linux box or the opposite) 
  4. Execute tests on the target machine, make sure clover.jar is in the classpath and it's the same major.minor version as the one used for instrumentation
  5. Move coverage recording files back to the instrumentation machine
  6. Generate Clover report


NOTE: You can generate report on a different machine than you instrumented the sources, but Clover for rendering HTML report needs access to the source code. Java files shall be in the same location like when Clover was performing the instrumentation, however you can override the root location of the project by using sourcepath tag

Sagar Vysyaraju May 18, 2017

I actually though of moving the same insturmented jar from windows to linux, but the paths mentioned in the build.xml will not be matchng the linux environment.

So I have instrumented a new one using new paths for clover.jar and coverage.db in linux machine.

To build a new instumented build in linux only clover.jar is enough or I need the total folder of clover-ant-4.1.2 ?

I tried with the complete folder of clover-ant-4.1.2 and build was successful, only thing is the coverege.db file is not getting created, even the .clover folder is also not getting created.

Grzegorz Lewandowski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
May 18, 2017

but the paths mentioned in the build.xml will not be matchng the linux environment.

You need to write proper path handling in the ANT project. You may use: 

  • relative paths instead of absolute ones
  • ANT's if-else conditions
  • or system properties to point ANT to the proper locations.

To build a new instumented build in linux only clover.jar is enough or I need the total folder of clover-ant-4.1.2 ?

Clover.jar will be sufficient. Clover-ant cotains API documentation, 3rd party libraries licenses and tutorial. The main part is clover.jar 

I tried with the complete folder of clover-ant-4.1.2 and build was successful, only thing is the coverege.db file is not getting created, even the .clover folder is also not getting created.

Without build logs and build file I can't really tell what's wrong. Also please note, there's no such thing like coverage.db. There's a Clover database which is generated during instrumentation phase, it contains infromation about your project structure and there're coverage recordings files which contains data about actual coverage. Those are created when instrumented code is executed and has access to Clover database. 

Sagar Vysyaraju May 21, 2017

Hi Grzegorz,

Was able to instrument the same java code in linux by istalling ant, and modifying the paths of clover.jar and clover registry file in build.xml.

Even the coverage recording files are getting created as well.

Thanks,

Sagar.

Anusha Rallabhandi April 19, 2018

I want to generate a clover report but that's possible only if I test my jars. How do I test my .jar files which have been instrumented by clover? 

Grzegorz Lewandowski
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 20, 2018

I don't know how your tests configuration looks like.  But replace 'normal production' JAR with instrumented JAR on a classpath.

Comment

Log in or Sign up to comment
TAGS
AUG Leaders

Atlassian Community Events