Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sanity checks and error handling in postflight mini-DSL #7940

Merged
merged 2 commits into from
Dec 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/cask/dsl/postflight.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ class Cask::DSL::Postflight < Cask::DSL::Base
include Cask::Staged

def suppress_move_to_applications(options = {})
permitted_keys = [:key]
unknown_keys = options.keys - permitted_keys
unless unknown_keys.empty?
opoo %Q{Unknown arguments to suppress_move_to_applications -- #{unknown_keys.inspect} (ignored). Running "brew update && brew upgrade brew-cask && brew cleanup && brew cask cleanup" will likely fix it.}
end
key = options[:key] || 'moveToApplicationsFolderAlertSuppress'
@command.run!('/usr/bin/defaults', :args => ['write', bundle_identifier, key, '-bool', 'true'])
begin
@command.run!('/usr/bin/defaults', :args => ['write', bundle_identifier, key, '-bool', 'true'])
rescue StandardError => e
raise CaskError.new("#{@cask.token}: 'suppress_move_to_applications' failed with: #{e}")
end
end

def method_missing(method, *args)
Expand Down
16 changes: 12 additions & 4 deletions lib/cask/staged.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
module Cask::Staged
def info_plist(index = 0)
def info_plist_file(index = 0)
index = 0 if index == :first
index = 1 if index == :second
index = -1 if index == :last
@cask.staged_path.join(@cask.artifacts[:app].to_a.at(index).first, 'Contents', 'Info.plist')
end

def plist_exec(cmd)
@command.run!('/usr/libexec/PlistBuddy', :args => ['-c', cmd, info_plist])
@command.run!('/usr/libexec/PlistBuddy', :args => ['-c', cmd, info_plist_file])
end

def plist_set(key, value)
plist_exec("Set #{key} #{value}")
begin
plist_exec("Set #{key} #{value}")
rescue StandardError => e
raise CaskError.new("#{@cask.token}: 'plist_set' failed with: #{e}")
end
end

def bundle_identifier
plist_exec('Print CFBundleIdentifier').stdout.chomp
begin
plist_exec('Print CFBundleIdentifier').stdout.chomp
rescue StandardError => e
raise CaskError.new("#{@cask.token}: 'bundle_identifier' failed with: #{e}")
end
end
end
6 changes: 3 additions & 3 deletions test/cask/dsl/postflight_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
end

it "can get the Info.plist file for the primary app" do
@dsl.info_plist.to_s.must_include 'basic-cask/1.2.3/TestCask.app/Contents/Info.plist'
@dsl.info_plist_file.to_s.must_include 'basic-cask/1.2.3/TestCask.app/Contents/Info.plist'
end

it "can execute commands on the Info.plist file" do
@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')

Cask::FakeSystemCommand.expects_command(
['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', @dsl.info_plist]
['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', @dsl.info_plist_file]
)
@dsl.plist_exec('Print CFBundleIdentifier')
end
Expand All @@ -30,7 +30,7 @@
@dsl.stubs(:bundle_identifier => 'com.example.BasicCask')

Cask::FakeSystemCommand.expects_command(
['/usr/libexec/PlistBuddy', '-c', 'Set :JVMOptions:JVMVersion 1.6+', @dsl.info_plist]
['/usr/libexec/PlistBuddy', '-c', 'Set :JVMOptions:JVMVersion 1.6+', @dsl.info_plist_file]
)
@dsl.plist_set(':JVMOptions:JVMVersion', '1.6+')
end
Expand Down