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

support for nested containers #1232

Merged
merged 1 commit into from
Oct 19, 2013
Merged
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
support for nested containers
 - this allows us to support casks for things like "dmg in zip" "zip in
   tar", etc, etc
 - a nested container can be any format that homebrew-cask supports
 - the existing container support is now referred to as a Cask's
   "primary container"
 - use the `nested_container` artifact type to indicate the relative
   path to a nested container that you wanted extracted
 - multiple layers of nesting should work with multiple nested_container
   directives (though this is untested as yet)
 - add SpeedDownload as the first cask to use this feature; refs #602
phinze committed Oct 19, 2013

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit c03ada18ec8dd206b3cca25ca4d232265116403d
8 changes: 8 additions & 0 deletions Casks/speed-download.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class SpeedDownload < Cask
url 'http://mirror.nscocoa.com/~yazsoftc1/files/sd5/sd5.zip'
homepage 'http://www.yazsoft.com/products/speed-download'
version 'latest'
no_checksum
nested_container 'Speed Download 5.dmg'
link 'Speed Download 5/Speed Download.app'
end
6 changes: 6 additions & 0 deletions lib/cask/artifact.rb
Original file line number Diff line number Diff line change
@@ -3,12 +3,18 @@ module Cask::Artifact; end
require 'cask/artifact/base'

require 'cask/artifact/app'
require 'cask/artifact/nested_container'
require 'cask/artifact/pkg'
require 'cask/artifact/prefpane'

module Cask::Artifact
#
# NOTE: order is important here, since we want to extract nested containers
# before we handle any other artifacts
#
def self.artifacts
[
Cask::Artifact::NestedContainer,
Cask::Artifact::App,
Cask::Artifact::Pkg,
Cask::Artifact::Prefpane,
23 changes: 23 additions & 0 deletions lib/cask/artifact/nested_container.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Cask::Artifact::NestedContainer < Cask::Artifact::Base
def self.me?(cask)
cask.artifacts[:nested_container].any?
end

def install
@cask.artifacts[:nested_container].each { |container| extract(container) }
end

def uninstall
# no need to take action; we will get removed by rmtree of parent
end

def extract(container_relative_path)
source = @cask.destination_path.join(container_relative_path)
container = Cask::Container.for_path(source, @command)
unless container
raise "aw dang, could not identify nested container at #{source}"
end
ohai "Extracting nested container #{source.basename}"
container.new(@cask, source, @command).extract
end
end
5 changes: 3 additions & 2 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
@@ -36,10 +36,11 @@ def artifacts
end

ARTIFACT_TYPES = [
:install,
:link,
:nested_container,
:prefpane,
:install,
:uninstall
:uninstall,
]

ARTIFACT_TYPES.each do |type|
6 changes: 3 additions & 3 deletions lib/cask/installer.rb
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ def install(force=false)
end

download
extract_container
extract_primary_container
install_artifacts

ohai "Success! #{@cask} installed to #{@cask.destination_path}"
@@ -26,11 +26,11 @@ def download
@downloaded_path = download.perform
end

def extract_container
def extract_primary_container
FileUtils.mkdir_p @cask.destination_path
container = Cask::Container.for_path(@downloaded_path, @command)
unless container
raise "uh oh, could not identify container for #{@downloaded_path}"
raise "uh oh, could not identify primary container for #{@downloaded_path}"
end
container.new(@cask, @downloaded_path, @command).extract
end
17 changes: 17 additions & 0 deletions test/cask/artifact/nested_container_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'test_helper'

describe Cask::Artifact::NestedContainer do
describe 'install' do
it 'extracts the specified paths as containers' do
cask = Cask.load('nested-app').tap do |c|
TestHelper.install_without_artifacts(c)
end

shutup do
Cask::Artifact::NestedContainer.new(cask).install
end

cask.destination_path.join('MyNestedApp.app').must_be :directory?
end
end
end
11 changes: 11 additions & 0 deletions test/cask/installer_test.rb
Original file line number Diff line number Diff line change
@@ -103,6 +103,17 @@
pkg = dest_path/'Naked.pkg'
pkg.must_be :file?
end

it "works fine with a nested container" do
nested_app = Cask.load('nested-app')

shutup do
Cask::Installer.new(nested_app).install
end

dest_path = Cask.appdir/'MyNestedApp.app'
TestHelper.valid_alias?(dest_path).must_equal true
end
end

describe "uninstall" do
9 changes: 9 additions & 0 deletions test/support/Casks/nested-app.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class NestedApp < TestCask
url TestHelper.local_binary('NestedApp.dmg.zip')
homepage 'http://example.com/nested-app'
version '1.2.3'
sha1 'de226f9ced77ae359ddb3c8764c605a391199d5c'
nested_container 'NestedApp.dmg'
link 'MyNestedApp.app'
end

Binary file added test/support/binaries/NestedApp.dmg.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -76,7 +76,7 @@ def self.valid_alias?(candidate)
def self.install_without_artifacts(cask)
Cask::Installer.new(cask).tap do |i|
shutup { i.download }
i.extract_container
i.extract_primary_container
end
end
end