From b3836f581d2b4939446c17bde52da10a77ea3dde Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Tue, 9 Dec 2014 10:47:23 -0500 Subject: [PATCH 1/2] recast info_plist as info_plist_file --- lib/cask/staged.rb | 4 ++-- test/cask/dsl/postflight_test.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/cask/staged.rb b/lib/cask/staged.rb index 6ee2c60dba8f..72a532507b32 100644 --- a/lib/cask/staged.rb +++ b/lib/cask/staged.rb @@ -1,5 +1,5 @@ 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 @@ -7,7 +7,7 @@ def info_plist(index = 0) 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) diff --git a/test/cask/dsl/postflight_test.rb b/test/cask/dsl/postflight_test.rb index cd24bf1d20f3..85d169a9e341 100644 --- a/test/cask/dsl/postflight_test.rb +++ b/test/cask/dsl/postflight_test.rb @@ -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 @@ -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 From a808befdd6a6f9e74922e4fbcd254e03487953f3 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Tue, 9 Dec 2014 10:49:03 -0500 Subject: [PATCH 2/2] sanity checks/error handling, postflight miniDSL report errors in all user-facing methods --- lib/cask/dsl/postflight.rb | 11 ++++++++++- lib/cask/staged.rb | 12 ++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/cask/dsl/postflight.rb b/lib/cask/dsl/postflight.rb index aaa1a8eebb38..c0eda165e73e 100644 --- a/lib/cask/dsl/postflight.rb +++ b/lib/cask/dsl/postflight.rb @@ -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) diff --git a/lib/cask/staged.rb b/lib/cask/staged.rb index 72a532507b32..54a518e4890c 100644 --- a/lib/cask/staged.rb +++ b/lib/cask/staged.rb @@ -11,10 +11,18 @@ def plist_exec(cmd) 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