# Copyright 2009 Max Howell and other contributors. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # 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 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