diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-06-01 12:49:40 +0300 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-06-09 12:44:10 +0900 |
commit | 8f37629519ad330032a38ac0e871b2912ed38a1b (patch) | |
tree | bb0529b77583d47993d8b0d608d68896aa3a5298 /lib/bundler/cli | |
parent | 66508992483ae5d77b56a98427c50c772341c0ac (diff) |
Merge bundler master from upstream.
Pick from 8dd59e3ba97eb80a599f8149f31bf40773b69dc0
Diffstat (limited to 'lib/bundler/cli')
-rw-r--r-- | lib/bundler/cli/add.rb | 43 | ||||
-rw-r--r-- | lib/bundler/cli/common.rb | 11 | ||||
-rw-r--r-- | lib/bundler/cli/doctor.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/exec.rb | 11 | ||||
-rw-r--r-- | lib/bundler/cli/install.rb | 4 | ||||
-rw-r--r-- | lib/bundler/cli/issue.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/outdated.rb | 8 | ||||
-rw-r--r-- | lib/bundler/cli/package.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/plugin.rb | 2 | ||||
-rw-r--r-- | lib/bundler/cli/update.rb | 42 |
10 files changed, 79 insertions, 48 deletions
diff --git a/lib/bundler/cli/add.rb b/lib/bundler/cli/add.rb index 9709e71be0..7c6235f17c 100644 --- a/lib/bundler/cli/add.rb +++ b/lib/bundler/cli/add.rb @@ -2,34 +2,45 @@ module Bundler class CLI::Add + attr_reader :gems, :options, :version + def initialize(options, gems) @gems = gems @options = options - @options[:group] = @options[:group].split(",").map(&:strip) if !@options[:group].nil? && !@options[:group].empty? + @options[:group] = options[:group].split(",").map(&:strip) unless options[:group].nil? + @version = options[:version].split(",").map(&:strip) unless options[:version].nil? end def run - raise InvalidOption, "You can not specify `--strict` and `--optimistic` at the same time." if @options[:strict] && @options[:optimistic] - - # raise error when no gems are specified - raise InvalidOption, "Please specify gems to add." if @gems.empty? + validate_options! + inject_dependencies + perform_bundle_install unless options["skip-install"] + end - version = @options[:version].nil? ? nil : @options[:version].split(",").map(&:strip) + private - unless version.nil? - version.each do |v| - raise InvalidOption, "Invalid gem requirement pattern '#{v}'" unless Gem::Requirement::PATTERN =~ v.to_s - end - end + def perform_bundle_install + Installer.install(Bundler.root, Bundler.definition) + end - dependencies = @gems.map {|g| Bundler::Dependency.new(g, version, @options) } + def inject_dependencies + dependencies = gems.map {|g| Bundler::Dependency.new(g, version, options) } Injector.inject(dependencies, - :conservative_versioning => @options[:version].nil?, # Perform conservative versioning only when version is not specified - :optimistic => @options[:optimistic], - :strict => @options[:strict]) + :conservative_versioning => options[:version].nil?, # Perform conservative versioning only when version is not specified + :optimistic => options[:optimistic], + :strict => options[:strict]) + end + + def validate_options! + raise InvalidOption, "You can not specify `--strict` and `--optimistic` at the same time." if options[:strict] && options[:optimistic] - Installer.install(Bundler.root, Bundler.definition) unless @options["skip-install"] + # raise error when no gems are specified + raise InvalidOption, "Please specify gems to add." if gems.empty? + + version.to_a.each do |v| + raise InvalidOption, "Invalid gem requirement pattern '#{v}'" unless Gem::Requirement::PATTERN =~ v.to_s + end end end end diff --git a/lib/bundler/cli/common.rb b/lib/bundler/cli/common.rb index 9ea52baa6b..cec7bcadb4 100644 --- a/lib/bundler/cli/common.rb +++ b/lib/bundler/cli/common.rb @@ -14,17 +14,18 @@ module Bundler Bundler.ui.info msg end - def self.output_without_groups_message + def self.output_without_groups_message(command) return if Bundler.settings[:without].empty? - Bundler.ui.confirm without_groups_message + Bundler.ui.confirm without_groups_message(command) end - def self.without_groups_message + def self.without_groups_message(command) + command_in_past_tense = command == :install ? "installed" : "updated" groups = Bundler.settings[:without] group_list = [groups[0...-1].join(", "), groups[-1..-1]]. reject {|s| s.to_s.empty? }.join(" and ") group_str = groups.size == 1 ? "group" : "groups" - "Gems in the #{group_str} #{group_list} were not installed." + "Gems in the #{group_str} #{group_list} were not #{command_in_past_tense}." end def self.select_spec(name, regex_match = nil) @@ -59,7 +60,7 @@ module Bundler end def self.gem_not_found_message(missing_gem_name, alternatives) - require "bundler/similarity_detector" + require_relative "../similarity_detector" message = "Could not find gem '#{missing_gem_name}'." alternate_names = alternatives.map {|a| a.respond_to?(:name) ? a.name : a } suggestions = SimilarityDetector.new(alternate_names).similar_word_list(missing_gem_name) diff --git a/lib/bundler/cli/doctor.rb b/lib/bundler/cli/doctor.rb index 6d038937c0..1b3913a300 100644 --- a/lib/bundler/cli/doctor.rb +++ b/lib/bundler/cli/doctor.rb @@ -56,7 +56,7 @@ module Bundler end def check! - require "bundler/cli/check" + require_relative "check" Bundler::CLI::Check.new({}).run end diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb index c29d632307..5dcf4a01ef 100644 --- a/lib/bundler/cli/exec.rb +++ b/lib/bundler/cli/exec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/current_ruby" +require_relative "../current_ruby" module Bundler class CLI::Exec @@ -27,12 +27,7 @@ module Bundler if !Bundler.settings[:disable_exec_load] && ruby_shebang?(bin_path) return kernel_load(bin_path, *args) end - # First, try to exec directly to something in PATH - if Bundler.current_ruby.jruby_18? - kernel_exec(bin_path, *args) - else - kernel_exec([bin_path, cmd], *args) - end + kernel_exec(bin_path, *args) else # exec using the given command kernel_exec(cmd, *args) @@ -69,7 +64,7 @@ module Bundler Process.setproctitle(process_title(file, args)) if Process.respond_to?(:setproctitle) ui = Bundler.ui Bundler.ui = nil - require "bundler/setup" + require_relative "../setup" TRAPPED_SIGNALS.each {|s| trap(s, "DEFAULT") } Kernel.load(file) rescue SystemExit, SignalException diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb index 03edc7fbd2..d823fb632f 100644 --- a/lib/bundler/cli/install.rb +++ b/lib/bundler/cli/install.rb @@ -66,7 +66,7 @@ module Bundler Bundler.load.cache if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen_bundle? Bundler.ui.confirm "Bundle complete! #{dependencies_count_for(definition)}, #{gems_installed_for(definition)}." - Bundler::CLI::Common.output_without_groups_message + Bundler::CLI::Common.output_without_groups_message(:install) if Bundler.use_system_gems? Bundler.ui.confirm "Use `bundle info [gemname]` to see where a bundled gem is installed." @@ -80,7 +80,7 @@ module Bundler warn_ambiguous_gems if CLI::Common.clean_after_install? - require "bundler/cli/clean" + require_relative "clean" Bundler::CLI::Clean.new(options).run end rescue GemNotFound, VersionConflict => e diff --git a/lib/bundler/cli/issue.rb b/lib/bundler/cli/issue.rb index bba1619340..054ce76315 100644 --- a/lib/bundler/cli/issue.rb +++ b/lib/bundler/cli/issue.rb @@ -33,7 +33,7 @@ module Bundler end def doctor - require "bundler/cli/doctor" + require_relative "doctor" Bundler::CLI::Doctor.new({}).run end end diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb index 3a0521de1e..857caf0a03 100644 --- a/lib/bundler/cli/outdated.rb +++ b/lib/bundler/cli/outdated.rb @@ -133,7 +133,7 @@ module Bundler unless options[:parseable] if groups - Bundler.ui.info "===== Group #{groups} =====" + Bundler.ui.info "===== #{groups_text("Group", groups)} =====" else Bundler.ui.info "===== Without group =====" end @@ -167,6 +167,10 @@ module Bundler private + def groups_text(group_text, groups) + "#{group_text}#{groups.split(",").size > 1 ? "s" : ""} \"#{groups}\"" + end + def retrieve_active_spec(strict, definition, current_spec) if strict active_spec = definition.find_resolved_spec(current_spec) @@ -212,7 +216,7 @@ module Bundler elsif options_include_groups || !groups " * #{spec_outdated_info}" else - " * #{spec_outdated_info} in groups \"#{groups}\"" + " * #{spec_outdated_info} in #{groups_text("group", groups)}" end Bundler.ui.info output_message.rstrip diff --git a/lib/bundler/cli/package.rb b/lib/bundler/cli/package.rb index cd01ce422e..120a3fdcf3 100644 --- a/lib/bundler/cli/package.rb +++ b/lib/bundler/cli/package.rb @@ -25,7 +25,7 @@ module Bundler private def install - require "bundler/cli/install" + require_relative "install" options = self.options.dup if Bundler.settings[:cache_all_platforms] options["local"] = false diff --git a/lib/bundler/cli/plugin.rb b/lib/bundler/cli/plugin.rb index b5dd5b6d4b..1155c4ec9b 100644 --- a/lib/bundler/cli/plugin.rb +++ b/lib/bundler/cli/plugin.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require "bundler/vendored_thor" +require_relative "../vendored_thor" module Bundler class CLI::Plugin < Thor desc "install PLUGINS", "Install the plugin from the source" diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb index b088853768..afd386bd54 100644 --- a/lib/bundler/cli/update.rb +++ b/lib/bundler/cli/update.rb @@ -58,24 +58,44 @@ module Bundler Bundler.settings.set_command_option_if_given :jobs, opts["jobs"] Bundler.definition.validate_runtime! + + if locked_gems = Bundler.definition.locked_gems + previous_locked_info = locked_gems.specs.reduce({}) do |h, s| + h[s.name] = { :spec => s, :version => s.version, :source => s.source.to_s } + h + end + end + installer = Installer.install Bundler.root, Bundler.definition, opts Bundler.load.cache if Bundler.app_cache.exist? if CLI::Common.clean_after_install? - require "bundler/cli/clean" + require_relative "clean" Bundler::CLI::Clean.new(options).run end - if locked_gems = Bundler.definition.locked_gems + if locked_gems gems.each do |name| - locked_version = locked_gems.specs.find {|s| s.name == name } - locked_version &&= locked_version.version - next unless locked_version - new_version = Bundler.definition.specs[name].first - new_version &&= new_version.version - if !new_version - Bundler.ui.warn "Bundler attempted to update #{name} but it was removed from the bundle" - elsif new_version < locked_version + locked_info = previous_locked_info[name] + next unless locked_info + + locked_spec = locked_info[:spec] + new_spec = Bundler.definition.specs[name].first + unless new_spec + if Bundler.rubygems.platforms.none? {|p| locked_spec.match_platform(p) } + Bundler.ui.warn "Bundler attempted to update #{name} but it was not considered because it is for a different platform from the current one" + end + + next + end + + locked_source = locked_info[:source] + new_source = new_spec.source.to_s + next if locked_source != new_source + + new_version = new_spec.version + locked_version = locked_info[:version] + if new_version < locked_version Bundler.ui.warn "Note: #{name} version regressed from #{locked_version} to #{new_version}" elsif new_version == locked_version Bundler.ui.warn "Bundler attempted to update #{name} but its version stayed the same" @@ -84,7 +104,7 @@ module Bundler end Bundler.ui.confirm "Bundle updated!" - Bundler::CLI::Common.output_without_groups_message + Bundler::CLI::Common.output_without_groups_message(:update) Bundler::CLI::Common.output_post_install_messages installer.post_install_messages end end |