Skip to content

Commit

Permalink
Merge pull request #1004 from cloudfoundry/no-lsb-release
Browse files Browse the repository at this point in the history
Don't use lsb_release to find platform
  • Loading branch information
pivotal-david-osullivan authored Mar 22, 2023
2 parents 990a896 + b8e54e3 commit a7b0b1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/java_buildpack/repository/repository_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ def platform
"#{tokens[1].downcase}#{tokens[2]}"
elsif `uname -s` =~ /Darwin/
'mountainlion'
elsif !`which lsb_release 2> /dev/null`.empty?
`lsb_release -cs`.strip
elsif `cat /etc/os-release | grep '^ID=' | cut -d'=' -f 2` =~ /ubuntu/
`cat /etc/os-release | grep '^VERSION_CODENAME=' | cut -d'=' -f 2`.strip
else
raise 'Unable to determine platform'
end
Expand Down
13 changes: 8 additions & 5 deletions spec/java_buildpack/repository/repository_index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@

allow_any_instance_of(described_class).to receive(:`).with('uname -s').and_return('Linux')
allow_any_instance_of(described_class).to receive(:`).with('uname -m').and_return('x86_64')
allow_any_instance_of(described_class).to receive(:`).with('which lsb_release 2> /dev/null').and_return('')
allow_any_instance_of(described_class).to receive(:`)
.with("cat /etc/os-release | grep '^ID=' | cut -d'=' -f 2").and_return('')
allow(redhat_release).to receive(:exist?).and_return(true)
allow(redhat_release).to receive(:read).and_return('CentOS release 6.4 (Final)')
allow(application_cache).to receive(:get).with('centos6/x86_64/test-uri/index.yml')
Expand Down Expand Up @@ -106,9 +107,10 @@

allow_any_instance_of(described_class).to receive(:`).with('uname -s').and_return('Linux')
allow_any_instance_of(described_class).to receive(:`).with('uname -m').and_return('x86_64')
allow_any_instance_of(described_class).to receive(:`).with('which lsb_release 2> /dev/null')
.and_return('/usr/bin/lsb_release')
allow_any_instance_of(described_class).to receive(:`).with('lsb_release -cs').and_return('precise')
allow_any_instance_of(described_class).to receive(:`).with("cat /etc/os-release | grep '^ID=' | cut -d'=' -f 2")
.and_return('ubuntu')
allow_any_instance_of(described_class).to receive(:`)
.with("cat /etc/os-release | grep '^VERSION_CODENAME=' | cut -d'=' -f 2").and_return('precise')
allow(application_cache).to receive(:get).with('precise/x86_64/test-uri/index.yml')
.and_yield(Pathname.new('spec/fixtures/test-index.yml').open)

Expand All @@ -124,7 +126,8 @@

allow_any_instance_of(File).to receive(:exists?).with('/etc/redhat-release').and_return(false)
allow_any_instance_of(described_class).to receive(:`).with('uname -s').and_return('Linux')
allow_any_instance_of(described_class).to receive(:`).with('which lsb_release 2> /dev/null').and_return('')
allow_any_instance_of(described_class).to receive(:`)
.with("cat /etc/os-release | grep '^ID=' | cut -d'=' -f 2").and_return('')

expect { described_class.new('{platform}/{architecture}/test-uri') }
.to raise_error('Unable to determine platform')
Expand Down

0 comments on commit a7b0b1b

Please sign in to comment.