class AbstractDownloadStrategy def initialize url, name, version, specs @url=url case specs when Hash @spec = specs.keys.first # only use first spec @ref = specs.values.first end @unique_token="#{name}-#{version}" unless name.to_s.empty? or name == '__UNKNOWN__' end def expand_safe_system_args args args.each_with_index do |arg, ii| if arg.is_a? Hash unless ARGV.verbose? args[ii] = arg[:quiet_flag] else args.delete_at ii end return args end end # 2 as default because commands are eg. svn up, git pull args.insert(2, '-q') unless ARGV.verbose? return args end def quiet_safe_system *args safe_system *expand_safe_system_args(args) end end class CurlDownloadStrategy '-qq'}, @tarball_path chdir when /^\037\213/, /^BZh/, /^\037\235/ # gzip/bz2/compress compressed # TODO check if it's really a tar archive safe_system '/usr/bin/tar', 'xf', @tarball_path chdir when 'Rar!' quiet_safe_system 'unrar', 'x', {:quiet_flag => '-inul'}, @tarball_path else # we are assuming it is not an archive, use original filename # this behaviour is due to ScriptFileFormula expectations # So I guess we should cp, but we mv, for this historic reason # HOWEVER if this breaks some expectation you had we *will* change the # behaviour, just open an issue at github # We also do this for jar files, as they are in fact zip files, but # we don't want to unzip them FileUtils.mv @tarball_path, File.basename(@url) end end private def chdir entries=Dir['*'] case entries.length when 0 then raise "Empty archive" when 1 then Dir.chdir entries.first rescue nil end end def ext # GitHub uses odd URLs for zip files, so check for those rx=%r[http://(www\.)?github\.com/.*/(zip|tar)ball/] if rx.match @url if $2 == 'zip' '.zip' else '.tgz' end else Pathname.new(@url).extname end end end # Use this strategy to download but not unzip a file. # Useful for installing jars. class NoUnzipCurlDownloadStrategy true end end end private def split_url(in_url) parts=in_url.sub(%r[^cvs://], '').split(/:/) mod=parts.pop url=parts.join(':') [ mod, url ] end end class MercurialDownloadStrategy