Merge pull request #8595 from rolandwalker/remove_homebrew_fork_resource

remove homebrew-fork resource.rb
This commit is contained in:
Roland Walker 2015-01-02 17:18:50 -05:00
commit 7741262b8f
4 changed files with 26 additions and 133 deletions

View File

@ -13,13 +13,7 @@ module Hbc::DownloadStrategy
@cask = cask
@command = command
@cask_url = cask.url
super(
cask.token,
Hbc::Resource.new(cask.token) do |r|
r.url cask.url.to_s
r.version cask.version.to_s
end
)
super(cask)
end
end

View File

@ -1,15 +1,14 @@
require 'vendor/homebrew-fork/resource'
class Hbc::HbAbstractDownloadStrategy
attr_reader :name, :resource
attr_reader :name, :url, :uri_object, :version
def initialize name, resource
@name = name
@resource = resource
@url = resource.url
def initialize(cask)
@name = cask.token
@url = cask.url.to_s
@uri_object = cask.url
@version = cask.version
end
def expand_safe_system_args args
def expand_safe_system_args(args)
args = args.dup
args.each_with_index do |arg, ii|
if arg.is_a? Hash
@ -26,7 +25,7 @@ class Hbc::HbAbstractDownloadStrategy
args
end
def quiet_safe_system *args
def quiet_safe_system(*args)
safe_system(*expand_safe_system_args(args))
end
@ -39,15 +38,17 @@ end
class Hbc::HbVCSDownloadStrategy < Hbc::HbAbstractDownloadStrategy
REF_TYPES = [:branch, :revision, :revisions, :tag].freeze
def initialize name, resource
def initialize(cask)
super
@ref_type, @ref = extract_ref(resource.specs)
@ref_type, @ref = extract_ref
@clone = HOMEBREW_CACHE.join(cache_filename)
end
def extract_ref(specs)
key = REF_TYPES.find { |type| specs.key?(type) }
return key, specs[key]
def extract_ref
key = REF_TYPES.find do |type|
uri_object.respond_to?(type) and uri_object.send(type)
end
return key, key ? uri_object.send(key) : nil
end
def cache_filename
@ -68,12 +69,13 @@ class Hbc::HbVCSDownloadStrategy < Hbc::HbAbstractDownloadStrategy
end
class Hbc::HbCurlDownloadStrategy < Hbc::HbAbstractDownloadStrategy
# todo should be part of url object
def mirrors
@mirrors ||= resource.mirrors.dup
@mirrors ||= []
end
def tarball_path
@tarball_path ||= Pathname.new("#{HOMEBREW_CACHE}/#{name}-#{resource.version}#{ext}")
@tarball_path ||= Pathname.new("#{HOMEBREW_CACHE}/#{name}-#{version}#{ext}")
end
def temporary_path
@ -159,7 +161,7 @@ end
class Hbc::HbSubversionDownloadStrategy < Hbc::HbVCSDownloadStrategy
def cache_tag
# todo: pass versions as symbols, support :head here
resource.version == 'head' ? "svn-HEAD" : "svn"
version == 'head' ? "svn-HEAD" : "svn"
end
def repo_valid?
@ -197,7 +199,7 @@ class Hbc::HbSubversionDownloadStrategy < Hbc::HbVCSDownloadStrategy
end
end
def shell_quote str
def shell_quote(str)
# Oh god escaping shell args.
# See http://notetoself.vrensk.com/2008/08/escaping-single-quotes-in-ruby-harder-than-expected/
str.gsub(/\\|'/) { |c| "\\#{c}" }
@ -210,7 +212,7 @@ class Hbc::HbSubversionDownloadStrategy < Hbc::HbVCSDownloadStrategy
end
end
def fetch_repo target, url, revision=nil, ignore_externals=false
def fetch_repo(target, url, revision=nil, ignore_externals=false)
# Use "svn up" when the repository already exists locally.
# This saves on bandwidth and will have a similar effect to verifying the
# cache as it will make any changes to get the right revision.
@ -246,7 +248,7 @@ end
# Download from SVN servers with invalid or self-signed certs
class Hbc::HbUnsafeSubversionDownloadStrategy < Hbc::HbSubversionDownloadStrategy
def fetch_repo target, url, revision=nil, ignore_externals=false
def fetch_repo(target, url, revision=nil, ignore_externals=false)
# Use "svn up" when the repository already exists locally.
# This saves on bandwidth and will have a similar effect to verifying the
# cache as it will make any changes to get the right revision.

View File

@ -1,102 +0,0 @@
require 'vendor/homebrew-fork/download_strategy'
# Resource is the fundamental representation of an external resource. The
# primary formula download, along with other declared resources, are instances
# of this class.
class Hbc::Resource
attr_reader :mirrors, :specs, :using
attr_writer :url, :version
attr_accessor :download_strategy
# Formula name must be set after the DSL, as we have no access to the
# formula name before initialization of the formula
attr_accessor :name, :owner
def initialize name=nil, &block
@name = name
@url = nil
@version = nil
@mirrors = []
@specs = {}
@using = nil
instance_eval(&block) if block_given?
end
# Create a temporary directory then yield. When the block returns,
# recursively delete the temporary directory.
def mktemp(prefix=name)
# I used /tmp rather than `mktemp -td` because that generates a directory
# name with exotic characters like + in it, and these break badly written
# scripts that don't escape strings before trying to regexp them :(
# If the user has FileVault enabled, then we can't mv symlinks from the
# /tmp volume to the other volume. So we let the user override the tmp
# prefix if they need to.
tempd = `/usr/bin/mktemp -d #{HOMEBREW_TEMP}/#{prefix}-XXXXXX`.chomp
raise "Failed to create sandbox" if tempd.empty?
prevd = pwd
cd tempd
yield
ensure
cd prevd if prevd
ignore_interrupts{ rm_r tempd } if tempd
end
def downloader
@downloader ||= download_strategy.new(download_name, self)
end
# Removes /s from resource names; this allows go package names
# to be used as resource names without confusing software that
# interacts with download_name, e.g. github.com/foo/bar
def escaped_name
name.gsub("/", '-')
end
def download_name
name.nil? ? owner.name : "#{owner.name}--#{escaped_name}"
end
def cached_download
downloader.cached_location
end
def clear_cache
downloader.clear_cache
end
Partial = Struct.new(:resource, :files)
def files(*files)
Partial.new(self, files)
end
# For brew-fetch and others.
def fetch
# Ensure the cache exists
HOMEBREW_CACHE.mkpath
downloader.fetch
rescue Hbc::ErrorDuringExecution, Hbc::CurlDownloadStrategyError => e
raise RuntimeError.new
else
cached_download
end
def url val=nil, specs={}
return @url if val.nil?
@url = val
@specs.merge!(specs)
@using = @specs.delete(:using)
@download_strategy = Hbc::HbDownloadStrategyDetector.detect(url, using)
end
def version val=nil
@version ||= val
end
def mirror val
mirrors << val
end
end

View File

@ -18,11 +18,10 @@ describe 'download strategies' do
allow(downloader.temporary_path).to receive(:rename)
end
it 'properly assigns a name and Resource based on the Cask' do
it 'properly assigns a name and uri based on the Cask' do
expect(downloader.name).to eq('some-cask')
expect(downloader.resource.name).to eq('some-cask')
expect(downloader.resource.url).to eq('http://example.com/cask.dmg')
expect(downloader.resource.version.to_s).to eq('1.2.3.4')
expect(downloader.url).to eq('http://example.com/cask.dmg')
expect(downloader.version.to_s).to eq('1.2.3.4')
end
it 'calls curl with default arguments for a simple Cask' do