Skip to content

Commit 52cd282

Browse files
committed
CentOS support
This change updates the RepositoryIndex functionality to substitute the 'centos#' as a value for platform. It also brings the platform resolution strategy inline with the way the java-buildpack-dependecy- builder does it to ensure that the values will match. [#58119316]
1 parent fe3a0f7 commit 52cd282

4 files changed

Lines changed: 46 additions & 60 deletions

File tree

Gemfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ GEM
88
crack (0.4.1)
99
safe_yaml (~> 0.9.0)
1010
diff-lcs (1.2.4)
11-
multi_json (1.8.1)
11+
multi_json (1.8.2)
1212
parser (2.0.0)
1313
ast (~> 1.1)
1414
slop (~> 3.4, >= 3.4.5)
@@ -20,10 +20,10 @@ GEM
2020
rspec-core (~> 2.14.0)
2121
rspec-expectations (~> 2.14.0)
2222
rspec-mocks (~> 2.14.0)
23-
rspec-core (2.14.5)
23+
rspec-core (2.14.6)
2424
rspec-expectations (2.14.3)
2525
diff-lcs (>= 1.1.3, < 2.0)
26-
rspec-mocks (2.14.3)
26+
rspec-mocks (2.14.4)
2727
rubocop (0.14.1)
2828
parser (~> 2.0)
2929
powerpack (~> 0.0.6)
@@ -34,7 +34,7 @@ GEM
3434
simplecov-html (~> 0.7.1)
3535
simplecov-html (0.7.1)
3636
slop (3.4.6)
37-
webmock (1.14.0)
37+
webmock (1.15.0)
3838
addressable (>= 2.2.7)
3939
crack (>= 0.3.2)
4040
yard (0.8.7.2)

lib/java_buildpack/repository/repository_index.rb

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def find_item(version)
5555
INDEX_PATH = '/index.yml'
5656

5757
def architecture
58-
RbConfig::CONFIG['host_cpu']
58+
`uname -m`.strip
5959
end
6060

6161
def canonical(raw)
@@ -66,25 +66,15 @@ def canonical(raw)
6666
cooked
6767
end
6868

69-
def linux_platform
70-
`lsb_release -cs`.strip
71-
end
72-
73-
def osx_platform
74-
version = `sw_vers -productVersion`
75-
76-
if version =~ /^10\.8/ || version =~ /^10\.9/
77-
return 'mountainlion'
78-
else
79-
fail "Unsupported OS X version '#{version}'"
80-
end
81-
end
82-
8369
def platform
84-
if RbConfig::CONFIG['host_os'] =~ /darwin/i
85-
osx_platform
70+
if File.exists? '/etc/redhat-release'
71+
File.open('/etc/redhat-release', 'r') { |f| "centos#{f.read.match(/CentOS release (\d)/)[1]}" }
72+
elsif `uname -s` =~ /Darwin/
73+
'mountainlion'
74+
elsif !`which lsb_release 2> /dev/null`.empty?
75+
`lsb_release -cs`.strip
8676
else
87-
linux_platform
77+
fail 'Unable to determine platform'
8878
end
8979
end
9080

spec/fixtures/redhat-release

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CentOS release 6.4 (Final)

spec/java_buildpack/repository/repository_index_spec.rb

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,51 +51,46 @@ module JavaBuildpack::Repository
5151
end
5252
end
5353

54-
it 'should handle Mac OS X 10.9 correctly' do
55-
with_host('darwin12.4.0', 'x86_64') do
56-
JavaBuildpack::Util::DownloadCache.stub(:new).and_return(application_cache)
57-
RepositoryIndex.any_instance.stub(:`).with('sw_vers -productVersion').and_return('10.9')
58-
application_cache.stub(:get).with('mountainlion/x86_64/test-uri/index.yml').and_yield(File.open('spec/fixtures/test-index.yml'))
59-
RepositoryIndex.new('{platform}/{architecture}/test-uri')
60-
expect(application_cache).to have_received(:get).with(%r(mountainlion/x86_64/test-uri/index\.yml))
61-
end
54+
it 'should handle Centos correctly' do
55+
JavaBuildpack::Util::DownloadCache.stub(:new).and_return(application_cache)
56+
RepositoryIndex.any_instance.stub(:`).with('uname -s').and_return('Linux')
57+
RepositoryIndex.any_instance.stub(:`).with('uname -m').and_return('x86_64')
58+
RepositoryIndex.any_instance.stub(:`).with('which lsb_release 2> /dev/null').and_return('')
59+
File.stub(:exists?).with('/etc/redhat-release').and_return(true)
60+
File.stub(:open).and_call_original
61+
File.stub(:open).with('/etc/redhat-release', 'r').and_yield(File.new('spec/fixtures/redhat-release'))
62+
application_cache.stub(:get).with('centos6/x86_64/test-uri/index.yml').and_yield(File.open('spec/fixtures/test-index.yml'))
63+
RepositoryIndex.new('{platform}/{architecture}/test-uri')
64+
expect(application_cache).to have_received(:get).with(%r(centos6/x86_64/test-uri/index\.yml))
6265
end
6366

64-
it 'should handle Mac OS X 10.8 correctly' do
65-
with_host('darwin12.3.0', 'x86_64') do
66-
JavaBuildpack::Util::DownloadCache.stub(:new).and_return(application_cache)
67-
RepositoryIndex.any_instance.stub(:`).with('sw_vers -productVersion').and_return('10.8.4')
68-
application_cache.stub(:get).with('mountainlion/x86_64/test-uri/index.yml').and_yield(File.open('spec/fixtures/test-index.yml'))
69-
RepositoryIndex.new('{platform}/{architecture}/test-uri')
70-
expect(application_cache).to have_received(:get).with(%r(mountainlion/x86_64/test-uri/index\.yml))
71-
end
67+
it 'should handle Mac OS X correctly' do
68+
JavaBuildpack::Util::DownloadCache.stub(:new).and_return(application_cache)
69+
RepositoryIndex.any_instance.stub(:`).with('uname -s').and_return('Darwin')
70+
RepositoryIndex.any_instance.stub(:`).with('uname -m').and_return('x86_64')
71+
application_cache.stub(:get).with('mountainlion/x86_64/test-uri/index.yml').and_yield(File.open('spec/fixtures/test-index.yml'))
72+
RepositoryIndex.new('{platform}/{architecture}/test-uri')
73+
expect(application_cache).to have_received(:get).with(%r(mountainlion/x86_64/test-uri/index\.yml))
7274
end
7375

74-
it 'should handle incorrect Mac OS X version correctly' do
75-
with_host('darwin12.3.0', 'x86_64') do
76-
JavaBuildpack::Util::DownloadCache.stub(:new).and_return(application_cache)
77-
RepositoryIndex.any_instance.stub(:`).with('sw_vers -productVersion').and_return('10.7.1')
78-
expect { RepositoryIndex.new('{platform}/{architecture}/test-uri') }.to raise_error(/Unsupported OS X version/)
79-
end
76+
it 'should handle Ubuntu correctly' do
77+
JavaBuildpack::Util::DownloadCache.stub(:new).and_return(application_cache)
78+
RepositoryIndex.any_instance.stub(:`).with('uname -s').and_return('Linux')
79+
RepositoryIndex.any_instance.stub(:`).with('uname -m').and_return('x86_64')
80+
RepositoryIndex.any_instance.stub(:`).with('which lsb_release 2> /dev/null').and_return('/usr/bin/lsb_release')
81+
RepositoryIndex.any_instance.stub(:`).with('lsb_release -cs').and_return('precise')
82+
application_cache.stub(:get).with('precise/x86_64/test-uri/index.yml').and_yield(File.open('spec/fixtures/test-index.yml'))
83+
RepositoryIndex.new('{platform}/{architecture}/test-uri')
84+
expect(application_cache).to have_received(:get).with(%r(precise/x86_64/test-uri/index\.yml))
8085
end
8186

82-
it 'should handle Linux correctly' do
83-
with_host('linux-gnu', 'x86_64') do
84-
JavaBuildpack::Util::DownloadCache.stub(:new).and_return(application_cache)
85-
RepositoryIndex.any_instance.stub(:`).with('lsb_release -cs').and_return('precise')
86-
application_cache.stub(:get).with('precise/x86_64/test-uri/index.yml').and_yield(File.open('spec/fixtures/test-index.yml'))
87-
RepositoryIndex.new('{platform}/{architecture}/test-uri')
88-
expect(application_cache).to have_received(:get).with(%r(precise/x86_64/test-uri/index\.yml))
89-
end
90-
end
87+
it 'should handle unknown OS correctly' do
88+
JavaBuildpack::Util::DownloadCache.stub(:new).and_return(application_cache)
89+
File.stub(:exists?).with('/etc/redhat-release').and_return(false)
90+
RepositoryIndex.any_instance.stub(:`).with('uname -s').and_return('Linux')
91+
RepositoryIndex.any_instance.stub(:`).with('which lsb_release 2> /dev/null').and_return('')
9192

92-
def with_host(host_os, host_cpu)
93-
previous_host_os, RbConfig::CONFIG['host_os'] = RbConfig::CONFIG['host_os'], host_os
94-
previous_host_cpu, RbConfig::CONFIG['host_cpu'] = RbConfig::CONFIG['host_cpu'], host_cpu
95-
yield
96-
ensure
97-
RbConfig::CONFIG['host_os'] = previous_host_os
98-
RbConfig::CONFIG['host_cpu'] = previous_host_cpu
93+
expect { RepositoryIndex.new('{platform}/{architecture}/test-uri') }.to raise_error('Unable to determine platform')
9994
end
10095

10196
def with_buildpack_cache(directory)

0 commit comments

Comments
 (0)