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,84 @@
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
+ # GemPathSearcher has the capability to find loadable files inside
11
+ # gems. It generates data up front to speed up searches later.
12
+ #
13
+ class Gem::GemPathSearcher
14
+
15
+ #
16
+ # Initialise the data we need to make searches later.
17
+ #
18
+ def initialize
19
+ # We want a record of all the installed gemspecs, in the order
20
+ # we wish to examine them.
21
+ @gemspecs = init_gemspecs
22
+ # Map gem spec to glob of full require_path directories.
23
+ # Preparing this information may speed up searches later.
24
+ @lib_dirs = {}
25
+ @gemspecs.each do |spec|
26
+ @lib_dirs[spec.object_id] = lib_dirs_for(spec)
27
+ end
28
+ end
29
+
30
+ #
31
+ # Look in all the installed gems until a matching _path_ is found.
32
+ # Return the _gemspec_ of the gem where it was found. If no match
33
+ # is found, return nil.
34
+ #
35
+ # The gems are searched in alphabetical order, and in reverse
36
+ # version order.
37
+ #
38
+ # For example:
39
+ #
40
+ # find('log4r') # -> (log4r-1.1 spec)
41
+ # find('log4r.rb') # -> (log4r-1.1 spec)
42
+ # find('rake/rdoctask') # -> (rake-0.4.12 spec)
43
+ # find('foobarbaz') # -> nil
44
+ #
45
+ # Matching paths can have various suffixes ('.rb', '.so', and
46
+ # others), which may or may not already be attached to _file_.
47
+ # This method doesn't care about the full filename that matches;
48
+ # only that there is a match.
49
+ #
50
+ def find(path)
51
+ @gemspecs.each do |spec|
52
+ return spec if matching_file(spec, path)
53
+ end
54
+ nil
55
+ end
56
+
57
+ private
58
+
59
+ # Attempts to find a matching path using the require_paths of the
60
+ # given _spec_.
61
+ #
62
+ # Some of the intermediate results are cached in @lib_dirs for
63
+ # speed.
64
+ def matching_file(spec, path) # :doc:
65
+ glob = File.join @lib_dirs[spec.object_id], "#{path}#{Gem.suffix_pattern}"
66
+ return true unless Dir[glob].select { |f| File.file?(f.untaint) }.empty?
67
+ end
68
+
69
+ # Return a list of all installed gemspecs, sorted by alphabetical
70
+ # order and in reverse version order.
71
+ def init_gemspecs
72
+ Gem.source_index.map { |_, spec| spec }.sort { |a,b|
73
+ (a.name <=> b.name).nonzero? || (b.version <=> a.version)
74
+ }
75
+ end
76
+
77
+ # Returns library directories glob for a gemspec. For example,
78
+ # '/usr/local/lib/ruby/gems/1.8/gems/foobar-1.0/{lib,ext}'
79
+ def lib_dirs_for(spec)
80
+ "#{spec.full_gem_path}/{#{spec.require_paths.join(',')}}"
81
+ end
82
+
83
+ end
84
+
@@ -1,11 +1,12 @@
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
 
8
- require 'rubygems/gem_commands'
7
+ require 'rubygems/command_manager'
8
+ require 'rubygems/config_file'
9
+ require 'rubygems/doc_manager'
9
10
 
10
11
  module Gem
11
12
 
@@ -22,12 +23,26 @@ module Gem
22
23
 
23
24
  # Run the gem command with the following arguments.
24
25
  def run(args)
26
+ start_time = Time.now
25
27
  do_configuration(args)
26
28
  cmd = @command_manager_class.instance
27
- cmd.command_names.each do |c|
28
- Command.add_specific_extra_args c, Array(Gem.configuration[c])
29
+ cmd.command_names.each do |command_name|
30
+ config_args = Gem.configuration[command_name]
31
+ config_args = case config_args
32
+ when String
33
+ config_args.split ' '
34
+ else
35
+ Array(config_args)
36
+ end
37
+ Command.add_specific_extra_args command_name, config_args
29
38
  end
30
39
  cmd.run(Gem.configuration.args)
40
+ end_time = Time.now
41
+ if Gem.configuration.benchmark
42
+ printf "\nExecution time: %0.2f seconds.\n", end_time-start_time
43
+ puts "Press Enter to finish"
44
+ STDIN.gets
45
+ end
31
46
  end
32
47
 
33
48
  private
@@ -35,7 +50,7 @@ module Gem
35
50
  def do_configuration(args)
36
51
  Gem.configuration = @config_file_class.new(args)
37
52
  Gem.use_paths(Gem.configuration[:gemhome], Gem.configuration[:gempath])
38
- Command.extra_args = Gem.configuration[:gem]
53
+ Gem::Command.extra_args = Gem.configuration[:gem]
39
54
  @doc_manager_class.configured_args = Gem.configuration[:rdoc]
40
55
  end
41
56
 
@@ -0,0 +1,163 @@
1
+ require 'fileutils'
2
+ require 'tmpdir'
3
+
4
+ require 'rubygems'
5
+ require 'rubygems/format'
6
+
7
+ begin
8
+ require 'builder/xchar'
9
+ rescue LoadError
10
+ end
11
+
12
+ ##
13
+ # Top level class for building the gem repository index.
14
+ class Gem::Indexer
15
+
16
+ include Gem::UserInteraction
17
+
18
+ ##
19
+ # Index install location
20
+
21
+ attr_reader :dest_directory
22
+
23
+ ##
24
+ # Index build directory
25
+
26
+ attr_reader :directory
27
+
28
+ # Create an indexer that will index the gems in +directory+.
29
+ def initialize(directory)
30
+ unless ''.respond_to? :to_xs then
31
+ fail "Gem::Indexer requires that the XML Builder library be installed:" \
32
+ "\n\tgem install builder"
33
+ end
34
+
35
+ @dest_directory = directory
36
+ @directory = File.join Dir.tmpdir, "gem_generate_index_#{$$}"
37
+
38
+ marshal_name = "Marshal.#{Gem.marshal_version}"
39
+
40
+ @master_index = Gem::Indexer::MasterIndexBuilder.new "yaml", @directory
41
+ @marshal_index = Gem::Indexer::MarshalIndexBuilder.new marshal_name, @directory
42
+ @quick_index = Gem::Indexer::QuickIndexBuilder.new "index", @directory
43
+ end
44
+
45
+ # Build the index.
46
+ def build_index
47
+ @master_index.build do
48
+ @quick_index.build do
49
+ @marshal_index.build do
50
+ progress = ui.progress_reporter gem_file_list.size,
51
+ "Generating index for #{gem_file_list.size} gems in #{@dest_directory}",
52
+ "Loaded all gems"
53
+
54
+ gem_file_list.each do |gemfile|
55
+ if File.size(gemfile.to_s) == 0 then
56
+ alert_warning "Skipping zero-length gem: #{gemfile}"
57
+ next
58
+ end
59
+
60
+ begin
61
+ spec = Gem::Format.from_file_by_path(gemfile).spec
62
+
63
+ unless gemfile =~ /\/#{Regexp.escape spec.original_name}.*\.gem\z/i then
64
+ alert_warning "Skipping misnamed gem: #{gemfile} => #{spec.full_name} (#{spec.original_name})"
65
+ next
66
+ end
67
+
68
+ abbreviate spec
69
+ sanitize spec
70
+
71
+ @master_index.add spec
72
+ @quick_index.add spec
73
+ @marshal_index.add spec
74
+
75
+ progress.updated spec.original_name
76
+
77
+ rescue SignalException => e
78
+ alert_error "Recieved signal, exiting"
79
+ raise
80
+ rescue Exception => e
81
+ alert_error "Unable to process #{gemfile}\n#{e.message} (#{e.class})\n\t#{e.backtrace.join "\n\t"}"
82
+ end
83
+ end
84
+
85
+ progress.done
86
+
87
+ say "Generating master indexes (this may take a while)"
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ def install_index
94
+ verbose = Gem.configuration.really_verbose
95
+
96
+ say "Moving index into production dir #{@dest_directory}" if verbose
97
+
98
+ files = @master_index.files + @quick_index.files + @marshal_index.files
99
+
100
+ files.each do |file|
101
+ relative_name = file[/\A#{@directory}.(.*)/, 1]
102
+ dest_name = File.join @dest_directory, relative_name
103
+
104
+ FileUtils.rm_rf dest_name, :verbose => verbose
105
+ FileUtils.mv file, @dest_directory, :verbose => verbose
106
+ end
107
+ end
108
+
109
+ def generate_index
110
+ FileUtils.rm_rf @directory
111
+ FileUtils.mkdir_p @directory, :mode => 0700
112
+
113
+ build_index
114
+ install_index
115
+ rescue SignalException
116
+ ensure
117
+ FileUtils.rm_rf @directory
118
+ end
119
+
120
+ # List of gem file names to index.
121
+ def gem_file_list
122
+ Dir.glob(File.join(@dest_directory, "gems", "*.gem"))
123
+ end
124
+
125
+ # Abbreviate the spec for downloading. Abbreviated specs are only
126
+ # used for searching, downloading and related activities and do not
127
+ # need deployment specific information (e.g. list of files). So we
128
+ # abbreviate the spec, making it much smaller for quicker downloads.
129
+ def abbreviate(spec)
130
+ spec.files = []
131
+ spec.test_files = []
132
+ spec.rdoc_options = []
133
+ spec.extra_rdoc_files = []
134
+ spec.cert_chain = []
135
+ spec
136
+ end
137
+
138
+ # Sanitize the descriptive fields in the spec. Sometimes non-ASCII
139
+ # characters will garble the site index. Non-ASCII characters will
140
+ # be replaced by their XML entity equivalent.
141
+ def sanitize(spec)
142
+ spec.summary = sanitize_string(spec.summary)
143
+ spec.description = sanitize_string(spec.description)
144
+ spec.post_install_message = sanitize_string(spec.post_install_message)
145
+ spec.authors = spec.authors.collect { |a| sanitize_string(a) }
146
+ spec
147
+ end
148
+
149
+ # Sanitize a single string.
150
+ def sanitize_string(string)
151
+ # HACK the #to_s is in here because RSpec has an Array of Arrays of
152
+ # Strings for authors. Need a way to disallow bad values on gempsec
153
+ # generation. (Probably won't happen.)
154
+ string ? string.to_s.to_xs : string
155
+ end
156
+
157
+ end
158
+
159
+ require 'rubygems/indexer/abstract_index_builder'
160
+ require 'rubygems/indexer/master_index_builder'
161
+ require 'rubygems/indexer/quick_index_builder'
162
+ require 'rubygems/indexer/marshal_index_builder'
163
+
@@ -0,0 +1,80 @@
1
+ require 'zlib'
2
+
3
+ require 'rubygems/indexer'
4
+
5
+ # Abstract base class for building gem indicies. Uses the template pattern
6
+ # with subclass specialization in the +begin_index+, +end_index+ and +cleanup+
7
+ # methods.
8
+ class Gem::Indexer::AbstractIndexBuilder
9
+
10
+ # Directory to put index files in
11
+ attr_reader :directory
12
+
13
+ # File name of the generated index
14
+ attr_reader :filename
15
+
16
+ # List of written files/directories to move into production
17
+ attr_reader :files
18
+
19
+ def initialize(filename, directory)
20
+ @filename = filename
21
+ @directory = directory
22
+ @files = []
23
+ end
24
+
25
+ # Build a Gem index. Yields to block to handle the details of the
26
+ # actual building. Calls +begin_index+, +end_index+ and +cleanup+ at
27
+ # appropriate times to customize basic operations.
28
+ def build
29
+ FileUtils.mkdir_p @directory unless File.exist? @directory
30
+ raise "not a directory: #{@directory}" unless File.directory? @directory
31
+
32
+ file_path = File.join @directory, @filename
33
+
34
+ @files << file_path
35
+
36
+ File.open file_path, "wb" do |file|
37
+ @file = file
38
+ start_index
39
+ yield
40
+ end_index
41
+ end
42
+ cleanup
43
+ ensure
44
+ @file = nil
45
+ end
46
+
47
+ # Compress the given file.
48
+ def compress(filename, ext="rz")
49
+ zipped = zip(File.open(filename, 'rb'){ |fp| fp.read })
50
+ File.open "#{filename}.#{ext}", "wb" do |file|
51
+ file.write zipped
52
+ end
53
+ end
54
+
55
+ # Called immediately before the yield in build. The index file is open and
56
+ # available as @file.
57
+ def start_index
58
+ end
59
+
60
+ # Called immediately after the yield in build. The index file is still open
61
+ # and available as @file.
62
+ def end_index
63
+ end
64
+
65
+ # Called from within builder after the index file has been closed.
66
+ def cleanup
67
+ end
68
+
69
+ # Return an uncompressed version of a compressed string.
70
+ def unzip(string)
71
+ Zlib::Inflate.inflate(string)
72
+ end
73
+
74
+ # Return a compressed version of the given string.
75
+ def zip(string)
76
+ Zlib::Deflate.deflate(string)
77
+ end
78
+
79
+ end
80
+
@@ -0,0 +1,17 @@
1
+ require 'rubygems/indexer'
2
+
3
+ # Construct the master Gem index file.
4
+ class Gem::Indexer::MarshalIndexBuilder < Gem::Indexer::MasterIndexBuilder
5
+ def end_index
6
+ gems = {}
7
+ index = Gem::SourceIndex.new
8
+
9
+ @index.each do |name, gemspec|
10
+ gems[gemspec.original_name] = gemspec
11
+ end
12
+
13
+ index.instance_variable_get(:@gems).replace gems
14
+
15
+ @file.write index.dump
16
+ end
17
+ end
@@ -0,0 +1,53 @@
1
+ require 'rubygems/indexer'
2
+
3
+ # Construct the master Gem index file.
4
+ class Gem::Indexer::MasterIndexBuilder < Gem::Indexer::AbstractIndexBuilder
5
+
6
+ def start_index
7
+ super
8
+ @index = Gem::SourceIndex.new
9
+ end
10
+
11
+ def end_index
12
+ super
13
+ @file.puts "--- !ruby/object:#{@index.class}"
14
+ @file.puts "gems:"
15
+
16
+ gems = @index.sort_by { |name, gemspec| gemspec.sort_obj }
17
+ gems.each do |name, gemspec|
18
+ yaml = gemspec.to_yaml.gsub(/^/, ' ')
19
+ yaml = yaml.sub(/\A ---/, '') # there's a needed extra ' ' here
20
+ @file.print " #{gemspec.original_name}:"
21
+ @file.puts yaml
22
+ end
23
+ end
24
+
25
+ def cleanup
26
+ super
27
+
28
+ index_file_name = File.join @directory, @filename
29
+
30
+ compress index_file_name, "Z"
31
+ compressed_file_name = "#{index_file_name}.Z"
32
+
33
+ paranoid index_file_name, compressed_file_name
34
+
35
+ @files << compressed_file_name
36
+ end
37
+
38
+ def add(spec)
39
+ @index.add_spec(spec)
40
+ end
41
+
42
+ private
43
+
44
+ def paranoid(fn, compressed_fn)
45
+ data = File.open(fn, 'rb') do |fp| fp.read end
46
+ compressed_data = File.open(compressed_fn, 'rb') do |fp| fp.read end
47
+
48
+ if data != unzip(compressed_data) then
49
+ fail "Compressed file #{compressed_fn} does not match uncompressed file #{fn}"
50
+ end
51
+ end
52
+
53
+ end