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 | |
parent | 4a1baea541298628d47b04520f23f9b3c6af0265 (diff) | |
download | bundler-1a9857473bbd7b91a5abd0b2e7da144f375ff761.tar.gz |
Multiple plugins to be installed by cli install
-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 | ||||
-rw-r--r-- | spec/bundler/plugin/installer_spec.rb | 23 | ||||
-rw-r--r-- | spec/bundler/plugin_spec.rb | 15 | ||||
-rw-r--r-- | spec/plugins/command.rb | 2 |
7 files changed, 69 insertions, 67 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 = {}) diff --git a/spec/bundler/plugin/installer_spec.rb b/spec/bundler/plugin/installer_spec.rb index c7e865dc79..0cda970b4b 100644 --- a/spec/bundler/plugin/installer_spec.rb +++ b/spec/bundler/plugin/installer_spec.rb @@ -12,18 +12,19 @@ describe Bundler::Plugin::Installer do describe "with mocked installers" do it "returns the installation path after installing git plugins" do - allow(installer).to receive(:install_git).and_return("/git/install/path") + allow(installer).to receive(:install_git). + and_return("new-plugin" => "/git/install/path") - expect(installer.install("new-plugin", :git => "https://some.ran/dom")). - to eq("/git/install/path") + expect(installer.install(["new-plugin"], :git => "https://some.ran/dom")). + to eq("new-plugin" => "/git/install/path") end it "returns the installation path after installing rubygems plugins" do allow(installer).to receive(:install_rubygems). - and_return("/rubygems/install/path") + and_return("new-plugin" => "/rubygems/install/path") - expect(installer.install("new-plugin", :source => "https://some.ran/dom")). - to eq("/rubygems/install/path") + expect(installer.install(["new-plugin"], :source => "https://some.ran/dom")). + to eq("new-plugin" => "/rubygems/install/path") end end @@ -34,12 +35,10 @@ describe Bundler::Plugin::Installer do end rev = revision_for(lib_path("ga-plugin")) - expected_path = Bundler::Plugin.root. - join("bundler", "gems", "ga-plugin-#{rev[0..11]}") + expected = { "ga-plugin" => Bundler::Plugin.root.join("bundler", "gems", "ga-plugin-#{rev[0..11]}").to_s } opts = { :git => "file://#{lib_path("ga-plugin")}" } - expect(installer.install("ga-plugin", opts)). - to eq(expected_path) + expect(installer.install(["ga-plugin"], opts)).to eq(expected) end it "returns the installation path after installing rubygems plugins" do @@ -48,8 +47,8 @@ describe Bundler::Plugin::Installer do end opts = { :source => "file://#{gem_repo2}" } - expect(installer.install("re-plugin", opts)). - to eq(plugin_gems("re-plugin-1.0").to_s) + expect(installer.install(["re-plugin"], opts)). + to eq("re-plugin" => plugin_gems("re-plugin-1.0").to_s) end end end diff --git a/spec/bundler/plugin_spec.rb b/spec/bundler/plugin_spec.rb index a46e5550c1..573a5d2271 100644 --- a/spec/bundler/plugin_spec.rb +++ b/spec/bundler/plugin_spec.rb @@ -25,29 +25,30 @@ describe Bundler::Plugin do let(:opts) { { "version" => "~> 1.0", "source" => "foo" } } before do - allow(installer). - to receive(:install).with("new-plugin", opts) { lib_path("new-plugin") } + allow(installer).to receive(:install).with(["new-plugin"], opts) do + { "new_plugin" => lib_path("new-plugin") } + end end it "passes the name and options to installer" do - allow(installer).to receive(:install).with("new-plugin", opts) do - lib_path("new-plugin") + allow(installer).to receive(:install).with(["new-plugin"], opts) do + { "new-plugin" => lib_path("new-plugin").to_s } end.once - subject.install "new-plugin", opts + subject.install ["new-plugin"], opts end it "validates the installed plugin" do allow(subject). to receive(:validate_plugin!).with(lib_path("new-plugin")).once - subject.install "new-plugin", opts + subject.install ["new-plugin"], opts end it "registers the plugin with index" do allow(index).to receive(:register_plugin). with("new-plugin", lib_path("new-plugin").to_s, []).once - subject.install "new-plugin", opts + subject.install ["new-plugin"], opts end end diff --git a/spec/plugins/command.rb b/spec/plugins/command.rb index 4ad58fb2c5..71e87a5b01 100644 --- a/spec/plugins/command.rb +++ b/spec/plugins/command.rb @@ -74,7 +74,7 @@ describe "command plugins" do expect(out).not_to include("Installed plugin copycat") - expect(out).to include("Failed to install plugin copycat") + expect(out).to include("Failed to install plugin") expect(out).to include("Command(s) `mahcommand` declared by copycat are already registered.") end |