Skip to content

Commit

Permalink
add an installer constructor for paths
Browse files Browse the repository at this point in the history
This allows us to provide objects that quack like a `Gem::Package` to
the installer class via `new`.
  • Loading branch information
tenderlove committed Apr 10, 2015
1 parent de3d2d3 commit de3f8d0
Show file tree
Hide file tree
Showing 15 changed files with 55 additions and 40 deletions.
2 changes: 1 addition & 1 deletion lib/rubygems/commands/install_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def install_gem_without_dependencies name, req # :nodoc:
gem = fetcher.download_to_cache dependency
end

inst = Gem::Installer.new gem, options
inst = Gem::Installer.at gem, options
inst.install

require 'rubygems/dependency_installer'
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/commands/pristine_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def execute
install_defaults.to_s['--env-shebang']
end

installer = Gem::Installer.new(gem,
installer = Gem::Installer.at(gem,
:wrappers => true,
:force => true,
:install_dir => spec.base_dir,
Expand Down
19 changes: 17 additions & 2 deletions lib/rubygems/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ def exec_format

end

##
# Construct an installer object for the gem file located at +path+

def self.at path, options = {}
package = Gem::Package.new path
new package, options
end

##
# Constructs an Installer instance that will install the gem located at
# +gem+. +options+ is a Hash with the following keys:
Expand All @@ -122,11 +130,18 @@ def exec_format
# :build_args:: An Array of arguments to pass to the extension builder
# process. If not set, then Gem::Command.build_args is used

def initialize(gem, options={})
def initialize(package, options={})
require 'fileutils'

@options = options
@package = Gem::Package.new gem
if package.is_a? String
@package = Gem::Package.new package
if $VERBOSE
warn "constructing an Installer object with a string is deprecated. Please use Gem::Installer.at (called from: #{caller.first})"
end
else
@package = package
end

process_options

Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems/installer_test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,15 @@ def util_setup_gem(ui = @ui) # HACK fix use_ui to make this automatic
end
end

@installer = Gem::Installer.new @gem
@installer = Gem::Installer.at @gem
end

##
# Creates an installer for +spec+ that will install into +gem_home+. If
# +user+ is true a user-install will be performed.

def util_installer(spec, gem_home, user=false)
Gem::Installer.new(spec.cache_file,
Gem::Installer.at(spec.cache_file,
:install_dir => gem_home,
:user_install => user)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/request_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def install options, &block # :yields: request, installer

path = req.download cache_dir

inst = Gem::Installer.new path, options
inst = Gem::Installer.at path, options

yield req, inst if block_given?

Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/resolver/git_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def add_dependency dependency # :nodoc:
def install options = {}
require 'rubygems/installer'

installer = Gem::Installer.new '', options
installer = Gem::Installer.at '', options
installer.spec = spec

yield installer if block_given?
Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/resolver/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def install options = {}

gem = source.download spec, destination

installer = Gem::Installer.new gem, options
installer = Gem::Installer.at gem, options

yield installer if block_given?

Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/test_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ def install_gem spec, options = {}
gem = File.join(@tempdir, File.basename(spec.cache_file)).untaint
end

Gem::Installer.new(gem, options.merge({:wrappers => true})).install
Gem::Installer.at(gem, options.merge({:wrappers => true})).install
end

##
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/simple_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@directory = options[:directory] || Gem.dir
@force = options[:force]
gem = Gem::Installer.new(__FILE__).install(@force, @directory)
gem = Gem::Installer.at(__FILE__).install(@force, @directory)
if options[:gen_rdoc]
Gem::DocManager.new(gem).generate_rdoc
end
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_commands_install_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ def test_execute_uses_deps_a_gemdeps_with_a_path
fetcher.gem 'r', '2.0', 'q' => nil
end

i = Gem::Installer.new specs['q-1.0'].cache_file, :install_dir => "gf-path"
i = Gem::Installer.at specs['q-1.0'].cache_file, :install_dir => "gf-path"
i.install

assert File.file?("gf-path/specifications/q-1.0.gemspec"), "not installed"
Expand Down
4 changes: 2 additions & 2 deletions test/rubygems/test_gem_commands_unpack_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def test_execute_exact_match

foo_path = File.join(@tempdir, "#{foo_spec.full_name}.gem")
foo_bar_path = File.join(@tempdir, "#{foo_bar_spec.full_name}.gem")
Gem::Installer.new(foo_path).install
Gem::Installer.new(foo_bar_path).install
Gem::Installer.at(foo_path).install
Gem::Installer.at(foo_bar_path).install

@cmd.options[:args] = %w[foo]

Expand Down
10 changes: 5 additions & 5 deletions test/rubygems/test_gem_dependency_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def test_install_dependency_development_shallow
def test_install_dependency_existing
util_setup_gems

Gem::Installer.new(@a1_gem).install
Gem::Installer.at(@a1_gem).install
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir
inst = nil
Expand Down Expand Up @@ -437,7 +437,7 @@ def test_install_dependency_existing_extension

_, f1_gem = util_gem 'f', '1', 'e' => nil

Gem::Installer.new(e1_gem).install
Gem::Installer.at(e1_gem).install
FileUtils.rm_r e1.extension_dir

FileUtils.mv e1_gem, @tempdir
Expand Down Expand Up @@ -525,7 +525,7 @@ def test_install_local_dependency_installed
inst = nil

Dir.chdir @tempdir do
Gem::Installer.new('a-1.gem').install
Gem::Installer.at('a-1.gem').install

inst = Gem::DependencyInstaller.new :domain => :local
inst.install 'b-1.gem'
Expand Down Expand Up @@ -669,7 +669,7 @@ def test_install_install_dir
FileUtils.mv @a1_gem, @tempdir
FileUtils.mv @b1_gem, @tempdir

inst = Gem::Installer.new @a1.file_name
inst = Gem::Installer.at @a1.file_name
inst.install

gemhome2 = File.join @tempdir, 'gemhome2'
Expand Down Expand Up @@ -799,7 +799,7 @@ def test_install_dual_repository
def test_install_reinstall
util_setup_gems

Gem::Installer.new(@a1_gem).install
Gem::Installer.at(@a1_gem).install
FileUtils.mv @a1_gem, @tempdir
inst = nil

Expand Down
4 changes: 2 additions & 2 deletions test/rubygems/test_gem_install_update_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def test_user_install_enabled

assert @cmd.options[:user_install]

@installer = Gem::Installer.new @gem, @cmd.options
@installer = Gem::Installer.at @gem, @cmd.options
@installer.install
assert_path_exists File.join(Gem.user_dir, 'gems')
assert_path_exists File.join(Gem.user_dir, 'gems', @spec.full_name)
Expand All @@ -149,7 +149,7 @@ def test_user_install_disabled_read_only
Gem.use_paths @gemhome, @userhome

assert_raises(Gem::FilePermissionError) do
Gem::Installer.new(@gem, @cmd.options).install
Gem::Installer.at(@gem, @cmd.options).install
end
end
ensure
Expand Down
36 changes: 18 additions & 18 deletions test/rubygems/test_gem_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def test_ensure_loadable_spec
s.add_dependency 'garbage ~> 5'
end

installer = Gem::Installer.new a_gem
installer = Gem::Installer.at a_gem

e = assert_raises Gem::InstallError do
installer.ensure_loadable_spec
Expand All @@ -275,7 +275,7 @@ def test_ensure_loadable_spec_security_policy
end

policy = Gem::Security::HighSecurity
installer = Gem::Installer.new a_gem, :security_policy => policy
installer = Gem::Installer.at a_gem, :security_policy => policy

assert_raises Gem::Security::Exception do
installer.ensure_loadable_spec
Expand Down Expand Up @@ -322,7 +322,7 @@ def test_generate_bin_bindir_with_user_install_warning
:install_dir => "/non/existent"
}

inst = Gem::Installer.new '', options
inst = Gem::Installer.at '', options

Gem::Installer.path_warning = false

Expand Down Expand Up @@ -672,14 +672,14 @@ def test_initialize
util_build_gem spec
FileUtils.mv spec.cache_file, @tempdir

installer = Gem::Installer.new gem
installer = Gem::Installer.at gem

assert_equal File.join(@gemhome, 'gems', spec.full_name), installer.gem_dir
assert_equal File.join(@gemhome, 'bin'), installer.bin_dir
end

def test_initialize_user_install
installer = Gem::Installer.new @gem, :user_install => true
installer = Gem::Installer.at @gem, :user_install => true

assert_equal File.join(Gem.user_dir, 'gems', @spec.full_name),
installer.gem_dir
Expand All @@ -688,7 +688,7 @@ def test_initialize_user_install

def test_initialize_user_install_bin_dir
installer =
Gem::Installer.new @gem, :user_install => true, :bin_dir => @tempdir
Gem::Installer.at @gem, :user_install => true, :bin_dir => @tempdir

assert_equal File.join(Gem.user_dir, 'gems', @spec.full_name),
installer.gem_dir
Expand Down Expand Up @@ -870,7 +870,7 @@ def test_install_with_no_prior_files
Gem::Package.build @spec
end
end
@installer = Gem::Installer.new @gem
@installer = Gem::Installer.at @gem
build_rake_in do
use_ui @ui do
assert_equal @spec, @installer.install
Expand All @@ -884,7 +884,7 @@ def test_install_with_no_prior_files

def test_install_force
use_ui @ui do
installer = Gem::Installer.new old_ruby_required, :force => true
installer = Gem::Installer.at old_ruby_required, :force => true
installer.install
end

Expand Down Expand Up @@ -993,7 +993,7 @@ def test_install_with_message
use_ui @ui do
path = Gem::Package.build @spec

@installer = Gem::Installer.new path
@installer = Gem::Installer.at path
@installer.install
end

Expand All @@ -1016,7 +1016,7 @@ def test_install_extension_dir
use_ui @ui do
path = Gem::Package.build @spec

installer = Gem::Installer.new path, :install_dir => gemhome2
installer = Gem::Installer.at path, :install_dir => gemhome2
installer.install
end

Expand Down Expand Up @@ -1056,7 +1056,7 @@ def test_install_extension_and_script
use_ui @ui do
path = Gem::Package.build @spec

@installer = Gem::Installer.new path
@installer = Gem::Installer.at path
@installer.install
end
assert_path_exists File.join @spec.gem_dir, rb
Expand Down Expand Up @@ -1097,7 +1097,7 @@ def test_install_extension_flat
use_ui @ui do
path = Gem::Package.build @spec

@installer = Gem::Installer.new path
@installer = Gem::Installer.at path
@installer.install
end
assert_path_exists so
Expand Down Expand Up @@ -1175,7 +1175,7 @@ def test_pre_install_checks_dependencies_install_dir
# that it work everything out on it's own.
Gem::Specification.reset

installer = Gem::Installer.new gem, :install_dir => gemhome2
installer = Gem::Installer.at gem, :install_dir => gemhome2

build_rake_in do
use_ui @ui do
Expand All @@ -1186,7 +1186,7 @@ def test_pre_install_checks_dependencies_install_dir

def test_pre_install_checks_ruby_version
use_ui @ui do
installer = Gem::Installer.new old_ruby_required
installer = Gem::Installer.at old_ruby_required
e = assert_raises Gem::InstallError do
installer.pre_install_checks
end
Expand All @@ -1205,7 +1205,7 @@ def test_pre_install_checks_wrong_rubygems_version
gem = File.join(@gemhome, 'cache', spec.file_name)

use_ui @ui do
@installer = Gem::Installer.new gem
@installer = Gem::Installer.at gem
e = assert_raises Gem::InstallError do
@installer.pre_install_checks
end
Expand All @@ -1231,7 +1231,7 @@ def test_process_options
def test_process_options_build_root
build_root = File.join @tempdir, 'build_root'

@installer = Gem::Installer.new @gem, :build_root => build_root
@installer = Gem::Installer.at @gem, :build_root => build_root

assert_equal Pathname(build_root), @installer.build_root
assert_equal File.join(build_root, @gemhome, 'bin'), @installer.bin_dir
Expand Down Expand Up @@ -1406,7 +1406,7 @@ def test_write_build_info_file_empty
end

def test_write_build_info_file_install_dir
installer = Gem::Installer.new @gem, :install_dir => "#{@gemhome}2"
installer = Gem::Installer.at @gem, :install_dir => "#{@gemhome}2"

installer.build_args = %w[
--with-libyaml-dir /usr/local/Cellar/libyaml/0.1.4
Expand All @@ -1426,7 +1426,7 @@ def test_write_cache_file
FileUtils.mv cache_file, gem
refute_path_exists cache_file

installer = Gem::Installer.new gem
installer = Gem::Installer.at gem
installer.spec = @spec
installer.gem_home = @gemhome

Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_gem_uninstaller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def test_uninstall_extension
use_ui @ui do
path = Gem::Package.build @spec

installer = Gem::Installer.new path
installer = Gem::Installer.at path
installer.install
end

Expand Down

0 comments on commit de3f8d0

Please sign in to comment.