From 4189457e12113b09eafc1ebabcf1559fc23ef7b9 Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Tue, 23 Sep 2014 15:31:56 -0700 Subject: [PATCH 1/7] [Source] Add the notion of a source URL --- lib/cocoapods-core/source.rb | 6 ++++++ lib/cocoapods-core/source/abstract_data_provider.rb | 6 ++++++ lib/cocoapods-core/source/file_system_data_provider.rb | 9 +++++++++ lib/cocoapods-core/source/github_data_provider.rb | 6 ++++++ 4 files changed, 27 insertions(+) diff --git a/lib/cocoapods-core/source.rb b/lib/cocoapods-core/source.rb index 3472f004d..45324357c 100644 --- a/lib/cocoapods-core/source.rb +++ b/lib/cocoapods-core/source.rb @@ -38,6 +38,12 @@ def name data_provider.name end + # @return [String] The URL of the source. + # + def url + data_provider.url + end + # @return [String] The type of the source. # def type diff --git a/lib/cocoapods-core/source/abstract_data_provider.rb b/lib/cocoapods-core/source/abstract_data_provider.rb index 95c890214..68731cbdb 100644 --- a/lib/cocoapods-core/source/abstract_data_provider.rb +++ b/lib/cocoapods-core/source/abstract_data_provider.rb @@ -14,6 +14,12 @@ def name raise StandardError, 'Abstract method.' end + # @return [String] The URL of the source. + # + def url + raise StandardError, 'Abstract method.' + end + # @return [String] The user friendly type of the source. # def type diff --git a/lib/cocoapods-core/source/file_system_data_provider.rb b/lib/cocoapods-core/source/file_system_data_provider.rb index 7fe39ded4..2ba7a7a7e 100644 --- a/lib/cocoapods-core/source/file_system_data_provider.rb +++ b/lib/cocoapods-core/source/file_system_data_provider.rb @@ -25,6 +25,15 @@ def name repo.basename.to_s end + # @return [String] The URL of the source. + # + def url + Dir.chdir(repo) do + remote = `git ls-remote --get-url` + remote if $?.success? + end + end + # @return [String] The user friendly type of the source. # def type diff --git a/lib/cocoapods-core/source/github_data_provider.rb b/lib/cocoapods-core/source/github_data_provider.rb index c414aa162..0c4974075 100644 --- a/lib/cocoapods-core/source/github_data_provider.rb +++ b/lib/cocoapods-core/source/github_data_provider.rb @@ -34,6 +34,12 @@ def name GitHub.normalized_repo_id(repo_id) end + # @return [String] The URL of the source. + # + def url + "https://github.com/#{name}.git" + end + # @return [String] The user friendly type of the source. # def type From 0103e51f77a0e0f17529015b0314586c699fe11a Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Tue, 23 Sep 2014 15:39:36 -0700 Subject: [PATCH 2/7] [RuboCop] Prefer $CHILD_STATUS from the English library over $?. --- lib/cocoapods-core/source/file_system_data_provider.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cocoapods-core/source/file_system_data_provider.rb b/lib/cocoapods-core/source/file_system_data_provider.rb index 2ba7a7a7e..794dc7bf8 100644 --- a/lib/cocoapods-core/source/file_system_data_provider.rb +++ b/lib/cocoapods-core/source/file_system_data_provider.rb @@ -30,7 +30,7 @@ def name def url Dir.chdir(repo) do remote = `git ls-remote --get-url` - remote if $?.success? + remote if $CHILD_STATUS.success? end end From 0afd4b7716ce40df0737ac57a0d80ddb878d4f11 Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Wed, 24 Sep 2014 11:20:31 -0700 Subject: [PATCH 3/7] [FileSystemDataProvider] chomp the url --- lib/cocoapods-core/source/file_system_data_provider.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cocoapods-core/source/file_system_data_provider.rb b/lib/cocoapods-core/source/file_system_data_provider.rb index 794dc7bf8..1d40a0fe6 100644 --- a/lib/cocoapods-core/source/file_system_data_provider.rb +++ b/lib/cocoapods-core/source/file_system_data_provider.rb @@ -29,7 +29,7 @@ def name # def url Dir.chdir(repo) do - remote = `git ls-remote --get-url` + remote = `git ls-remote --get-url`.chomp remote if $CHILD_STATUS.success? end end From 64d5b311a7ee1dd6e0ad8716a1bd5033436d04d8 Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Wed, 24 Sep 2014 11:50:34 -0700 Subject: [PATCH 4/7] [RuboCop] Update .rubocop_cocoapods.yml --- .rubocop_cocoapods.yml | 9 ++++++--- lib/cocoapods-core/source/file_system_data_provider.rb | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.rubocop_cocoapods.yml b/.rubocop_cocoapods.yml index f8e309704..546746874 100644 --- a/.rubocop_cocoapods.yml +++ b/.rubocop_cocoapods.yml @@ -1,10 +1,10 @@ AllCops: Include: - - Rakefile - - Gemfile + - ./Rakefile + - ./Gemfile - ./*.gemspec Exclude: - - spec/fixtures/**/* + - ./spec/fixtures/**/* # At the moment not ready to be used # https://github.com/bbatsov/rubocop/issues/947 @@ -64,6 +64,9 @@ DotPosition: EachWithObject: Enabled: false +Style/SpecialGlobalVars: + Enabled: false + #- CocoaPods specs -----------------------------------------------------------# # Allow for `should.match /regexp/`. diff --git a/lib/cocoapods-core/source/file_system_data_provider.rb b/lib/cocoapods-core/source/file_system_data_provider.rb index 1d40a0fe6..a322a0c76 100644 --- a/lib/cocoapods-core/source/file_system_data_provider.rb +++ b/lib/cocoapods-core/source/file_system_data_provider.rb @@ -30,7 +30,7 @@ def name def url Dir.chdir(repo) do remote = `git ls-remote --get-url`.chomp - remote if $CHILD_STATUS.success? + remote if $?.success? end end From c128c7eab73550bc8d55e23bd58492a76dc89edf Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Wed, 24 Sep 2014 14:06:50 -0700 Subject: [PATCH 5/7] [Documentation] Update documentation for Podfile#source to reflect the fact that the parameter is now a URL string --- lib/cocoapods-core/podfile/dsl.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/cocoapods-core/podfile/dsl.rb b/lib/cocoapods-core/podfile/dsl.rb index 63b49010a..bc17159b7 100644 --- a/lib/cocoapods-core/podfile/dsl.rb +++ b/lib/cocoapods-core/podfile/dsl.rb @@ -480,21 +480,20 @@ def set_arc_compatibility_flag! # # ----- # - # By default, the github Cocoapods/specs repository is used. Use this - # method to specify (an) other(s) source(s). The order of the sources is + # By default, the GitHub Cocoapods/Specs repository is used. Use this + # method to specify sources. The order of the sources is # relevant. CocoaPods will use the highest version of a Pod of the first # source which includes the Pod (regardless whether other sources have a # higher version). # # @param [String] source - # The name of a specs repo. Previously specified by user - # via pod repo add command + # The URL of a specs repo. # # @example Specifying to use first `my_private_repo` and then the # CocoaPods Master Repo # - # source 'my_private_repo' - # source 'master' + # source 'https://banana.com/corp/my_private_repo.git' + # source 'https://github.com/CocoaPods/Specs.git' # # @return [void] # From 6608bba9b113122adae45940c94255ca05208ceb Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Thu, 25 Sep 2014 08:43:00 -0700 Subject: [PATCH 6/7] [GitHubDataProvider] Remove the GitHub Data Provider, as it is unused See https://github.com/CocoaPods/Core/pull/174 for the discussion. --- CHANGELOG.md | 7 +- lib/cocoapods-core/source.rb | 1 - .../source/github_data_provider.rb | 150 ------------------ spec/source/github_data_provider_spec.rb | 145 ----------------- 4 files changed, 5 insertions(+), 298 deletions(-) delete mode 100644 lib/cocoapods-core/source/github_data_provider.rb delete mode 100644 spec/source/github_data_provider_spec.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index c8b294e5e..8110394d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ [Fabio Pelosin](https://github.com/fabiopelosin) [CocoaPods#2335](https://github.com/CocoaPods/CocoaPods/issues/2335) +* Removes the unused `Source::GitHubDataProvider` class. + [Samuel Giddins](https://github.com/segiddins) + [#174](https://github.com/CocoaPods/Core/pull/174) + ## 0.34.0.rc2 @@ -111,7 +115,7 @@ This version only introduces changes in the CocoaPods gem. [#69](https://github.com/CocoaPods/Core/issues/69) [#100](https://github.com/CocoaPods/Core/pull/100) -* Added a check to the linter to ensure that the `social_media_url` has +* Added a check to the linter to ensure that the `social_media_url` has been changed from the example value. [Richard Lee](https://github.com/dlackty) [#67](https://github.com/CocoaPods/Core/issues/67) @@ -203,4 +207,3 @@ This version only introduces changes in the CocoaPods gem. ## 0.30.0 Introduction of the Changelog. - diff --git a/lib/cocoapods-core/source.rb b/lib/cocoapods-core/source.rb index 45324357c..9962b3897 100644 --- a/lib/cocoapods-core/source.rb +++ b/lib/cocoapods-core/source.rb @@ -3,7 +3,6 @@ require 'cocoapods-core/source/health_reporter' require 'cocoapods-core/source/abstract_data_provider' require 'cocoapods-core/source/file_system_data_provider' -require 'cocoapods-core/source/github_data_provider' module Pod # The Source class is responsible to manage a collection of podspecs. diff --git a/lib/cocoapods-core/source/github_data_provider.rb b/lib/cocoapods-core/source/github_data_provider.rb deleted file mode 100644 index 0c4974075..000000000 --- a/lib/cocoapods-core/source/github_data_provider.rb +++ /dev/null @@ -1,150 +0,0 @@ -module Pod - class Source - # Data provider for a `Pod::Source` backed by a repository hosted on GitHub - # and accessed via the HTTP API. Only pure JSON repos using the `Specs` - # subdir to store the specifications are supported. - # - class GitHubDataProvider < AbstractDataProvider - # @return [String] The identifier of the repository (user name and repo - # name) or the full URL of the repo. - # - attr_reader :repo_id - - # @return [String] The branch of the repo if the default one shouldn't be - # used. - # - attr_reader :branch - - # @param [String] repo_id @see repo_id - # @param [String] branch @see branch - # - def initialize(repo_id, branch = nil) - @repo_id = repo_id - @branch = branch - end - - public - - # @group Data Source - #-----------------------------------------------------------------------# - - # @return [String] The name of the Source. User name and repo. - # - def name - GitHub.normalized_repo_id(repo_id) - end - - # @return [String] The URL of the source. - # - def url - "https://github.com/#{name}.git" - end - - # @return [String] The user friendly type of the source. - # - def type - 'GitHub API' - end - - # @return [Array] The list of the name of all the Pods known to - # the Source. - # - def pods - root_contents = get_github_contents('Specs') - pods = dir_names(root_contents) - pods.sort if pods - end - - # @return [Array] All the available versions of a given Pod, - # sorted from highest to lowest. - # - # @param [String] name - # The name of the Pod. - # - def versions(name) - raise ArgumentError, 'No name' unless name - contents = get_github_contents("Specs/#{name}") - pre_vers = dir_names(contents) - return nil if pre_vers.nil? - pre_vers.each do |v| - Version.new(v) - end.sort.reverse.map(&:to_s) - end - - # @return [Specification] The specification for a given version of a Pod. - # - # @param [String] name - # The name of the Pod. - # - # @param [String] version - # The version of the Pod. - # - def specification(name, version) - raise ArgumentError, 'No name' unless name - raise ArgumentError, 'No version' unless version - spec_content = specification_contents(name, version) - if spec_content - Pod::Specification.from_json(spec_content) - end - end - - # @return [Specification] The contents of the specification for a given - # version of a Pod. - # - # @param [String] name - # the name of the Pod. - # - # @param [String] version - # the version of the Pod. - # - def specification_contents(name, version) - raise ArgumentError, 'No name' unless name - raise ArgumentError, 'No version' unless version - path = "Specs/#{name}/#{version}/#{name}.podspec.json" - file_contents = get_github_contents(path) - if file_contents - if file_contents['encoding'] == 'base64' - require 'base64' - Base64.decode64(file_contents['content']) - end - end - end - - private - - # @group Private Helpers - #-----------------------------------------------------------------------# - - # Performs a get request with the given URL. - # - # @param [String] url - # The URL of the resource. - # - # @return [Array, Hash] The information of the resource as Ruby objects. - # - def get_github_contents(path = nil) - Pod::GitHub.contents(repo_id, path, branch) - end - - # @param [Array] [Array] The contents of a directory. - # - # @return [Array] Returns the list of the directories given the - # contents returned for the API of a directory. - # - # @return [Nil] If the directory was not found or the contents is not an - # array. - # - def dir_names(contents) - if contents.is_a?(Array) - contents.map do |entry| - if entry['type'] == 'dir' - entry['name'] - end - end.compact - end - end - - #-----------------------------------------------------------------------# - end - end -end diff --git a/spec/source/github_data_provider_spec.rb b/spec/source/github_data_provider_spec.rb deleted file mode 100644 index 2d6de1ce5..000000000 --- a/spec/source/github_data_provider_spec.rb +++ /dev/null @@ -1,145 +0,0 @@ -require File.expand_path('../../spec_helper', __FILE__) - -module Pod - describe Source::GitHubDataProvider do - - before do - @subject = Source::GitHubDataProvider.new('CocoaPods/Specs', 'json_podspecs') - end - - #-------------------------------------------------------------------------# - - describe 'In general' do - it 'returns the name of the source' do - @subject.name.should == 'CocoaPods/Specs' - end - - it 'returns the type of the source' do - @subject.type.should == 'GitHub API' - end - end - - #-------------------------------------------------------------------------# - - describe '#pods' do - it 'returns the list of all the Pods' do - VCR.use_cassette('GitHubDataProvider', :record => :new_episodes) do - @subject.pods.should.include?('ARAnalytics') - end - end - - it 'only considers directories to compute the name of Pods' do - VCR.use_cassette('GitHubDataProvider', :record => :new_episodes) do - @subject.pods.should.not.include?('Readme.md') - end - end - - it 'returns nil if no Pods could be found' do - VCR.use_cassette('GitHubDataProvider', :record => :new_episodes) do - @subject = Source::GitHubDataProvider.new('CocoaPods/Missing_Specs') - @subject.pods.should.be.nil - end - end - end - - #-------------------------------------------------------------------------# - - describe '#versions' do - it 'returns the available versions of a Pod' do - VCR.use_cassette('GitHubDataProvider', :record => :new_episodes) do - @subject.versions('A3GridTableView').should == ['0.0.1'] - end - end - - it 'returns nil the Pod is unknown' do - VCR.use_cassette('GitHubDataProvider', :record => :new_episodes) do - @subject.versions('Unknown_Pod').should.be.nil - end - end - - it 'raises if the name of the Pod is not provided' do - should.raise ArgumentError do - @subject.versions(nil) - end.message.should.match /No name/ - end - end - - #-------------------------------------------------------------------------# - - describe '#specification' do - it 'returns the specification given the name and the version' do - VCR.use_cassette('GitHubDataProvider', :record => :new_episodes) do - spec = @subject.specification('ARAnalytics', '1.3.1') - spec.name.should == 'ARAnalytics' - spec.version.to_s.should == '1.3.1' - end - end - - it 'returns nil if the Pod is unknown' do - VCR.use_cassette('GitHubDataProvider', :record => :new_episodes) do - spec = @subject.specification('Unknown_Pod', '1.3.1') - spec.should.be.nil - end - end - - it "returns nil if the version of the Pod doesn't exists" do - VCR.use_cassette('GitHubDataProvider', :record => :new_episodes) do - spec = @subject.specification('ARAnalytics', '0.99.0') - spec.should.be.nil - end - end - - it 'raises if the name of the Pod is not provided' do - should.raise ArgumentError do - @subject.specification(nil, '0.99.0') - end.message.should.match /No name/ - end - - it 'raises if the name of the Pod is not provided' do - should.raise ArgumentError do - @subject.specification('ARAnalytics', nil) - end.message.should.match /No version/ - end - end - - #-------------------------------------------------------------------------# - - describe '#specification_contents' do - it 'returns the specification given the name and the version' do - VCR.use_cassette('GitHubDataProvider', :record => :new_episodes) do - spec = @subject.specification_contents('ARAnalytics', '1.3.1') - spec.should.include("{\n \"name\": \"ARAnalytics\",\n \"version\": \"1.3.1\"") - end - end - - it 'returns nil if the Pod is unknown' do - VCR.use_cassette('GitHubDataProvider', :record => :new_episodes) do - spec = @subject.specification_contents('Unknown_Pod', '1.3.1') - spec.should.be.nil - end - end - - it "returns nil if the version of the Pod doesn't exists" do - VCR.use_cassette('GitHubDataProvider', :record => :new_episodes) do - spec = @subject.specification_contents('ARAnalytics', '0.99.0') - spec.should.be.nil - end - end - - it 'raises if the name of the Pod is not provided' do - should.raise ArgumentError do - @subject.specification_contents(nil, '0.99.0') - end.message.should.match /No name/ - end - - it 'raises if the name of the Pod is not provided' do - should.raise ArgumentError do - @subject.specification_contents('ARAnalytics', nil) - end.message.should.match /No version/ - end - end - - #-------------------------------------------------------------------------# - - end -end From 66bab6009c752a8617b713719108ccf98178caf8 Mon Sep 17 00:00:00 2001 From: "Samuel E. Giddins" Date: Thu, 25 Sep 2014 08:44:49 -0700 Subject: [PATCH 7/7] [Changelog] Add entry for Source#url --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8110394d4..149aebb0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ [Samuel Giddins](https://github.com/segiddins) [#174](https://github.com/CocoaPods/Core/pull/174) +* Adds a `url` attribute to `Source`. + Note that this attribute is currently only gathered from `git`. + [Samuel Giddins](https://github.com/segiddins) + ## 0.34.0.rc2