diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index c852bed9081..9f33f771470 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -546,6 +546,20 @@ def version end map %w(-v --version) => :version + desc "licenses", "Prints the license of all gems in the bundle" + def licenses + Bundler.load.specs.sort_by { |s| s.license.to_s }.reverse.each do |s| + gem_name = s.name + license = s.license || s.licenses + + if license.empty? + Bundler.ui.warn "#{gem_name}: Unknown" + else + Bundler.ui.info "#{gem_name}: #{license}" + end + end + end + desc 'viz', "Generates a visual dependency graph" long_desc <<-D Viz generates a PNG file of the current Gemfile as a dependency graph. diff --git a/spec/other/licenses_spec.rb b/spec/other/licenses_spec.rb new file mode 100644 index 00000000000..81b39fc43f7 --- /dev/null +++ b/spec/other/licenses_spec.rb @@ -0,0 +1,18 @@ +require "spec_helper" + +describe "bundle licenses" do + before :each do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rails" + gem "with_license" + G + end + + it "prints license information for all gems in the bundle" do + bundle "licenses" + + out.should include("actionpack: Unknown") + out.should include("with_license: MIT") + end +end diff --git a/spec/support/builders.rb b/spec/support/builders.rb index 6a71a43cb2c..350abf4520f 100644 --- a/spec/support/builders.rb +++ b/spec/support/builders.rb @@ -126,6 +126,10 @@ def build_repo1 s.add_development_dependency "activesupport", "= 2.3.5" end + build_gem "with_license" do |s| + s.license = "MIT" + end + build_gem "with_implicit_rake_dep" do |s| s.extensions << "Rakefile" s.write "Rakefile", <<-RUBY