diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-01 15:47:30 -0800 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-02-09 09:16:06 -0800 |
commit | aa74c0ac58393e9186c2ebecbc3144c2c8d2ee85 (patch) | |
tree | 13a59b98b8c643e9bfe3b0a0958ddc396d609f46 /lib/chef/cookbook | |
parent | 99ea57ca5bdd46902855a7cd80b86d24d3371486 (diff) | |
download | chef-aa74c0ac58393e9186c2ebecbc3144c2c8d2ee85.tar.gz |
get the formatting for cookbook gems correct
this leverages the PR:
https://github.com/bundler/bundler/pull/4245
to redirect output from bundler into chef's logger/formatter to get the
UI right. if you don't have that in the external bundler you'll just
get output on STDOUT. fix is to upgrade bundler.
Diffstat (limited to 'lib/chef/cookbook')
-rw-r--r-- | lib/chef/cookbook/cookbook_collection.rb | 6 | ||||
-rw-r--r-- | lib/chef/cookbook/gem_installer.rb | 72 |
2 files changed, 65 insertions, 13 deletions
diff --git a/lib/chef/cookbook/cookbook_collection.rb b/lib/chef/cookbook/cookbook_collection.rb index 7e633da03d..d06b8fd042 100644 --- a/lib/chef/cookbook/cookbook_collection.rb +++ b/lib/chef/cookbook/cookbook_collection.rb @@ -1,7 +1,7 @@ #-- # Author:: Tim Hinderliter (<tim@chef.io>) # Author:: Christopher Walters (<cw@chef.io>) -# Copyright:: Copyright 2010-2016, Chef Software, Inc. +# Copyright:: Copyright 2010-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -56,8 +56,8 @@ class Chef end end - def install_gems - Cookbook::GemInstaller.new(self).install + def install_gems(events) + Cookbook::GemInstaller.new(self, events).install end end end diff --git a/lib/chef/cookbook/gem_installer.rb b/lib/chef/cookbook/gem_installer.rb index 38e23d4807..fa6dccfa4f 100644 --- a/lib/chef/cookbook/gem_installer.rb +++ b/lib/chef/cookbook/gem_installer.rb @@ -17,16 +17,22 @@ # limitations under the License. # -require 'tmpdir' -require 'bundler/inline' +require "tmpdir" +begin + require "bundler/inline" +rescue LoadError + raise RuntimeError, "The RFC060 metadata gem feature requires bundler 1.10.0 or greater." +end class Chef class Cookbook class GemInstaller + attr_accessor :events attr_accessor :cookbook_collection - def initialize(cookbook_collection) + def initialize(cookbook_collection, events) @cookbook_collection = cookbook_collection + @events = events end def install @@ -36,24 +42,70 @@ class Chef cookbook_gems += cookbook_version.metadata.gems end - return if cookbook_gems.empty? + events.cookbook_gem_start(cookbook_gems) - gemfile(true) do - source 'https://rubygems.org' - cookbook_gems.each do |args| - gem *args + unless cookbook_gems.empty? + begin + inline_gemfile do + source "https://rubygems.org" + cookbook_gems.each do |args| + gem *args + end + end + rescue Exception => e + events.cookbook_gem_failed(e) + raise end end + + events.cookbook_gem_finished end class ChefBundlerUI < Bundler::UI::Silent + attr_accessor :events + + def initialize(events) + @events = events + super() + end + def confirm(msg, newline = nil) - Chef::Log.warn("CONFIRM: #{msg}") + # looks like "Installing time_ago_in_words 0.1.1" when installing + if msg =~ /Installing\s+(\S+)\s+(\S+)/ + events.cookbook_gem_installing($1, $2) + end + Chef::Log.info(msg) end def error(msg, newline = nil) - Chef::Log.warn("ERROR: #{msg}") + Chef::Log.error(msg) + end + + def debug(msg, newline = nil) + Chef::Log.debug(msg) end + + def info(msg, newline = nil) + # looks like "Using time_ago_in_words 0.1.1" when using, plus other misc output + if msg =~ /Using\s+(\S+)\s+(\S+)/ + events.cookbook_gem_using($1, $2) + end + Chef::Log.info(msg) + end + + def warn(msg, newline = nil) + Chef::Log.warn(msg) + end + end + + private + + def inline_gemfile(&block) + # requires https://github.com/bundler/bundler/pull/4245 + gemfile(true, ui: ChefBundlerUI.new(events), &block) + rescue ArgumentError # Method#arity doesn't inspect optional arguments, so we rescue + # requires bundler 1.10.0 + gemfile(true, &block) end end end |