lib/vagrant/plugin/manager.rb in vagrant-unbundled-1.8.5.2 vs lib/vagrant/plugin/manager.rb in vagrant-unbundled-1.9.1.1

- old
+ new

@@ -42,50 +42,57 @@ # @return [Gem::Specification] def install_plugin(name, **opts) local = false if name =~ /\.gem$/ # If this is a gem file, then we install that gem locally. - local_spec = Vagrant::Bundler.instance.install_local(name) + local_spec = Vagrant::Bundler.instance.install_local(name, opts) name = local_spec.name opts[:version] = local_spec.version.to_s - local = true end plugins = installed_plugins plugins[name] = { "require" => opts[:require], "gem_version" => opts[:version], "sources" => opts[:sources], } - result = nil - install_lambda = lambda do - Vagrant::Bundler.instance.install(plugins, local).each do |spec| - next if spec.name != name - next if result && result.version >= spec.version - result = spec + if local_spec.nil? + result = nil + install_lambda = lambda do + Vagrant::Bundler.instance.install(plugins, local).each do |spec| + next if spec.name != name + next if result && result.version >= spec.version + result = spec + end end - end - if opts[:verbose] - Vagrant::Bundler.instance.verbose(&install_lambda) + if opts[:verbose] + Vagrant::Bundler.instance.verbose(&install_lambda) + else + install_lambda.call + end else - install_lambda.call + result = local_spec end - # Add the plugin to the state file @user_file.add_plugin( result.name, version: opts[:version], require: opts[:require], sources: opts[:sources], + installed_gem_version: result.version.to_s ) + # After install clean plugin gems to remove any cruft. This is useful + # for removing outdated dependencies or other versions of an installed + # plugin if the plugin is upgraded/downgraded + Vagrant::Bundler.instance.clean(installed_plugins) result - rescue ::Bundler::GemNotFound + rescue Gem::GemNotFoundException raise Errors::PluginGemNotFound, name: name - rescue ::Bundler::BundlerError => e + rescue Gem::Exception => e raise Errors::BundlerError, message: e.to_s end # Uninstalls the plugin with the given name. # @@ -100,18 +107,34 @@ @user_file.remove_plugin(name) # Clean the environment, removing any old plugins Vagrant::Bundler.instance.clean(installed_plugins) - rescue ::Bundler::BundlerError => e + rescue Gem::Exception => e raise Errors::BundlerError, message: e.to_s end # Updates all or a specific set of plugins. def update_plugins(specific) - Vagrant::Bundler.instance.update(installed_plugins, specific) - rescue ::Bundler::BundlerError => e + result = Vagrant::Bundler.instance.update(installed_plugins, specific) + installed_plugins.each do |name, info| + matching_spec = result.detect{|s| s.name == name} + info = Hash[ + info.map do |key, value| + [key.to_sym, value] + end + ] + if matching_spec + @user_file.add_plugin(name, **info.merge( + version: "> 0", + installed_gem_version: matching_spec.version.to_s + )) + end + end + Vagrant::Bundler.instance.clean(installed_plugins) + result + rescue Gem::Exception => e raise Errors::BundlerError, message: e.to_s end # This returns the list of plugins that should be enabled. # @@ -121,11 +144,17 @@ if @system_file @system_file.installed_plugins.each do |k, v| system[k] = v.merge("system" => true) end end + plugin_list = system.merge(@user_file.installed_plugins) - system.merge(@user_file.installed_plugins) + # Sort plugins by name + Hash[ + plugin_list.map{|plugin_name, plugin_info| + [plugin_name, plugin_info] + }.sort_by(&:first) + ] end # This returns the list of plugins that are installed as # Gem::Specifications. #