Commit 15c2cb7e authored by Eric Amorde's avatar Eric Amorde

[Installer] Add support for source provider plugin hook

parent 9e796e48
...@@ -136,6 +136,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -136,6 +136,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
is now a default plugin. is now a default plugin.
[Samuel Giddins](https://github.com/segiddins) [Samuel Giddins](https://github.com/segiddins)
* Added a `:source_provider` hook to allow plugins to provide their own sources
[Eric Amorde](https://github.com/amorde)
[#3792](https://github.com/CocoaPods/CocoaPods/pull/3792)
##### Bug Fixes ##### Bug Fixes
* Ensure that the `prepare_command` is run even when skipping the download * Ensure that the `prepare_command` is run even when skipping the download
......
...@@ -29,18 +29,19 @@ module Pod ...@@ -29,18 +29,19 @@ module Pod
# source control. # source control.
# #
class Installer class Installer
autoload :AggregateTargetInstaller, 'cocoapods/installer/target_installer/aggregate_target_installer' autoload :AggregateTargetInstaller, 'cocoapods/installer/target_installer/aggregate_target_installer'
autoload :Analyzer, 'cocoapods/installer/analyzer' autoload :Analyzer, 'cocoapods/installer/analyzer'
autoload :FileReferencesInstaller, 'cocoapods/installer/file_references_installer' autoload :FileReferencesInstaller, 'cocoapods/installer/file_references_installer'
autoload :PostInstallHooksContext, 'cocoapods/installer/post_install_hooks_context' autoload :PostInstallHooksContext, 'cocoapods/installer/post_install_hooks_context'
autoload :PreInstallHooksContext, 'cocoapods/installer/pre_install_hooks_context' autoload :PreInstallHooksContext, 'cocoapods/installer/pre_install_hooks_context'
autoload :Migrator, 'cocoapods/installer/migrator' autoload :SourceProviderHooksContext, 'cocoapods/installer/source_provider_hooks_context'
autoload :PodfileValidator, 'cocoapods/installer/podfile_validator' autoload :Migrator, 'cocoapods/installer/migrator'
autoload :PodSourceInstaller, 'cocoapods/installer/pod_source_installer' autoload :PodfileValidator, 'cocoapods/installer/podfile_validator'
autoload :PodSourcePreparer, 'cocoapods/installer/pod_source_preparer' autoload :PodSourceInstaller, 'cocoapods/installer/pod_source_installer'
autoload :PodTargetInstaller, 'cocoapods/installer/target_installer/pod_target_installer' autoload :PodSourcePreparer, 'cocoapods/installer/pod_source_preparer'
autoload :TargetInstaller, 'cocoapods/installer/target_installer' autoload :PodTargetInstaller, 'cocoapods/installer/target_installer/pod_target_installer'
autoload :UserProjectIntegrator, 'cocoapods/installer/user_project_integrator' autoload :TargetInstaller, 'cocoapods/installer/target_installer'
autoload :UserProjectIntegrator, 'cocoapods/installer/user_project_integrator'
include Config::Mixin include Config::Mixin
...@@ -125,6 +126,9 @@ module Pod ...@@ -125,6 +126,9 @@ module Pod
def resolve_dependencies def resolve_dependencies
analyzer = create_analyzer analyzer = create_analyzer
plugin_sources = run_source_provider_hooks
analyzer.sources.push(*plugin_sources)
UI.section 'Updating local specs repositories' do UI.section 'Updating local specs repositories' do
analyzer.update_repositories analyzer.update_repositories
end unless config.skip_repo_update? end unless config.skip_repo_update?
...@@ -453,6 +457,16 @@ module Pod ...@@ -453,6 +457,16 @@ module Pod
HooksManager.run(:post_install, context, plugins) HooksManager.run(:post_install, context, plugins)
end end
# Runs the registered callbacks for the source provider plugin hooks.
#
# @return [void]
#
def run_source_provider_hooks
context = SourceProviderHooksContext.generate
HooksManager.run(:source_provider, context, plugins)
context.sources
end
# Ensures that all plugins specified in the {#podfile} are loaded. # Ensures that all plugins specified in the {#podfile} are loaded.
# #
# @return [void] # @return [void]
......
module Pod
class Installer
# Context object designed to be used with the HooksManager which describes
# the context of the installer before spec sources have been created
#
class SourceProviderHooksContext
# @return [Array<Source>] The source objects to send to the installer
#
attr_reader :sources
# @return [SourceProviderHooksContext] Convenience class method to generate the
# static context.
#
def self.generate
result = new
result
end
def initialize
@sources = []
end
# @param [Source] Source object to be added to the installer
#
def add_source(source)
unless source.nil?
@sources << source
end
end
end
end
end
require File.expand_path('../../../spec_helper', __FILE__)
module Pod
describe Installer::SourceProviderHooksContext do
it 'offers a convenience method to be generated' do
result = Installer::SourceProviderHooksContext.generate
result.class.should == Installer::SourceProviderHooksContext
result.sources.should == []
end
end
end
...@@ -93,6 +93,51 @@ module Pod ...@@ -93,6 +93,51 @@ module Pod
@installer.install! @installer.install!
end end
it 'runs source provider hooks before analyzing' do
config.skip_repo_update = true
@installer.unstub(:resolve_dependencies)
@installer.stubs(:validate_build_configurations)
@installer.stubs(:prepare_for_legacy_compatibility)
@installer.stubs(:clean_sandbox)
def @installer.run_source_provider_hooks
@hook_called = true
end
def @installer.analyze(*)
@hook_called.should.be.true
end
@installer.install!
end
it 'includes sources from source provider plugins' do
plugin_name = 'test-plugin'
Pod::HooksManager.register(plugin_name, :source_provider) do |context, options|
source_url = options['sources'].first
return unless source_url
source = Pod::Source.new(source_url)
context.add_source(source)
end
test_source_name = 'https://github.com/artsy/Specs.git'
plugins_hash = Installer::DEFAULT_PLUGINS.merge(plugin_name => { 'sources' => [test_source_name] })
@installer.podfile.stubs(:plugins).returns(plugins_hash)
@installer.unstub(:resolve_dependencies)
@installer.stubs(:validate_build_configurations)
@installer.stubs(:prepare_for_legacy_compatibility)
@installer.stubs(:clean_sandbox)
@installer.stubs(:ensure_plugins_are_installed!)
@installer.stubs(:analyze)
config.skip_repo_update = true
analyzer = Installer::Analyzer.new(config.sandbox, @installer.podfile, @installer.lockfile)
analyzer.stubs(:analyze)
@installer.stubs(:create_analyzer).returns(analyzer)
@installer.install!
source = Pod::Source.new(test_source_name)
names = analyzer.sources.map(&:name)
names.should.include(source.name)
end
it 'integrates the user targets if the corresponding config is set' do it 'integrates the user targets if the corresponding config is set' do
config.integrate_targets = true config.integrate_targets = true
@installer.expects(:integrate_user_project) @installer.expects(:integrate_user_project)
...@@ -726,6 +771,14 @@ module Pod ...@@ -726,6 +771,14 @@ module Pod
@installer.send(:run_plugins_post_install_hooks) @installer.send(:run_plugins_post_install_hooks)
end end
it 'runs plugins source provider hook' do
context = stub
context.stubs(:sources).returns([])
Installer::SourceProviderHooksContext.expects(:generate).returns(context)
HooksManager.expects(:run).with(:source_provider, context, Installer::DEFAULT_PLUGINS)
@installer.send(:run_source_provider_hooks)
end
it 'only runs the podfile-specified hooks' do it 'only runs the podfile-specified hooks' do
context = stub context = stub
Installer::PostInstallHooksContext.expects(:generate).returns(context) Installer::PostInstallHooksContext.expects(:generate).returns(context)
......
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