Skip to content

Commit 6bbee1c

Browse files
committed
Migrate from Ruby 2.5.9 to Ruby 3.4.7 with Psych 4.0+ compatibility
Update buildpack to use Ruby 3.4.7, addressing YAML loading changes in Psych 4.0+, adding required standard library gems, and modernizing Ruby syntax. All core utility specs (266 examples) pass successfully. Key changes: - Update YAML.load_file calls to use permitted_classes and aliases parameters - Add Psych::DisallowedClass to exception handling - Include base64, bigdecimal, digest, set, and tmpdir gems explicitly - Adopt endless range syntax (tokens[1..] vs tokens[1..-1]) - Remove Ruby 2.x version-specific test code - Modernize RuboCop configuration for rubocop-rspec
1 parent 1c46ab6 commit 6bbee1c

File tree

11 files changed

+38
-43
lines changed

11 files changed

+38
-43
lines changed

.rubocop.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
2-
require: rubocop-rspec
2+
require:
3+
- rubocop-rspec
34

45
AllCops:
56
NewCops: enable
@@ -40,7 +41,9 @@ RSpec/ExampleLength:
4041
Max: 20
4142
RSpec/ExpectOutput:
4243
Enabled: false
43-
RSpec/FilePath:
44+
RSpec/SpecFilePathFormat:
45+
Enabled: false
46+
RSpec/SpecFilePathSuffix:
4447
Enabled: false
4548
RSpec/MissingExampleGroupArgument:
4649
Enabled: false

.ruby-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.5.9
1+
3.4.7

Gemfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
source 'https://rubygems.org'
44

5+
# Ruby 3.4+ standard library gems that need to be explicit
6+
gem 'base64'
7+
gem 'bigdecimal'
8+
gem 'digest'
9+
gem 'set'
10+
gem 'tmpdir'
11+
512
group :development do
613
gem 'rake'
714
gem 'redcarpet'

Gemfile.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ GEM
44
addressable (2.8.0)
55
public_suffix (>= 2.0.2, < 5.0)
66
ast (2.4.2)
7+
base64 (0.3.0)
8+
bigdecimal (3.3.1)
79
crack (0.4.5)
810
rexml
911
diff-lcs (1.5.0)
12+
digest (3.2.1)
13+
fileutils (1.8.0)
1014
hashdiff (1.0.1)
1115
parallel (1.22.1)
1216
parser (3.1.2.0)
@@ -45,9 +49,12 @@ GEM
4549
rubocop (~> 1.19)
4650
ruby-progressbar (1.11.0)
4751
rubyzip (2.3.2)
52+
set (1.1.2)
4853
tee (1.0.0)
4954
terminal-table (3.0.2)
5055
unicode-display_width (>= 1.1.1, < 3)
56+
tmpdir (0.3.1)
57+
fileutils
5158
unicode-display_width (2.1.0)
5259
webmock (3.14.0)
5360
addressable (>= 2.8.0)
@@ -61,14 +68,19 @@ PLATFORMS
6168
ruby
6269

6370
DEPENDENCIES
71+
base64
72+
bigdecimal
73+
digest
6474
rake
6575
redcarpet
6676
rspec
6777
rubocop
6878
rubocop-rspec
6979
rubyzip
80+
set
7081
tee
7182
terminal-table
83+
tmpdir
7284
webmock
7385
yard
7486

lib/java_buildpack/framework/multi_buildpack.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def add_system_properties(java_opts)
269269
end
270270

271271
def config(config_file)
272-
YAML.load_file(config_file)
272+
YAML.load_file(config_file, permitted_classes: [Symbol], aliases: true)
273273
end
274274

275275
def config_file(dep_directory)

lib/java_buildpack/repository/repository_index.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def initialize(repository_root)
3939
.chomp('/')
4040

4141
cache.get("#{canonical repository_root}#{INDEX_PATH}") do |file|
42-
@index = YAML.load_file(file)
42+
@index = YAML.load_file(file, permitted_classes: [Symbol], aliases: true)
4343
@logger.debug { @index }
4444
end
4545
end

lib/java_buildpack/util/configuration_utils.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ def header(file)
119119

120120
def load_configuration(file, operator_provided, operator_var_name, user_provided, user_var_name,
121121
clean_nil_values, should_log)
122-
configuration = YAML.load_file(file)
122+
configuration = YAML.load_file(file, permitted_classes: [Symbol], aliases: true)
123123
logger.debug { "Configuration from #{file}: #{configuration}" } if should_log
124124

125125
if operator_provided
126126
begin
127127
operator_provided_value = YAML.safe_load(operator_provided)
128128
configuration = merge_configuration(configuration, operator_provided_value, operator_var_name, should_log)
129-
rescue Psych::SyntaxError => e
129+
rescue Psych::SyntaxError, Psych::DisallowedClass => e
130130
raise "Default configuration value in environment variable #{operator_var_name} has invalid syntax: #{e}"
131131
end
132132
end
@@ -135,7 +135,7 @@ def load_configuration(file, operator_provided, operator_var_name, user_provided
135135
begin
136136
user_provided_value = YAML.safe_load(user_provided)
137137
configuration = merge_configuration(configuration, user_provided_value, user_var_name, should_log)
138-
rescue Psych::SyntaxError => e
138+
rescue Psych::SyntaxError, Psych::DisallowedClass => e
139139
raise "User configuration value in environment variable #{user_var_name} has invalid syntax: #{e}"
140140
end
141141
logger.debug { "Configuration from #{file} modified with: #{user_provided}" } if should_log

lib/java_buildpack/util/tokenized_version.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ def major_or_minor_and_tail(s)
9393

9494
tokens = s.match(/^([^.]+)(?:\.(.*))?/)
9595

96-
# disable as we still have to support Ruby 2.5, remove & update when we drop Bionic support
97-
# rubocop:disable Style/SlicingWithRange
98-
major_or_minor, tail = tokens[1..-1]
99-
# rubocop:enable Style/SlicingWithRange
96+
major_or_minor, tail = tokens[1..]
10097

10198
raise "Invalid major or minor version '#{major_or_minor}'" unless valid_major_minor_or_micro major_or_minor
10299
end
@@ -113,10 +110,7 @@ def micro_and_qualifier(s)
113110

114111
tokens = s.match(/^([^_]+)(?:_(.*))?/)
115112

116-
# disable as we still have to support Ruby 2.5, remove & update when we drop Bionic support
117-
# rubocop:disable Style/SlicingWithRange
118-
micro, qualifier = tokens[1..-1]
119-
# rubocop:enable Style/SlicingWithRange
113+
micro, qualifier = tokens[1..]
120114

121115
raise "Invalid micro version '#{micro}'" unless valid_major_minor_or_micro micro
122116
raise "Invalid qualifier '#{qualifier}'" unless valid_qualifier qualifier

spec/java_buildpack/util/cache/download_cache_spec.rb

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -326,18 +326,7 @@
326326
.to_return(status: 200, body: 'foo-cached', headers: { Etag: 'foo-etag', 'Last-Modified' => 'foo-last-modified' })
327327

328328
allow(Net::HTTP).to receive(:Proxy).and_call_original
329-
330-
# behavior changed between ruby 2 & 3 with how default hash kwargs are passed
331-
# this causes different arguments for the mock based on the ruby version
332-
# Remove this when we drop support for ruby 2
333-
case RUBY_VERSION
334-
when /2\.\d+\.\d+/
335-
allow(Net::HTTP).to receive(:start).with('foo-uri', 80, {}).and_call_original
336-
when /3\.\d+\.\d+/
337-
allow(Net::HTTP).to receive(:start).with('foo-uri', 80).and_call_original
338-
else
339-
raise 'unexpected ruby version'
340-
end
329+
allow(Net::HTTP).to receive(:start).with('foo-uri', 80).and_call_original
341330

342331
download_cache.get(uri) {}
343332
end
@@ -348,18 +337,7 @@
348337

349338
allow(ca_certs_directory).to receive(:exist?).and_return(true)
350339
allow(Net::HTTP).to receive(:Proxy).and_call_original
351-
352-
# behavior changed between ruby 2 & 3 with how default hash kwargs are passed
353-
# this causes different arguments for the mock based on the ruby version
354-
# Remove this when we drop support for ruby 2
355-
case RUBY_VERSION
356-
when /2\.\d+\.\d+/
357-
allow(Net::HTTP).to receive(:start).with('foo-uri', 80, {}).and_call_original
358-
when /3\.\d+\.\d+/
359-
allow(Net::HTTP).to receive(:start).with('foo-uri', 80).and_call_original
360-
else
361-
raise 'unexpected ruby version'
362-
end
340+
allow(Net::HTTP).to receive(:start).with('foo-uri', 80).and_call_original
363341

364342
download_cache.get(uri) {}
365343
end

spec/java_buildpack/util/filtering_pathname_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,15 +409,15 @@
409409
end
410410

411411
it 'raises error if getwd is used' do
412-
expect { described_class.getwd }.to raise_error(/undefined method `getwd'/)
412+
expect { described_class.getwd }.to raise_error(NoMethodError, /undefined method [`']getwd'/)
413413
end
414414

415415
it 'raises error if glob is used' do
416-
expect { described_class.glob '' }.to raise_error(/undefined method `glob'/)
416+
expect { described_class.glob '' }.to raise_error(NoMethodError, /undefined method [`']glob'/)
417417
end
418418

419419
it 'raises error if pwd is used' do
420-
expect { described_class.pwd }.to raise_error(/undefined method `pwd'/)
420+
expect { described_class.pwd }.to raise_error(NoMethodError, /undefined method [`']pwd'/)
421421
end
422422

423423
def create_file(filename)

0 commit comments

Comments
 (0)