diff options
author | Asutosh Palai <asupalai@gmail.com> | 2016-05-24 11:38:09 +0530 |
---|---|---|
committer | Asutosh Palai <asupalai@gmail.com> | 2016-05-24 21:15:01 +0530 |
commit | c34633e591f35c3506bbec6515ee2ba33e7ee024 (patch) | |
tree | 616d8c93643b9b8d8fcfb6366fcd30fa6af4ddef | |
parent | 867e2d9c6cfc033f689340c2c592db9119dcaa8c (diff) | |
download | bundler-c34633e591f35c3506bbec6515ee2ba33e7ee024.tar.gz |
Added spec helper to build plugin
-rw-r--r-- | lib/bundler/cli/plugin.rb | 11 | ||||
-rw-r--r-- | lib/bundler/plugin.rb | 12 | ||||
-rw-r--r-- | lib/bundler/plugin/index.rb | 9 | ||||
-rw-r--r-- | lib/bundler/plugin/installer.rb | 23 | ||||
-rw-r--r-- | lib/bundler/source.rb | 2 | ||||
-rw-r--r-- | lib/bundler/source/git.rb | 8 | ||||
-rw-r--r-- | spec/plugins/install.rb | 16 | ||||
-rw-r--r-- | spec/support/builders.rb | 10 |
8 files changed, 34 insertions, 57 deletions
diff --git a/lib/bundler/cli/plugin.rb b/lib/bundler/cli/plugin.rb index 05d8819be7..66eacd1d1e 100644 --- a/lib/bundler/cli/plugin.rb +++ b/lib/bundler/cli/plugin.rb @@ -2,20 +2,19 @@ require "bundler/vendored_thor" module Bundler class CLI::Plugin < Thor - desc "install PLUGIN", "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). D - method_option "source", :type=> :string, :default => nil, :banner => + method_option "source", :type => :string, :default => nil, :banner => "URL of the RubyGems source to fetch the plugin from" - method_option "version", :type=> :string, :default => nil, :banner => + method_option "version", :type => :string, :default => nil, :banner => "The version of the plugin to fetch from" - method_option "git", :type=> :string, :default => nil, :banner => + method_option "git", :type => :string, :default => nil, :banner => "URL of the git repo to fetch from" - method_option "branch", :type=> :string, :default => nil, :banner => + method_option "branch", :type => :string, :default => nil, :banner => "The git branch to checkout" - method_option "ref", :type=> :string, :default => nil, :banner => + method_option "ref", :type => :string, :default => nil, :banner => "The git revision to check out" def install(plugin) Bundler::Plugin.install(plugin, options) diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb index ad20094db7..5c6ba5dd00 100644 --- a/lib/bundler/plugin.rb +++ b/lib/bundler/plugin.rb @@ -1,11 +1,10 @@ -#frozen_string_literal: true +# frozen_string_literal: true module Bundler class Plugin autoload :Index, "bundler/plugin/index" class << self - # Installs a new plugin by the given name # # @@ -34,10 +33,9 @@ module Bundler # @param [Pathname] plugin_path the path plugin is installed at # # @raise [Error] if plugin.rb file is not found - def validate_plugin! plugin_path - unless File.file? plugin_path.join("plugin.rb") - raise "plugin.rb was not found in the plugin gem!" - end + def validate_plugin!(plugin_path) + plugin_file = plugin_path.join("plugin.rb") + raise "plugin.rb was not found in the plugin!" unless plugin_file.file? end # Runs the plugin.rb file, records the plugin actions it registers for and @@ -45,7 +43,7 @@ module Bundler # # @param [String] name the name of the plugin # @param [Pathname] path the path where the plugin is installed at - def register_plugin name, path + def register_plugin(name, path) require path.join("plugin.rb") # this shall latter be used to find the actions the plugin performs index.register_plugin name, path.to_s diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb index 800a59ce47..87a9de9acb 100644 --- a/lib/bundler/plugin/index.rb +++ b/lib/bundler/plugin/index.rb @@ -1,4 +1,4 @@ -# forzen_string_literal: true +# frozen_string_literal: true require "yaml" module Bundler @@ -6,7 +6,6 @@ module Bundler # which plugin does what (currently the features are not implemented so this class is # now a stub class). class Plugin::Index - def initialize @plugin_sources = {} @@ -17,7 +16,7 @@ module Bundler def load_index SharedHelpers.filesystem_access(index_file, :read) do |index_f| valid_file = index_f && index_f.exist? && !index_f.size.zero? - return unless valid_file + break unless valid_file index = YAML.load_file(index_f) @plugin_sources = index["plugin_sources"] end @@ -27,12 +26,12 @@ module Bundler # variables in YAML format. (The instance variables are supposed to be only String key value pairs) def save_index index = { - "plugin_sources" => @plugin_sources + "plugin_sources" => @plugin_sources, } SharedHelpers.filesystem_access(index_file) do |index_f| FileUtils.mkdir_p(index_f.dirname) - File.open(index_f, "w") { |f| f.puts YAML.dump(index) } + File.open(index_f, "w") {|f| f.puts YAML.dump(index) } end end diff --git a/lib/bundler/plugin/installer.rb b/lib/bundler/plugin/installer.rb index 5e37b9a48b..fbbde807ac 100644 --- a/lib/bundler/plugin/installer.rb +++ b/lib/bundler/plugin/installer.rb @@ -1,4 +1,4 @@ -#frozen_string_literal: true +# frozen_string_literal: true module Bundler # Handles the installation of plugin in appropriate directories. @@ -9,12 +9,8 @@ module Bundler # # @todo: Remove the dependencies of Source's subclasses and try to use the Bundler sources directly. This will reduce the redundancies. class Plugin::Installer - def self.install(name, options) if options[:git] - #uri = options[:git] - #revision = options[:ref] || options[:branch] || "master" - install_git(name, options) elsif options[:source] source = options[:source] @@ -66,7 +62,6 @@ module Bundler install_from_spec specs.first end - # Installs the plugin from the provided spec and returns the path where the # plugin was installed. # @@ -95,21 +90,5 @@ module Bundler ).install.full_gem_path end end - - def self.base_name uri - File.basename(uri.sub(%r{^(\w+://)?([^/:]+:)?(//\w*/)?(\w*/)*}, ""), ".git") - end - - def self.uri_hash uri - if uri =~ %r{^\w+://(\w+@)?} - # Downcase the domain component of the URI - # and strip off a trailing slash, if one is present - input = URI.parse(uri).normalize.to_s.sub(%r{/$}, "") - else - # If there is no URI scheme, assume it is an ssh/git URI - input = uri - end - Digest::SHA1.hexdigest(input) - end end end diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb index 7430f87e3e..52ae4d767d 100644 --- a/lib/bundler/source.rb +++ b/lib/bundler/source.rb @@ -18,7 +18,7 @@ module Bundler def version_message(spec) message = "#{spec.name} #{spec.version}" - if !@options[:plugin] and Bundler.locked_gems + if !@options[:plugin] && Bundler.locked_gems locked_spec = Bundler.locked_gems.specs.find {|s| s.name == spec.name } locked_spec_version = locked_spec.version if locked_spec if locked_spec_version && spec.version != locked_spec_version diff --git a/lib/bundler/source/git.rb b/lib/bundler/source/git.rb index 9624f97cb1..c142d1c559 100644 --- a/lib/bundler/source/git.rb +++ b/lib/bundler/source/git.rb @@ -207,12 +207,10 @@ module Bundler if @options[:plugin] Plugin.cache.join("bundler", "git", git_scope) + elsif Bundler.requires_sudo? + Bundler.user_bundle_path.join("cache/git", git_scope) else - if Bundler.requires_sudo? - Bundler.user_bundle_path.join("cache/git", git_scope) - else - Bundler.cache.join("git", git_scope) - end + Bundler.cache.join("git", git_scope) end end end diff --git a/spec/plugins/install.rb b/spec/plugins/install.rb index 576eb041ee..e1d9d80498 100644 --- a/spec/plugins/install.rb +++ b/spec/plugins/install.rb @@ -1,12 +1,10 @@ -#frozen_string_literal: true -require 'spec_helper' +# frozen_string_literal: true +require "spec_helper" describe "bundler plugin install" do before do build_repo2 do - build_gem "foo" do |s| - s.write "plugin.rb" - end + build_plugin "foo" end end @@ -32,8 +30,7 @@ describe "bundler plugin install" do it "shows error for plugins with dependencies" do build_repo2 do - build_gem "kung-foo" do |s| - s.write "plugin.rb" + build_plugin "kung-foo" do |s| s.add_dependency "rake" end end @@ -48,7 +45,6 @@ describe "bundler plugin install" do end context "malformatted plugin" do - it "fails when plugin.rb is missing" do build_repo2 do build_gem "charlie" @@ -63,10 +59,9 @@ describe "bundler plugin install" do expect(plugin_gems("charlie-1.0")).not_to be_directory end - it "fails when plugin.rb throws exception on load" do build_repo2 do - build_gem "chaplin" do |s| + build_plugin "chaplin" do |s| s.write "plugin.rb", <<-RUBY raise "I got you man" RUBY @@ -79,7 +74,6 @@ describe "bundler plugin install" do expect(plugin_gems("chaplin-1.0")).not_to be_directory end - end context "git plugins" do diff --git a/spec/support/builders.rb b/spec/support/builders.rb index eaa68f51df..feabdc0e47 100644 --- a/spec/support/builders.rb +++ b/spec/support/builders.rb @@ -419,6 +419,10 @@ module Spec GitReader.new lib_path(spec.full_name) end + def build_plugin(name, *args, &blk) + build_with(PluginBuilder, name, args, &blk) + end + private def build_with(builder, name, args, &blk) @@ -701,6 +705,12 @@ module Spec end end + class PluginBuilder < GemBuilder + def _default_files + @_default_files ||= super.merge("plugin.rb" => "") + end + end + TEST_CERT = <<-CERT.gsub(/^\s*/, "") -----BEGIN CERTIFICATE----- MIIDMjCCAhqgAwIBAgIBATANBgkqhkiG9w0BAQUFADAnMQwwCgYDVQQDDAN5b3Ux |