Merge pull request #8327 from chrisroberts/plugins/local-path

Force path as preferred source on local install
This commit is contained in:
Chris Roberts 2017-03-07 15:00:39 -08:00 committed by GitHub
commit c03ca851b1
2 changed files with 22 additions and 9 deletions

View File

@ -3,6 +3,7 @@ require "pathname"
require "set" require "set"
require "tempfile" require "tempfile"
require "fileutils" require "fileutils"
require "uri"
require "rubygems/package" require "rubygems/package"
require "rubygems/uninstaller" require "rubygems/uninstaller"
@ -113,7 +114,7 @@ module Vagrant
plugin_source.spec.name => { plugin_source.spec.name => {
"gem_version" => plugin_source.spec.version.to_s, "gem_version" => plugin_source.spec.version.to_s,
"local_source" => plugin_source, "local_source" => plugin_source,
"sources" => opts.fetch(:sources, Gem.sources.map(&:to_s)) "sources" => opts.fetch(:sources, [])
} }
} }
@logger.debug("Installing local plugin - #{plugin_info}") @logger.debug("Installing local plugin - #{plugin_info}")
@ -209,9 +210,6 @@ module Vagrant
protected protected
def internal_install(plugins, update, **extra) def internal_install(plugins, update, **extra)
# Only allow defined Gem sources
Gem.sources.clear
update = {} if !update.is_a?(Hash) update = {} if !update.is_a?(Hash)
skips = [] skips = []
source_list = {} source_list = {}
@ -225,11 +223,12 @@ module Vagrant
else else
gem_version = info['gem_version'].to_s.empty? ? '> 0' : info['gem_version'] gem_version = info['gem_version'].to_s.empty? ? '> 0' : info['gem_version']
end end
source_list[name] ||= []
if plugin_source = info.delete("local_source") if plugin_source = info.delete("local_source")
installer_set.add_local(plugin_source.spec.name, plugin_source.spec, plugin_source) installer_set.add_local(plugin_source.spec.name, plugin_source.spec, plugin_source)
source_list[name] << plugin_source.path
end end
Array(info["sources"]).each do |source| Array(info["sources"]).each do |source|
source_list[name] ||= []
if !source.end_with?("/") if !source.end_with?("/")
source = source + "/" source = source + "/"
end end
@ -244,8 +243,12 @@ module Vagrant
default_sources = DEFAULT_GEM_SOURCES & all_sources default_sources = DEFAULT_GEM_SOURCES & all_sources
all_sources -= DEFAULT_GEM_SOURCES all_sources -= DEFAULT_GEM_SOURCES
# Only allow defined Gem sources
Gem.sources.clear
@logger.debug("Enabling user defined remote RubyGems sources") @logger.debug("Enabling user defined remote RubyGems sources")
all_sources.each do |src| all_sources.each do |src|
next if URI.parse(src).scheme.nil?
@logger.debug("Adding RubyGems source #{src}") @logger.debug("Adding RubyGems source #{src}")
Gem.sources << src Gem.sources << src
end end
@ -255,9 +258,10 @@ module Vagrant
@logger.debug("Adding source - #{src}") @logger.debug("Adding source - #{src}")
Gem.sources << src Gem.sources << src
end end
source_list.values.each{|srcs| srcs.delete_if{|src| default_sources.include?(src)}}
installer_set.prefer_sources = source_list installer_set.prefer_sources = source_list
@logger.debug("Current source list for install: #{Gem.sources}") @logger.debug("Current source list for install: #{Gem.sources.to_a}")
# Create the request set for the new plugins # Create the request set for the new plugins
request_set = Gem::RequestSet.new(*plugin_deps) request_set = Gem::RequestSet.new(*plugin_deps)
@ -401,8 +405,16 @@ module Vagrant
def find_all(req) def find_all(req)
result = super result = super
subset = result.find_all do |idx_spec| subset = result.find_all do |idx_spec|
prefer_sources[req.name] && preferred = false
prefer_sources[req.name].include?(idx_spec.source.uri.to_s) if prefer_sources[req.name]
if idx_spec.source.respond_to?(:path)
preferred = prefer_sources[req.name].include?(idx_spec.source.path.to_s)
end
if !preferred
preferred = prefer_sources[req.name].include?(idx_spec.source.uri.to_s)
end
end
preferred
end end
subset.empty? ? result : subset subset.empty? ? result : subset
end end

View File

@ -64,10 +64,11 @@ describe Vagrant::Util::Subprocess do
end end
context "when subprocess is running" do context "when subprocess is running" do
it "should return true" do it "should return true" do
sp = described_class.new("sleep", "0.2") sp = described_class.new("sleep", "5")
thread = Thread.new{ sp.execute } thread = Thread.new{ sp.execute }
sleep(0.1) sleep(0.1)
expect(sp.running?).to be_true expect(sp.running?).to be_true
sp.stop
thread.join thread.join
end end
end end