-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5723 from federicobond/postflight-dsl
Add DSL for after_install and similar blocks
- Loading branch information
Showing
15 changed files
with
196 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Cask::Decorator | ||
def initialize(module_, cask, command = Cask::SystemCommand) | ||
self.extend(module_) | ||
|
||
@cask = cask | ||
@command = command | ||
end | ||
|
||
def system_command(executable, options = {}) | ||
@command.run!(executable, options) | ||
end | ||
|
||
def method_missing(m, *args, &block) | ||
if @cask.respond_to?(m) | ||
@cask.send(m, *args, &block) | ||
else | ||
super | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Cask::DSL::AfterInstall | ||
include Cask::DSL::Installed | ||
|
||
def suppress_move_to_applications | ||
system_command("/usr/bin/defaults", :args => ["write", bundle_identifier, "moveToApplicationsFolderAlertSuppress", "-bool", "true"]) | ||
end | ||
|
||
def enable_accessibility_access | ||
if MacOS.version < :mavericks | ||
system_command("touch", :args => ["/private/var/db/.AccessibilityAPIEnabled"]) | ||
else | ||
system_command("sqlite3", :args => [ | ||
"/Library/Application\ Support/com.apple.TCC/TCC.db", | ||
"INSERT INTO access VALUES('kTCCServiceAccessibility','#{bundle_identifier}',0,1,1,NULL);" | ||
], :sudo => true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module Cask::DSL::AfterUninstall; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module Cask::DSL::BeforeInstall; end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Cask::DSL::BeforeUninstall | ||
include Cask::DSL::Installed | ||
|
||
def remove_accessibility_access | ||
if MacOS.version >= :mavericks | ||
system_command("sqlite3", :args => [ | ||
"/Library/Application\ Support/com.apple.TCC/TCC.db", | ||
"DELETE FROM access WHERE client='#{bundle_identifier}';" | ||
], :sudo => true) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Cask::DSL::Installed | ||
def info_plist | ||
"#{destination_path}/#{artifacts[:link].first.first}/Contents/Info.plist" | ||
end | ||
|
||
def plist_exec(cmd) | ||
system_command("/usr/libexec/PlistBuddy", :args => ["-c", cmd, info_plist]) | ||
end | ||
|
||
def plist_set(key, value) | ||
plist_exec("Set #{key} #{value}") | ||
end | ||
|
||
def bundle_identifier | ||
plist_exec("Print CFBundleIdentifier") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'test_helper' | ||
|
||
describe Cask::Decorator do | ||
it "forwards methods to cask" do | ||
cask = Cask.load('basic-cask') | ||
decorator = Cask::Decorator.new(Cask::DSL::BeforeInstall, cask) | ||
decorator.title.must_equal 'basic-cask' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
require "test_helper" | ||
|
||
describe Cask::DSL::AfterInstall do | ||
before do | ||
cask = Cask.load('basic-cask') | ||
@decorator = Cask::Decorator.new(Cask::DSL::AfterInstall, cask, Cask::FakeSystemCommand) | ||
end | ||
|
||
it "can run system commands with list-form arguments" do | ||
Cask::FakeSystemCommand.expects_command( | ||
['echo', 'homebrew-cask', 'rocks!'] | ||
) | ||
@decorator.system_command("echo", :args => ["homebrew-cask", "rocks!"]) | ||
end | ||
|
||
it "can get the Info.plist file for the primary app" do | ||
@decorator.info_plist.must_include "basic-cask/1.2.3/TestCask.app/Contents/Info.plist" | ||
end | ||
|
||
it "can execute commands on the Info.plist file" do | ||
Cask::FakeSystemCommand.expects_command( | ||
['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', @decorator.info_plist] | ||
) | ||
@decorator.plist_exec('Print CFBundleIdentifier') | ||
end | ||
|
||
it "can retrieve the bundle identifier for the primary app" do | ||
Cask::FakeSystemCommand.stubs_command( | ||
['/usr/libexec/PlistBuddy', '-c', 'Print CFBundleIdentifier', @decorator.info_plist], | ||
"com.example.BasicCask" | ||
) | ||
@decorator.bundle_identifier.must_equal "com.example.BasicCask" | ||
end | ||
|
||
it "can set a key in the Info.plist file" do | ||
Cask::FakeSystemCommand.expects_command( | ||
['/usr/libexec/PlistBuddy', '-c', 'Set :JVMOptions:JVMVersion 1.6+', @decorator.info_plist] | ||
) | ||
@decorator.plist_set(':JVMOptions:JVMVersion', '1.6+') | ||
end | ||
|
||
it "can suppress move to applications folder alert " do | ||
@decorator.stubs(:bundle_identifier => 'com.example.BasicCask') | ||
|
||
Cask::FakeSystemCommand.expects_command( | ||
['/usr/bin/defaults', 'write', 'com.example.BasicCask', 'moveToApplicationsFolderAlertSuppress', '-bool', 'true'] | ||
) | ||
@decorator.suppress_move_to_applications | ||
end | ||
|
||
it "can enable accessibility access" do | ||
MacOS.stubs(:version => OS::Mac::Version.new('10.9')) | ||
|
||
@decorator.stubs(:bundle_identifier => 'com.example.BasicCask') | ||
|
||
Cask::FakeSystemCommand.expects_command( | ||
["/usr/bin/sudo", "-E", "--", "sqlite3", "/Library/Application Support/com.apple.TCC/TCC.db", "INSERT INTO access VALUES('kTCCServiceAccessibility','com.example.BasicCask',0,1,1,NULL);"] | ||
) | ||
@decorator.enable_accessibility_access | ||
end | ||
|
||
it "can enable accessibility access in OS X versions prior to Mavericks" do | ||
MacOS.stubs(:version => OS::Mac::Version.new('10.8')) | ||
|
||
Cask::FakeSystemCommand.expects_command( | ||
['touch', '/private/var/db/.AccessibilityAPIEnabled'] | ||
) | ||
@decorator.enable_accessibility_access | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
require "test_helper" | ||
|
||
describe Cask::DSL::BeforeUninstall do | ||
before do | ||
cask = Cask.load('basic-cask') | ||
@decorator = Cask::Decorator.new(Cask::DSL::BeforeUninstall, cask, Cask::FakeSystemCommand) | ||
end | ||
|
||
it "can remove accessibility access" do | ||
MacOS.stubs(:version => OS::Mac::Version.new('10.9')) | ||
|
||
@decorator.stubs(:bundle_identifier => 'com.example.BasicCask') | ||
|
||
Cask::FakeSystemCommand.expects_command( | ||
["/usr/bin/sudo", "-E", "--", "sqlite3", "/Library/Application Support/com.apple.TCC/TCC.db", "DELETE FROM access WHERE client='com.example.BasicCask';"] | ||
) | ||
@decorator.remove_accessibility_access | ||
end | ||
end |