rubygems-update 0.9.4 → 0.9.5

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 (225) hide show
  1. data/ChangeLog +587 -0
  2. data/README +0 -1
  3. data/Rakefile +39 -12
  4. data/TODO +0 -5
  5. data/bin/gem +7 -7
  6. data/bin/update_rubygems +1 -1
  7. data/examples/application/an-app.gemspec +1 -1
  8. data/gemspecs/cgikit-1.1.0.gemspec +1 -2
  9. data/gemspecs/jabber4r.gemspec +1 -1
  10. data/gemspecs/linguistics.gemspec +1 -1
  11. data/gemspecs/ook.gemspec +1 -1
  12. data/gemspecs/progressbar.gemspec +1 -1
  13. data/gemspecs/redcloth.gemspec +1 -1
  14. data/gemspecs/rublog.gemspec +1 -1
  15. data/gemspecs/ruby-doom.gemspec +1 -1
  16. data/gemspecs/rubyjdwp.gemspec +1 -1
  17. data/gemspecs/statistics.gemspec +1 -1
  18. data/lib/rubygems.rb +167 -105
  19. data/lib/rubygems/builder.rb +12 -10
  20. data/lib/rubygems/command.rb +177 -60
  21. data/lib/rubygems/command_manager.rb +30 -38
  22. data/lib/rubygems/commands/build_command.rb +42 -46
  23. data/lib/rubygems/commands/cert_command.rb +72 -69
  24. data/lib/rubygems/commands/check_command.rb +63 -63
  25. data/lib/rubygems/commands/cleanup_command.rb +25 -7
  26. data/lib/rubygems/commands/contents_command.rb +70 -62
  27. data/lib/rubygems/commands/dependency_command.rb +131 -86
  28. data/lib/rubygems/commands/environment_command.rb +67 -46
  29. data/lib/rubygems/commands/fetch_command.rb +62 -0
  30. data/lib/rubygems/commands/generate_index_command.rb +57 -0
  31. data/lib/rubygems/commands/help_command.rb +163 -73
  32. data/lib/rubygems/commands/install_command.rb +114 -128
  33. data/lib/rubygems/commands/list_command.rb +10 -8
  34. data/lib/rubygems/commands/lock_command.rb +101 -0
  35. data/lib/rubygems/commands/mirror_command.rb +105 -0
  36. data/lib/rubygems/commands/outdated_command.rb +24 -15
  37. data/lib/rubygems/commands/pristine_command.rb +118 -88
  38. data/lib/rubygems/commands/query_command.rb +109 -77
  39. data/lib/rubygems/commands/rdoc_command.rb +13 -10
  40. data/lib/rubygems/commands/search_command.rb +10 -8
  41. data/lib/rubygems/commands/server_command.rb +48 -0
  42. data/lib/rubygems/commands/sources_command.rb +104 -83
  43. data/lib/rubygems/commands/specification_command.rb +65 -51
  44. data/lib/rubygems/commands/uninstall_command.rb +17 -12
  45. data/lib/rubygems/commands/unpack_command.rb +68 -68
  46. data/lib/rubygems/commands/update_command.rb +72 -25
  47. data/lib/rubygems/commands/which_command.rb +86 -0
  48. data/lib/rubygems/config_file.rb +202 -78
  49. data/lib/rubygems/custom_require.rb +7 -88
  50. data/lib/rubygems/dependency.rb +65 -0
  51. data/lib/rubygems/dependency_installer.rb +232 -0
  52. data/lib/rubygems/dependency_list.rb +133 -105
  53. data/lib/rubygems/digest/md5.rb +4 -1
  54. data/lib/rubygems/digest/sha2.rb +1 -1
  55. data/lib/rubygems/doc_manager.rb +41 -19
  56. data/lib/rubygems/exceptions.rb +63 -0
  57. data/lib/rubygems/ext.rb +18 -0
  58. data/lib/rubygems/ext/builder.rb +56 -0
  59. data/lib/rubygems/ext/configure_builder.rb +24 -0
  60. data/lib/rubygems/ext/ext_conf_builder.rb +23 -0
  61. data/lib/rubygems/ext/rake_builder.rb +27 -0
  62. data/lib/rubygems/format.rb +16 -6
  63. data/lib/rubygems/gem_openssl.rb +43 -6
  64. data/lib/rubygems/gem_path_searcher.rb +84 -0
  65. data/lib/rubygems/gem_runner.rb +20 -5
  66. data/lib/rubygems/indexer.rb +163 -0
  67. data/lib/rubygems/indexer/abstract_index_builder.rb +80 -0
  68. data/lib/rubygems/indexer/marshal_index_builder.rb +17 -0
  69. data/lib/rubygems/indexer/master_index_builder.rb +53 -0
  70. data/lib/rubygems/indexer/quick_index_builder.rb +48 -0
  71. data/lib/rubygems/install_update_options.rb +87 -0
  72. data/lib/rubygems/installer.rb +316 -562
  73. data/lib/rubygems/local_remote_options.rb +106 -0
  74. data/lib/rubygems/old_format.rb +5 -13
  75. data/lib/rubygems/open-uri.rb +2 -0
  76. data/lib/rubygems/package.rb +28 -32
  77. data/lib/rubygems/platform.rb +187 -0
  78. data/lib/rubygems/remote_fetcher.rb +46 -29
  79. data/lib/rubygems/remote_installer.rb +11 -18
  80. data/lib/rubygems/requirement.rb +157 -0
  81. data/lib/rubygems/rubygems_version.rb +1 -1
  82. data/lib/rubygems/security.rb +715 -457
  83. data/lib/rubygems/server.rb +77 -59
  84. data/lib/rubygems/source_index.rb +154 -83
  85. data/lib/rubygems/source_info_cache.rb +73 -30
  86. data/lib/rubygems/source_info_cache_entry.rb +12 -3
  87. data/lib/rubygems/specification.rb +378 -145
  88. data/lib/rubygems/uninstaller.rb +183 -0
  89. data/lib/rubygems/user_interaction.rb +38 -9
  90. data/lib/rubygems/validator.rb +53 -24
  91. data/lib/rubygems/version.rb +126 -289
  92. data/lib/rubygems/version_option.rb +49 -0
  93. data/pkgs/sources/lib/sources.rb +1 -4
  94. data/pkgs/sources/sources.gemspec +3 -3
  95. data/scripts/gemdoc.rb +0 -1
  96. data/setup.rb +166 -1505
  97. data/test/bogussources.rb +0 -1
  98. data/test/data/gem-private_key.pem +27 -0
  99. data/test/data/gem-public_cert.pem +20 -0
  100. data/test/functional.rb +3 -105
  101. data/test/gemutilities.rb +145 -24
  102. data/test/insure_session.rb +0 -1
  103. data/test/{test_datadir.rb → test_config.rb} +7 -13
  104. data/test/test_gem.rb +360 -9
  105. data/test/test_gem_builder.rb +34 -0
  106. data/test/{test_command.rb → test_gem_command.rb} +119 -62
  107. data/test/{test_parse_commands.rb → test_gem_command_manager.rb} +64 -40
  108. data/test/test_gem_commands_build_command.rb +75 -0
  109. data/test/test_gem_commands_cert_command.rb +122 -0
  110. data/test/test_gem_commands_check_command.rb +25 -0
  111. data/test/test_gem_commands_contents_command.rb +92 -0
  112. data/test/test_gem_commands_dependency_command.rb +108 -0
  113. data/test/test_gem_commands_environment_command.rb +117 -0
  114. data/test/test_gem_commands_fetch_command.rb +34 -0
  115. data/test/test_gem_commands_generate_index_command.rb +32 -0
  116. data/test/test_gem_commands_install_command.rb +160 -0
  117. data/test/test_gem_commands_mirror_command.rb +56 -0
  118. data/test/test_gem_commands_pristine_command.rb +100 -0
  119. data/test/test_gem_commands_query_command.rb +82 -0
  120. data/test/test_gem_commands_sources_command.rb +147 -0
  121. data/test/test_gem_commands_specification_command.rb +93 -0
  122. data/test/test_gem_commands_unpack_command.rb +55 -0
  123. data/test/test_gem_config_file.rb +210 -0
  124. data/test/test_gem_dependency.rb +89 -0
  125. data/test/test_gem_dependency_installer.rb +542 -0
  126. data/test/test_gem_dependency_list.rb +212 -0
  127. data/test/test_gem_doc_manager.rb +32 -0
  128. data/test/test_gem_ext_configure_builder.rb +13 -17
  129. data/test/test_gem_ext_ext_conf_builder.rb +9 -9
  130. data/test/test_gem_ext_rake_builder.rb +23 -11
  131. data/test/test_gem_format.rb +69 -0
  132. data/test/test_gem_gem_path_searcher.rb +57 -0
  133. data/test/test_gem_gem_runner.rb +35 -0
  134. data/test/test_gem_indexer.rb +119 -0
  135. data/test/test_gem_install_update_options.rb +40 -0
  136. data/test/test_gem_installer.rb +796 -0
  137. data/test/test_gem_local_remote_options.rb +84 -0
  138. data/test/test_gem_outdated_command.rb +11 -9
  139. data/test/test_gem_platform.rb +240 -0
  140. data/test/{test_remote_fetcher.rb → test_gem_remote_fetcher.rb} +124 -55
  141. data/test/{test_remote_installer.rb → test_gem_remote_installer.rb} +3 -4
  142. data/test/test_gem_requirement.rb +223 -0
  143. data/test/test_gem_server.rb +71 -0
  144. data/test/test_gem_source_index.rb +429 -0
  145. data/test/test_gem_source_info_cache.rb +79 -17
  146. data/test/test_gem_source_info_cache_entry.rb +11 -9
  147. data/test/test_gem_specification.rb +738 -0
  148. data/test/test_gem_stream_ui.rb +117 -0
  149. data/test/test_gem_validator.rb +70 -0
  150. data/test/test_gem_version.rb +191 -0
  151. data/test/test_gem_version_option.rb +77 -0
  152. data/test/{test_require_gem.rb → test_kernel.rb} +19 -12
  153. data/test/test_open_uri.rb +1 -2
  154. data/test/test_package.rb +45 -34
  155. metadata +116 -141
  156. data/Releases +0 -127
  157. data/bin/gem_mirror +0 -73
  158. data/bin/gem_server +0 -6
  159. data/bin/gemlock +0 -127
  160. data/bin/gemri +0 -24
  161. data/bin/gemwhich +0 -89
  162. data/bin/index_gem_repository.rb +0 -302
  163. data/lib/gemconfigure.rb +0 -24
  164. data/lib/rubygems/gem_commands.rb +0 -273
  165. data/pkgs/sources/sources-0.0.1.gem +0 -0
  166. data/post-install.rb +0 -121
  167. data/test/brokenbuildgem.rb +0 -35
  168. data/test/data/PostMessage-0.0.1.gem +0 -0
  169. data/test/data/a-0.0.1.gem +0 -0
  170. data/test/data/a-0.0.2.gem +0 -0
  171. data/test/data/b-0.0.2.gem +0 -0
  172. data/test/data/broken-1.0.0.gem +0 -0
  173. data/test/data/broken_build/broken-build.gemspec +0 -20
  174. data/test/data/broken_build/ext/extconf.rb +0 -3
  175. data/test/data/broken_build/ext/foo.c +0 -1
  176. data/test/data/c-1.2.gem +0 -0
  177. data/test/data/gemhome/cache/a-0.0.1.gem +0 -0
  178. data/test/data/gemhome/cache/a-0.0.2.gem +0 -0
  179. data/test/data/gemhome/cache/b-0.0.2.gem +0 -0
  180. data/test/data/gemhome/cache/c-1.2.gem +0 -0
  181. data/test/data/gemhome/gems/a-0.0.1/lib/code.rb +0 -1
  182. data/test/data/gemhome/gems/a-0.0.2/lib/code.rb +0 -1
  183. data/test/data/gemhome/gems/b-0.0.2/lib/code.rb +0 -1
  184. data/test/data/gemhome/gems/c-1.2/lib/code.rb +0 -1
  185. data/test/data/gemhome/specifications/a-0.0.1.gemspec +0 -8
  186. data/test/data/gemhome/specifications/a-0.0.2.gemspec +0 -8
  187. data/test/data/gemhome/specifications/b-0.0.2.gemspec +0 -8
  188. data/test/data/gemhome/specifications/c-1.2.gemspec +0 -8
  189. data/test/data/legacy/keyedlist-0.4.0.ruby +0 -11
  190. data/test/data/legacy/keyedlist-0.4.0.yaml +0 -16
  191. data/test/data/lib/code.rb +0 -1
  192. data/test/data/one/README.one +0 -1
  193. data/test/data/one/lib/one.rb +0 -9
  194. data/test/data/one/one-0.0.1.gem +0 -0
  195. data/test/data/one/one.gemspec +0 -17
  196. data/test/data/one/one.yaml +0 -40
  197. data/test/data/post_install.gemspec +0 -19
  198. data/test/functional_extension_gems.rb +0 -48
  199. data/test/functional_generate_yaml_index.rb +0 -104
  200. data/test/gemenvironment.rb +0 -59
  201. data/test/io_capture.rb +0 -33
  202. data/test/mock/gems/gems/sources-0.0.1/lib/sources.rb +0 -11
  203. data/test/mock/gems/specifications/sources-0.0.1.gemspec +0 -8
  204. data/test/onegem.rb +0 -35
  205. data/test/test_builder.rb +0 -34
  206. data/test/test_check_command.rb +0 -34
  207. data/test/test_configfile.rb +0 -42
  208. data/test/test_dependency_list.rb +0 -169
  209. data/test/test_file_list.rb +0 -101
  210. data/test/test_format.rb +0 -49
  211. data/test/test_gem_sources_command.rb +0 -135
  212. data/test/test_gemloadpaths.rb +0 -51
  213. data/test/test_gempaths.rb +0 -170
  214. data/test/test_installer.rb +0 -369
  215. data/test/test_loadmanager.rb +0 -48
  216. data/test/test_process_commands.rb +0 -52
  217. data/test/test_source_index.rb +0 -231
  218. data/test/test_specific_extras.rb +0 -46
  219. data/test/test_specification.rb +0 -565
  220. data/test/test_user_interaction.rb +0 -48
  221. data/test/test_validator.rb +0 -59
  222. data/test/test_version_comparison.rb +0 -321
  223. data/test/testgem.rc +0 -7
  224. data/test/user_capture.rb +0 -7
  225. data/test/yaml_data.rb +0 -63
@@ -0,0 +1,65 @@
1
+ #--
2
+ # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+ require 'rubygems'
8
+
9
+ ##
10
+ # The Dependency class holds a Gem name and a Gem::Requirement
11
+ class Gem::Dependency
12
+
13
+ attr_accessor :name
14
+
15
+ attr_writer :version_requirements
16
+
17
+ def <=>(other)
18
+ [@name] <=> [other.name]
19
+ end
20
+
21
+ ##
22
+ # Constructs the dependency
23
+ #
24
+ # name:: [String] name of the Gem
25
+ # version_requirements:: [String Array] version requirement (e.g. ["> 1.2"])
26
+ #
27
+ def initialize(name, version_requirements)
28
+ @name = name
29
+ @version_requirements = Gem::Requirement.create version_requirements
30
+ @version_requirement = nil # Avoid warnings.
31
+ end
32
+
33
+ def version_requirements
34
+ normalize if defined? @version_requirement and @version_requirement
35
+ @version_requirements
36
+ end
37
+
38
+ def requirement_list
39
+ version_requirements.as_list
40
+ end
41
+
42
+ alias requirements_list requirement_list
43
+
44
+ def normalize
45
+ ver = @version_requirement.instance_eval { @version }
46
+ @version_requirements = Gem::Requirement.new([ver])
47
+ @version_requirement = nil
48
+ end
49
+
50
+ def to_s # :nodoc:
51
+ "#{name} (#{version_requirements})"
52
+ end
53
+
54
+ def ==(other) # :nodoc:
55
+ self.class === other &&
56
+ self.name == other.name &&
57
+ self.version_requirements == other.version_requirements
58
+ end
59
+
60
+ def hash
61
+ name.hash + version_requirements.hash
62
+ end
63
+
64
+ end
65
+
@@ -0,0 +1,232 @@
1
+ require 'rubygems'
2
+ require 'rubygems/dependency_list'
3
+ require 'rubygems/installer'
4
+ require 'rubygems/source_info_cache'
5
+ require 'rubygems/user_interaction'
6
+
7
+ class Gem::DependencyInstaller
8
+
9
+ include Gem::UserInteraction
10
+
11
+ attr_reader :gems_to_install
12
+ attr_reader :installed_gems
13
+
14
+ DEFAULT_OPTIONS = {
15
+ :env_shebang => false,
16
+ :domain => :both, # HACK dup
17
+ :force => false,
18
+ :ignore_dependencies => false,
19
+ :security_policy => Gem::Security::NoSecurity, # HACK AlmostNo? Low?
20
+ :wrappers => true
21
+ }
22
+
23
+ ##
24
+ # Creates a new installer instance that will install +gem_name+ using
25
+ # version requirement +version+ and +options+.
26
+ #
27
+ # Options are:
28
+ # :env_shebang:: See Gem::Installer::new.
29
+ # :domain:: :local, :remote, or :both. :local only searches gems in the
30
+ # current directory. :remote searches only gems in Gem::sources.
31
+ # :both searches both.
32
+ # :force:: See Gem::Installer#install.
33
+ # :ignore_dependencies: Don't install any dependencies.
34
+ # :install_dir: See Gem::Installer#install.
35
+ # :security_policy: See Gem::Installer::new and Gem::Security.
36
+ # :wrappers: See Gem::Installer::new
37
+ def initialize(gem_name, version = nil, options = {})
38
+ options = DEFAULT_OPTIONS.merge options
39
+ @env_shebang = options[:env_shebang]
40
+ @domain = options[:domain]
41
+ @force = options[:force]
42
+ @ignore_dependencies = options[:ignore_dependencies]
43
+ @install_dir = options[:install_dir] || Gem.dir
44
+ @security_policy = options[:security_policy]
45
+ @wrappers = options[:wrappers]
46
+
47
+ @installed_gems = []
48
+
49
+ spec_and_source = nil
50
+
51
+ local_gems = Dir["#{gem_name}*"].sort.reverse
52
+ unless local_gems.empty? then
53
+ local_gems.each do |gem_file|
54
+ next unless gem_file =~ /gem$/
55
+ begin
56
+ spec = Gem::Format.from_file_by_path(gem_file).spec
57
+ spec_and_source = [spec, gem_file]
58
+ break
59
+ rescue SystemCallError, Gem::Package::FormatError
60
+ end
61
+ end
62
+ end
63
+
64
+ if spec_and_source.nil? then
65
+ version ||= Gem::Requirement.default
66
+ @dep = Gem::Dependency.new gem_name, version
67
+ spec_and_sources = find_gems_with_sources(@dep).reverse
68
+
69
+ spec_and_source = spec_and_sources.find do |spec, source|
70
+ Gem::Platform.match spec.platform
71
+ end
72
+ end
73
+
74
+ if spec_and_source.nil? then
75
+ raise Gem::GemNotFoundException,
76
+ "could not find #{gem_name} locally or in a repository"
77
+ end
78
+
79
+ @specs_and_sources = [spec_and_source]
80
+
81
+ gather_dependencies
82
+ end
83
+
84
+ ##
85
+ # Returns a list of pairs of gemspecs and source_uris that match
86
+ # Gem::Dependency +dep+ from both local (Dir.pwd) and remote (Gem.sources)
87
+ # sources. Gems are sorted with newer gems prefered over older gems, and
88
+ # local gems prefered over remote gems.
89
+ def find_gems_with_sources(dep)
90
+ gems_and_sources = []
91
+
92
+ if @domain == :both or @domain == :local then
93
+ Dir[File.join(Dir.pwd, "#{dep.name}-[0-9]*.gem")].each do |gem_file|
94
+ spec = Gem::Format.from_file_by_path(gem_file).spec
95
+ gems_and_sources << [spec, gem_file] if spec.name == dep.name
96
+ end
97
+ end
98
+
99
+ if @domain == :both or @domain == :remote then
100
+ gems_and_sources.push(*Gem::SourceInfoCache.search_with_source(dep, true))
101
+ end
102
+
103
+ gems_and_sources.sort_by do |gem, source|
104
+ [gem, source !~ /^http:\/\// ? 1 : 0] # local gems win
105
+ end
106
+ end
107
+
108
+ ##
109
+ # Moves the gem +spec+ from +source_uri+ to the cache dir unless it is
110
+ # already there. If the source_uri is local the gem cache dir copy is
111
+ # always replaced.
112
+ def download(spec, source_uri)
113
+ gem_file_name = "#{spec.full_name}.gem"
114
+ local_gem_path = File.join @install_dir, 'cache', gem_file_name
115
+
116
+ Gem.ensure_gem_subdirectories @install_dir
117
+
118
+ source_uri = URI.parse source_uri unless URI::Generic === source_uri
119
+ scheme = source_uri.scheme
120
+
121
+ # URI.parse gets confused by MS Windows paths with forward slashes.
122
+ scheme = nil if scheme =~ /^[a-z]$/i
123
+
124
+ case scheme
125
+ when 'http' then
126
+ unless File.exist? local_gem_path then
127
+ begin
128
+ say "Downloading gem #{gem_file_name}" if
129
+ Gem.configuration.really_verbose
130
+
131
+ remote_gem_path = source_uri + "gems/#{gem_file_name}"
132
+
133
+ gem = Gem::RemoteFetcher.fetcher.fetch_path remote_gem_path
134
+ rescue Gem::RemoteFetcher::FetchError
135
+ raise if spec.original_platform == spec.platform
136
+
137
+ alternate_name = "#{spec.name}-#{spec.version}-#{spec.original_platform}.gem"
138
+
139
+ say "Failed, downloading gem #{alternate_name}" if
140
+ Gem.configuration.really_verbose
141
+
142
+ remote_gem_path = source_uri + "gems/#{alternate_name}"
143
+
144
+ gem = Gem::RemoteFetcher.fetcher.fetch_path remote_gem_path
145
+ end
146
+
147
+ File.open local_gem_path, 'wb' do |fp|
148
+ fp.write gem
149
+ end
150
+ end
151
+ when nil, 'file' then # TODO test for local overriding cache
152
+ begin
153
+ FileUtils.cp source_uri.to_s, local_gem_path
154
+ rescue Errno::EACCES
155
+ local_gem_path = source_uri.to_s
156
+ end
157
+
158
+ say "Using local gem #{local_gem_path}" if
159
+ Gem.configuration.really_verbose
160
+ else
161
+ raise Gem::InstallError, "unsupported URI scheme #{source_uri.scheme}"
162
+ end
163
+
164
+ local_gem_path
165
+ end
166
+
167
+ ##
168
+ # Gathers all dependencies necessary for the installation from local and
169
+ # remote sources unless the ignore_dependencies was given.
170
+ def gather_dependencies
171
+ specs = @specs_and_sources.map { |spec,_| spec }
172
+
173
+ dependency_list = Gem::DependencyList.new
174
+ dependency_list.add(*specs)
175
+
176
+ unless @ignore_dependencies then
177
+ to_do = specs.dup
178
+ seen = {}
179
+
180
+ until to_do.empty? do
181
+ spec = to_do.shift
182
+ next if spec.nil? or seen[spec.name]
183
+ seen[spec.name] = true
184
+
185
+ spec.dependencies.each do |dep|
186
+ results = find_gems_with_sources(dep).reverse # local gems first
187
+
188
+ results.each do |dep_spec, source_uri|
189
+ next if seen[dep_spec.name]
190
+ @specs_and_sources << [dep_spec, source_uri]
191
+ dependency_list.add dep_spec
192
+ to_do.push dep_spec
193
+ end
194
+ end
195
+ end
196
+ end
197
+
198
+ @gems_to_install = dependency_list.dependency_order.reverse
199
+ end
200
+
201
+ ##
202
+ # Installs the gem and all its dependencies.
203
+ def install
204
+ spec_dir = File.join @install_dir, 'specifications'
205
+ source_index = Gem::SourceIndex.from_gems_in spec_dir
206
+
207
+ @gems_to_install.each do |spec|
208
+ last = spec == @gems_to_install.last
209
+ # HACK is this test for full_name acceptable?
210
+ next if source_index.any? { |n,_| n == spec.full_name } and not last
211
+
212
+ say "Installing gem #{spec.full_name}" if Gem.configuration.really_verbose
213
+
214
+ _, source_uri = @specs_and_sources.assoc spec
215
+ local_gem_path = download spec, source_uri
216
+
217
+ inst = Gem::Installer.new local_gem_path,
218
+ :env_shebang => @env_shebang,
219
+ :force => @force,
220
+ :ignore_dependencies => @ignore_dependencies,
221
+ :install_dir => @install_dir,
222
+ :security_policy => @security_policy,
223
+ :wrappers => @wrappers
224
+
225
+ spec = inst.install
226
+
227
+ @installed_gems << spec
228
+ end
229
+ end
230
+
231
+ end
232
+
@@ -1,137 +1,165 @@
1
- #!/usr/bin/env ruby
2
1
  #--
3
2
  # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
4
3
  # All rights reserved.
5
4
  # See LICENSE.txt for permissions.
6
5
  #++
7
6
 
7
+ require 'tsort'
8
8
 
9
- module Gem
10
- class DependencyList
11
- def self.from_source_index(src_index)
12
- deps = DependencyList.new
13
- src_index.each do |full_name, spec|
14
- deps.add(spec)
15
- end
16
- deps
17
- end
9
+ class Gem::DependencyList
18
10
 
19
- def initialize
20
- @specs = []
21
- end
11
+ include TSort
22
12
 
23
- # Are all the dependencies in the list satisfied?
24
- def ok?
25
- @specs.all? { |spec|
26
- spec.dependencies.all? { |dep|
27
- @specs.find { |s| s.satisfies_requirement?(dep) }
28
- }
29
- }
30
- end
13
+ def self.from_source_index(src_index)
14
+ deps = new
31
15
 
32
- # Add a gemspec to the dependency list.
33
- def add(gemspec)
34
- @specs << gemspec
16
+ src_index.each do |full_name, spec|
17
+ deps.add spec
35
18
  end
36
19
 
37
- def find_name(full_name)
38
- @specs.find { |spec| spec.full_name == full_name }
39
- end
20
+ deps
21
+ end
40
22
 
41
- def remove_by_name(full_name)
42
- @specs.delete_if { |spec| spec.full_name == full_name }
43
- end
23
+ def initialize
24
+ @specs = []
25
+ end
44
26
 
45
- # Is is ok to remove a gem from the dependency list?
46
- #
47
- # If removing the gemspec creates breaks a currently ok dependency,
48
- # then it is NOT ok to remove the gem.
49
- def ok_to_remove?(full_name)
50
- gem_to_remove = find_name(full_name)
51
- siblings = @specs.find_all { |s|
52
- s.name == gem_to_remove.name &&
53
- s.full_name != gem_to_remove.full_name
54
- }
55
- deps = []
56
- @specs.each do |spec|
57
- spec.dependencies.each do |dep|
58
- deps << dep if gem_to_remove.satisfies_requirement?(dep)
27
+ # Adds +gemspecs+ to the dependency list.
28
+ def add(*gemspecs)
29
+ @specs.push(*gemspecs)
30
+ end
31
+
32
+ # Return a list of the specifications in the dependency list,
33
+ # sorted in order so that no spec in the list depends on a gem
34
+ # earlier in the list.
35
+ #
36
+ # This is useful when removing gems from a set of installed gems.
37
+ # By removing them in the returned order, you don't get into as
38
+ # many dependency issues.
39
+ #
40
+ # If there are circular dependencies (yuck!), then gems will be
41
+ # returned in order until only the circular dependents and anything
42
+ # they reference are left. Then arbitrary gemspecs will be returned
43
+ # until the circular dependency is broken, after which gems will be
44
+ # returned in dependency order again.
45
+ def dependency_order
46
+ sorted = strongly_connected_components.flatten
47
+
48
+ result = []
49
+ seen = {}
50
+
51
+ sorted.each do |spec|
52
+ if index = seen[spec.name] then
53
+ if result[index].version < spec.version then
54
+ result[index] = spec
59
55
  end
56
+ else
57
+ seen[spec.name] = result.length
58
+ result << spec
60
59
  end
61
- deps.all? { |dep|
62
- siblings.any? { |s|
63
- s.satisfies_requirement?(dep)
64
- }
65
- }
66
60
  end
67
61
 
68
- # Return a list of the specifications in the dependency list,
69
- # sorted in order so that no spec in the list depends on a gem
70
- # earlier in the list.
71
- #
72
- # This is useful when removing gems from a set of installed gems.
73
- # By removing them in the returned order, you don't get into as
74
- # many dependency issues.
75
- #
76
- # If there are circular dependencies (yuck!), then gems will be
77
- # returned in order until only the circular dependents and anything
78
- # they reference are left. Then arbitrary gemspecs will be returned
79
- # until the circular dependency is broken, after which gems will be
80
- # returned in dependency order again.
81
- def dependency_order
82
- result = []
83
- disabled = {}
84
- predecessors = build_predecessors
85
- while disabled.size < @specs.size
86
- candidate = @specs.find { |spec|
87
- ! disabled[spec.full_name] &&
88
- active_count(predecessors[spec.full_name], disabled) == 0
89
- }
90
- if candidate
91
- disabled[candidate.full_name] = true
92
- result << candidate
93
- elsif candidate = @specs.find { |spec| ! disabled[spec.full_name] }
94
- # This case handles circular dependencies. Just choose a
95
- # candidate and move on.
96
- disabled[candidate.full_name] = true
97
- result << candidate
98
- else
99
- # We should never get here, but just in case we will terminate
100
- # the loop.
101
- break
102
- end
62
+ result.reverse
63
+ end
64
+
65
+ def find_name(full_name)
66
+ @specs.find { |spec| spec.full_name == full_name }
67
+ end
68
+
69
+ # Are all the dependencies in the list satisfied?
70
+ def ok?
71
+ @specs.all? do |spec|
72
+ spec.dependencies.all? do |dep|
73
+ @specs.find { |s| s.satisfies_requirement? dep }
103
74
  end
104
- result
105
75
  end
76
+ end
106
77
 
107
- private
78
+ # Is is ok to remove a gem from the dependency list?
79
+ #
80
+ # If removing the gemspec creates breaks a currently ok dependency,
81
+ # then it is NOT ok to remove the gem.
82
+ def ok_to_remove?(full_name)
83
+ gem_to_remove = find_name full_name
108
84
 
109
- # Count the number of gemspecs in the list +specs+ that are still
110
- # active (e.g. not listed in the ignore hash).
111
- def active_count(specs, ignored)
112
- result = 0
113
- specs.each do |spec|
114
- result += 1 unless ignored[spec.full_name]
85
+ siblings = @specs.find_all { |s|
86
+ s.name == gem_to_remove.name &&
87
+ s.full_name != gem_to_remove.full_name
88
+ }
89
+
90
+ deps = []
91
+
92
+ @specs.each do |spec|
93
+ spec.dependencies.each do |dep|
94
+ deps << dep if gem_to_remove.satisfies_requirement?(dep)
115
95
  end
116
- result
117
96
  end
118
97
 
119
- # Return a hash of predecessors. E.g. results[spec.full_name] is a
120
- # list of gemspecs that have a dependency satisfied by spec.
121
- def build_predecessors
122
- result = Hash.new { |h,k| h[k] = [] }
123
- @specs.each do |spec|
124
- @specs.each do |other|
125
- next if spec.full_name == other.full_name
126
- other.dependencies.each do |dep|
127
- if spec.satisfies_requirement?(dep)
128
- result[spec.full_name] << other
129
- end
98
+ deps.all? { |dep|
99
+ siblings.any? { |s|
100
+ s.satisfies_requirement? dep
101
+ }
102
+ }
103
+ end
104
+
105
+ def remove_by_name(full_name)
106
+ @specs.delete_if { |spec| spec.full_name == full_name }
107
+ end
108
+
109
+ # Return a hash of predecessors. <tt>result[spec]</tt> is an
110
+ # Array of gemspecs that have a dependency satisfied by the named
111
+ # spec.
112
+ def spec_predecessors
113
+ result = Hash.new { |h,k| h[k] = [] }
114
+
115
+ specs = @specs.sort.reverse
116
+
117
+ specs.each do |spec|
118
+ specs.each do |other|
119
+ next if spec == other
120
+
121
+ other.dependencies.each do |dep|
122
+ if spec.satisfies_requirement? dep then
123
+ result[spec] << other
130
124
  end
131
125
  end
132
126
  end
133
- result
134
127
  end
135
128
 
129
+ result
130
+ end
131
+
132
+ def tsort_each_node(&block)
133
+ @specs.each(&block)
136
134
  end
135
+
136
+ def tsort_each_child(node, &block)
137
+ specs = @specs.sort.reverse
138
+
139
+ node.dependencies.each do |dep|
140
+ specs.each do |spec|
141
+ if spec.satisfies_requirement? dep then
142
+ begin
143
+ yield spec
144
+ rescue TSort::Cyclic
145
+ end
146
+ break
147
+ end
148
+ end
149
+ end
150
+ end
151
+
152
+ private
153
+
154
+ # Count the number of gemspecs in the list +specs+ that are not in
155
+ # +ignored+.
156
+ def active_count(specs, ignored)
157
+ result = 0
158
+ specs.each do |spec|
159
+ result += 1 unless ignored[spec.full_name]
160
+ end
161
+ result
162
+ end
163
+
137
164
  end
165
+