Commit ad457f58 authored by Fabio Pelosin's avatar Fabio Pelosin

Merge branch 'master' into pod-push

* master:
  correct typo
  add functional spec for http downloader
  refactor: raise a UnsupportedFileTypeError when unexpected file type is given
  cleanup http downloader, add spec
  load yaml only when needed
  add http downloader - that download repo with http and then decompress them
  Travis build status only for master branch
  Small cleanup.
  Removed broken Xcodeproj bundle install command from rake bootstrap task
parents c16445d8 f9e77af9
# CocoaPods – an Objective-C library manager
[![Build Status](https://secure.travis-ci.org/CocoaPods/CocoaPods.png)](https://secure.travis-ci.org/CocoaPods/CocoaPods)
[![Build Status](https://secure.travis-ci.org/CocoaPods/CocoaPods.png?branch=master)](https://secure.travis-ci.org/CocoaPods/CocoaPods)
CocoaPods manages library dependencies for your Xcode project.
......
......@@ -208,7 +208,6 @@ task :bootstrap do
puts "Installing gems"
`bundle install`
`cd external/XcodeProj && bundle install`
end
desc "Run all specs"
......
......@@ -58,6 +58,7 @@ module Pod
end
def check_versions(dir)
require 'yaml'
bin_version = Gem::Version.new(VERSION)
yaml_file = dir + 'CocoaPods-version.yml'
return unless yaml_file.exist?
......
......@@ -6,6 +6,7 @@ module Pod
autoload :GitHub, 'cocoapods/downloader/git'
autoload :Mercurial, 'cocoapods/downloader/mercurial'
autoload :Subversion, 'cocoapods/downloader/subversion'
autoload :Http, 'cocoapods/downloader/http'
extend Executable
......@@ -40,6 +41,8 @@ module Pod
Mercurial.new(target_path, url, options)
elsif url = options.delete(:svn)
Subversion.new(target_path, url, options)
elsif url = options.delete(:http)
Http.new(target_path, url, options)
else
raise "Unsupported download strategy `#{options.inspect}'."
end
......
require 'open-uri'
require 'tempfile'
require 'zlib'
require 'yaml'
module Pod
class Downloader
class Http < Downloader
class UnsupportedFileTypeError < StandardError; end
executable :curl
executable :unzip
executable :tar
attr_accessor :filename, :download_path
def download
@filename = filename_with_type type
@download_path = target_path + @filename
download_file @download_path
extract_with_type @download_path, type
end
def type
options[:type] || type_with_url(url)
end
def clean
FileUtils.rm @download_path
end
private
def type_with_url(url)
if url =~ /.zip$/
:zip
elsif url =~ /.tgz$/
:tgz
elsif url =~ /.tar$/
:tar
else
nil
end
end
def filename_with_type(type=:zip)
case type
when :zip
"file.zip"
when :tgz
"file.tgz"
when :tar
"file.tar"
else
raise UnsupportedFileTypeError.new "Unsupported file type: #{type}"
end
end
def download_file(full_filename)
curl "-L -o '#{full_filename}' '#{url}'"
end
def extract_with_type(full_filename, type=:zip)
case type
when :zip
unzip "'#{full_filename}' -d #{target_path}"
when :tgz
tar "xfz '#{full_filename}' -d #{target_path}"
when :tar
tar "xf '#{full_filename}' -d #{target_path}"
else
raise UnsupportedFileTypeError.new "Unsupported file type: #{type}"
end
end
end
end
end
......@@ -13,7 +13,7 @@ module Pod
end
def all_sets
all.map {|source| source.pod_sets}.flatten
all.map(&:pod_sets).flatten
end
def search(dependency)
......
......@@ -139,5 +139,32 @@ describe "Pod::Downloader" do
(@pod.root + '.svn').should.not.exist
end
end
describe "for Http" do
extend SpecHelper::TemporaryDirectory
it "download file and unzip it" do
@pod.specification.stubs(:source).returns(
:http => 'http://dl.google.com/googleadmobadssdk/googleadmobsearchadssdkios.zip'
)
downloader = Pod::Downloader.for_pod(@pod)
VCR.use_cassette('tarballs', :record => :new_episodes) { downloader.download }
(@pod.root + 'GoogleAdMobSearchAdsSDK/GADSearchRequest.h').should.exist
(@pod.root + 'GoogleAdMobSearchAdsSDK/GADSearchRequest.h').read.strip.should =~ /Google Search Ads iOS SDK/
end
it "removes the .zip when cleaning" do
@pod.specification.stubs(:source).returns(
:http => 'http://dl.google.com/googleadmobadssdk/googleadmobsearchadssdkios.zip'
)
downloader = Pod::Downloader.for_pod(@pod)
downloader.download
downloader.clean
(@pod.root + 'file.zip').should.not.exist
end
end
end
require File.expand_path('../../spec_helper', __FILE__)
def stub_pod_with_source(source_options)
specification = stub(
:part_of_other_pod? => false,
:source => source_options
)
stub('pod') do
stubs(:root).returns(temporary_sandbox.root)
stubs(:specification).returns(specification)
end
end
describe Pod::Downloader::Http do
it 'should find download file type' do
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:http => 'https://testflightapp.com/media/sdk-downloads/TestFlightSDK1.0.zip'
))
downloader.should.be.instance_of Pod::Downloader::Http
downloader.type.should == :zip
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:http => 'https://testflightapp.com/media/sdk-downloads/TestFlightSDK1.0.tar'
))
downloader.should.be.instance_of Pod::Downloader::Http
downloader.type.should == :tar
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:http => 'https://testflightapp.com/media/sdk-downloads/TestFlightSDK1.0.tgz'
))
downloader.should.be.instance_of Pod::Downloader::Http
downloader.type.should == :tgz
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:http => 'https://testflightapp.com/media/sdk-downloads/TestFlightSDK1.0',
:type => :zip
))
downloader.should.be.instance_of Pod::Downloader::Http
downloader.type.should == :zip
end
it 'should download file and extract it with proper type' do
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:http => 'https://testflightapp.com/media/sdk-downloads/TestFlightSDK1.0.zip'
))
downloader.expects(:download_file).with(anything())
downloader.expects(:extract_with_type).with(anything(), :zip).at_least_once
downloader.download
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:http => 'https://testflightapp.com/media/sdk-downloads/TestFlightSDK1.0.tgz'
))
downloader.expects(:download_file).with(anything())
downloader.expects(:extract_with_type).with(anything(), :tgz).at_least_once
downloader.download
end
it 'should raise error when unsupported filetype is pass' do
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:http => 'https://testflightapp.com/media/sdk-downloads/TestFlightSDK1.0.rar'
))
downloader.expects(:download).raises(Pod::Downloader::Http::UnsupportedFileTypeError)
downloader.download rescue nil
downloader = Pod::Downloader.for_pod(stub_pod_with_source(
:http => 'https://testflightapp.com/media/sdk-downloads/TestFlightSDK1.0',
:type => :rar
))
downloader.expects(:download).raises(Pod::Downloader::Http::UnsupportedFileTypeError)
downloader.download rescue nil
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment