rubygems-update 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rubygems-update might be problematic. Click here for more details.

Files changed (172) hide show
  1. data.tar.gz.sig +0 -0
  2. data/ChangeLog +248 -0
  3. data/README +2 -0
  4. data/Rakefile +47 -23
  5. data/bin/gem +9 -4
  6. data/bin/update_rubygems +15 -1
  7. data/examples/application/bin/myapp +0 -0
  8. data/lib/rubygems.rb +506 -373
  9. data/lib/rubygems/builder.rb +14 -7
  10. data/lib/rubygems/command.rb +9 -9
  11. data/lib/rubygems/command_manager.rb +1 -0
  12. data/lib/rubygems/commands/cleanup_command.rb +67 -69
  13. data/lib/rubygems/commands/environment_command.rb +16 -10
  14. data/lib/rubygems/commands/fetch_command.rb +7 -9
  15. data/lib/rubygems/commands/install_command.rb +9 -3
  16. data/lib/rubygems/commands/list_command.rb +2 -4
  17. data/lib/rubygems/commands/mirror_command.rb +1 -1
  18. data/lib/rubygems/commands/query_command.rb +52 -5
  19. data/lib/rubygems/commands/sources_command.rb +19 -10
  20. data/lib/rubygems/commands/specification_command.rb +10 -6
  21. data/lib/rubygems/commands/uninstall_command.rb +23 -6
  22. data/lib/rubygems/commands/unpack_command.rb +15 -3
  23. data/lib/rubygems/commands/update_command.rb +27 -25
  24. data/lib/rubygems/custom_require.rb +1 -1
  25. data/lib/rubygems/defaults.rb +8 -1
  26. data/lib/rubygems/dependency_installer.rb +72 -104
  27. data/lib/rubygems/digest/digest_adapter.rb +0 -0
  28. data/lib/rubygems/digest/md5.rb +0 -0
  29. data/lib/rubygems/digest/sha1.rb +0 -0
  30. data/lib/rubygems/digest/sha2.rb +0 -0
  31. data/lib/rubygems/exceptions.rb +22 -1
  32. data/lib/rubygems/format.rb +16 -10
  33. data/lib/rubygems/indexer.rb +46 -33
  34. data/lib/rubygems/indexer/abstract_index_builder.rb +10 -2
  35. data/lib/rubygems/indexer/latest_index_builder.rb +35 -0
  36. data/lib/rubygems/indexer/master_index_builder.rb +9 -8
  37. data/lib/rubygems/indexer/quick_index_builder.rb +5 -3
  38. data/lib/rubygems/install_update_options.rb +7 -1
  39. data/lib/rubygems/installer.rb +8 -5
  40. data/lib/rubygems/package.rb +17 -774
  41. data/lib/rubygems/package/f_sync_dir.rb +24 -0
  42. data/lib/rubygems/package/tar_header.rb +245 -0
  43. data/lib/rubygems/package/tar_input.rb +219 -0
  44. data/lib/rubygems/package/tar_output.rb +143 -0
  45. data/lib/rubygems/package/tar_reader.rb +86 -0
  46. data/lib/rubygems/package/tar_reader/entry.rb +99 -0
  47. data/lib/rubygems/package/tar_writer.rb +180 -0
  48. data/lib/rubygems/remote_fetcher.rb +131 -16
  49. data/lib/rubygems/requirement.rb +2 -0
  50. data/lib/rubygems/rubygems_version.rb +1 -1
  51. data/lib/rubygems/security.rb +1 -0
  52. data/lib/rubygems/server.rb +85 -104
  53. data/lib/rubygems/source_index.rb +412 -329
  54. data/lib/rubygems/source_info_cache.rb +232 -99
  55. data/lib/rubygems/source_info_cache_entry.rb +14 -4
  56. data/lib/rubygems/specification.rb +9 -10
  57. data/lib/rubygems/timer.rb +0 -0
  58. data/lib/rubygems/uninstaller.rb +56 -32
  59. data/lib/rubygems/user_interaction.rb +4 -10
  60. data/lib/rubygems/validator.rb +0 -0
  61. data/scripts/gemdoc.rb +0 -0
  62. data/scripts/specdoc.rb +0 -0
  63. data/setup.rb +56 -19
  64. data/test/gem_installer_test_case.rb +86 -0
  65. data/test/gem_installer_test_case.rbc +0 -0
  66. data/test/gem_package_tar_test_case.rb +146 -0
  67. data/test/gem_package_tar_test_case.rbc +0 -0
  68. data/test/gemutilities.rb +123 -38
  69. data/test/gemutilities.rbc +0 -0
  70. data/test/mockgemui.rb +5 -13
  71. data/test/mockgemui.rbc +0 -0
  72. data/test/private_key.pem +27 -0
  73. data/test/public_cert.pem +20 -0
  74. data/test/simple_gem.rbc +0 -0
  75. data/test/test_config.rbc +0 -0
  76. data/test/test_gem.rb +46 -4
  77. data/test/test_gem.rbc +0 -0
  78. data/test/test_gem_builder.rbc +0 -0
  79. data/test/test_gem_command.rbc +0 -0
  80. data/test/test_gem_command_manager.rb +4 -2
  81. data/test/test_gem_command_manager.rbc +0 -0
  82. data/test/test_gem_commands_build_command.rbc +0 -0
  83. data/test/test_gem_commands_cert_command.rb +5 -1
  84. data/test/test_gem_commands_cert_command.rbc +0 -0
  85. data/test/test_gem_commands_check_command.rbc +0 -0
  86. data/test/test_gem_commands_contents_command.rbc +0 -0
  87. data/test/test_gem_commands_dependency_command.rbc +0 -0
  88. data/test/test_gem_commands_environment_command.rb +17 -1
  89. data/test/test_gem_commands_environment_command.rbc +0 -0
  90. data/test/test_gem_commands_fetch_command.rb +6 -5
  91. data/test/test_gem_commands_fetch_command.rbc +0 -0
  92. data/test/test_gem_commands_generate_index_command.rbc +0 -0
  93. data/test/test_gem_commands_install_command.rb +36 -28
  94. data/test/test_gem_commands_install_command.rbc +0 -0
  95. data/test/test_gem_commands_mirror_command.rbc +0 -0
  96. data/test/test_gem_commands_pristine_command.rbc +0 -0
  97. data/test/test_gem_commands_query_command.rb +143 -19
  98. data/test/test_gem_commands_query_command.rbc +0 -0
  99. data/test/test_gem_commands_server_command.rb +1 -1
  100. data/test/test_gem_commands_server_command.rbc +0 -0
  101. data/test/test_gem_commands_sources_command.rb +67 -9
  102. data/test/test_gem_commands_sources_command.rbc +0 -0
  103. data/test/test_gem_commands_specification_command.rb +3 -2
  104. data/test/test_gem_commands_specification_command.rbc +0 -0
  105. data/test/test_gem_commands_unpack_command.rb +46 -4
  106. data/test/test_gem_commands_unpack_command.rbc +0 -0
  107. data/test/test_gem_commands_update_command.rb +174 -0
  108. data/test/test_gem_commands_update_command.rbc +0 -0
  109. data/test/test_gem_config_file.rbc +0 -0
  110. data/test/test_gem_dependency.rbc +0 -0
  111. data/test/test_gem_dependency_installer.rb +172 -187
  112. data/test/test_gem_dependency_installer.rbc +0 -0
  113. data/test/test_gem_dependency_list.rbc +0 -0
  114. data/test/test_gem_digest.rb +0 -0
  115. data/test/test_gem_digest.rbc +0 -0
  116. data/test/test_gem_doc_manager.rbc +0 -0
  117. data/test/test_gem_ext_configure_builder.rb +9 -6
  118. data/test/test_gem_ext_configure_builder.rbc +0 -0
  119. data/test/test_gem_ext_ext_conf_builder.rbc +0 -0
  120. data/test/test_gem_ext_rake_builder.rbc +0 -0
  121. data/test/test_gem_format.rb +1 -1
  122. data/test/test_gem_format.rbc +0 -0
  123. data/test/test_gem_gem_path_searcher.rbc +0 -0
  124. data/test/test_gem_gem_runner.rbc +0 -0
  125. data/test/test_gem_indexer.rb +7 -2
  126. data/test/test_gem_indexer.rbc +0 -0
  127. data/test/test_gem_install_update_options.rbc +0 -0
  128. data/test/test_gem_installer.rb +5 -84
  129. data/test/test_gem_installer.rbc +0 -0
  130. data/test/test_gem_local_remote_options.rbc +0 -0
  131. data/test/test_gem_outdated_command.rbc +0 -0
  132. data/test/test_gem_package_tar_header.rb +137 -0
  133. data/test/test_gem_package_tar_header.rbc +0 -0
  134. data/test/test_gem_package_tar_input.rb +119 -0
  135. data/test/test_gem_package_tar_input.rbc +0 -0
  136. data/test/test_gem_package_tar_output.rb +104 -0
  137. data/test/test_gem_package_tar_output.rbc +0 -0
  138. data/test/test_gem_package_tar_reader.rb +53 -0
  139. data/test/test_gem_package_tar_reader.rbc +0 -0
  140. data/test/test_gem_package_tar_reader_entry.rb +116 -0
  141. data/test/test_gem_package_tar_reader_entry.rbc +0 -0
  142. data/test/test_gem_package_tar_writer.rb +151 -0
  143. data/test/test_gem_package_tar_writer.rbc +0 -0
  144. data/test/test_gem_platform.rbc +0 -0
  145. data/test/test_gem_remote_fetcher.rb +189 -17
  146. data/test/test_gem_remote_fetcher.rbc +0 -0
  147. data/test/test_gem_requirement.rbc +0 -0
  148. data/test/test_gem_server.rb +13 -12
  149. data/test/test_gem_server.rbc +0 -0
  150. data/test/test_gem_source_index.rb +305 -56
  151. data/test/test_gem_source_index.rbc +0 -0
  152. data/test/test_gem_source_info_cache.rb +179 -53
  153. data/test/test_gem_source_info_cache.rbc +0 -0
  154. data/test/test_gem_source_info_cache_entry.rb +41 -10
  155. data/test/test_gem_source_info_cache_entry.rbc +0 -0
  156. data/test/test_gem_specification.rb +7 -7
  157. data/test/test_gem_specification.rbc +0 -0
  158. data/test/test_gem_stream_ui.rbc +0 -0
  159. data/test/test_gem_uninstaller.rb +43 -0
  160. data/test/test_gem_uninstaller.rbc +0 -0
  161. data/test/test_gem_validator.rbc +0 -0
  162. data/test/test_gem_version.rb +1 -1
  163. data/test/test_gem_version.rbc +0 -0
  164. data/test/test_gem_version_option.rbc +0 -0
  165. data/test/test_kernel.rb +1 -0
  166. data/test/test_kernel.rbc +0 -0
  167. metadata +85 -8
  168. metadata.gz.sig +0 -0
  169. data/lib/rubygems/gem_open_uri.rb +0 -7
  170. data/lib/rubygems/open-uri.rb +0 -773
  171. data/test/test_open_uri.rb +0 -13
  172. data/test/test_package.rb +0 -608
@@ -39,8 +39,11 @@ class Gem::Commands::SourcesCommand < Gem::Command
39
39
  options[:list] = !(options[:add] || options[:remove] || options[:clear_all] || options[:update])
40
40
 
41
41
  if options[:clear_all] then
42
- remove_cache_file("user", Gem::SourceInfoCache.user_cache_file)
43
- remove_cache_file("system", Gem::SourceInfoCache.system_cache_file)
42
+ sic = Gem::SourceInfoCache
43
+ remove_cache_file 'user', sic.user_cache_file
44
+ remove_cache_file 'latest user', sic.latest_user_cache_file
45
+ remove_cache_file 'system', sic.system_cache_file
46
+ remove_cache_file 'latest system', sic.latest_system_cache_file
44
47
  end
45
48
 
46
49
  if options[:add] then
@@ -48,7 +51,7 @@ class Gem::Commands::SourcesCommand < Gem::Command
48
51
 
49
52
  sice = Gem::SourceInfoCacheEntry.new nil, nil
50
53
  begin
51
- sice.refresh source_uri
54
+ sice.refresh source_uri, true
52
55
 
53
56
  Gem::SourceInfoCache.cache_data[source_uri] = sice
54
57
  Gem::SourceInfoCache.cache.update
@@ -66,7 +69,7 @@ class Gem::Commands::SourcesCommand < Gem::Command
66
69
  end
67
70
 
68
71
  if options[:update] then
69
- Gem::SourceInfoCache.cache.refresh
72
+ Gem::SourceInfoCache.cache true
70
73
  Gem::SourceInfoCache.cache.flush
71
74
 
72
75
  say "source cache successfully updated"
@@ -78,6 +81,11 @@ class Gem::Commands::SourcesCommand < Gem::Command
78
81
  unless Gem.sources.include? source_uri then
79
82
  say "source #{source_uri} not present in cache"
80
83
  else
84
+ begin # HACK figure out how to get the cache w/o update
85
+ Gem::SourceInfoCache.cache
86
+ rescue Gem::RemoteFetcher::FetchError
87
+ end
88
+
81
89
  Gem::SourceInfoCache.cache_data.delete source_uri
82
90
  Gem::SourceInfoCache.cache.update
83
91
  Gem::SourceInfoCache.cache.flush
@@ -92,19 +100,20 @@ class Gem::Commands::SourcesCommand < Gem::Command
92
100
  say "*** CURRENT SOURCES ***"
93
101
  say
94
102
 
95
- Gem.sources.each do |source_uri|
96
- say source_uri
103
+ Gem.sources.each do |source|
104
+ say source
97
105
  end
98
106
  end
99
107
  end
100
108
 
101
109
  private
102
110
 
103
- def remove_cache_file(desc, fn)
104
- FileUtils.rm_rf fn rescue nil
105
- if ! File.exist?(fn)
111
+ def remove_cache_file(desc, path)
112
+ FileUtils.rm_rf path
113
+
114
+ if not File.exist?(path) then
106
115
  say "*** Removed #{desc} source cache ***"
107
- elsif ! File.writable?(fn)
116
+ elsif not File.writable?(path) then
108
117
  say "*** Unable to remove #{desc} source cache (write protected) ***"
109
118
  else
110
119
  say "*** Unable to remove #{desc} source cache ***"
@@ -3,6 +3,7 @@ require 'rubygems/command'
3
3
  require 'rubygems/local_remote_options'
4
4
  require 'rubygems/version_option'
5
5
  require 'rubygems/source_info_cache'
6
+ require 'rubygems/format'
6
7
 
7
8
  class Gem::Commands::SpecificationCommand < Gem::Command
8
9
 
@@ -41,13 +42,16 @@ class Gem::Commands::SpecificationCommand < Gem::Command
41
42
  gem = get_one_gem_name
42
43
 
43
44
  if local? then
44
- source_index = Gem::SourceIndex.from_installed_gems
45
- specs.push(*source_index.search(/\A#{gem}\z/, options[:version]))
45
+ if File.exist? gem then
46
+ specs << Gem::Format.from_file_by_path(gem).spec rescue nil
47
+ end
48
+
49
+ if specs.empty? then
50
+ specs.push(*Gem.source_index.search(/\A#{gem}\z/, options[:version]))
51
+ end
46
52
  end
47
53
 
48
54
  if remote? then
49
- alert_warning "Remote information is not complete\n\n"
50
-
51
55
  Gem::SourceInfoCache.cache_data.each do |_,sice|
52
56
  specs.push(*sice.source_index.search(gem, options[:version]))
53
57
  end
@@ -58,12 +62,12 @@ class Gem::Commands::SpecificationCommand < Gem::Command
58
62
  terminate_interaction 1
59
63
  end
60
64
 
61
- output = lambda { |spec| say spec.to_yaml; say "\n" }
65
+ output = lambda { |s| say s.to_yaml; say "\n" }
62
66
 
63
67
  if options[:all] then
64
68
  specs.each(&output)
65
69
  else
66
- spec = specs.sort_by { |spec| spec.version }.last
70
+ spec = specs.sort_by { |s| s.version }.last
67
71
  output[spec]
68
72
  end
69
73
  end
@@ -18,18 +18,28 @@ module Gem
18
18
  options[:all] = value
19
19
  end
20
20
 
21
- add_option('-i', '--[no-]ignore-dependencies',
22
- 'Ignore dependency requirements while',
23
- 'uninstalling') do |value, options|
21
+ add_option('-I', '--[no-]ignore-dependencies',
22
+ 'Ignore dependency requirements while',
23
+ 'uninstalling') do |value, options|
24
24
  options[:ignore] = value
25
25
  end
26
26
 
27
- add_option('-x', '--[no-]executables',
27
+ add_option('-x', '--[no-]executables',
28
28
  'Uninstall applicable executables without',
29
29
  'confirmation') do |value, options|
30
30
  options[:executables] = value
31
31
  end
32
32
 
33
+ add_option('-i', '--install-dir DIR',
34
+ 'Directory to uninstall gem from') do |value, options|
35
+ options[:install_dir] = File.expand_path(value)
36
+ end
37
+
38
+ add_option('-n', '--bindir DIR',
39
+ 'Directory to remove binaries from') do |value, options|
40
+ options[:bin_dir] = File.expand_path(value)
41
+ end
42
+
33
43
  add_version_option
34
44
  add_platform_option
35
45
  end
@@ -39,7 +49,8 @@ module Gem
39
49
  end
40
50
 
41
51
  def defaults_str # :nodoc:
42
- "--version '#{Gem::Requirement.default}' --no-force"
52
+ "--version '#{Gem::Requirement.default}' --no-force " \
53
+ "--install-dir #{Gem.dir}"
43
54
  end
44
55
 
45
56
  def usage # :nodoc:
@@ -48,7 +59,13 @@ module Gem
48
59
 
49
60
  def execute
50
61
  get_all_gem_names.each do |gem_name|
51
- Gem::Uninstaller.new(gem_name, options).uninstall
62
+ begin
63
+ Gem::Uninstaller.new(gem_name, options).uninstall
64
+ rescue Gem::GemNotInHomeException => e
65
+ spec = e.spec
66
+ alert("In order to remove #{spec.name}, please execute:\n" \
67
+ "\tgem uninstall #{spec.name} --install-dir=#{spec.installation_path}")
68
+ end
52
69
  end
53
70
  end
54
71
  end
@@ -38,6 +38,7 @@ class Gem::Commands::UnpackCommand < Gem::Command
38
38
  def execute
39
39
  gemname = get_one_gem_name
40
40
  path = get_path(gemname, options[:version])
41
+
41
42
  if path then
42
43
  basename = File.basename(path).sub(/\.gem$/, '')
43
44
  target_dir = File.expand_path File.join(options[:target], basename)
@@ -66,16 +67,27 @@ class Gem::Commands::UnpackCommand < Gem::Command
66
67
  # source directories?
67
68
  def get_path(gemname, version_req)
68
69
  return gemname if gemname =~ /\.gem$/i
69
- specs = Gem::SourceIndex.from_installed_gems.search(/\A#{gemname}\z/, version_req)
70
+
71
+ specs = Gem::source_index.search(/\A#{gemname}\z/, version_req)
72
+
70
73
  selected = specs.sort_by { |s| s.version }.last
74
+
71
75
  return nil if selected.nil?
76
+
72
77
  # We expect to find (basename).gem in the 'cache' directory.
73
78
  # Furthermore, the name match must be exact (ignoring case).
74
79
  if gemname =~ /^#{selected.name}$/i
75
80
  filename = selected.full_name + '.gem'
76
- return File.join(Gem.dir, 'cache', filename)
81
+ path = nil
82
+
83
+ Gem.path.find do |gem_dir|
84
+ path = File.join gem_dir, 'cache', filename
85
+ File.exist? path
86
+ end
87
+
88
+ path
77
89
  else
78
- return nil
90
+ nil
79
91
  end
80
92
  end
81
93
 
@@ -1,8 +1,10 @@
1
1
  require 'rubygems/command'
2
+ require 'rubygems/command_manager'
2
3
  require 'rubygems/install_update_options'
3
4
  require 'rubygems/local_remote_options'
4
5
  require 'rubygems/source_info_cache'
5
6
  require 'rubygems/version_option'
7
+ require 'rubygems/commands/install_command'
6
8
 
7
9
  class Gem::Commands::UpdateCommand < Gem::Command
8
10
 
@@ -45,7 +47,7 @@ class Gem::Commands::UpdateCommand < Gem::Command
45
47
 
46
48
  def execute
47
49
  if options[:system] then
48
- say "Updating RubyGems..."
50
+ say "Updating RubyGems"
49
51
 
50
52
  unless options[:args].empty? then
51
53
  fail "No gem names are allowed with the --system option"
@@ -53,10 +55,10 @@ class Gem::Commands::UpdateCommand < Gem::Command
53
55
 
54
56
  options[:args] = ["rubygems-update"]
55
57
  else
56
- say "Updating installed gems..."
58
+ say "Updating installed gems"
57
59
  end
58
60
 
59
- hig = highest_installed_gems = {}
61
+ hig = {}
60
62
 
61
63
  Gem::SourceIndex.from_installed_gems.each do |name, spec|
62
64
  if hig[spec.name].nil? or hig[spec.name].version < spec.version then
@@ -64,25 +66,28 @@ class Gem::Commands::UpdateCommand < Gem::Command
64
66
  end
65
67
  end
66
68
 
67
- remote_gemspecs = Gem::SourceInfoCache.search(//)
69
+ pattern = if options[:args].empty? then
70
+ //
71
+ else
72
+ Regexp.union(*options[:args])
73
+ end
68
74
 
69
- gems_to_update = if options[:args].empty? then
70
- which_to_update(highest_installed_gems, remote_gemspecs)
71
- else
72
- options[:args]
73
- end
75
+ remote_gemspecs = Gem::SourceInfoCache.search pattern
74
76
 
75
- options[:domain] = :remote # install from remote source
77
+ gems_to_update = which_to_update hig, remote_gemspecs
76
78
 
77
- # HACK use the real API
78
- install_command = Gem::CommandManager.instance['install']
79
+ updated = []
79
80
 
81
+ # HACK use the real API
80
82
  gems_to_update.uniq.sort.each do |name|
81
- say "Attempting remote update of #{name}"
82
- options[:args] = [name]
83
- options[:ignore_dependencies] = true # HACK skip seen gems instead
84
- install_command.merge_options(options)
85
- install_command.execute
83
+ next if updated.any? { |spec| spec.name == name }
84
+ say "Updating #{name}"
85
+ installer = Gem::DependencyInstaller.new options
86
+ installer.install name
87
+ installer.installed_gems.each do |spec|
88
+ updated << spec
89
+ say "Successfully installed #{spec.full_name}"
90
+ end
86
91
  end
87
92
 
88
93
  if gems_to_update.include? "rubygems-update" then
@@ -97,12 +102,10 @@ class Gem::Commands::UpdateCommand < Gem::Command
97
102
 
98
103
  say "RubyGems system software updated" if installed
99
104
  else
100
- updated = gems_to_update.uniq.sort.collect { |g| g.to_s }
101
-
102
105
  if updated.empty? then
103
106
  say "Nothing to update"
104
107
  else
105
- say "Gems updated: #{updated.join ', '}"
108
+ say "Gems updated: #{updated.map { |spec| spec.name }.join ', '}"
106
109
  end
107
110
  end
108
111
  end
@@ -122,11 +125,10 @@ class Gem::Commands::UpdateCommand < Gem::Command
122
125
  setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
123
126
 
124
127
  # Make sure old rubygems isn't loaded
125
- if Gem.win_platform? then
126
- system "set RUBYOPT= & #{setup_cmd}"
127
- else
128
- system "RUBYOPT=\"\" #{setup_cmd}"
129
- end
128
+ old = ENV["RUBYOPT"]
129
+ ENV.delete("RUBYOPT")
130
+ system setup_cmd
131
+ ENV["RUBYOPT"] = old if old
130
132
  end
131
133
  end
132
134
 
@@ -28,7 +28,7 @@ module Kernel
28
28
  rescue LoadError => load_error
29
29
  if load_error.message =~ /\A[Nn]o such file to load -- #{Regexp.escape path}\z/ and
30
30
  spec = Gem.searcher.find(path) then
31
- Gem.activate(spec.name, false, "= #{spec.version}")
31
+ Gem.activate(spec.name, "= #{spec.version}")
32
32
  gem_original_require path
33
33
  else
34
34
  raise load_error
@@ -11,6 +11,9 @@ module Gem
11
11
  if defined? RUBY_FRAMEWORK_VERSION then
12
12
  File.join File.dirname(ConfigMap[:sitedir]), 'Gems',
13
13
  ConfigMap[:ruby_version]
14
+ elsif defined? RUBY_ENGINE then
15
+ File.join ConfigMap[:libdir], RUBY_ENGINE, 'gems',
16
+ ConfigMap[:ruby_version]
14
17
  else
15
18
  File.join ConfigMap[:libdir], 'ruby', 'gems', ConfigMap[:ruby_version]
16
19
  end
@@ -29,7 +32,11 @@ module Gem
29
32
 
30
33
  # The default directory for binaries
31
34
  def self.default_bindir
32
- Config::CONFIG['bindir']
35
+ if defined? RUBY_FRAMEWORK_VERSION then # mac framework support
36
+ '/usr/bin'
37
+ else # generic install
38
+ ConfigMap[:bindir]
39
+ end
33
40
  end
34
41
 
35
42
  # The default system-wide source info cache directory.
@@ -22,8 +22,7 @@ class Gem::DependencyInstaller
22
22
  }
23
23
 
24
24
  ##
25
- # Creates a new installer instance that will install +gem_name+ using
26
- # version requirement +version+ and +options+.
25
+ # Creates a new installer instance.
27
26
  #
28
27
  # Options are:
29
28
  # :env_shebang:: See Gem::Installer::new.
@@ -36,7 +35,7 @@ class Gem::DependencyInstaller
36
35
  # :install_dir: See Gem::Installer#install.
37
36
  # :security_policy: See Gem::Installer::new and Gem::Security.
38
37
  # :wrappers: See Gem::Installer::new
39
- def initialize(gem_name, version = nil, options = {})
38
+ def initialize(options = {})
40
39
  options = DEFAULT_OPTIONS.merge options
41
40
  @env_shebang = options[:env_shebang]
42
41
  @domain = options[:domain]
@@ -46,49 +45,9 @@ class Gem::DependencyInstaller
46
45
  @install_dir = options[:install_dir] || Gem.dir
47
46
  @security_policy = options[:security_policy]
48
47
  @wrappers = options[:wrappers]
48
+ @bin_dir = options[:bin_dir]
49
49
 
50
50
  @installed_gems = []
51
-
52
- spec_and_source = nil
53
-
54
- glob = if File::ALT_SEPARATOR then
55
- gem_name.gsub File::ALT_SEPARATOR, File::SEPARATOR
56
- else
57
- gem_name
58
- end
59
-
60
- local_gems = Dir["#{glob}*"].sort.reverse
61
-
62
- unless local_gems.empty? then
63
- local_gems.each do |gem_file|
64
- next unless gem_file =~ /gem$/
65
- begin
66
- spec = Gem::Format.from_file_by_path(gem_file).spec
67
- spec_and_source = [spec, gem_file]
68
- break
69
- rescue SystemCallError, Gem::Package::FormatError
70
- end
71
- end
72
- end
73
-
74
- if spec_and_source.nil? then
75
- version ||= Gem::Requirement.default
76
- @dep = Gem::Dependency.new gem_name, version
77
- spec_and_sources = find_gems_with_sources(@dep).reverse
78
-
79
- spec_and_source = spec_and_sources.find do |spec, source|
80
- Gem::Platform.match spec.platform
81
- end
82
- end
83
-
84
- if spec_and_source.nil? then
85
- raise Gem::GemNotFoundException,
86
- "could not find #{gem_name} locally or in a repository"
87
- end
88
-
89
- @specs_and_sources = [spec_and_source]
90
-
91
- gather_dependencies
92
51
  end
93
52
 
94
53
  ##
@@ -107,71 +66,30 @@ class Gem::DependencyInstaller
107
66
  end
108
67
 
109
68
  if @domain == :both or @domain == :remote then
110
- gems_and_sources.push(*Gem::SourceInfoCache.search_with_source(dep, true))
111
- end
112
-
113
- gems_and_sources.sort_by do |gem, source|
114
- [gem, source !~ /^http:\/\// ? 1 : 0] # local gems win
115
- end
116
- end
117
-
118
- ##
119
- # Moves the gem +spec+ from +source_uri+ to the cache dir unless it is
120
- # already there. If the source_uri is local the gem cache dir copy is
121
- # always replaced.
122
- def download(spec, source_uri)
123
- gem_file_name = "#{spec.full_name}.gem"
124
- local_gem_path = File.join @install_dir, 'cache', gem_file_name
125
-
126
- Gem.ensure_gem_subdirectories @install_dir
127
-
128
- source_uri = URI.parse source_uri unless URI::Generic === source_uri
129
- scheme = source_uri.scheme
130
-
131
- # URI.parse gets confused by MS Windows paths with forward slashes.
132
- scheme = nil if scheme =~ /^[a-z]$/i
133
-
134
- case scheme
135
- when 'http' then
136
- unless File.exist? local_gem_path then
137
- begin
138
- say "Downloading gem #{gem_file_name}" if
139
- Gem.configuration.really_verbose
140
-
141
- remote_gem_path = source_uri + "gems/#{gem_file_name}"
142
-
143
- gem = Gem::RemoteFetcher.fetcher.fetch_path remote_gem_path
144
- rescue Gem::RemoteFetcher::FetchError
145
- raise if spec.original_platform == spec.platform
146
-
147
- alternate_name = "#{spec.name}-#{spec.version}-#{spec.original_platform}.gem"
69
+ begin
70
+ requirements = dep.version_requirements.requirements.map do |req, ver|
71
+ req
72
+ end
148
73
 
149
- say "Failed, downloading gem #{alternate_name}" if
150
- Gem.configuration.really_verbose
74
+ all = requirements.length > 1 ||
75
+ requirements.first != ">=" || requirements.first != ">"
151
76
 
152
- remote_gem_path = source_uri + "gems/#{alternate_name}"
77
+ found = Gem::SourceInfoCache.search_with_source dep, true, all
153
78
 
154
- gem = Gem::RemoteFetcher.fetcher.fetch_path remote_gem_path
155
- end
79
+ gems_and_sources.push(*found)
156
80
 
157
- File.open local_gem_path, 'wb' do |fp|
158
- fp.write gem
81
+ rescue Gem::RemoteFetcher::FetchError => e
82
+ if Gem.configuration.really_verbose then
83
+ say "Error fetching remote data:\t\t#{e.message}"
84
+ say "Falling back to local-only install"
159
85
  end
86
+ @domain = :local
160
87
  end
161
- when nil, 'file' then # TODO test for local overriding cache
162
- begin
163
- FileUtils.cp source_uri.to_s, local_gem_path
164
- rescue Errno::EACCES
165
- local_gem_path = source_uri.to_s
166
- end
167
-
168
- say "Using local gem #{local_gem_path}" if
169
- Gem.configuration.really_verbose
170
- else
171
- raise Gem::InstallError, "unsupported URI scheme #{source_uri.scheme}"
172
88
  end
173
89
 
174
- local_gem_path
90
+ gems_and_sources.sort_by do |gem, source|
91
+ [gem, source =~ /^http:\/\// ? 0 : 1] # local gems win
92
+ end
175
93
  end
176
94
 
177
95
  ##
@@ -208,9 +126,57 @@ class Gem::DependencyInstaller
208
126
  @gems_to_install = dependency_list.dependency_order.reverse
209
127
  end
210
128
 
129
+ def find_spec_by_name_and_version gem_name, version = Gem::Requirement.default
130
+ spec_and_source = nil
131
+
132
+ glob = if File::ALT_SEPARATOR then
133
+ gem_name.gsub File::ALT_SEPARATOR, File::SEPARATOR
134
+ else
135
+ gem_name
136
+ end
137
+
138
+ local_gems = Dir["#{glob}*"].sort.reverse
139
+
140
+ unless local_gems.empty? then
141
+ local_gems.each do |gem_file|
142
+ next unless gem_file =~ /gem$/
143
+ begin
144
+ spec = Gem::Format.from_file_by_path(gem_file).spec
145
+ spec_and_source = [spec, gem_file]
146
+ break
147
+ rescue SystemCallError, Gem::Package::FormatError
148
+ end
149
+ end
150
+ end
151
+
152
+ if spec_and_source.nil? then
153
+ dep = Gem::Dependency.new gem_name, version
154
+ spec_and_sources = find_gems_with_sources(dep).reverse
155
+
156
+ spec_and_source = spec_and_sources.find { |spec, source|
157
+ Gem::Platform.match spec.platform
158
+ }
159
+ end
160
+
161
+ if spec_and_source.nil? then
162
+ raise Gem::GemNotFoundException,
163
+ "could not find #{gem_name} locally or in a repository"
164
+ end
165
+
166
+ @specs_and_sources = [spec_and_source]
167
+ end
168
+
211
169
  ##
212
170
  # Installs the gem and all its dependencies.
213
- def install
171
+ def install dep_or_name, version = Gem::Requirement.default
172
+ if String === dep_or_name then
173
+ find_spec_by_name_and_version dep_or_name, version
174
+ else
175
+ @specs_and_sources = [find_gems_with_sources(dep_or_name).last]
176
+ end
177
+
178
+ gather_dependencies
179
+
214
180
  spec_dir = File.join @install_dir, 'specifications'
215
181
  source_index = Gem::SourceIndex.from_gems_in spec_dir
216
182
 
@@ -219,10 +185,11 @@ class Gem::DependencyInstaller
219
185
  # HACK is this test for full_name acceptable?
220
186
  next if source_index.any? { |n,_| n == spec.full_name } and not last
221
187
 
188
+ # TODO: make this sorta_verbose so other users can benefit from it
222
189
  say "Installing gem #{spec.full_name}" if Gem.configuration.really_verbose
223
190
 
224
191
  _, source_uri = @specs_and_sources.assoc spec
225
- local_gem_path = download spec, source_uri
192
+ local_gem_path = Gem::RemoteFetcher.fetcher.download spec, source_uri
226
193
 
227
194
  inst = Gem::Installer.new local_gem_path,
228
195
  :env_shebang => @env_shebang,
@@ -231,7 +198,8 @@ class Gem::DependencyInstaller
231
198
  :ignore_dependencies => @ignore_dependencies,
232
199
  :install_dir => @install_dir,
233
200
  :security_policy => @security_policy,
234
- :wrappers => @wrappers
201
+ :wrappers => @wrappers,
202
+ :bin_dir => @bin_dir
235
203
 
236
204
  spec = inst.install
237
205