diff options
author | Asutosh Palai <asupalai@gmail.com> | 2016-06-07 20:12:07 +0530 |
---|---|---|
committer | Asutosh Palai <asupalai@gmail.com> | 2016-06-07 20:15:19 +0530 |
commit | 1a9857473bbd7b91a5abd0b2e7da144f375ff761 (patch) | |
tree | 3dcce32238261351ab998e50043177b317dd5f30 /lib | |
parent | 4a1baea541298628d47b04520f23f9b3c6af0265 (diff) | |
download | bundler-1a9857473bbd7b91a5abd0b2e7da144f375ff761.tar.gz |
Multiple plugins to be installed by cli install
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bundler/cli/plugin.rb | 8 | ||||
-rw-r--r-- | lib/bundler/plugin.rb | 35 | ||||
-rw-r--r-- | lib/bundler/plugin/installer.rb | 49 | ||||
-rw-r--r-- | lib/bundler/plugin/source_list.rb | 4 |
4 files changed, 49 insertions, 47 deletions
diff --git a/lib/bundler/cli/plugin.rb b/lib/bundler/cli/plugin.rb index c00e3f1855..87a37d98ca 100644 --- a/lib/bundler/cli/plugin.rb +++ b/lib/bundler/cli/plugin.rb @@ -2,9 +2,9 @@ require "bundler/vendored_thor" module Bundler class CLI::Plugin < Thor - desc "install PLUGIN", "Install the plugin from the source" + desc "install PLUGINS", "Install the plugin from the source" long_desc <<-D - Install a plugin named PLUGIN wither from the rubygems source provided (with --source option) or from a git source provided with (--git option). + Install plugins either from the rubygems source provided (with --source option) or from a git source provided with (--git option). D method_option "source", :type => :string, :default => nil, :banner => "URL of the RubyGems source to fetch the plugin from" @@ -16,8 +16,8 @@ module Bundler "The git branch to checkout" method_option "ref", :type => :string, :default => nil, :banner => "The git revision to check out" - def install(plugin) - Bundler::Plugin.install(plugin, options) + def install(*plugins) + Bundler::Plugin.install(plugins, options) end end end diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index f7816eab3c..b01ba7aad1 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -19,20 +19,16 @@ module Bundler # Installs a new plugin by the given name # - # @param [String] name the name of plugin to be installed + # @param [Array<String>] names the name of plugin to be installed # @param [Hash] options various parameters as described in description # @option options [String] :source rubygems source to fetch the plugin gem from # @option options [String] :version (optional) the version of the plugin to install - def install(name, options) - plugin_path = Pathname.new Installer.new.install(name, options) + def install(names, options) + paths = Installer.new.install(names, options) - validate_plugin! plugin_path - - register_plugin name, plugin_path - - Bundler.ui.info "Installed plugin #{name}" + save_plugins paths rescue PluginError => e - Bundler.rm_rf(plugin_path) if plugin_path + paths.values.map {|path| Bundler.rm_rf(path)} if paths Bundler.ui.error "Failed to install plugin #{name}: #{e.message}\n #{e.backtrace.join("\n ")}" end @@ -46,12 +42,7 @@ module Bundler plugins = Installer.new.install_definition(definition) - plugins.each do |name, path| - path = Pathname.new path - validate_plugin! path - register_plugin name, path - Bundler.ui.info "Installed plugin #{name}" - end + save_plugins plugins end # The index object used to store the details about the plugin @@ -89,6 +80,18 @@ module Bundler @commands[command].new.exec(command, args) end + # Post installation processing and registering with index + # + # @param [Hash] plugins mapped to their installtion path + def save_plugins(plugins) + plugins.each do |name, path| + path = Pathname.new path + validate_plugin! path + register_plugin name, path + Bundler.ui.info "Installed plugin #{name}" + end + end + # Checks if the gem is good to be a plugin # # At present it only checks whether it contains plugins.rb file @@ -134,7 +137,7 @@ module Bundler end class << self - private :load_plugin, :register_plugin, :validate_plugin! + private :load_plugin, :register_plugin, :save_plugins, :validate_plugin! end end end diff --git a/lib/bundler/plugin/installer.rb b/lib/bundler/plugin/installer.rb index df80457ac4..15de7a54ec 100644 --- a/lib/bundler/plugin/installer.rb +++ b/lib/bundler/plugin/installer.rb @@ -11,14 +11,14 @@ module Bundler autoload :Rubygems, "bundler/plugin/installer/rubygems" autoload :Git, "bundler/plugin/installer/git" - def install(name, options) + def install(names, options) + version = options[:version] || [">= 0"] + if options[:git] - install_git(name, options) + install_git(names, version, options) elsif options[:source] source = options[:source] - version = options[:version] || [">= 0"] - - install_rubygems(name, source, version) + install_rubygems(names, version, source) else raise(ArgumentError, "You need to provide the source") end @@ -42,42 +42,39 @@ module Bundler private - def install_git(name, options) + def install_git(names, version, options) uri = options.delete(:git) - - options["name"] = name options["uri"] = uri - git_source = Git.new options - git_source.remote! + source_list = SourceList.new + source_list.add_git_source(options) + + # To support bot sources + if options[:source] + source_list.add_rubygems_source("remotes" => options[:source]) + end - git_source.install(git_source.specs.first) + deps = names.map {|name| Dependency.new name, version } - git_source.path + definition = Definition.new(nil, deps, source_list, {}) + install_definition(definition) end # Installs the plugin from rubygems source and returns the path where the # plugin was installed # # @param [String] name of the plugin gem to search in the source + # @param [Array] version of the gem to install # @param [String] source the rubygems URL to resolve the gem - # @param [Array, String] version (optional) of the gem to install # # @return [String] the path where the plugin was installed - def install_rubygems(name, source, version = [">= 0"]) - rg_source = Rubygems.new "remotes" => source - rg_source.remote! - rg_source.dependency_names << name - - dep = Dependency.new name, version - - deps_proxies = [DepProxy.new(dep, GemHelpers.generic_local_platform)] - idx = rg_source.specs - - specs = Resolver.resolve(deps_proxies, idx).materialize([dep]) - paths = install_from_specs specs + def install_rubygems(names, version, source) + deps = names.map {|name| Dependency.new name, version } + source_list = SourceList.new + source_list.add_rubygems_source("remotes" => source) - paths[name] + definition = Definition.new(nil, deps, source_list, {}) + install_definition(definition) end # Installs the plugins and deps from the provided specs and returns map of diff --git a/lib/bundler/plugin/source_list.rb b/lib/bundler/plugin/source_list.rb index 29acc5beb0..6b1f1aee36 100644 --- a/lib/bundler/plugin/source_list.rb +++ b/lib/bundler/plugin/source_list.rb @@ -6,8 +6,10 @@ module Bundler module Plugin class SourceList < Bundler::SourceList def initialize - super + @path_sources = [] + @git_sources = [] @rubygems_aggregate = Plugin::Installer::Rubygems.new + @rubygems_sources = [] end def add_git_source(options = {}) |