Skip to content

Commit a0c3514

Browse files
Adding Support for JaCoCo Agent Configuration Options
This change introduces support for additional configuration options for the JaCoCo agent, enhancing its flexibility and usability. These changes were made to be backwards compatible, ensuring that existing configurations continue to work without modification. Added optional configuration options: - destfile - append - exclclassloader - inclbootstrapclasses - inclnolocationclasses - sessionid (defaulted to instance uuid) - dumponexit - classdumpdir - jmx Issue: #1116
1 parent 1c46ab6 commit a0c3514

File tree

3 files changed

+57
-11
lines changed

3 files changed

+57
-11
lines changed

docs/framework-jacoco_agent.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@ Users may optionally provide their own JaCoCo service. A user-provided JaCoCo se
2121

2222
The credential payload of the service may contain the following entries:
2323

24-
| Name | Description
25-
| ---- | -----------
26-
| `address` | The host for the agent to connect to or listen on
27-
| `excludes` | (Optional) A list of class names that should be excluded from execution analysis. The list entries are separated by a colon (:) and may use wildcard characters (* and ?).
28-
| `includes` | (Optional) A list of class names that should be included in execution analysis. The list entries are separated by a colon (:) and may use wildcard characters (* and ?).
29-
| `port` | (Optional) The port for the agent to connect to or listen on
30-
| `output` | (Optional) The mode for the agent. Possible values are either tcpclient (default) or tcpserver.
24+
| Name | Description
25+
|------------------------|------------
26+
| `address` | The host for the agent to connect to or listen on.
27+
| `destfile` | (Optional) The path to the file where execution data is written. Default is `jacoco.exec`.
28+
| `sessionid` | (Optional) The identifier for the coverage session. Useful for distinguishing between different test runs.
29+
| `append` | (Optional) If set to `true`, coverage data is appended to the existing file. Default is `false`.
30+
| `includes` | (Optional) A list of class names to include in execution analysis. Entries are separated by a colon (`:`) and may use wildcards (`*`, `?`).
31+
| `excludes` | (Optional) A list of class names to exclude from execution analysis. Entries are separated by a colon (`:`) and may use wildcards (`*`, `?`).
32+
| `exclclassloader` | (Optional) A list of class loader names to exclude from instrumentation. Entries are separated by a colon (`:`).
33+
| `inclbootstrapclasses` | (Optional) If set to `true`, includes bootstrap classes for instrumentation. Default is `false`.
34+
| `inclnolocationclasses`| (Optional) If set to `true`, includes classes without a location for instrumentation. Default is `false`.
35+
| `dumponexit` | (Optional) If set to `true`, coverage data is written on JVM shutdown. Default is `true`.
36+
| `output` | (Optional) The mode for the agent. Possible values are `tcpclient` (default) or `tcpserver`.
37+
| `port` | (Optional) The port for the agent to connect to or listen on.
38+
| `classdumpdir` | (Optional) The directory where class files are dumped if class dumping is enabled.
39+
| `jmx` | (Optional) If set to `true`, enables JMX control for the agent. Default is `false`.
3140

3241
## Configuration
3342
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].

lib/java_buildpack/framework/jacoco_agent.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,27 @@ def compile
3232
# (see JavaBuildpack::Component::BaseComponent#release)
3333
def release
3434
credentials = @application.services.find_service(FILTER, ADDRESS)['credentials']
35+
3536
properties = {
3637
'address' => credentials[ADDRESS],
3738
'output' => 'tcpclient',
3839
'sessionid' => '$CF_INSTANCE_GUID'
3940
}
4041

41-
properties['excludes'] = credentials['excludes'] if credentials.key? 'excludes'
42-
properties['includes'] = credentials['includes'] if credentials.key? 'includes'
43-
properties['port'] = credentials['port'] if credentials.key? 'port'
44-
properties['output'] = credentials['output'] if credentials.key? 'output'
42+
# Add SuppPattern match for all other JaCoCo agent options
43+
properties['destfile'] = credentials['destfile'] if credentials.key?('destfile')
44+
properties['sessionid'] = credentials['sessionid'] if credentials.key?('sessionid')
45+
properties['append'] = credentials['append'] if credentials.key?('append')
46+
properties['includes'] = credentials['includes'] if credentials.key?('includes')
47+
properties['excludes'] = credentials['excludes'] if credentials.key?('excludes')
48+
properties['exclclassloader'] = credentials['exclclassloader'] if credentials.key?('exclclassloader')
49+
properties['inclbootstrapclasses'] = credentials['inclbootstrapclasses'] if credentials.key?('inclbootstrapclasses')
50+
properties['inclnolocationclasses'] = credentials['inclnolocationclasses'] if credentials.key?('inclnolocationclasses')
51+
properties['dumponexit'] = credentials['dumponexit'] if credentials.key?('dumponexit')
52+
properties['output'] = credentials['output'] if credentials.key?('output')
53+
properties['port'] = credentials['port'] if credentials.key?('port')
54+
properties['classdumpdir'] = credentials['classdumpdir'] if credentials.key?('classdumpdir')
55+
properties['jmx'] = credentials['jmx'] if credentials.key?('jmx')
4556

4657
@droplet.java_opts.add_javaagent_with_props(@droplet.sandbox + 'jacocoagent.jar', properties)
4758
end

spec/java_buildpack/framework/jacoco_agent_spec.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,32 @@
6868
'excludes=test-excludes,includes=test-includes,port=6300')
6969
end
7070

71+
it 'updates JAVA_OPTS with extended options' do
72+
allow(services).to receive(:find_service).and_return('credentials' => {
73+
'address' => 'ext-address',
74+
'output' => 'tcpserver',
75+
'sessionid' => 'ext-session',
76+
'excludes' => 'ex.*',
77+
'includes' => 'in.*',
78+
'port' => 7654,
79+
'destfile' => 'custom.exec',
80+
'append' => 'false',
81+
'exclclassloader' => 'loader.*',
82+
'inclbootstrapclasses' => 'true',
83+
'inclnolocationclasses' => 'true',
84+
'dumponexit' => 'false',
85+
'classdumpdir' => 'dumpdir',
86+
'jmx' => 'true'
87+
})
88+
89+
component.release
90+
91+
expect(java_opts).to include('-javaagent:$PWD/.java-buildpack/jacoco_agent/jacocoagent.jar=' \
92+
'address=ext-address,output=tcpserver,sessionid=ext-session,excludes=ex.*,includes=in.*,port=7654,' \
93+
'destfile=custom.exec,append=false,exclclassloader=loader.*,inclbootstrapclasses=true,' \
94+
'inclnolocationclasses=true,dumponexit=false,classdumpdir=dumpdir,jmx=true')
95+
end
96+
7197
end
7298

7399
end

0 commit comments

Comments
 (0)