Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
8eba1796
Commit
8eba1796
authored
Sep 24, 2014
by
Samuel E. Giddins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make the specification of URL in Podfile much more robust
parent
9e47e11d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
167 additions
and
31 deletions
+167
-31
Gemfile.lock
Gemfile.lock
+1
-1
analyzer.rb
lib/cocoapods/installer/analyzer.rb
+8
-5
sources_manager.rb
lib/cocoapods/sources_manager.rb
+59
-25
analyzer_spec.rb
spec/unit/installer/analyzer_spec.rb
+43
-0
sources_manager_spec.rb
spec/unit/sources_manager_spec.rb
+56
-0
No files found.
Gemfile.lock
View file @
8eba1796
...
@@ -7,7 +7,7 @@ GIT
...
@@ -7,7 +7,7 @@ GIT
GIT
GIT
remote: https://github.com/CocoaPods/Core.git
remote: https://github.com/CocoaPods/Core.git
revision:
4189457e12113b09eafc1ebabcf1559fc23ef7b9
revision:
64d5b311a7ee1dd6e0ad8716a1bd5033436d04d8
branch: source-url
branch: source-url
specs:
specs:
cocoapods-core (0.34.0.rc2)
cocoapods-core (0.34.0.rc2)
...
...
lib/cocoapods/installer/analyzer.rb
View file @
8eba1796
...
@@ -371,13 +371,16 @@ module Pod
...
@@ -371,13 +371,16 @@ module Pod
@sources
||=
begin
@sources
||=
begin
sources
=
podfile
.
sources
sources
=
podfile
.
sources
if
sources
.
empty?
if
sources
.
empty?
SourcesManager
.
master
SourcesManager
.
all
.
tap
do
|
all
|
UI
.
warn
all
.
reduce
(
"The use of implicit sources has been "
\
"deprecated. To replicate the previous behavior, add the "
\
"following to your Podfile:"
)
\
{
|
w
,
s
|
w
<<
"
\n
source '
#{
s
.
url
}
'"
}
end
else
else
urls
=
sources
.
select
{
|
s
|
s
=~
/\A
#{
URI
.
regexp
}
\z/
}
sources
.
map
do
|
url
|
url_sources
=
urls
.
map
do
|
url
|
SourcesManager
.
find_or_create_source_with_url
(
url
)
SourcesManager
.
find_or_create_source_with_url!
(
url
)
end
end
SourcesManager
.
sources
(
sources
-
urls
)
+
url_sources
end
end
end
end
end
end
...
...
lib/cocoapods/sources_manager.rb
View file @
8eba1796
...
@@ -26,41 +26,25 @@ module Pod
...
@@ -26,41 +26,25 @@ module Pod
# Returns the source whose {Source#url} is equal to `url`, adding the repo
# Returns the source whose {Source#url} is equal to `url`, adding the repo
# in a manner similarly to `pod repo add` if it is not found.
# in a manner similarly to `pod repo add` if it is not found.
#
#
# @raise If no source with the given `url` could be created,
# @raise
If no source with the given `url` could be created,
#
#
# @return [Source] The source whose {Source#url} is equal to `url`,
# @return [Source] The source whose {Source#url} is equal to `url`,
#
#
# @param [String] url
# @param
[String] url
# The URL of the source.
#
The URL of the source.
#
#
def
find_or_create_source_with_url
(
url
)
def
find_or_create_source_with_url
(
url
)
unless
source
=
source_with_url
(
url
)
unless
source
=
source_with_url
(
url
)
name
=
URI
(
url
).
path
.
split
(
'/'
)[
-
2
]
name
=
name_for_url
(
url
)
UI
.
section
(
"Cloning spec repo `
#{
name
}
` from `
#{
url
}
`"
)
do
Command
::
Repo
::
Add
.
new
(
CLAide
::
ARGV
.
new
([
name
,
url
])).
run
config
.
repos_dir
.
mkpath
source
=
source_with_url
(
url
)
Dir
.
chdir
(
config
.
repos_dir
)
do
command
=
"clone '
#{
url
}
'
#{
name
}
"
output
=
git
(
command
)
end
check_version_information
(
config
.
repos_dir
+
name
)
source
=
sources
([
name
]).
find
end
end
end
raise
Informative
,
"Unable to add a source with url `
#{
url
}
`:
\n\n
"
+
raise
Informative
,
"Unable to add a source with url `
#{
url
}
` named "
\
output
unless
source
"`
#{
name
}
`.
\n
You can add it manually via `pod repo add NAME "
\
"
#{
url
}
`.
\n\n
#{
output
}
"
unless
source
source
source
end
end
# @return [Source] The source whose {Source#url} is equal to `url`.
#
# @param [String] url
# The URL of the source.
#
def
source_with_url
(
url
)
aggregate
.
sources
.
find
{
|
s
|
s
.
url
==
url
}
end
# @return [Array<Source>] The list of all the sources known to this
# @return [Array<Source>] The list of all the sources known to this
# installation of CocoaPods.
# installation of CocoaPods.
#
#
...
@@ -381,6 +365,56 @@ module Pod
...
@@ -381,6 +365,56 @@ module Pod
raise
Informative
,
"Unable to find the `
#{
name
}
` repo."
raise
Informative
,
"Unable to find the `
#{
name
}
` repo."
end
end
end
end
# @return [Source] The source whose {Source#url} is equal to `url`.
#
# @param [String] url
# The URL of the source.
#
def
source_with_url
(
url
)
aggregate
.
sources
.
find
{
|
s
|
s
.
url
==
url
}
end
# Returns a suitable repository name for `url`.
#
# @example A GitHub.com URL
#
# name_for_url('https://github.com/Artsy/Specs.git')
# # "artsy"
# name_for_url('https://github.com/Artsy/Specs.git')
# # "artsy-1"
#
# @example A non-Github.com URL
#
# name_for_url('https://sourceforge.org/Artsy/Specs.git')
# # sourceforge-artsy-specs
#
# @param [#to_s] url
# The URL of the source.
#
# @return [String] A suitable repository name for `url`.
#
def
name_for_url
(
url
)
case
url
.
downcase
when
%r{github.com(:|/)cocoapods/specs}
base
=
'master'
when
%r{github.com(:|/)(.+)/(.+)}
base
=
Regexp
.
last_match
[
2
]
else
raise
Informative
,
"`
#{
url
}
` is not a valid URL."
unless
url
=~
URI
.
regexp
url
=
URI
(
url
.
downcase
)
base
=
url
.
host
.
split
(
'.'
)[
-
2
]
+
url
.
path
.
gsub
(
/.git$/
,
''
).
split
(
'/'
).
join
(
'-'
)
end
name
=
base
infinity
=
1.0
/
0
(
1
..
infinity
).
each
do
|
i
|
break
unless
source_dir
(
name
).
exist?
name
=
"
#{
base
}
-
#{
i
}
"
end
name
end
end
end
end
end
end
end
spec/unit/installer/analyzer_spec.rb
View file @
8eba1796
...
@@ -465,6 +465,49 @@ module Pod
...
@@ -465,6 +465,49 @@ module Pod
e
.
message
.
should
.
match
/Targets with different platforms/
e
.
message
.
should
.
match
/Targets with different platforms/
end
end
end
end
#--------------------------------------#
describe
'sources'
do
describe
'when there are no explicit sources'
do
it
'defaults to all sources'
do
@analyzer
.
send
(
:sources
).
map
(
&
:url
).
should
==
SourcesManager
.
all
.
map
(
&
:url
)
end
it
'prints a warning about the deprecation of implicit sources'
do
@analyzer
.
send
(
:sources
)
UI
.
warnings
.
should
.
match
/implicit(.+)sources(.+)deprecated/
end
it
'prints a warning about how to add explicit sources'
do
@analyzer
.
send
(
:sources
)
UI
.
warnings
.
should
.
match
%r{^source 'https://github.com/CocoaPods/Specs.git'$}
end
end
describe
'when there are explicit sources'
do
it
'raises if no specs repo with that URL could be added'
do
podfile
=
Podfile
.
new
do
source
'not-a-git-repo'
end
@analyzer
.
instance_variable_set
(
:@podfile
,
podfile
)
should
.
raise
Informative
do
@analyzer
.
send
(
:sources
)
end
.
message
.
should
.
match
/not a valid URL/
end
it
'fetches a specs repo that is specified by the podfile'
do
podfile
=
Podfile
.
new
do
source
'https://github.com/artsy/Specs.git'
end
@analyzer
.
instance_variable_set
(
:@podfile
,
podfile
)
SourcesManager
.
expects
(
:find_or_create_source_with_url
).
once
@analyzer
.
send
(
:sources
)
end
end
end
end
end
end
end
end
end
spec/unit/sources_manager_spec.rb
View file @
8eba1796
...
@@ -101,6 +101,62 @@ module Pod
...
@@ -101,6 +101,62 @@ module Pod
path
=
SourcesManager
.
search_index_path
.
to_s
path
=
SourcesManager
.
search_index_path
.
to_s
path
.
should
.
match
%r{Library/Caches/CocoaPods/search_index.yaml}
path
.
should
.
match
%r{Library/Caches/CocoaPods/search_index.yaml}
end
end
describe
'managing sources by URL'
do
describe
'generating a repo name from a URL'
do
it
'uses `master` for the master CocoaPods repository'
do
url
=
'https://github.com/CocoaPods/Specs.git'
Pathname
.
any_instance
.
stubs
(
:exist?
).
returns
(
false
).
then
.
returns
(
true
)
SourcesManager
.
send
(
:name_for_url
,
url
).
should
==
'master'
url
=
'git@github.com:CocoaPods/Specs.git'
Pathname
.
any_instance
.
stubs
(
:exist?
).
returns
(
false
).
then
.
returns
(
true
)
SourcesManager
.
send
(
:name_for_url
,
url
).
should
==
'master'
end
it
'uses the organization name for github.com URLs'
do
url
=
'https://github.com/segiddins/banana.git'
SourcesManager
.
send
(
:name_for_url
,
url
).
should
==
'segiddins'
end
it
'uses a combination of host and path for other URLs'
do
url
=
'https://sourceforge.org/Artsy/Specs.git'
SourcesManager
.
send
(
:name_for_url
,
url
).
should
==
'sourceforge-artsy-specs'
end
it
'appends a number to the name if the base name dir exists'
do
url
=
'https://github.com/segiddins/banana.git'
Pathname
.
any_instance
.
stubs
(
:exist?
).
returns
(
true
).
then
.
returns
(
false
)
SourcesManager
.
send
(
:name_for_url
,
url
).
should
==
'segiddins-1'
url
=
'https://sourceforge.org/Artsy/Specs.git'
Pathname
.
any_instance
.
stubs
(
:exist?
).
returns
(
true
).
then
.
returns
(
false
)
SourcesManager
.
send
(
:name_for_url
,
url
).
should
==
'sourceforge-artsy-specs-1'
end
end
describe
'finding or creating a source by URL'
do
it
'returns an existing matching source'
do
Source
.
any_instance
.
stubs
(
:url
).
returns
(
'url'
)
SourcesManager
.
expects
(
:name_for_url
).
never
SourcesManager
.
find_or_create_source_with_url
(
'url'
).
url
.
should
==
'url'
end
it
'runs `pod repo add` when there is no matching source'
do
Command
::
Repo
::
Add
.
any_instance
.
stubs
(
:run
).
once
SourcesManager
.
stubs
(
:source_with_url
).
returns
(
nil
).
then
.
returns
(
true
)
SourcesManager
.
find_or_create_source_with_url
(
'https://banana.com/local/specs.git'
).
should
==
true
end
end
end
end
end
#-------------------------------------------------------------------------#
#-------------------------------------------------------------------------#
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment