Skip to content

Commit

Permalink
[ExternalSources] Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiopelosin committed Apr 15, 2014
1 parent 36fefd7 commit e238047
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 246 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
[Andrea Mazzini](https://github.com/andreamazz)
[#2008](https://github.com/CocoaPods/CocoaPods/issues/2008)

* Dependencies declared with external sources now support HTTP downloads and
have improved support for all the options supported by the downloader.
[Fabio Pelosin][irrationalfab]

##### Bug Fixes

* Support HTTP redirects when linting homepage and screenshots.
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT

GIT
remote: https://github.com/CocoaPods/Core.git
revision: f8a920b02c19273f689c1f930af580d473c7852f
revision: 46411b865c33a0f7fc172be70559611e2f7fbe21
branch: master
specs:
cocoapods-core (0.31.1)
Expand All @@ -27,7 +27,7 @@ GIT

GIT
remote: https://github.com/CocoaPods/cocoapods-downloader.git
revision: d1cca92979882fe7dfef27001705ed4b9bc43faa
revision: a66c45ed7118540a2ff98ff30e916f9652d9eea3
branch: master
specs:
cocoapods-downloader (0.4.1)
Expand Down
143 changes: 30 additions & 113 deletions lib/cocoapods/external_sources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,30 @@ def self.from_dependency(dependency, podfile_path)
name = dependency.root_name
params = dependency.external_source

klass = if params.key?(:git) then GitSource
elsif params.key?(:svn) then SvnSource
elsif params.key?(:hg) then MercurialSource
elsif params.key?(:bzr) then BazaarSource
elsif params.key?(:podspec) then PodspecSource
elsif params.key?(:path) then PathSource
end

if params.key?(:local)
klass = PathSource
UI.warn "The `:local` option of the Podfile has been renamed to `:path` and is deprecated." \
end

if klass
if klass = concrete_class_from_params(params)
klass.new(name, params, podfile_path)
else
msg = "Unknown external source parameters for `#{name}`: `#{params}`"
raise Informative, msg
end
end

# @return [Class]
#
def self.concrete_class_from_params(params)
if params.key?(:podspec)
PodspecSource
elsif params.key?(:path)
PathSource
elsif params.key?(:local)
UI.warn "The `:local` option of the Podfile has been " \
"renamed to `:path` and it is deprecated."
PathSource
elsif Downloader.strategy_from_options(params)
DownloaderSource
end
end

#-------------------------------------------------------------------------#

# Abstract class that defines the common behaviour of external sources.
Expand Down Expand Up @@ -134,7 +137,8 @@ def description
# @return [void]
#
def pre_download(sandbox)
UI.titled_section("Pre-downloading: `#{name}` #{description}", { :verbose_prefix => "-> " }) do
title = "Pre-downloading: `#{name}` #{description}"
UI.titled_section(title, { :verbose_prefix => "-> " }) do
target = sandbox.root + name
target.rmtree if target.exist?
downloader = Config.instance.downloader(target, params)
Expand Down Expand Up @@ -175,103 +179,13 @@ def store_podspec(sandbox, spec)

#-------------------------------------------------------------------------#

# Provides support for fetching a specification file from a Git remote.
#
# Supports all the options of the downloader (is similar to the git key of
# `source` attribute of a specification).
#
# @note The podspec must be in the root of the repository and should have a
# name matching the one of the dependency.
#
class GitSource < AbstractExternalSource

# @see AbstractExternalSource#fetch
#
def fetch(sandbox)
pre_download(sandbox)
end

# @see AbstractExternalSource#description
#
def description
"from `#{params[:git]}`".tap do |description|
description << ", commit `#{params[:commit]}`" if params[:commit]
description << ", branch `#{params[:branch]}`" if params[:branch]
description << ", tag `#{params[:tag]}`" if params[:tag]
end
end
end

#-------------------------------------------------------------------------#

# Provides support for fetching a specification file from a SVN source
# remote.
#
# Supports all the options of the downloader (is similar to the git key of
# `source` attribute of a specification).
#
# @note The podspec must be in the root of the repository and should have a
# name matching the one of the dependency.
#
class SvnSource < AbstractExternalSource

# @see AbstractExternalSource#fetch
#
def fetch(sandbox)
pre_download(sandbox)
end

# @see AbstractExternalSource#description
#
def description
"from `#{params[:svn]}`".tap do |description|
description << ", folder `#{params[:folder]}`" if params[:folder]
description << ", tag `#{params[:tag]}`" if params[:tag]
description << ", revision `#{params[:revision]}`" if params[:revision]
end
end
end

#-------------------------------------------------------------------------#

# Provides support for fetching a specification file from a Mercurial
# source remote.
#
# Supports all the options of the downloader (is similar to the git key of
# `source` attribute of a specification).
#
# @note The podspec must be in the root of the repository and should have a
# name matching the one of the dependency.
#
class MercurialSource < AbstractExternalSource

# @see AbstractExternalSource#fetch
#
def fetch(sandbox)
pre_download(sandbox)
end

# @see AbstractExternalSource#description
#
def description
"from `#{params[:hg]}`".tap do |description|
description << ", revision `#{params[:revision]}`" if params[:revision]
end
end
end

#-------------------------------------------------------------------------#

# Provides support for fetching a specification file from a Bazaar
# source remote.
#
# Supports all the options of the downloader (is similar to the git key of
# `source` attribute of a specification).
# Provides support for fetching a specification file from a source handled
# by the downloader. Supports all the options of the downloader
#
# @note The podspec must be in the root of the repository and should have a
# name matching the one of the dependency.
#
class BazaarSource < AbstractExternalSource
class DownloaderSource < AbstractExternalSource

# @see AbstractExternalSource#fetch
#
Expand All @@ -282,10 +196,14 @@ def fetch(sandbox)
# @see AbstractExternalSource#description
#
def description
"from `#{params[:bzr]}`".tap do |description|
description << ", tag `#{params[:tag]}`" if params[:tag]
description << ", revision `#{params[:revision]}`" if params[:revision]
strategy = Downloader.strategy_from_options(params)
options = params.dup
url = options.delete(strategy)
result = "from `#{url}`"
options.each do |key, value|
result << ", #{key} `#{value}`"
end
result
end
end

Expand All @@ -300,7 +218,6 @@ class PodspecSource < AbstractExternalSource
#
def fetch(sandbox)
UI.titled_section("Fetching podspec for `#{name}` #{description}", { :verbose_prefix => "-> " }) do

require 'open-uri'
open(podspec_uri) { |io| store_podspec(sandbox, io.read) }
end
Expand Down Expand Up @@ -374,7 +291,7 @@ def description
def declared_path
Pathname.new params[:path] || params[:local]
end

# @return [Pathname] the path of the podspec.
#
def podspec_path
Expand Down
Loading

0 comments on commit e238047

Please sign in to comment.