Skip to content

Commit ee94b02

Browse files
mmanciopnebhale
authored andcommitted
Quote arguments that could have special chars for BASH
[#789] Signed-off-by: Ben Hale <[email protected]>
1 parent cde1bb4 commit ee94b02

File tree

2 files changed

+40
-13
lines changed
  • lib/java_buildpack/framework/java_memory_assistant
  • spec/java_buildpack/framework/java_memory_assistant

2 files changed

+40
-13
lines changed

lib/java_buildpack/framework/java_memory_assistant/agent.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ def release
5151
end
5252

5353
add_system_prop_if_config_present 'check_interval', 'jma.check_interval'
54-
add_system_prop_if_config_present 'max_frequency', 'jma.max_frequency'
54+
55+
if @configuration.key?('max_frequency')
56+
@droplet.java_opts.add_preformatted_options "'-Djma.max_frequency=#{@configuration['max_frequency']}'"
57+
end
5558

5659
return unless @configuration.key?('thresholds')
5760

5861
@configuration['thresholds'].each do |key, value|
59-
@droplet.java_opts.add_system_property "jma.thresholds.#{key}", value.to_s
62+
@droplet.java_opts.add_preformatted_options "'-Djma.thresholds.#{key}=#{value.to_s}'"
6063
end
6164
end
6265

spec/java_buildpack/framework/java_memory_assistant/agent_spec.rb

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@
5959
expect(java_opts).to include('-Djma.enabled=true')
6060

6161
expect(java_opts).to include('-Djma.check_interval=5s')
62-
expect(java_opts).to include('-Djma.max_frequency=1/1m')
62+
expect(java_opts).to include('\'-Djma.max_frequency=1/1m\'')
6363

64-
expect(java_opts).to include('-Djma.thresholds.heap=90')
65-
expect(java_opts).to include('-Djma.thresholds.old_gen=90')
64+
expect(java_opts).to include('\'-Djma.thresholds.heap=90\'')
65+
expect(java_opts).to include('\'-Djma.thresholds.old_gen=90\'')
6666

6767
end
6868

@@ -132,15 +132,15 @@
132132
'java-memory-assistant-0.1.0.jar')
133133
expect(java_opts).to include('-Djma.enabled=true')
134134
expect(java_opts).to include('-Djma.check_interval=10m')
135-
expect(java_opts).to include('-Djma.max_frequency=4/10h')
135+
expect(java_opts).to include('\'-Djma.max_frequency=4/10h\'')
136136
expect(java_opts).to include('-Djma.log_level=DEBUG')
137-
expect(java_opts).to include('-Djma.thresholds.heap=60')
138-
expect(java_opts).to include('-Djma.thresholds.code_cache=30')
139-
expect(java_opts).to include('-Djma.thresholds.metaspace=5')
140-
expect(java_opts).to include('-Djma.thresholds.perm_gen=45.5')
141-
expect(java_opts).to include('-Djma.thresholds.eden=90')
142-
expect(java_opts).to include('-Djma.thresholds.survivor=95.5')
143-
expect(java_opts).to include('-Djma.thresholds.old_gen=30')
137+
expect(java_opts).to include('\'-Djma.thresholds.heap=60\'')
138+
expect(java_opts).to include('\'-Djma.thresholds.code_cache=30\'')
139+
expect(java_opts).to include('\'-Djma.thresholds.metaspace=5\'')
140+
expect(java_opts).to include('\'-Djma.thresholds.perm_gen=45.5\'')
141+
expect(java_opts).to include('\'-Djma.thresholds.eden=90\'')
142+
expect(java_opts).to include('\'-Djma.thresholds.survivor=95.5\'')
143+
expect(java_opts).to include('\'-Djma.thresholds.old_gen=30\'')
144144
end
145145

146146
end
@@ -160,6 +160,30 @@
160160

161161
end
162162

163+
context do
164+
let(:configuration) do
165+
{
166+
'thresholds' => {
167+
'heap' => '>600MB',
168+
'eden' => '< 30MB'
169+
}
170+
}
171+
end
172+
173+
let(:version) { '0.1.0' }
174+
175+
it 'escapses redirection characters' do
176+
component.release
177+
178+
expect(java_opts).to include('-javaagent:$PWD/.java-buildpack/java_memory_assistant_agent/' \
179+
'java-memory-assistant-0.1.0.jar')
180+
181+
expect(java_opts).to include('\'-Djma.thresholds.heap=>600MB\'')
182+
expect(java_opts).to include('\'-Djma.thresholds.eden=< 30MB\'')
183+
end
184+
185+
end
186+
163187
context do
164188
let(:configuration) do
165189
{

0 commit comments

Comments
 (0)