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
@@ -1,86 +1,118 @@
1
- module Gem
2
- module Commands
3
- class QueryCommand < Command
4
- include LocalRemoteOptions
5
-
6
- def initialize(name='query', summary='Query gem information in local or remote repositories')
7
- super(name,
8
- summary,
9
- {:name=>/.*/, :domain=>:local, :details=>false}
10
- )
11
- add_option('-n', '--name-matches REGEXP', 'Name of gem(s) to query on matches the provided REGEXP') do |value, options|
12
- options[:name] = /#{value}/i
13
- end
14
- add_option('-d', '--[no-]details', 'Display detailed information of gem(s)') do |value, options|
15
- options[:details] = value
1
+ require 'rubygems/command'
2
+ require 'rubygems/local_remote_options'
3
+ require 'rubygems/source_info_cache'
4
+
5
+ class Gem::Commands::QueryCommand < Gem::Command
6
+
7
+ include Gem::LocalRemoteOptions
8
+
9
+ def initialize(name = 'query',
10
+ summary = 'Query gem information in local or remote repositories')
11
+ super name, summary,
12
+ :name => /.*/, :domain => :local, :details => false, :versions => true
13
+
14
+ add_option('-n', '--name-matches REGEXP',
15
+ 'Name of gem(s) to query on matches the',
16
+ 'provided REGEXP') do |value, options|
17
+ options[:name] = /#{value}/i
18
+ end
19
+
20
+ add_option('-d', '--[no-]details',
21
+ 'Display detailed information of gem(s)') do |value, options|
22
+ options[:details] = value
23
+ end
24
+
25
+ add_option( '--[no-]versions',
26
+ 'Display only gem names') do |value, options|
27
+ options[:versions] = value
28
+ options[:details] = false unless value
29
+ end
30
+
31
+ add_local_remote_options
32
+ end
33
+
34
+ def defaults_str # :nodoc:
35
+ "--local --name-matches '.*' --no-details --versions"
36
+ end
37
+
38
+ def execute
39
+ name = options[:name]
40
+
41
+ if local? then
42
+ say
43
+ say "*** LOCAL GEMS ***"
44
+ say
45
+ output_query_results Gem.cache.search(name)
46
+ end
47
+
48
+ if remote? then
49
+ say
50
+ say "*** REMOTE GEMS ***"
51
+ say
52
+ output_query_results Gem::SourceInfoCache.search(name)
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def output_query_results(gemspecs)
59
+ output = []
60
+ gem_list_with_version = {}
61
+
62
+ gemspecs.flatten.each do |gemspec|
63
+ gem_list_with_version[gemspec.name] ||= []
64
+ gem_list_with_version[gemspec.name] << gemspec
65
+ end
66
+
67
+ gem_list_with_version = gem_list_with_version.sort_by do |name, spec|
68
+ name.downcase
69
+ end
70
+
71
+ gem_list_with_version.each do |gem_name, list_of_matching|
72
+ list_of_matching = list_of_matching.sort_by { |x| x.version.to_ints }.reverse
73
+ seen_versions = {}
74
+
75
+ list_of_matching.delete_if do |item|
76
+ if seen_versions[item.version] then
77
+ true
78
+ else
79
+ seen_versions[item.version] = true
80
+ false
16
81
  end
17
- add_local_remote_options
18
82
  end
19
83
 
20
- def defaults_str
21
- "--local --name-matches '.*' --no-details"
22
- end
23
-
24
- def execute
25
- if local?
26
- say
27
- say "*** LOCAL GEMS ***"
28
- output_query_results(Gem::cache.search(options[:name]))
29
- end
30
- if remote?
31
- say
32
- say "*** REMOTE GEMS ***"
33
- output_query_results(Gem::SourceInfoCache.search(options[:name]))
34
- end
84
+ entry = gem_name.dup
85
+ if options[:versions] then
86
+ entry << " (#{list_of_matching.map{|gem| gem.version.to_s}.join(", ")})"
35
87
  end
36
88
 
37
- private
89
+ entry << "\n" << format_text(list_of_matching[0].summary, 68, 4) if
90
+ options[:details]
91
+ output << entry
92
+ end
38
93
 
39
- def output_query_results(gemspecs)
40
- gem_list_with_version = {}
41
- gemspecs.flatten.each do |gemspec|
42
- gem_list_with_version[gemspec.name] ||= []
43
- gem_list_with_version[gemspec.name] << gemspec
44
- end
45
-
46
- gem_list_with_version = gem_list_with_version.sort do |first, second|
47
- first[0].downcase <=> second[0].downcase
48
- end
49
- gem_list_with_version.each do |gem_name, list_of_matching|
50
- say
51
- list_of_matching = list_of_matching.sort_by { |x| x.version }.reverse
52
- seen_versions = []
53
- list_of_matching.delete_if do |item|
54
- if(seen_versions.member?(item.version))
55
- true
56
- else
57
- seen_versions << item.version
58
- false
59
- end
60
- end
61
- say "#{gem_name} (#{list_of_matching.map{|gem| gem.version.to_s}.join(", ")})"
62
- say format_text(list_of_matching[0].summary, 68, 4)
63
- end
64
- end
65
-
66
- ##
67
- # Used for wrapping and indenting text
68
- #
69
- def format_text(text, wrap, indent=0)
70
- result = []
71
- pattern = Regexp.new("^(.{0,#{wrap}})[ \n]")
72
- work = text.dup
73
- while work.length > wrap
74
- if work =~ pattern
75
- result << $1
76
- work.slice!(0, $&.length)
77
- else
78
- result << work.slice!(0, wrap)
79
- end
80
- end
81
- result << work if work.length.nonzero?
82
- result.join("\n").gsub(/^/, " " * indent)
94
+ say output.join(options[:details] ? "\n\n" : "\n")
95
+ end
96
+
97
+ ##
98
+ # Used for wrapping and indenting text
99
+ #
100
+ def format_text(text, wrap, indent=0)
101
+ result = []
102
+ work = text.dup
103
+
104
+ while work.length > wrap
105
+ if work =~ /^(.{0,#{wrap}})[ \n]/o then
106
+ result << $1
107
+ work.slice!(0, $&.length)
108
+ else
109
+ result << work.slice!(0, wrap)
83
110
  end
84
111
  end
112
+
113
+ result << work if work.length.nonzero?
114
+ result.join("\n").gsub(/^/, " " * indent)
85
115
  end
86
- end
116
+
117
+ end
118
+
@@ -1,14 +1,17 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/version_option'
3
+ require 'rubygems/doc_manager'
4
+
1
5
  module Gem
2
6
  module Commands
3
7
  class RdocCommand < Command
4
8
  include VersionOption
5
- include CommandAids
6
9
 
7
10
  def initialize
8
11
  super('rdoc',
9
12
  'Generates RDoc for pre-installed gems',
10
13
  {
11
- :version => "> 0.0.0",
14
+ :version => Gem::Requirement.default,
12
15
  :include_rdoc => true,
13
16
  :include_ri => true,
14
17
  })
@@ -27,19 +30,19 @@ module Gem
27
30
  ) do |value, options|
28
31
  options[:include_ri] = value
29
32
  end
30
- add_version_option('rdoc')
33
+ add_version_option
31
34
  end
32
35
 
33
- def defaults_str
34
- "--version '> 0.0.0' --rdoc --ri"
36
+ def arguments # :nodoc:
37
+ "GEMNAME gem to generate documentation for (unless --all)"
35
38
  end
36
39
 
37
- def usage
38
- "#{program_name} [args]"
40
+ def defaults_str # :nodoc:
41
+ "--version '#{Gem::Requirement.default}' --rdoc --ri"
39
42
  end
40
43
 
41
- def arguments
42
- "GEMNAME The gem to generate RDoc for (unless --all)"
44
+ def usage # :nodoc:
45
+ "#{program_name} [args]"
43
46
  end
44
47
 
45
48
  def execute
@@ -72,4 +75,4 @@ module Gem
72
75
  end
73
76
 
74
77
  end
75
- end
78
+ end
@@ -1,8 +1,10 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/commands/query_command'
3
+
1
4
  module Gem
2
5
  module Commands
3
6
 
4
7
  class SearchCommand < QueryCommand
5
- include CommandAids
6
8
 
7
9
  def initialize
8
10
  super(
@@ -12,16 +14,16 @@ module Gem
12
14
  remove_option('--name-matches')
13
15
  end
14
16
 
15
- def defaults_str
16
- "--local --no-details"
17
+ def arguments # :nodoc:
18
+ "STRING fragment of gem name to search for"
17
19
  end
18
20
 
19
- def usage
20
- "#{program_name} [STRING]"
21
+ def defaults_str # :nodoc:
22
+ "--local --no-details"
21
23
  end
22
24
 
23
- def arguments
24
- "STRING fragment of gem name to look for"
25
+ def usage # :nodoc:
26
+ "#{program_name} [STRING]"
25
27
  end
26
28
 
27
29
  def execute
@@ -32,4 +34,4 @@ module Gem
32
34
  end
33
35
 
34
36
  end
35
- end
37
+ end
@@ -0,0 +1,48 @@
1
+ require 'rubygems/command'
2
+ require 'rubygems/server'
3
+
4
+ class Gem::Commands::ServerCommand < Gem::Command
5
+
6
+ def initialize
7
+ super 'server', 'Documentation and gem repository HTTP server',
8
+ :port => 8808, :gemdir => Gem.dir, :daemon => false
9
+
10
+ add_option '-p', '--port=PORT',
11
+ 'port to listen on' do |port, options|
12
+ options[:port] = port
13
+ end
14
+
15
+ add_option '-d', '--dir=GEMDIR',
16
+ 'directory from which to serve gems' do |gemdir, options|
17
+ options[:gemdir] = gemdir
18
+ end
19
+
20
+ add_option '--[no]-daemon', 'run as a daemon' do |daemon, options|
21
+ options[:daemon] = daemon
22
+ end
23
+ end
24
+
25
+ def defaults_str # :nodoc:
26
+ "--port 8808 --dir #{Gem.dir} --no-daemon"
27
+ end
28
+
29
+ def description # :nodoc:
30
+ <<-EOF
31
+ The server command starts up a web server that hosts the RDoc for your
32
+ installed gems and can operate as a server for installation of gems on other
33
+ machines.
34
+
35
+ The cache files for installed gems must exist to use the server as a source
36
+ for gem installation.
37
+
38
+ To install gems from a running server, use `gem install GEMNAME --source
39
+ http://gem_server_host:8808`
40
+ EOF
41
+ end
42
+
43
+ def execute
44
+ Gem::Server.run options
45
+ end
46
+
47
+ end
48
+
@@ -1,94 +1,115 @@
1
- module Gem
2
- module Commands
3
-
4
- class SourcesCommand < Command
1
+ require 'rubygems/command'
2
+ require 'rubygems/remote_fetcher'
3
+ require 'rubygems/source_info_cache'
4
+ require 'rubygems/source_info_cache_entry'
5
+
6
+ class Gem::Commands::SourcesCommand < Gem::Command
7
+
8
+ def initialize
9
+ super 'sources',
10
+ 'Manage the sources and cache file RubyGems uses to search for gems'
11
+
12
+ add_option '-a', '--add SOURCE_URI', 'Add source' do |value, options|
13
+ options[:add] = value
14
+ end
15
+
16
+ add_option '-l', '--list', 'List sources' do |value, options|
17
+ options[:list] = value
18
+ end
19
+
20
+ add_option '-r', '--remove SOURCE_URI', 'Remove source' do |value, options|
21
+ options[:remove] = value
22
+ end
23
+
24
+ add_option '-u', '--update', 'Update source cache' do |value, options|
25
+ options[:update] = value
26
+ end
27
+
28
+ add_option '-c', '--clear-all',
29
+ 'Remove all sources (clear the cache)' do |value, options|
30
+ options[:clear_all] = value
31
+ end
32
+ end
33
+
34
+ def defaults_str
35
+ '--list'
36
+ end
37
+
38
+ def execute
39
+ options[:list] = !(options[:add] || options[:remove] || options[:clear_all] || options[:update])
40
+
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)
44
+ end
45
+
46
+ if options[:add] then
47
+ source_uri = options[:add]
48
+
49
+ sice = Gem::SourceInfoCacheEntry.new nil, nil
50
+ begin
51
+ sice.refresh source_uri
52
+
53
+ Gem::SourceInfoCache.cache_data[source_uri] = sice
54
+ Gem::SourceInfoCache.cache.update
55
+ Gem::SourceInfoCache.cache.flush
56
+
57
+ Gem.sources << source_uri
58
+ Gem.configuration.write
59
+
60
+ say "#{source_uri} added to sources"
61
+ rescue URI::Error, ArgumentError
62
+ say "#{source_uri} is not a URI"
63
+ rescue Gem::RemoteFetcher::FetchError => e
64
+ say "Error fetching #{source_uri}:\n\t#{e.message}"
65
+ end
66
+ end
5
67
 
6
- def initialize
7
- super 'sources', 'Manage the sources RubyGems will search forgems'
68
+ if options[:update] then
69
+ Gem::SourceInfoCache.cache.refresh
70
+ Gem::SourceInfoCache.cache.flush
8
71
 
9
- add_option '-a', '--add SOURCE_URI', 'Add source' do |value, options|
10
- options[:add] = value
11
- end
72
+ say "source cache successfully updated"
73
+ end
12
74
 
13
- add_option '-l', '--list', 'List sources' do |value, options|
14
- options[:list] = value
15
- end
75
+ if options[:remove] then
76
+ source_uri = options[:remove]
16
77
 
17
- add_option '-r', '--remove SOURCE_URI', 'Remove source' do |value, options|
18
- options[:remove] = value
19
- end
78
+ unless Gem.sources.include? source_uri then
79
+ say "source #{source_uri} not present in cache"
80
+ else
81
+ Gem::SourceInfoCache.cache_data.delete source_uri
82
+ Gem::SourceInfoCache.cache.update
83
+ Gem::SourceInfoCache.cache.flush
84
+ Gem.sources.delete source_uri
85
+ Gem.configuration.write
20
86
 
21
- add_option '-c', '--clear-all', 'Remove all sources' do |value, options|
22
- options[:clear_all] = value
23
- end
87
+ say "#{source_uri} removed from sources"
24
88
  end
89
+ end
25
90
 
26
- def defaults_str
27
- '--list'
28
- end
91
+ if options[:list] then
92
+ say "*** CURRENT SOURCES ***"
93
+ say
29
94
 
30
- def execute
31
- options[:list] = ! (options[:add] || options[:remove] || options[:clear_all])
32
-
33
- if options[:clear_all] then
34
- remove_cache_file("user", Gem::SourceInfoCache.user_cache_file)
35
- remove_cache_file("system", Gem::SourceInfoCache.system_cache_file)
36
- end
37
-
38
- if options[:add] then
39
- source_uri = options[:add]
40
-
41
- sice = Gem::SourceInfoCacheEntry.new nil, nil
42
- begin
43
- sice.refresh source_uri
44
- rescue ArgumentError
45
- say "#{source_uri} is not a URI"
46
- rescue Gem::RemoteFetcher::FetchError => e
47
- say "Error fetching #{source_uri}:\n\t#{e.message}"
48
- else
49
- Gem::SourceInfoCache.cache_data[source_uri] = sice
50
- Gem::SourceInfoCache.cache.update
51
- Gem::SourceInfoCache.cache.flush
52
-
53
- say "#{source_uri} added to sources"
54
- end
55
- end
56
-
57
- if options[:remove] then
58
- source_uri = options[:remove]
59
-
60
- unless Gem::SourceInfoCache.cache_data.include? source_uri then
61
- say "source #{source_uri} not present in cache"
62
- else
63
- Gem::SourceInfoCache.cache_data.delete source_uri
64
- Gem::SourceInfoCache.cache.update
65
- Gem::SourceInfoCache.cache.flush
66
- say "#{source_uri} removed from sources"
67
- end
68
- end
69
-
70
- if options[:list] then
71
- say "*** CURRENT SOURCES ***"
72
- say
73
-
74
- Gem::SourceInfoCache.cache_data.keys.each do |source_uri|
75
- say source_uri
76
- end
77
- end
95
+ Gem.sources.each do |source_uri|
96
+ say source_uri
78
97
  end
98
+ end
99
+ end
79
100
 
80
- def remove_cache_file(desc, fn)
81
- FileUtils.rm_rf fn rescue nil
82
- if ! File.exist?(fn)
83
- say "*** Removed #{desc} source cache ***"
84
- elsif ! File.writable?(fn)
85
- say "*** Unable to remove #{desc} source cache (write protected) ***"
86
- else
87
- say "*** Unable to remove #{desc} source cache ***"
88
- end
89
- end
90
- private :remove_cache_file
101
+ private
102
+
103
+ def remove_cache_file(desc, fn)
104
+ FileUtils.rm_rf fn rescue nil
105
+ if ! File.exist?(fn)
106
+ say "*** Removed #{desc} source cache ***"
107
+ elsif ! File.writable?(fn)
108
+ say "*** Unable to remove #{desc} source cache (write protected) ***"
109
+ else
110
+ say "*** Unable to remove #{desc} source cache ***"
111
+ end
112
+ end
113
+
114
+ end
91
115
 
92
- end # class SourcesCommand
93
- end # module Commands
94
- end # module Gem