Marc R. Hoffmann | 235a09e | 2012-12-23 15:57:16 +0100 | [diff] [blame] | 1 | <?xml version="1.0" encoding="UTF-8" ?> |
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 3 | <html xmlns="http://www.w3.org/1999/xhtml" lang="en"> |
| 4 | <head> |
| 5 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 6 | <link rel="stylesheet" href=".resources/doc.css" charset="UTF-8" type="text/css" /> |
| 7 | <link rel="shortcut icon" href=".resources/report.gif" type="image/gif" /> |
| 8 | <title>JaCoCo - Offline Instrumentation</title> |
| 9 | </head> |
| 10 | <body> |
| 11 | |
| 12 | <div class="breadcrumb"> |
| 13 | <a href="../index.html" class="el_report">JaCoCo</a> > |
| 14 | <a href="index.html" class="el_group">Documentation</a> > |
| 15 | <span class="el_source">Offline Instrumentation</span> |
| 16 | </div> |
| 17 | <div id="content"> |
| 18 | |
| 19 | <h1>Offline Instrumentation</h1> |
| 20 | |
| 21 | <p> |
| 22 | One of the main benefits of JaCoCo is the Java agent, which instruments |
| 23 | classes on-the-fly. This simplifies code coverage analysis a lot as no |
| 24 | pre-instrumentation and classpath tweaking is required. However, there can be |
| 25 | situations where on-the-fly instrumentation is not suitable, for example: |
| 26 | </p> |
| 27 | <ul> |
| 28 | <li>Runtime environments that do not support Java agents.</li> |
| 29 | <li>Deployments where it is not possible to configure JVM options.</li> |
| 30 | <li>Bytecode needs to be converted for another VM like the Android Dalvik VM.</li> |
| 31 | <li>Conflicts with other agents that do dynamic classfile transformation.</li> |
| 32 | </ul> |
| 33 | |
| 34 | <p> |
| 35 | For such scenarios class files can be pre-instrumented with JaCoCo, for |
| 36 | example with the <a href="ant.html#instrument"><code>instrument</code></a> |
| 37 | Ant task. At runtime the pre-instrumented classes needs be on the classpath |
| 38 | instead of the original classes. In addition <code>jacocoagent.jar</code> must |
| 39 | be put on the classpath. |
| 40 | </p> |
| 41 | |
| 42 | <h2>Configuration</h2> |
| 43 | <p> |
| 44 | In offline mode the JaCoCo runtime can be configured with Java System |
| 45 | properties. The same set of properties as for the |
| 46 | <a href="agent.html">agent</a> is available, but prefixed with |
| 47 | "<code>jacoco.</code>". For example the location of the <code>*.exec</code> |
| 48 | file can be configured with the system property |
| 49 | "<code>jacoco.destfile</code>". |
| 50 | </p> |
| 51 | |
| 52 | <h2>Class Loading and Initialization</h2> |
| 53 | <p> |
| 54 | Unlike with on-the-fly instrumentation offline instrumented classes get a |
| 55 | direct dependency on the JaCoCo runtime. Therefore |
| 56 | <code>jacocoagent.jar</code> has to be on the classpath and accessible by the |
| 57 | instrumented classes. The proper location for <code>jacocoagent.jar</code> |
| 58 | might depend on your deployment scenario. The first instrumented class loaded |
| 59 | will trigger the initialization of the JaCoCo runtime. If no instrumented |
| 60 | class is loaded the JaCoCo runtime will not get started at all. |
| 61 | </p> |
| 62 | |
| 63 | <h2>Using Pre-Instrumented Classes With the Java Agent</h2> |
| 64 | <p> |
| 65 | It is possible to also use offline-instrumented classes with the JaCoCo Java |
| 66 | agent. In this case the configuration is taken from the agent options. The |
| 67 | agent must be configured in a way that pre-instrumented classes are excluded, |
| 68 | e.g. with <code>excludes=*</code>. Otherwise it will result in error messages |
| 69 | on the console if the agent instruments such classes again. |
| 70 | </p> |
| 71 | |
| 72 | <h2>Execution Data Collection</h2> |
| 73 | <p> |
| 74 | If <code>jacocoagent.jar</code> is used on the classpath it will collect |
| 75 | execution data the same way as used as a <a href="agent.html">Java agent</a>. |
| 76 | Depending on the <code>output</code> configuration execution data can be |
| 77 | collected via a remote connection or is written to the file system when the |
| 78 | JVM terminates. For the latter it is required that e.g. a <code>java</code> |
| 79 | task is executed with <code>fork="true"</code>. |
| 80 | </p> |
| 81 | |
| 82 | <h2>Report Generation</h2> |
| 83 | <p> |
| 84 | Based on the collected <code>*.exec</code> files reports can be created the |
| 85 | same way as for execution data collected with the Java agent. Note that for |
| 86 | report generation the original class files have to be supplied, not the |
| 87 | instrumented copies. |
| 88 | </p> |
| 89 | |
| 90 | </div> |
| 91 | <div class="footer"> |
| 92 | <span class="right"><a href="@jacoco.home.url@">JaCoCo</a> @qualified.bundle.version@</span> |
| 93 | <a href="license.html">Copyright</a> © @copyright.years@ Mountainminds GmbH & Co. KG and Contributors |
| 94 | </div> |
| 95 | |
| 96 | </body> |
| 97 | </html> |