Skip to content

Commit b053d52

Browse files
committed
Merge branch 'dmitri-gb-master'
[resolves #176]
2 parents 397865f + a2269a9 commit b053d52

9 files changed

Lines changed: 67 additions & 26 deletions

File tree

config/jrebel_agent.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
# Configuration for the JRebel framework
1717
---
1818
version: 6.+
19-
repository_root: "{default.repository.root}/jrebel"
19+
repository_root: "http://dl.zeroturnaround.com/jrebel"

docs/framework-jrebel_agent.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# JRebel Agent Framework
2-
The JRebel Agent Framework causes an application to be automatically configured to work with an IDE using [JRebel][].
2+
3+
The JRebel Agent Framework causes an application to be automatically configured to work with [JRebel][]. Pushing any [JRebel Cloud/Remote][] enabled application (containing `rebel-remote.xml`) will automatically download the latest version of [JRebel][] and set it up for use.
34

45
<table>
56
<tr>
67
<td><strong>Detection Criterion</strong></td>
7-
<td>Existence of the `rebel.xml` and `rebel-remote.xml` files in either the root or `WEB-INF/classes` directory or the application.</td>
8+
<td>Existence of a <tt>rebel-remote.xml</tt> file inside the application archive. This file is present in every application that is configured to use <a href="http://manuals.zeroturnaround.com/jrebel/remoting/index.html" target="_blank">JRebel Cloud/Remote</a>.</td>
89
</tr>
910
<tr>
1011
<td><strong>Tags</strong></td>
@@ -13,6 +14,8 @@ The JRebel Agent Framework causes an application to be automatically configured
1314
</table>
1415
Tags are printed to standard output by the buildpack detect script
1516

17+
For more information regarding setup and configuration, please refer to the [JRebel with Pivotal Cloud Foundry tutorial][pivotal].
18+
1619
## Configuration
1720
For general information on configuring the buildpack, refer to [Configuration and Extension][].
1821

@@ -21,11 +24,13 @@ The framework can be configured by modifying the [`config/jrebel_agent.yml`][] f
2124
| Name | Description
2225
| ---- | -----------
2326
| `repository_root` | The URL of the JRebel repository index ([details][repositories]).
24-
| `version` | The version of Jrebel to use. Candidate versions can be found in [this listing][].
27+
| `version` | The version of JRebel to use. Candidate versions can be found in [this listing][].
2528

2629
[Configuration and Extension]: ../README.md#configuration-and-extension
2730
[`config/jrebel_agent.yml`]: ../config/jrebel_agent.yml
31+
[JRebel Cloud/Remote]: http://manuals.zeroturnaround.com/jrebel/remoting/index.html
2832
[JRebel]: http://zeroturnaround.com/software/jrebel/
33+
[pivotal]: http://manuals.zeroturnaround.com/jrebel/remoting/pivotal.html
2934
[repositories]: extending-repositories.md
30-
[this listing]: http://download.pivotal.io.s3.amazonaws.com/jrebel/index.yml
35+
[this listing]: http://dl.zeroturnaround.com/jrebel/index.yml
3136
[version syntax]: extending-repositories.md#version-syntax-and-ordering

lib/java_buildpack/component/java_opts.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ def add_javaagent(path)
4343
self
4444
end
4545

46+
# Adds an +agentpath+ 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 +native+ +agent+
50+
# @return [JavaOpts] +self+ for chaining
51+
def add_agentpath(path)
52+
self << "-agentpath:#{qualify_path path}"
53+
self
54+
end
55+
4656
# Adds a +bootclasspath/p+ 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
#

lib/java_buildpack/framework/jrebel_agent.rb

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,49 @@ module Framework
2424
# Encapsulates the functionality for enabling zero-touch JRebel support.
2525
class JrebelAgent < JavaBuildpack::Component::VersionedDependencyComponent
2626

27+
def initialize(context, &version_validator)
28+
super(context, &version_validator)
29+
@component_name = 'JRebel Agent'
30+
end
31+
2732
# (see JavaBuildpack::Component::BaseComponent#compile)
2833
def compile
29-
download_zip false
30-
FileUtils.mv(download_location + 'jrebel.jar', @droplet.sandbox + jar_name)
31-
FileUtils.remove_dir(download_location, true)
34+
download_zip
3235
end
3336

3437
# (see JavaBuildpack::Component::BaseComponent#release)
3538
def release
3639
@droplet.java_opts
37-
.add_javaagent(@droplet.sandbox + jar_name)
38-
.add_bootclasspath_p(@droplet.sandbox + jar_name)
40+
.add_agentpath(@droplet.sandbox + ('lib/' + lib_name))
3941
.add_system_property('rebel.remoting_plugin', true)
42+
.add_system_property('rebel.log', true)
43+
.add_system_property('rebel.cloud.platform', 'cloudfoundry/java-buildpack')
4044
end
4145

4246
protected
4347

4448
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
4549
def supports?
46-
jrebel_configured?(@application.root) || jrebel_configured?(@application.root + 'WEB-INF/classes')
50+
jrebel_configured?(@application.root) || jrebel_configured?(@application.root + 'WEB-INF/classes') ||
51+
jars_with_jrebel_configured?(@application.root)
4752
end
4853

4954
private
5055

5156
def jrebel_configured?(root_path)
52-
(root_path + 'rebel.xml').exist? && (root_path + 'rebel-remote.xml').exist?
57+
(root_path + 'rebel-remote.xml').exist?
58+
end
59+
60+
def jars_with_jrebel_configured?(root_path)
61+
(root_path + '**/*.jar').glob.any? { |jar| ! `unzip -l "#{jar}" | grep "rebel-remote\\.xml$"`.strip.empty? }
62+
end
63+
64+
def lib_name
65+
architecture == 'x86_64' || architecture == 'i686' ? 'libjrebel64.so' : 'libjrebel32.so'
5366
end
5467

55-
def download_location
56-
@droplet.sandbox + 'jrebel'
68+
def architecture
69+
`uname -m`.strip
5770
end
5871

5972
end

spec/fixtures/framework_jrebel_app/rebel-remote.xml renamed to spec/fixtures/framework_jrebel_app_simple/rebel-remote.xml

File renamed without changes.

spec/fixtures/framework_jrebel_app/rebel.xml renamed to spec/fixtures/framework_jrebel_app_war/WEB-INF/classes/rebel-remote.xml

File renamed without changes.
Binary file not shown.
782 Bytes
Binary file not shown.

spec/java_buildpack/framework/jrebel_agent_spec.rb

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,48 @@
2121
describe JavaBuildpack::Framework::JrebelAgent do
2222
include_context 'component_helper'
2323

24-
it 'does not detect without JRebel config files present' do
24+
it 'does not detect when rebel-remote.xml is not present' do
2525
expect(component.detect).to be_nil
2626
end
2727

28-
it 'detects with JRebel config files are present',
29-
app_fixture: 'framework_jrebel_app',
30-
cache_fixture: 'stub-jrebel-archive.zip' do
28+
it 'detects when rebel-remote.xml is present in the top-level directory',
29+
app_fixture: 'framework_jrebel_app_simple' do
30+
expect(component.detect).to eq("jrebel-agent=#{version}")
31+
end
32+
33+
it 'detects when rebel-remote.xml is present in WEB-INF/classes',
34+
app_fixture: 'framework_jrebel_app_war' do
3135
expect(component.detect).to eq("jrebel-agent=#{version}")
3236
end
3337

34-
it 'downloads JRebel agent JAR',
35-
app_fixture: 'framework_jrebel_app',
38+
it 'detects when rebel-remote.xml is present inside an embedded JAR',
39+
app_fixture: 'framework_jrebel_app_war_with_jar' do
40+
expect(component.detect).to eq("jrebel-agent=#{version}")
41+
end
42+
43+
it 'downloads the JRebel JAR and the native agent',
44+
app_fixture: 'framework_jrebel_app_simple',
3645
cache_fixture: 'stub-jrebel-archive.zip' do
3746

3847
component.compile
3948

40-
expect(sandbox + "jrebel_agent-#{version}.jar").to exist
49+
expect(sandbox + 'lib/jrebel.jar').to exist
50+
expect(sandbox + 'lib/libjrebel64.so').to exist
51+
expect(sandbox + 'lib/libjrebel32.so').to exist
4152
end
4253

43-
it 'updates JAVA_OPTS',
44-
app_fixture: 'framework_jrebel_app',
54+
it 'adds correct arguments to JAVA_OPTS',
55+
app_fixture: 'framework_jrebel_app_simple',
4556
cache_fixture: 'stub-jrebel-archive.zip' do
46-
allow(services).to receive(:find_service).and_return('credentials' => { 'licenseKey' => 'test-license-key' })
57+
58+
allow(component).to receive(:architecture).and_return('x86_64')
4759

4860
component.release
4961

50-
expect(java_opts).to include("-javaagent:$PWD/.java-buildpack/jrebel_agent/jrebel_agent-#{version}.jar")
62+
expect(java_opts).to include('-agentpath:$PWD/.java-buildpack/jrebel_agent/lib/libjrebel64.so')
5163
expect(java_opts).to include('-Drebel.remoting_plugin=true')
52-
expect(java_opts).to include("-Xbootclasspath/p:$PWD/.java-buildpack/jrebel_agent/jrebel_agent-#{version}.jar")
64+
expect(java_opts).to include('-Drebel.log=true')
65+
expect(java_opts).to include('-Drebel.cloud.platform=cloudfoundry/java-buildpack')
5366
end
5467

5568
end

0 commit comments

Comments
 (0)