Skip to content

Commit 763d051

Browse files
committed
JaCoCo Agent Support
This change updates the buildpack to include JaCoCo agent support. [resolves cloudfoundry#529]
1 parent 76f8170 commit 763d051

File tree

11 files changed

+225
-1
lines changed

11 files changed

+225
-1
lines changed

.idea/dictionaries/bhale.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ The buildpack supports extension through the use of Git repository forking. The
8484
* [Dynatrace SaaS/Managed OneAgent](docs/framework-dynatrace_one_agent.md) ([Configuration](docs/framework-dynatrace_one_agent.md#configuration))
8585
* [Google Stackdriver Debugger](docs/framework-google_stackdriver_debugger.md) ([Configuration](docs/framework-google_stackdriver_debugger.md#configuration))
8686
* [Introscope Agent](docs/framework-introscope_agent.md) ([Configuration](docs/framework-introscope_agent.md#configuration))
87+
* [JaCoCo Agent](docs/framework-jacoco_agent.md) ([Configuration](docs/framework-jacoco_agent.md#configuration))
8788
* [Java Memory Assistant](docs/framework-java_memory_assistant.md) ([Configuration](docs/framework-java_memory_assistant.md#configuration))
8889
* [Java Options](docs/framework-java_opts.md) ([Configuration](docs/framework-java_opts.md#configuration))
8990
* [JRebel Agent](docs/framework-jrebel_agent.md) ([Configuration](docs/framework-jrebel_agent.md#configuration))

config/components.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ frameworks:
5151
- "JavaBuildpack::Framework::DynatraceOneAgent"
5252
- "JavaBuildpack::Framework::GoogleStackdriverDebugger"
5353
- "JavaBuildpack::Framework::IntroscopeAgent"
54+
- "JavaBuildpack::Framework::JacocoAgent"
5455
- "JavaBuildpack::Framework::JavaMemoryAssistant"
5556
- "JavaBuildpack::Framework::Jmx"
5657
- "JavaBuildpack::Framework::JrebelAgent"

config/jacoco_agent.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Cloud Foundry Java Buildpack
2+
# Copyright 2013-2017 the original author or authors.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Configuration for the JaCoco Agent framework
17+
---
18+
version: 0.+
19+
repository_root: "{default.repository.root}/jacoco"

docs/framework-jacoco_agent.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# JaCoco Agent Framework
2+
The JaCoCo Agent Framework causes an application to be automatically configured to work with a bound [JaCoCo Service][].
3+
4+
<table>
5+
<tr>
6+
<td><strong>Detection Criterion</strong></td><td>Existence of a single bound JaCoCo service.
7+
<ul>
8+
<li>Existence of a JaCoCo service is defined as the <a href="http://docs.cloudfoundry.org/devguide/deploy-apps/environment-variable.html#VCAP-SERVICES"><code>VCAP_SERVICES</code></a> payload containing a service who's name, label or tag has <code>jacoco</code> as a substring.</li>
9+
</ul>
10+
</td>
11+
</tr>
12+
<tr>
13+
<td><strong>Tags</strong></td>
14+
<td><tt>jacoco-agent=&lt;version&gt;</tt></td>
15+
</tr>
16+
</table>
17+
Tags are printed to standard output by the buildpack detect script
18+
19+
## User-Provided Service (Optional)
20+
Users may optionally provide their own JaCoCo service. A user-provided JaCoCo service must have a name or tag with `jacoco` in it so that the JaCoCo Agent Framework will automatically configure the application to work with the service.
21+
22+
The credential payload of the service may contain the following entries:
23+
24+
| Name | Description
25+
| ---- | -----------
26+
| `address` | The host for the agent to connect to
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
30+
31+
## Configuration
32+
For general information on configuring the buildpack, including how to specify configuration values through environment variables, refer to [Configuration and Extension][].
33+
34+
The framework can be configured by modifying the [`config/jacoc_agent.yml`][] file in the buildpack fork. The framework uses the [`Repository` utility support][repositories] and so it supports the [version syntax][] defined there.
35+
36+
| Name | Description
37+
| ---- | -----------
38+
| `repository_root` | The URL of the JaCoCo repository index ([details][repositories]).
39+
| `version` | The version of JaCoCo to use. Candidate versions can be found in [this listing][].
40+
41+
### Additional Resources
42+
The framework can also be configured by overlaying a set of resources on the default distribution. To do this, add files to the `resources/jacoco_agent` directory in the buildpack fork. For example, to override the default `jacoco.yml` add your custom file to `resources/jacoco_agent/jacoco.yml`.
43+
44+
[Configuration and Extension]: ../README.md#configuration-and-extension
45+
[`config/jacoco_agent.yml`]: ../config/jacoco_agent.yml
46+
[JaCoCo Service]: http://www.jacoco.org/jacoco/
47+
[repositories]: extending-repositories.md
48+
[this listing]: https://java-buildpack.cloudfoundry.org/jacoco/index.yml
49+
[version syntax]: extending-repositories.md#version-syntax-and-ordering

lib/java_buildpack/component/java_opts.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,21 @@ def add_javaagent(path)
4343
add_preformatted_options "-javaagent:#{qualify_path path}"
4444
end
4545

46+
# Adds a +javaagent+ entry to the +JAVA_OPTS+. Prepends +$PWD+ to the path (relative to the droplet root) to
47+
# ensure that the path is always accurate.
48+
#
49+
# @param [Pathname] path the path to the +javaagent+ JAR
50+
# @param [Properties] props to append to the +javaagent+ entry
51+
# @return [JavaOpts] +self+ for chaining
52+
def add_javaagent_with_props(path, props)
53+
add_preformatted_options "-javaagent:#{qualify_path path}=" + props.map { |k, v| "#{k}=#{v}" }.join(',')
54+
end
55+
4656
# Adds a +agentpath+ entry to the +JAVA_OPTS+. Prepends +$PWD+ to the path (relative to the droplet root) to
4757
# ensure that the path is always accurate.
4858
#
4959
# @param [Pathname] path the path to the +agentpath+ shared library
50-
# @param [Properties] props to append to the agentpath entry
60+
# @param [Properties] props to append to the +agentpath+ entry
5161
# @return [JavaOpts] +self+ for chaining
5262
def add_agentpath_with_props(path, props)
5363
add_preformatted_options "-agentpath:#{qualify_path path}=" + props.map { |k, v| "#{k}=#{v}" }.join(',')
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# frozen_string_literal: true
2+
3+
# Cloud Foundry Java Buildpack
4+
# Copyright 2013-2017 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
require 'java_buildpack/component/versioned_dependency_component'
19+
require 'java_buildpack/framework'
20+
21+
module JavaBuildpack
22+
module Framework
23+
24+
# Encapsulates the functionality for enabling zero-touch JacCoCo support.
25+
class JacocoAgent < JavaBuildpack::Component::VersionedDependencyComponent
26+
27+
# (see JavaBuildpack::Component::BaseComponent#compile)
28+
def compile
29+
download_zip false
30+
end
31+
32+
# (see JavaBuildpack::Component::BaseComponent#release)
33+
def release
34+
credentials = @application.services.find_service(FILTER, ADDRESS)['credentials']
35+
properties = {
36+
'address' => credentials[ADDRESS],
37+
'output' => 'tcpclient',
38+
'sessionid' => '$CF_INSTANCE_GUID'
39+
}
40+
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+
45+
@droplet.java_opts.add_javaagent_with_props(@droplet.sandbox + 'jacocoagent.jar', properties)
46+
end
47+
48+
protected
49+
50+
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
51+
def supports?
52+
@application.services.one_service? FILTER, ADDRESS
53+
end
54+
55+
ADDRESS = 'address'
56+
57+
FILTER = /jacoco/
58+
59+
private_constant :ADDRESS, :FILTER
60+
61+
end
62+
63+
end
64+
end

rakelib/versions_task.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def initialize
6666
'google_stackdriver_debugger' => 'Google Stackdriver Debugger',
6767
'groovy' => 'Groovy',
6868
'introscope_agent' => 'CA Introscope APM Framework',
69+
'jacoco_agent' => 'JaCoCo Agent',
6970
'jre' => 'OpenJDK JRE',
7071
'jrebel_agent' => 'JRebel Agent',
7172
'jvmkill_agent' => 'jvmkill Agent',
448 Bytes
Binary file not shown.

spec/java_buildpack/component/java_opts_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
expect(opts).to include('-javaagent:$PWD/.java-buildpack/java_opts/test-java-agent')
3131
end
3232

33+
it 'adds a qualified javaagent with properties to the collection' do
34+
opts.add_javaagent_with_props(droplet.sandbox + 'test-java-agent', 'key1' => 'value1', 'key2' => 'value2')
35+
36+
expect(opts).to include('-javaagent:$PWD/.java-buildpack/java_opts/test-java-agent=key1=value1,key2=value2')
37+
end
38+
3339
it 'adds a qualified agentpath to the collection' do
3440
opts.add_agentpath droplet.sandbox + 'test-agentpath'
3541

0 commit comments

Comments
 (0)