Commit 897dfd7b authored by Samuel E. Giddins's avatar Samuel E. Giddins

[Validator] Allow the validator to take specific sources

Allows customizable source for `pod spec lint` and `pod lib lint`, with both defaulting to `master`.
parent 986d437b
...@@ -7,14 +7,21 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides ...@@ -7,14 +7,21 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
##### Bug Fixes ##### Bug Fixes
* Improved sanitizing of configuration names to avoid generating invalid * Improved sanitizing of configuration names to avoid generating invalid
preprocessor definitions. preprocessor definitions.
[Boris Bügling](https://github.com/neonichu) [Boris Bügling](https://github.com/neonichu)
[#2542](https://github.com/CocoaPods/CocoaPods/issues/2542) [#2542](https://github.com/CocoaPods/CocoaPods/issues/2542)
* More robust generation of source names from URLs. * More robust generation of source names from URLs.
[Samuel Giddins](https://github.com/segiddins) [Samuel Giddins](https://github.com/segiddins)
[#2534](https://github.com/CocoaPods/CocoaPods/issues/2534) [#2534](https://github.com/CocoaPods/CocoaPods/issues/2534)
* Allow the `Validator` to only use specific sources.
Allows customizable source for `pod spec lint` and `pod lib lint`,
with both defaulting to `master`.
[Samuel Giddins](https://github.com/segiddins)
[#2543](https://github.com/CocoaPods/CocoaPods/issues/2543)
[cocoapods-trunk#28](https://github.com/CocoaPods/cocoapods-trunk/issues/28)
## 0.34.1 ## 0.34.1
......
...@@ -112,7 +112,9 @@ module Pod ...@@ -112,7 +112,9 @@ module Pod
['--only-errors', 'Lint validates even if warnings are present'], ['--only-errors', 'Lint validates even if warnings are present'],
['--subspec=NAME', 'Lint validates only the given subspec'], ['--subspec=NAME', 'Lint validates only the given subspec'],
['--no-subspecs', 'Lint skips validation of subspecs'], ['--no-subspecs', 'Lint skips validation of subspecs'],
['--no-clean', 'Lint leaves the build directory intact for inspection']].concat(super) ['--no-clean', 'Lint leaves the build directory intact for inspection'],
['--sources=https://github.com/artsy/Specs', 'The sources to pull dependant pods from ' \
'(defaults to https://github.com/CocoaPods/Specs.git)']].concat(super)
end end
def initialize(argv) def initialize(argv)
...@@ -121,6 +123,7 @@ module Pod ...@@ -121,6 +123,7 @@ module Pod
@clean = argv.flag?('clean', true) @clean = argv.flag?('clean', true)
@subspecs = argv.flag?('subspecs', true) @subspecs = argv.flag?('subspecs', true)
@only_subspec = argv.option('subspec') @only_subspec = argv.option('subspec')
@sources = argv.option('sources', 'https://github.com/CocoaPods/Specs.git').split(',')
@podspecs_paths = argv.arguments! @podspecs_paths = argv.arguments!
super super
end end
...@@ -133,7 +136,7 @@ module Pod ...@@ -133,7 +136,7 @@ module Pod
UI.puts UI.puts
podspecs_to_lint.each do |podspec| podspecs_to_lint.each do |podspec|
validator = Validator.new(podspec) validator = Validator.new(podspec, sources)
validator.local = true validator.local = true
validator.quick = @quick validator.quick = @quick
validator.no_clean = !@clean validator.no_clean = !@clean
...@@ -166,6 +169,10 @@ module Pod ...@@ -166,6 +169,10 @@ module Pod
#----------------------------------------# #----------------------------------------#
def sources
@sources ||= @source_urls.map { |url| SourcesManager.find_or_create_source_with_url(url) }
end
# !@group Private helpers # !@group Private helpers
# @return [Pathname] The path of the podspec found in the current # @return [Pathname] The path of the podspec found in the current
......
...@@ -82,7 +82,7 @@ module Pod ...@@ -82,7 +82,7 @@ module Pod
def validate_podspec_files def validate_podspec_files
UI.puts "\nValidating #{'spec'.pluralize(count)}".yellow UI.puts "\nValidating #{'spec'.pluralize(count)}".yellow
podspec_files.each do |podspec| podspec_files.each do |podspec|
validator = Validator.new(podspec) validator = Validator.new(podspec, SourcesManager.all)
validator.only_errors = @allow_warnings validator.only_errors = @allow_warnings
begin begin
validator.validate validator.validate
......
...@@ -67,7 +67,9 @@ module Pod ...@@ -67,7 +67,9 @@ module Pod
['--only-errors', 'Lint validates even if warnings are present'], ['--only-errors', 'Lint validates even if warnings are present'],
['--subspec=NAME', 'Lint validates only the given subspec'], ['--subspec=NAME', 'Lint validates only the given subspec'],
['--no-subspecs', 'Lint skips validation of subspecs'], ['--no-subspecs', 'Lint skips validation of subspecs'],
['--no-clean', 'Lint leaves the build directory intact for inspection']].concat(super) ['--no-clean', 'Lint leaves the build directory intact for inspection'],
['--sources=https://github.com/artsy/Specs', 'The sources to pull dependant pods from ' \
'(defaults to https://github.com/CocoaPods/Specs.git)']].concat(super)
end end
def initialize(argv) def initialize(argv)
...@@ -76,6 +78,7 @@ module Pod ...@@ -76,6 +78,7 @@ module Pod
@clean = argv.flag?('clean', true) @clean = argv.flag?('clean', true)
@subspecs = argv.flag?('subspecs', true) @subspecs = argv.flag?('subspecs', true)
@only_subspec = argv.option('subspec') @only_subspec = argv.option('subspec')
@source_urls = argv.option('sources', 'https://github.com/CocoaPods/Specs.git').split(',')
@podspecs_paths = argv.arguments! @podspecs_paths = argv.arguments!
super super
end end
...@@ -84,7 +87,7 @@ module Pod ...@@ -84,7 +87,7 @@ module Pod
UI.puts UI.puts
invalid_count = 0 invalid_count = 0
podspecs_to_lint.each do |podspec| podspecs_to_lint.each do |podspec|
validator = Validator.new(podspec) validator = Validator.new(podspec, sources)
validator.quick = @quick validator.quick = @quick
validator.no_clean = !@clean validator.no_clean = !@clean
validator.only_errors = @only_errors validator.only_errors = @only_errors
...@@ -112,6 +115,10 @@ module Pod ...@@ -112,6 +115,10 @@ module Pod
private private
def sources
@sources ||= @source_urls.map { |url| SourcesManager.find_or_create_source_with_url(url) }
end
def podspecs_to_lint def podspecs_to_lint
@podspecs_to_lint ||= begin @podspecs_to_lint ||= begin
files = [] files = []
......
...@@ -19,7 +19,8 @@ module Pod ...@@ -19,7 +19,8 @@ module Pod
# @param [Specification, Pathname, String] spec_or_path # @param [Specification, Pathname, String] spec_or_path
# the Specification or the path of the `podspec` file to lint. # the Specification or the path of the `podspec` file to lint.
# #
def initialize(spec_or_path) def initialize(spec_or_path, sources)
@sources = sources
@linter = Specification::Linter.new(spec_or_path) @linter = Specification::Linter.new(spec_or_path)
end end
...@@ -408,6 +409,11 @@ module Pod ...@@ -408,6 +409,11 @@ module Pod
# !@group Helpers # !@group Helpers
# @return [Array<Source>] an array of sources used to create the
# {Podfile} used in the linting process
#
attr_reader :sources
# @return [Podfile] a podfile that requires the specification on the # @return [Podfile] a podfile that requires the specification on the
# current platform. # current platform.
# #
...@@ -419,6 +425,7 @@ module Pod ...@@ -419,6 +425,7 @@ module Pod
podspec = file.realpath podspec = file.realpath
local = local? local = local?
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
sources.each { |s| source(s.url) }
platform(platform_name, deployment_target) platform(platform_name, deployment_target)
if local if local
pod name, :path => podspec.dirname.to_s pod name, :path => podspec.dirname.to_s
......
...@@ -47,7 +47,7 @@ module Pod ...@@ -47,7 +47,7 @@ module Pod
describe 'Quick mode' do describe 'Quick mode' do
it 'validates a correct podspec' do it 'validates a correct podspec' do
sut = Validator.new(podspec_path) sut = Validator.new(podspec_path, SourcesManager.master)
sut.quick = true sut.quick = true
sut.validate sut.validate
sut.results.should == [] sut.results.should == []
...@@ -57,7 +57,7 @@ module Pod ...@@ -57,7 +57,7 @@ module Pod
it 'lints the podspec during validation' do it 'lints the podspec during validation' do
podspec = stub_podspec(/.*name.*/, '"name": "TEST",') podspec = stub_podspec(/.*name.*/, '"name": "TEST",')
file = write_podspec(podspec) file = write_podspec(podspec)
sut = Validator.new(file) sut = Validator.new(file, SourcesManager.master)
sut.quick = true sut.quick = true
sut.validate sut.validate
sut.results.map(&:to_s).first.should.match /should match the name/ sut.results.map(&:to_s).first.should.match /should match the name/
...@@ -66,7 +66,7 @@ module Pod ...@@ -66,7 +66,7 @@ module Pod
it 'respects quick mode' do it 'respects quick mode' do
file = write_podspec(stub_podspec) file = write_podspec(stub_podspec)
sut = Validator.new(file) sut = Validator.new(file, SourcesManager.master)
sut.quick = true sut.quick = true
sut.expects(:perform_extensive_analysis).never sut.expects(:perform_extensive_analysis).never
sut.validate sut.validate
...@@ -75,7 +75,7 @@ module Pod ...@@ -75,7 +75,7 @@ module Pod
it 'respects the only errors option' do it 'respects the only errors option' do
podspec = stub_podspec(/.*summary.*/, '"summary": "A short description of",') podspec = stub_podspec(/.*summary.*/, '"summary": "A short description of",')
file = write_podspec(podspec) file = write_podspec(podspec)
sut = Validator.new(file) sut = Validator.new(file, SourcesManager.master)
sut.quick = true sut.quick = true
sut.only_errors = true sut.only_errors = true
sut.validate sut.validate
...@@ -85,7 +85,7 @@ module Pod ...@@ -85,7 +85,7 @@ module Pod
it 'handles symlinks' do it 'handles symlinks' do
file = write_podspec(stub_podspec) file = write_podspec(stub_podspec)
validator = Validator.new(file) validator = Validator.new(file, SourcesManager.master)
validator.quick = true validator.quick = true
validator.stubs(:validate_url) validator.stubs(:validate_url)
validator.validate validator.validate
...@@ -99,7 +99,7 @@ module Pod ...@@ -99,7 +99,7 @@ module Pod
describe 'URL validation' do describe 'URL validation' do
before do before do
@sut = Validator.new(podspec_path) @sut = Validator.new(podspec_path, SourcesManager.master)
@sut.stubs(:install_pod) @sut.stubs(:install_pod)
@sut.stubs(:build_pod) @sut.stubs(:build_pod)
@sut.stubs(:check_file_patterns) @sut.stubs(:check_file_patterns)
...@@ -257,7 +257,7 @@ module Pod ...@@ -257,7 +257,7 @@ module Pod
it 'respects the no clean option' do it 'respects the no clean option' do
file = write_podspec(stub_podspec) file = write_podspec(stub_podspec)
sut = Validator.new(file) sut = Validator.new(file, SourcesManager.master)
sut.stubs(:validate_url) sut.stubs(:validate_url)
sut.no_clean = true sut.no_clean = true
sut.validate sut.validate
...@@ -266,7 +266,7 @@ module Pod ...@@ -266,7 +266,7 @@ module Pod
it 'builds the pod per platform' do it 'builds the pod per platform' do
file = write_podspec(stub_podspec) file = write_podspec(stub_podspec)
sut = Validator.new(file) sut = Validator.new(file, SourcesManager.master)
sut.stubs(:validate_url) sut.stubs(:validate_url)
sut.expects(:install_pod).twice sut.expects(:install_pod).twice
sut.expects(:build_pod).twice sut.expects(:build_pod).twice
...@@ -275,7 +275,7 @@ module Pod ...@@ -275,7 +275,7 @@ module Pod
end end
it 'uses the deployment target of the specification' do it 'uses the deployment target of the specification' do
sut = Validator.new(podspec_path) sut = Validator.new(podspec_path, SourcesManager.master)
sut.stubs(:validate_url) sut.stubs(:validate_url)
sut.stubs(:validate_screenshots) sut.stubs(:validate_screenshots)
podfile = sut.send(:podfile_from_spec, :ios, '5.0') podfile = sut.send(:podfile_from_spec, :ios, '5.0')
...@@ -284,7 +284,7 @@ module Pod ...@@ -284,7 +284,7 @@ module Pod
end end
it 'respects the local option' do it 'respects the local option' do
sut = Validator.new(podspec_path) sut = Validator.new(podspec_path, SourcesManager.master)
sut.stubs(:validate_url) sut.stubs(:validate_url)
podfile = sut.send(:podfile_from_spec, :ios, '5.0') podfile = sut.send(:podfile_from_spec, :ios, '5.0')
deployment_target = podfile.target_definitions['Pods'].platform.deployment_target deployment_target = podfile.target_definitions['Pods'].platform.deployment_target
...@@ -292,7 +292,7 @@ module Pod ...@@ -292,7 +292,7 @@ module Pod
end end
it 'uses xcodebuild to generate notes and warnings' do it 'uses xcodebuild to generate notes and warnings' do
sut = Validator.new(podspec_path) sut = Validator.new(podspec_path, SourcesManager.master)
sut.stubs(:check_file_patterns) sut.stubs(:check_file_patterns)
sut.stubs(:xcodebuild).returns("file.m:1:1: warning: direct access to objective-c's isa is deprecated") sut.stubs(:xcodebuild).returns("file.m:1:1: warning: direct access to objective-c's isa is deprecated")
sut.stubs(:validate_url) sut.stubs(:validate_url)
...@@ -304,7 +304,7 @@ module Pod ...@@ -304,7 +304,7 @@ module Pod
it 'checks for file patterns' do it 'checks for file patterns' do
file = write_podspec(stub_podspec(/.*source_files.*/, '"source_files": "wrong_paht.*",')) file = write_podspec(stub_podspec(/.*source_files.*/, '"source_files": "wrong_paht.*",'))
sut = Validator.new(file) sut = Validator.new(file, SourcesManager.master)
sut.stubs(:build_pod) sut.stubs(:build_pod)
sut.stubs(:validate_url) sut.stubs(:validate_url)
sut.validate sut.validate
...@@ -319,7 +319,7 @@ module Pod ...@@ -319,7 +319,7 @@ module Pod
file = write_podspec(podspec, 'ZKit.podspec.json') file = write_podspec(podspec, 'ZKit.podspec.json')
spec = Specification.from_file(file) spec = Specification.from_file(file)
sut = Validator.new(spec) sut = Validator.new(spec, SourcesManager.master)
sut.stubs(:validate_url) sut.stubs(:validate_url)
sut.stubs(:build_pod) sut.stubs(:build_pod)
sut.validate sut.validate
......
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