From 055f95b62dae20eaa34a4cf2a4919b1fbd0da4ed Mon Sep 17 00:00:00 2001 From: Stefan Lance Date: Sat, 20 Jun 2015 15:49:57 -0500 Subject: Show deprecation warning when using --binstubs --- lib/bundler/cli/install.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/bundler/cli') diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 07950c90..30673241 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -55,6 +55,12 @@ module Bundler Bundler::Fetcher.disable_endpoint = options["full-index"] + if options["binstubs"] + Bundler.ui.deprecate("The --binstubs option will be removed from "\ + "Bundler 2.0 and replaced with "\ + "`bundle binstubs`\n") + end + # rubygems plugins sometimes hook into the gem install process Gem.load_env_plugins if Gem.respond_to?(:load_env_plugins) -- cgit v1.2.3 From 54d620bd797abc50423d958c141ad95a4db2974d Mon Sep 17 00:00:00 2001 From: Dimitris Zorbas Date: Sat, 3 Oct 2015 13:25:00 +0300 Subject: Show deprecation warning when using console command --- lib/bundler/cli/console.rb | 4 ++++ spec/commands/console_spec.rb | 8 ++++++++ 2 files changed, 12 insertions(+) (limited to 'lib/bundler/cli') diff --git a/lib/bundler/cli/console.rb b/lib/bundler/cli/console.rb index 5e72cdbf..9b43e94a 100644 --- a/lib/bundler/cli/console.rb +++ b/lib/bundler/cli/console.rb @@ -8,6 +8,10 @@ module Bundler end def run + Bundler.ui.deprecate "bundle console is deprecated and will be replaced " \ + "by `bin/console` generated by `bundle gem ` " \ + "in Bundler 2.0.", true + group ? Bundler.require(:default, *(group.split.map!(&:to_sym))) : Bundler.require ARGV.clear diff --git a/spec/commands/console_spec.rb b/spec/commands/console_spec.rb index b60ac2c9..6bf09f24 100644 --- a/spec/commands/console_spec.rb +++ b/spec/commands/console_spec.rb @@ -11,6 +11,14 @@ describe "bundle console" do G end + it "prints a deprecation warning" do + bundle "console" + + expect(err).to include("bundle console is deprecated and will be replaced " \ + "by `bin/console` generated by `bundle gem ` " \ + "in Bundler 2.0.") + end + it "starts IRB with the default group loaded" do bundle "console" do |input, _, _| input.puts("puts RACK") -- cgit v1.2.3 From 56c3b82d5ee5f6577ded051a9778b9aeeae14ab7 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Fri, 1 Jul 2016 12:00:00 -0300 Subject: Migrate 1-99 deprecations to new major_deprecation machinery --- lib/bundler/cli.rb | 6 +- lib/bundler/cli/console.rb | 5 +- lib/bundler/cli/install.rb | 5 +- lib/bundler/deployment.rb | 3 +- lib/bundler/dsl.rb | 15 ++-- lib/bundler/settings.rb | 12 ++- lib/bundler/shared_helpers.rb | 12 +-- lib/bundler/ui/silent.rb | 3 - spec/deprecation_spec.rb | 145 ----------------------------------- spec/other/major_deprecation_spec.rb | 138 ++++++++++++++++++++++++++++++++- 10 files changed, 166 insertions(+), 178 deletions(-) delete mode 100644 spec/deprecation_spec.rb (limited to 'lib/bundler/cli') diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index a054aff2..6a75078c 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -224,12 +224,11 @@ module Bundler method_option "outdated", :type => :boolean, :banner => "Show verbose output including whether gems are outdated." def show(gem_name = nil) - # TODO: 2.0 remove `bundle list` - Bundler.ui.deprecate("`bundle list` is deprecated and will be removed in " \ - "Bundler 2.0. Use `bundle show` instead.", true) if ARGV[0] == "list" + Bundler::SharedHelpers.major_deprecation("use `bundle show` instead of `bundle list`") if ARGV[0] == "list" require "bundler/cli/show" Show.new(options, gem_name).run end + # TODO: 2.0 remove `bundle list` map %w(list) => "show" desc "binstubs GEM [OPTIONS]", "Install the binstubs of the listed gem" @@ -344,6 +343,7 @@ module Bundler desc "console [GROUP]", "Opens an IRB session with the bundle pre-loaded" def console(group = nil) + # TODO: Remove for 2.0 require "bundler/cli/console" Console.new(options, group).run end diff --git a/lib/bundler/cli/console.rb b/lib/bundler/cli/console.rb index 9b43e94a..715abf25 100644 --- a/lib/bundler/cli/console.rb +++ b/lib/bundler/cli/console.rb @@ -8,9 +8,8 @@ module Bundler end def run - Bundler.ui.deprecate "bundle console is deprecated and will be replaced " \ - "by `bin/console` generated by `bundle gem ` " \ - "in Bundler 2.0.", true + Bundler::SharedHelpers.major_deprecation "bundle console will be replaced " \ + "by `bin/console` generated by `bundle gem `" group ? Bundler.require(:default, *(group.split.map!(&:to_sym))) : Bundler.require ARGV.clear diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 30673241..2dee4a5a 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -56,9 +56,8 @@ module Bundler Bundler::Fetcher.disable_endpoint = options["full-index"] if options["binstubs"] - Bundler.ui.deprecate("The --binstubs option will be removed from "\ - "Bundler 2.0 and replaced with "\ - "`bundle binstubs`\n") + Bundler::SharedHelpers.major_deprecation \ + "the --binstubs option will be removed in favor of `bundle binstubs`" end # rubygems plugins sometimes hook into the gem install process diff --git a/lib/bundler/deployment.rb b/lib/bundler/deployment.rb index 52f20a45..94f2fac6 100644 --- a/lib/bundler/deployment.rb +++ b/lib/bundler/deployment.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -$stderr.puts "DEPRECATION: Bundler no longer integrates with " \ +require "bundler/shared_helpers" +Bundler::SharedHelpers.major_deprecation "Bundler no longer integrates with " \ "Capistrano, but Capistrano provides its own integration with " \ "Bundler via the capistrano-bundler gem. Use it instead." diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 961b7e40..0436b58f 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -422,7 +422,7 @@ module Bundler "should come from that source. To downgrade this error to a warning, run " \ "`bundle config --delete disable_multisource`" else - Bundler.ui.deprecate "Your Gemfile contains multiple primary sources. " \ + Bundler::SharedHelpers.major_deprecation "Your Gemfile contains multiple primary sources. " \ "Using `source` more than once without a block is a security risk, and " \ "may result in installing unexpected gems. To resolve this warning, use " \ "a block to indicate which gems should come from the secondary source. " \ @@ -433,18 +433,19 @@ module Bundler def warn_github_source_change(repo_name) # TODO: 2.0 remove deprecation - Bundler.ui.deprecate "The :github option uses the git: protocol, which is not secure. " \ + Bundler::SharedHelpers.major_deprecation "The :github option uses the git: protocol, which is not secure. " \ "Bundler 2.0 will use the https: protocol, which is secure. Enable this change now by " \ "running `bundle config github.https true`." end def warn_deprecated_git_source(name, repo_string) # TODO: 2.0 remove deprecation - Bundler.ui.deprecate "The :#{name} git source is deprecated, and will be removed " \ - "in Bundler 2.0. Add this code to your Gemfile to ensure it continues to work:\n" \ - " git_source(:#{name}) do |repo_name|\n" \ - " \"#{repo_string}\"\n" \ - " end", true + Bundler::SharedHelpers.major_deprecation <<-EOS +The :#{name} git source is deprecated, and will be removed in Bundler 2.0. Add this code to your Gemfile to ensure it continues to work: + git_source(:#{name}) do |repo_name| + "#{repo_string}" + end + EOS end class DSLError < GemfileError diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb index 8587eb3e..e8daa98f 100644 --- a/lib/bundler/settings.rb +++ b/lib/bundler/settings.rb @@ -55,11 +55,17 @@ module Bundler def []=(key, value) if self[:options_given] + command = if value.nil? + "bundle config --delete #{key}" + else + "bundle config #{key} #{Array(value).join(":")}" + end + Bundler::SharedHelpers.major_deprecation \ - "Starting in Bundler 2.0, flags passed to commands "\ + "flags passed to commands " \ "will no longer be automatically remembered. Instead please set flags " \ - "you want remembered between commands using `bundle config "\ - " `, i.e. `bundle config #{key} #{value}`." + "you want remembered between commands using `bundle config " \ + " `, i.e. `#{command}`" end local_config_file || raise(GemfileNotFound, "Could not locate Gemfile") set_key(key, value, @local_config, local_config_file) diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb index 59cf7a05..efbedeb3 100644 --- a/lib/bundler/shared_helpers.rb +++ b/lib/bundler/shared_helpers.rb @@ -22,7 +22,6 @@ module Bundler def default_gemfile gemfile = find_gemfile - deprecate_gemfile(gemfile) raise GemfileNotFound, "Could not locate Gemfile" unless gemfile Pathname.new(gemfile) end @@ -129,6 +128,7 @@ module Bundler end def print_major_deprecations! + deprecate_gemfile(find_gemfile) if find_gemfile == find_file("Gemfile") if RUBY_VERSION < "2" major_deprecation("Bundler will only support ruby >= 2.0, you are running #{RUBY_VERSION}") end @@ -231,13 +231,9 @@ module Bundler end def deprecate_gemfile(gemfile) - if gemfile && File.basename(gemfile) == "Gemfile" - Bundler.respond_to?(:ui) && Bundler.ui.deprecate( - "Gemfile and Gemfile.lock are " \ - "deprecated and will be replaced with gems.rb and " \ - "gems.locked in Bundler 2.0.", true - ) - end + return unless gemfile && File.basename(gemfile) == "Gemfile" + Bundler::SharedHelpers.major_deprecation \ + "gems.rb and gems.locked will be prefered to Gemfile and Gemfile.lock." end extend self diff --git a/lib/bundler/ui/silent.rb b/lib/bundler/ui/silent.rb index fc12c6a0..7e40749f 100644 --- a/lib/bundler/ui/silent.rb +++ b/lib/bundler/ui/silent.rb @@ -44,9 +44,6 @@ module Bundler def trace(message, newline = nil) end - def major_deprecation(message) - end - def silence yield end diff --git a/spec/deprecation_spec.rb b/spec/deprecation_spec.rb deleted file mode 100644 index 312974ad..00000000 --- a/spec/deprecation_spec.rb +++ /dev/null @@ -1,145 +0,0 @@ -# frozen_string_literal: true -require "spec_helper" - -describe "Bundler version 1.99" do - context "when bundle is run" do - it "should not warn about gems.rb" do - create_file "gems.rb", <<-G - source "file://#{gem_repo1}" - gem "rack" - G - - bundle :install - expect(err).to lack_errors - end - - it "should print a Gemfile deprecation warning" do - install_gemfile <<-G - source "file://#{gem_repo1}" - gem "rack" - G - - expect(err).to include("DEPRECATION: Gemfile and Gemfile.lock are " \ - "deprecated and will be replaced with gems.rb and gems.locked in " \ - "Bundler 2.0.") - end - - context "with flags" do - it "should print a deprecation warning about autoremembering flags" do - install_gemfile <<-G, :path => "vendor/bundle" - source "file://#{gem_repo1}" - gem "rack" - G - - expect(err).to include("DEPRECATION") - expect(err).to include("flags passed to commands will no longer be automatically remembered.") - end - end - end - - context "when Bundler.setup is run in a ruby script" do - it "should print a single deprecation warning" do - install_gemfile <<-G - source "file://#{gem_repo1}" - gem "rack", :group => :test - G - - ruby <<-RUBY - require 'rubygems' - require 'bundler' - require 'bundler/vendored_thor' - - Bundler.ui = Bundler::UI::Shell.new - Bundler.setup - Bundler.setup - RUBY - - expect(err).to eq("DEPRECATION: Gemfile and Gemfile.lock are " \ - "deprecated and will be replaced with gems.rb and gems.locked in " \ - "Bundler 2.0.") - end - end - - context "when `bundler/deployment` is required in a ruby script" do - it "should print a capistrano deprecation warning" do - install_gemfile <<-G - source "file://#{gem_repo1}" - gem "rack", :group => :test - G - - ruby(<<-RUBY, :expect_err => true) - require 'bundler/deployment' - RUBY - - expect(err).to eq("DEPRECATION: Bundler no longer integrates " \ - "with Capistrano, but Capistrano provides " \ - "its own integration with Bundler via the " \ - "capistrano-bundler gem. Use it instead.") - end - end - - describe Bundler::Dsl do - before do - @rubygems = double("rubygems") - allow(Bundler::Source::Rubygems).to receive(:new) { @rubygems } - end - - context "with github gems" do - it "warns about the https change" do - allow(Bundler.ui).to receive(:deprecate) - msg = "The :github option uses the git: protocol, which is not secure. " \ - "Bundler 2.0 will use the https: protocol, which is secure. Enable this change now by " \ - "running `bundle config github.https true`." - expect(Bundler.ui).to receive(:deprecate).with(msg) - subject.gem("sparks", :github => "indirect/sparks") - end - - it "upgrades to https on request" do - Bundler.settings["github.https"] = true - subject.gem("sparks", :github => "indirect/sparks") - github_uri = "https://github.com/indirect/sparks.git" - expect(subject.dependencies.first.source.uri).to eq(github_uri) - end - end - - context "with bitbucket gems" do - it "warns about removal" do - allow(Bundler.ui).to receive(:deprecate) - msg = "The :bitbucket git source is deprecated, and will be removed " \ - "in Bundler 2.0. Add this code to your Gemfile to ensure it " \ - "continues to work:\n git_source(:bitbucket) do |repo_name|\n " \ - " \"https://\#{user_name}@bitbucket.org/\#{user_name}/\#{repo_name}" \ - ".git\"\n end" - expect(Bundler.ui).to receive(:deprecate).with(msg, true) - subject.gem("not-really-a-gem", :bitbucket => "mcorp/flatlab-rails") - end - end - - context "with gist gems" do - it "warns about removal" do - allow(Bundler.ui).to receive(:deprecate) - msg = "The :gist git source is deprecated, and will be removed " \ - "in Bundler 2.0. Add this code to your Gemfile to ensure it " \ - "continues to work:\n git_source(:gist) do |repo_name|\n " \ - " \"https://gist.github.com/\#{repo_name}.git\"\n" \ - " end" - expect(Bundler.ui).to receive(:deprecate).with(msg, true) - subject.gem("not-really-a-gem", :gist => "1234") - end - end - end - - context "bundle list" do - it "prints a deprecation warning" do - install_gemfile <<-G - source "file://#{gem_repo1}" - gem "rack" - G - - bundle :list - - expect(err).to include("DEPRECATION: `bundle list` is deprecated") - expect(err).to include("Use `bundle show`") - end - end -end diff --git a/spec/other/major_deprecation_spec.rb b/spec/other/major_deprecation_spec.rb index 0b41a723..74f4d0e0 100644 --- a/spec/other/major_deprecation_spec.rb +++ b/spec/other/major_deprecation_spec.rb @@ -81,9 +81,143 @@ describe "major deprecations" do gem 'rack' G - bundle :install, :binstubs - expect(warnings).to have_major_deprecation a_string_including("The --binstubs option will be removed") + bundle :install, :binstubs => true + expect(warnings).to have_major_deprecation a_string_including("the --binstubs option will be removed") end end end + + context "when bundle is run" do + it "should not warn about gems.rb" do + create_file "gems.rb", <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + bundle :install + expect(err).not_to have_major_deprecation + expect(out).not_to have_major_deprecation + end + + it "should print a Gemfile deprecation warning" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + expect(warnings).to have_major_deprecation("gems.rb and gems.locked will be prefered to Gemfile and Gemfile.lock.") + end + + context "with flags" do + it "should print a deprecation warning about autoremembering flags" do + install_gemfile <<-G, :path => "vendor/bundle" + source "file://#{gem_repo1}" + gem "rack" + G + + expect(warnings).to have_major_deprecation a_string_including( + "flags passed to commands will no longer be automatically remembered.") + end + end + end + + context "when Bundler.setup is run in a ruby script" do + it "should print a single deprecation warning" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack", :group => :test + G + + ruby <<-RUBY + require 'rubygems' + require 'bundler' + require 'bundler/vendored_thor' + + Bundler.ui = Bundler::UI::Shell.new + Bundler.setup + Bundler.setup + RUBY + + expect(warnings).to have_major_deprecation("gems.rb and gems.locked will be prefered to Gemfile and Gemfile.lock.") + end + end + + context "when `bundler/deployment` is required in a ruby script" do + it "should print a capistrano deprecation warning" do + ruby(<<-RUBY, :expect_err => true) + require 'bundler/deployment' + RUBY + + expect(warnings).to have_major_deprecation("Bundler no longer integrates " \ + "with Capistrano, but Capistrano provides " \ + "its own integration with Bundler via the " \ + "capistrano-bundler gem. Use it instead.") + end + end + + describe Bundler::Dsl do + before do + @rubygems = double("rubygems") + allow(Bundler::Source::Rubygems).to receive(:new) { @rubygems } + end + + context "with github gems" do + it "warns about the https change" do + msg = "The :github option uses the git: protocol, which is not secure. " \ + "Bundler 2.0 will use the https: protocol, which is secure. Enable this change now by " \ + "running `bundle config github.https true`." + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(msg) + subject.gem("sparks", :github => "indirect/sparks") + end + + it "upgrades to https on request" do + Bundler.settings["github.https"] = true + subject.gem("sparks", :github => "indirect/sparks") + expect(Bundler::SharedHelpers).to receive(:major_deprecation).never + github_uri = "https://github.com/indirect/sparks.git" + expect(subject.dependencies.first.source.uri).to eq(github_uri) + end + end + + context "with bitbucket gems" do + it "warns about removal" do + allow(Bundler.ui).to receive(:deprecate) + msg = "The :bitbucket git source is deprecated, and will be removed " \ + "in Bundler 2.0. Add this code to your Gemfile to ensure it " \ + "continues to work:\n git_source(:bitbucket) do |repo_name|\n " \ + " \"https://\#{user_name}@bitbucket.org/\#{user_name}/\#{repo_name}" \ + ".git\"\n end\n" + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(msg) + subject.gem("not-really-a-gem", :bitbucket => "mcorp/flatlab-rails") + end + end + + context "with gist gems" do + it "warns about removal" do + allow(Bundler.ui).to receive(:deprecate) + msg = "The :gist git source is deprecated, and will be removed " \ + "in Bundler 2.0. Add this code to your Gemfile to ensure it " \ + "continues to work:\n git_source(:gist) do |repo_name|\n " \ + " \"https://gist.github.com/\#{repo_name}.git\"\n" \ + " end\n" + expect(Bundler::SharedHelpers).to receive(:major_deprecation).with(msg) + subject.gem("not-really-a-gem", :gist => "1234") + end + end + end + + context "bundle list" do + it "prints a deprecation warning" do + install_gemfile <<-G + source "file://#{gem_repo1}" + gem "rack" + G + + bundle :list + + out.gsub!(/gems included.*?\[DEPRECATED/im, "[DEPRECATED") + + expect(warnings).to have_major_deprecation("use `bundle show` instead of `bundle list`") + end + end end -- cgit v1.2.3