Skip to content

Commit

Permalink
Fixed Homebrew#1248, Better nested container syntax
Browse files Browse the repository at this point in the history
I add a new `container` dsl. With this new dsl, we can drop `nested_container`.
  • Loading branch information
Võ Anh Duy committed Apr 19, 2014
1 parent 9d8fa23 commit 70034f2
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 19 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Additional stanzas you might need for special use-cases:
| `binary` | relative path to a binary that should be linked into the `/usr/local/bin` folder on installation
| `input_method` | relative path to a input method that should be linked into the `~/Library/Input Methods` folder on installation
| `screen_saver` | relative path to a Screen Saver that should be linked into the `~/Library/Screen Savers` folder on installation
| `container` | relative path to an inner container that must be extracted and link to installation; this allows us to support dmg inside tar, zip inside dmg, etc. (see __Container Details__ for more information)
| `nested_container` | relative path to an inner container that must be extracted before moving on with the installation; this allows us to support dmg inside tar, zip inside dmg, etc.
| `caveats` | a string or Ruby block providing the user with Cask-specific information at install time (see also [Caveats Details](doc/CASK_LANGUAGE_REFERENCE.md#caveats-details))

Expand Down
3 changes: 2 additions & 1 deletion lib/cask/artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ module Cask::Artifact; end
require 'cask/artifact/before_block'
require 'cask/artifact/colorpicker'
require 'cask/artifact/font'
require 'cask/artifact/container'
require 'cask/artifact/nested_container'
require 'cask/artifact/pkg'
require 'cask/artifact/prefpane'
Expand All @@ -20,7 +21,6 @@ module Cask::Artifact; end
require 'cask/artifact/input_method'
require 'cask/artifact/screen_saver'


module Cask::Artifact
#
# NOTE: order is important here, since we want to extract nested containers
Expand All @@ -29,6 +29,7 @@ module Cask::Artifact
def self.artifacts
[
Cask::Artifact::BeforeBlock,
Cask::Artifact::Container,
Cask::Artifact::NestedContainer,
Cask::Artifact::App,
Cask::Artifact::Colorpicker,
Expand Down
20 changes: 20 additions & 0 deletions lib/cask/artifact/container.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Cask::Artifact::Container < Cask::Artifact::Base
def install
@cask.artifacts[self.class.artifact_dsl_key].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 CaskError.new "Aw dang, could not identify nested_container at '#{source}'"
end
ohai "Extracting nested container #{source.basename}"
container.new(@cask, source, @command).extract
end

end
19 changes: 1 addition & 18 deletions lib/cask/artifact/nested_container.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,2 @@
class Cask::Artifact::NestedContainer < Cask::Artifact::Base
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 CaskError.new "Aw dang, could not identify nested_container at '#{source}'"
end
ohai "Extracting nested container #{source.basename}"
container.new(@cask, source, @command).extract
end
class Cask::Artifact::NestedContainer < Cask::Artifact::Container
end
12 changes: 12 additions & 0 deletions lib/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ def self.ordinary_artifact_types
end
end

ARTIFACT_AGRS_WITH_BLOCKS_TYPES = [
:container
]

ARTIFACT_AGRS_WITH_BLOCKS_TYPES.each do |type|
define_method(type) do |*args, &block|
artifacts[type].merge(args)
block.call(args)
end
end


attr_reader :sums

def hash_name(hash_type)
Expand Down
20 changes: 20 additions & 0 deletions test/cask/artifact/container_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'test_helper'

describe Cask::Artifact::Container do
describe 'install' do
before {
@cask = Cask.load('nested-app-with-container')

shutup do
Cask::Installer.new(@cask).install
end
}

it 'extracts the specified paths as containers' do
@cask.destination_path.join('MyNestedApp.app').must_be :directory?
end
it "links the noted applications to the proper directory" do
TestHelper.valid_alias?(Cask.appdir/'MyNestedApp.app').must_equal true
end
end
end
9 changes: 9 additions & 0 deletions test/support/Casks/nested-app-with-container.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class NestedAppWithContainer < TestCask
url TestHelper.local_binary('NestedApp.dmg.zip')
homepage 'http://example.com/nested-app'
version '1.2.3'
sha256 '1866dfa833b123bb8fe7fa7185ebf24d28d300d0643d75798bc23730af734216'
container 'NestedApp.dmg' do
link 'MyNestedApp.app'
end
end

0 comments on commit 70034f2

Please sign in to comment.