Commit 57a3cae6 authored by Fabio Pelosin's avatar Fabio Pelosin

[ExternalSources] Minor cleanup

parent b25d4110
...@@ -79,23 +79,6 @@ module Pod ...@@ -79,23 +79,6 @@ module Pod
public public
# @!group Fetching
# Fetches the external source from the remote according to the params.
#
# @param [Sandbox] sandbox
# the sandbox where the specification should be stored.
#
# @return [void]
#
def fetch(sandbox)
raise "Abstract method"
end
#--------------------------------------#
public
# @!group Subclasses hooks # @!group Subclasses hooks
# Fetches the external source from the remote according to the params. # Fetches the external source from the remote according to the params.
...@@ -117,6 +100,26 @@ module Pod ...@@ -117,6 +100,26 @@ module Pod
#--------------------------------------# #--------------------------------------#
protected
# @return [String] The uri of the podspec appending the name of the file
# and expanding it if necessary.
#
# @note If the declared path is expanded only if the represents a path
# relative to the file system.
#
def normalized_podspec_path(declared_path)
if File.extname(declared_path) == '.podspec'
path_with_ext = declared_path
else
path_with_ext = "#{declared_path}/#{name}.podspec"
end
podfile_dir = File.dirname(podfile_path || '')
File.expand_path(path_with_ext, podfile_dir)
end
#--------------------------------------#
private private
# @! Subclasses helpers # @! Subclasses helpers
...@@ -174,7 +177,6 @@ module Pod ...@@ -174,7 +177,6 @@ module Pod
def store_podspec(sandbox, spec) def store_podspec(sandbox, spec)
sandbox.store_podspec(name, spec, true) sandbox.store_podspec(name, spec, true)
end end
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -217,7 +219,8 @@ module Pod ...@@ -217,7 +219,8 @@ module Pod
# @see AbstractExternalSource#fetch # @see AbstractExternalSource#fetch
# #
def fetch(sandbox) def fetch(sandbox)
UI.titled_section("Fetching podspec for `#{name}` #{description}", { :verbose_prefix => "-> " }) do title = "Fetching podspec for `#{name}` #{description}"
UI.titled_section(title, { :verbose_prefix => "-> " }) do
require 'open-uri' require 'open-uri'
open(podspec_uri) { |io| store_podspec(sandbox, io.read) } open(podspec_uri) { |io| store_podspec(sandbox, io.read) }
end end
...@@ -229,8 +232,6 @@ module Pod ...@@ -229,8 +232,6 @@ module Pod
"from `#{params[:podspec]}`" "from `#{params[:podspec]}`"
end end
#--------------------------------------#
private private
# @!group Helpers # @!group Helpers
...@@ -246,10 +247,7 @@ module Pod ...@@ -246,10 +247,7 @@ module Pod
if declared_path.match(%r{^.+://}) if declared_path.match(%r{^.+://})
declared_path declared_path
else else
path_with_ext = File.extname(declared_path) == '.podspec' ? declared_path : "#{declared_path}/#{name}.podspec" normalized_podspec_path(declared_path)
podfile_dir = File.dirname(podfile_path || '')
absolute_path = File.expand_path(path_with_ext, podfile_dir)
absolute_path
end end
end end
end end
...@@ -266,11 +264,16 @@ module Pod ...@@ -266,11 +264,16 @@ module Pod
# @see AbstractExternalSource#fetch # @see AbstractExternalSource#fetch
# #
def fetch(sandbox) def fetch(sandbox)
UI.titled_section("Fetching podspec for `#{name}` #{description}", { :verbose_prefix => "-> " }) do title = "Fetching podspec for `#{name}` #{description}"
UI.titled_section(title, { :verbose_prefix => "-> " }) do
podspec = podspec_path podspec = podspec_path
unless podspec.exist?
raise Informative, "No podspec found for `#{name}` in " \
"`#{declared_path}`"
end
store_podspec(sandbox, podspec) store_podspec(sandbox, podspec)
path_is_absolute_or_rooted_to_home = declared_path.absolute? || declared_path.to_s.start_with?('~') is_absolute = absolute?(podspec)
sandbox.store_local_path(name, podspec.dirname, path_is_absolute_or_rooted_to_home) sandbox.store_local_path(name, podspec.dirname, is_absolute)
end end
end end
...@@ -280,30 +283,27 @@ module Pod ...@@ -280,30 +283,27 @@ module Pod
"from `#{params[:path] || params[:local]}`" "from `#{params[:path] || params[:local]}`"
end end
#--------------------------------------#
private private
# @!group Helpers # @!group Helpers
# @return [Pathname] the path as declared in the podspec # @return [String] The path as declared by the user.
# #
def declared_path def declared_path
Pathname.new params[:path] || params[:local] result = params[:path] || params[:local]
result.to_s if result
end end
# @return [Pathname] the path of the podspec. # @return [Pathname] The absolute path of the podspec.
# #
def podspec_path def podspec_path
path_with_ext = File.extname(declared_path) == '.podspec' ? declared_path : "#{declared_path}/#{name}.podspec" Pathname(normalized_podspec_path(declared_path))
podfile_dir = File.dirname(podfile_path || '') end
absolute_path = File.expand_path(path_with_ext, podfile_dir)
pathname = Pathname.new(absolute_path)
unless pathname.exist? # @return [Bool]
raise Informative, "No podspec found for `#{name}` in `#{declared_path}`" #
end def absolute?(path)
pathname Pathname(path).absolute? || path.to_s.start_with?('~')
end end
end end
......
...@@ -161,6 +161,7 @@ module Pod ...@@ -161,6 +161,7 @@ module Pod
end end
it "expands the tilde" do it "expands the tilde" do
File.stubs(:exist?).returns(true)
@subject.stubs(:params).returns(:podspec => '~/Reachability') @subject.stubs(:params).returns(:podspec => '~/Reachability')
path = @subject.send(:podspec_uri) path = @subject.send(:podspec_uri)
path.should == ENV['HOME'] + '/Reachability/Reachability.podspec' path.should == ENV['HOME'] + '/Reachability/Reachability.podspec'
...@@ -179,8 +180,8 @@ module Pod ...@@ -179,8 +180,8 @@ module Pod
describe ExternalSources::PathSource do describe ExternalSources::PathSource do
before do before do
podspec_path = fixture('integration/Reachability/Reachability.podspec') params = { :path => fixture('integration/Reachability') }
dependency = Dependency.new("Reachability", :path => fixture('integration/Reachability')) dependency = Dependency.new("Reachability", params)
podfile_path = fixture('integration/Podfile') podfile_path = fixture('integration/Podfile')
@subject = ExternalSources.from_dependency(dependency, podfile_path) @subject = ExternalSources.from_dependency(dependency, podfile_path)
end end
...@@ -191,11 +192,12 @@ module Pod ...@@ -191,11 +192,12 @@ module Pod
path.should.exist? path.should.exist?
end end
it "creates a copy of the podspec [Deprecated local option]" do it "supports the deprecated local key" do
dependency = Dependency.new("Reachability", :local => fixture('integration/Reachability')) params = { :local => fixture('integration/Reachability') }
dependency = Dependency.new("Reachability", params)
podfile_path = fixture('integration/Podfile') podfile_path = fixture('integration/Podfile')
external_source = ExternalSources.from_dependency(dependency, podfile_path) @subject = ExternalSources.from_dependency(dependency, podfile_path)
external_source.fetch(config.sandbox) @subject.fetch(config.sandbox)
path = config.sandbox.root + 'Local Podspecs/Reachability.podspec' path = config.sandbox.root + 'Local Podspecs/Reachability.podspec'
path.should.exist? path.should.exist?
end end
...@@ -211,6 +213,13 @@ module Pod ...@@ -211,6 +213,13 @@ module Pod
} }
end end
it "raises if the podspec cannot be found" do
@subject.stubs(:params).returns(:path => temporary_directory)
should.raise Informative do
@subject.fetch(config.sandbox)
end.message.should.match /No podspec found for `Reachability` in `#{temporary_directory}`/
end
describe "Helpers" do describe "Helpers" do
it "handles absolute paths" do it "handles absolute paths" do
...@@ -233,17 +242,13 @@ module Pod ...@@ -233,17 +242,13 @@ module Pod
end end
it "expands the tilde" do it "expands the tilde" do
File.stubs(:exist?).returns(true)
@subject.stubs(:params).returns(:path => '~/Reachability') @subject.stubs(:params).returns(:path => '~/Reachability')
Pathname.any_instance.stubs(:exist?).returns(true) Pathname.any_instance.stubs(:exist?).returns(true)
path = @subject.send(:podspec_path) path = @subject.send(:podspec_path)
path.should == Pathname(ENV['HOME']) + 'Reachability/Reachability.podspec' path.should == Pathname(ENV['HOME']) + 'Reachability/Reachability.podspec'
end end
it "raises if the podspec cannot be found" do
@subject.stubs(:params).returns(:path => temporary_directory)
e = lambda { @subject.send(:podspec_path) }.should.raise Informative
e.message.should.match /No podspec found for `Reachability` in `#{temporary_directory}`/
end
end end
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