rubygems-update 0.9.2 → 0.9.3

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 (53) hide show
  1. data/ChangeLog +60 -0
  2. data/lib/rubygems.rb +18 -15
  3. data/lib/rubygems/builder.rb +29 -23
  4. data/lib/rubygems/{cmd_manager.rb → command_manager.rb} +35 -24
  5. data/lib/rubygems/commands/build_command.rb +57 -0
  6. data/lib/rubygems/commands/cert_command.rb +83 -0
  7. data/lib/rubygems/commands/check_command.rb +74 -0
  8. data/lib/rubygems/commands/cleanup_command.rb +75 -0
  9. data/lib/rubygems/commands/contents_command.rb +66 -0
  10. data/lib/rubygems/commands/dependency_command.rb +105 -0
  11. data/lib/rubygems/commands/environment_command.rb +59 -0
  12. data/lib/rubygems/commands/help_command.rb +82 -0
  13. data/lib/rubygems/commands/install_command.rb +139 -0
  14. data/lib/rubygems/commands/list_command.rb +33 -0
  15. data/lib/rubygems/commands/outdated_command.rb +21 -0
  16. data/lib/rubygems/commands/pristine_command.rb +103 -0
  17. data/lib/rubygems/commands/query_command.rb +86 -0
  18. data/lib/rubygems/commands/rdoc_command.rb +75 -0
  19. data/lib/rubygems/commands/search_command.rb +35 -0
  20. data/lib/rubygems/commands/sources_command.rb +73 -0
  21. data/lib/rubygems/commands/specification_command.rb +58 -0
  22. data/lib/rubygems/commands/uninstall_command.rb +51 -0
  23. data/lib/rubygems/commands/unpack_command.rb +76 -0
  24. data/lib/rubygems/commands/update_command.rb +102 -0
  25. data/lib/rubygems/digest/digest_adapter.rb +40 -0
  26. data/lib/rubygems/digest/md5.rb +20 -0
  27. data/lib/rubygems/digest/sha1.rb +17 -0
  28. data/lib/rubygems/digest/sha2.rb +17 -0
  29. data/lib/rubygems/format.rb +1 -1
  30. data/lib/rubygems/gem_commands.rb +6 -1407
  31. data/lib/rubygems/gem_runner.rb +2 -2
  32. data/lib/rubygems/installer.rb +13 -5
  33. data/lib/rubygems/open-uri.rb +2 -2
  34. data/lib/rubygems/package.rb +13 -14
  35. data/lib/rubygems/rubygems_version.rb +1 -1
  36. data/lib/rubygems/source_index.rb +4 -4
  37. data/lib/rubygems/specification.rb +5 -0
  38. data/lib/rubygems/validator.rb +8 -8
  39. data/setup.rb +806 -588
  40. data/test/gemutilities.rb +2 -2
  41. data/test/test_builder.rb +15 -0
  42. data/test/test_check_command.rb +1 -1
  43. data/test/test_command.rb +1 -1
  44. data/test/test_gem_digest.rb +44 -0
  45. data/test/test_gem_outdated_command.rb +2 -1
  46. data/test/test_gem_sources_command.rb +11 -6
  47. data/test/test_installer.rb +1 -1
  48. data/test/test_open_uri.rb +14 -0
  49. data/test/test_parse_commands.rb +25 -25
  50. data/test/test_process_commands.rb +5 -5
  51. data/test/test_specific_extras.rb +1 -1
  52. data/test/test_validator.rb +3 -3
  53. metadata +30 -4
@@ -0,0 +1,33 @@
1
+ module Gem
2
+ module Commands
3
+ class ListCommand < QueryCommand
4
+ include CommandAids
5
+
6
+ def initialize
7
+ super(
8
+ 'list',
9
+ 'Display all gems whose name starts with STRING'
10
+ )
11
+ remove_option('--name-matches')
12
+ end
13
+
14
+ def defaults_str
15
+ "--local --no-details"
16
+ end
17
+
18
+ def usage
19
+ "#{program_name} [STRING]"
20
+ end
21
+
22
+ def arguments
23
+ "STRING start of gem name to look for"
24
+ end
25
+
26
+ def execute
27
+ string = get_one_optional_argument || ''
28
+ options[:name] = /^#{string}/i
29
+ super
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,21 @@
1
+ module Gem
2
+ module Commands
3
+
4
+ class OutdatedCommand < Command
5
+
6
+ def initialize
7
+ super 'outdated', 'Display all gems that need updates'
8
+ end
9
+
10
+ def execute
11
+ locals = Gem::SourceIndex.from_installed_gems
12
+ locals.outdated.each do |name|
13
+ local = locals.search(/^#{name}$/).last
14
+ remote = Gem::SourceInfoCache.search(/^#{name}$/).last
15
+ say "#{local.name} (#{local.version} < #{remote.version})"
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,103 @@
1
+ module Gem
2
+ module Commands
3
+ class PristineCommand < Command
4
+ include VersionOption
5
+ include CommandAids
6
+ def initialize
7
+ super('pristine',
8
+ 'Restores gem directories to pristine condition from files located in the gem cache',
9
+ {
10
+ :version => "> 0.0.0"
11
+ })
12
+ add_option('--all',
13
+ 'Restore all installed gems to pristine', 'condition'
14
+ ) do |value, options|
15
+ options[:all] = value
16
+ end
17
+ add_version_option('restore to', 'pristine condition')
18
+ end
19
+
20
+ def defaults_str
21
+ "--all"
22
+ end
23
+
24
+ def usage
25
+ "#{program_name} [args]"
26
+ end
27
+
28
+ def arguments
29
+ "GEMNAME The gem to restore to pristine condition (unless --all)"
30
+ end
31
+
32
+ def execute
33
+ say "Restoring gem(s) to pristine condition..."
34
+ if options[:all]
35
+ all_gems = true
36
+ specs = Gem::SourceIndex.from_installed_gems.collect do |name, spec|
37
+ spec
38
+ end
39
+ else
40
+ all_gems = false
41
+ gem_name = get_one_gem_name
42
+ specs = Gem::SourceIndex.from_installed_gems.search(gem_name, options[:version])
43
+ end
44
+
45
+ if specs.empty?
46
+ fail "Failed to find gem #{gem_name} #{options[:version]} to restore to pristine condition"
47
+ end
48
+ install_dir = Gem.dir # TODO use installer option
49
+ raise Gem::FilePermissionError.new(install_dir) unless File.writable?(install_dir)
50
+
51
+ gems_were_pristine = true
52
+
53
+ specs.each do |spec|
54
+ installer = Gem::Installer.new nil, :wrappers => true # HACK ugly TODO use installer option
55
+
56
+ gem_file = File.join(install_dir, "cache", "#{spec.full_name}.gem")
57
+ security_policy = nil # TODO use installer option
58
+ format = Gem::Format.from_file_by_path(gem_file, security_policy)
59
+ target_directory = File.join(install_dir, "gems", format.spec.full_name).untaint
60
+ pristine_files = format.file_entries.collect {|data| data[0]["path"]}
61
+ file_map = {}
62
+ format.file_entries.each {|entry, file_data| file_map[entry["path"]] = file_data}
63
+ require 'fileutils'
64
+
65
+ Dir.chdir target_directory do
66
+ deployed_files = Dir.glob(File.join("**", "*")) +
67
+ Dir.glob(File.join("**", ".*"))
68
+ to_redeploy = (pristine_files - deployed_files).collect {|path| path.untaint}
69
+ if to_redeploy.length > 0
70
+ gems_were_pristine = false
71
+ say "Restoring #{to_redeploy.length} file#{to_redeploy.length == 1 ? "" : "s"} to #{spec.full_name}..."
72
+ to_redeploy.each do |path|
73
+ say " #{path}"
74
+ FileUtils.mkdir_p File.dirname(path)
75
+ File.open(path, "wb") do |out|
76
+ out.write file_map[path]
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ installer.generate_bin spec, install_dir
83
+ end
84
+
85
+ say "Rebuilt all bin stubs"
86
+
87
+ if gems_were_pristine
88
+ if all_gems
89
+ say "All installed gem files are already in pristine condition"
90
+ else
91
+ say "#{specs[0].full_name} is already in pristine condition"
92
+ end
93
+ else
94
+ if all_gems
95
+ say "All installed gem files restored to pristine condition"
96
+ else
97
+ say "#{specs[0].full_name} restored to pristine condition"
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,86 @@
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
16
+ end
17
+ add_local_remote_options
18
+ end
19
+
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
35
+ end
36
+
37
+ private
38
+
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)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,75 @@
1
+ module Gem
2
+ module Commands
3
+ class RdocCommand < Command
4
+ include VersionOption
5
+ include CommandAids
6
+
7
+ def initialize
8
+ super('rdoc',
9
+ 'Generates RDoc for pre-installed gems',
10
+ {
11
+ :version => "> 0.0.0",
12
+ :include_rdoc => true,
13
+ :include_ri => true,
14
+ })
15
+ add_option('--all',
16
+ 'Generate RDoc/RI documentation for all',
17
+ 'installed gems') do |value, options|
18
+ options[:all] = value
19
+ end
20
+ add_option('--[no-]rdoc',
21
+ 'Include RDoc generated documents') do
22
+ |value, options|
23
+ options[:include_rdoc] = value
24
+ end
25
+ add_option('--[no-]ri',
26
+ 'Include RI generated documents'
27
+ ) do |value, options|
28
+ options[:include_ri] = value
29
+ end
30
+ add_version_option('rdoc')
31
+ end
32
+
33
+ def defaults_str
34
+ "--version '> 0.0.0' --rdoc --ri"
35
+ end
36
+
37
+ def usage
38
+ "#{program_name} [args]"
39
+ end
40
+
41
+ def arguments
42
+ "GEMNAME The gem to generate RDoc for (unless --all)"
43
+ end
44
+
45
+ def execute
46
+ if options[:all]
47
+ specs = Gem::SourceIndex.from_installed_gems.collect { |name, spec|
48
+ spec
49
+ }
50
+ else
51
+ gem_name = get_one_gem_name
52
+ specs = Gem::SourceIndex.from_installed_gems.search(
53
+ gem_name, options[:version])
54
+ end
55
+
56
+ if specs.empty?
57
+ fail "Failed to find gem #{gem_name} to generate RDoc for #{options[:version]}"
58
+ end
59
+ if options[:include_ri]
60
+ specs.each do |spec|
61
+ Gem::DocManager.new(spec).generate_ri
62
+ end
63
+ end
64
+ if options[:include_rdoc]
65
+ specs.each do |spec|
66
+ Gem::DocManager.new(spec).generate_rdoc
67
+ end
68
+ end
69
+
70
+ true
71
+ end
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,35 @@
1
+ module Gem
2
+ module Commands
3
+
4
+ class SearchCommand < QueryCommand
5
+ include CommandAids
6
+
7
+ def initialize
8
+ super(
9
+ 'search',
10
+ 'Display all gems whose name contains STRING'
11
+ )
12
+ remove_option('--name-matches')
13
+ end
14
+
15
+ def defaults_str
16
+ "--local --no-details"
17
+ end
18
+
19
+ def usage
20
+ "#{program_name} [STRING]"
21
+ end
22
+
23
+ def arguments
24
+ "STRING fragment of gem name to look for"
25
+ end
26
+
27
+ def execute
28
+ string = get_one_optional_argument
29
+ options[:name] = /#{string}/i
30
+ super
31
+ end
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,73 @@
1
+ module Gem
2
+ module Commands
3
+
4
+ class SourcesCommand < Command
5
+
6
+ def initialize
7
+ super 'sources', 'Manage the sources RubyGems will search forgems'
8
+
9
+ add_option '-a', '--add SOURCE_URI', 'Add source' do |value, options|
10
+ options[:add] = value
11
+ end
12
+
13
+ add_option '-l', '--list', 'List sources' do |value, options|
14
+ options[:list] = value
15
+ end
16
+
17
+ add_option '-r', '--remove SOURCE_URI', 'Remove source' do |value, options|
18
+ options[:remove] = value
19
+ end
20
+ end
21
+
22
+ def defaults_str
23
+ '--list'
24
+ end
25
+
26
+ def execute
27
+ if options[:add] then
28
+ source_uri = options[:add]
29
+
30
+ sice = Gem::SourceInfoCacheEntry.new nil, nil
31
+ begin
32
+ sice.refresh source_uri
33
+ rescue ArgumentError
34
+ say "#{source_uri} is not a URI"
35
+ rescue Gem::RemoteFetcher::FetchError => e
36
+ say "Error fetching #{source_uri}:\n\t#{e.message}"
37
+ else
38
+ Gem::SourceInfoCache.cache_data[source_uri] = sice
39
+ Gem::SourceInfoCache.cache.update
40
+ Gem::SourceInfoCache.cache.flush
41
+
42
+ say "#{source_uri} added to sources"
43
+ end
44
+ end
45
+
46
+ if options[:remove] then
47
+ source_uri = options[:remove]
48
+
49
+ unless Gem::SourceInfoCache.cache_data.include? source_uri then
50
+ say "source #{source_uri} not present in cache"
51
+ else
52
+ Gem::SourceInfoCache.cache_data.delete source_uri
53
+ Gem::SourceInfoCache.cache.update
54
+ Gem::SourceInfoCache.cache.flush
55
+ say "#{source_uri} removed from sources"
56
+ end
57
+ end
58
+
59
+ if options[:list] or not (options[:add] or options[:remove]) then
60
+ say "*** CURRENT SOURCES ***"
61
+ say
62
+
63
+ Gem::SourceInfoCache.cache_data.keys.each do |source_uri|
64
+ say source_uri
65
+ end
66
+ end
67
+ end
68
+
69
+ end
70
+
71
+
72
+ end
73
+ end
@@ -0,0 +1,58 @@
1
+ module Gem
2
+ module Commands
3
+ class SpecificationCommand < Command
4
+ include VersionOption
5
+ include LocalRemoteOptions
6
+ include CommandAids
7
+
8
+ def initialize
9
+ super('specification', 'Display gem specification (in yaml)',
10
+ {:domain=>:local, :version=>"> 0.0.0"})
11
+ add_version_option('examine')
12
+ add_local_remote_options
13
+ add_option('--all', 'Output specifications for all versions of',
14
+ 'the gem') do |value, options|
15
+ options[:all] = true
16
+ end
17
+ end
18
+
19
+ def defaults_str
20
+ "--local --version '(latest)'"
21
+ end
22
+
23
+ def usage
24
+ "#{program_name} GEMFILE"
25
+ end
26
+
27
+ def arguments
28
+ "GEMFILE Name of a .gem file to examine"
29
+ end
30
+
31
+ def execute
32
+ if local?
33
+ gem = get_one_gem_name
34
+ gem_specs = Gem::SourceIndex.from_installed_gems.search(gem, options[:version])
35
+ unless gem_specs.empty?
36
+ require 'yaml'
37
+ output = lambda { |spec| say spec.to_yaml; say "\n" }
38
+ if options[:all]
39
+ gem_specs.each(&output)
40
+ else
41
+ spec = gem_specs.sort_by { |spec| spec.version }.last
42
+ output[spec]
43
+ end
44
+ else
45
+ alert_error "Unknown gem #{gem}"
46
+ end
47
+ end
48
+
49
+ if remote?
50
+ say "(Remote 'info' operation is not yet implemented.)"
51
+ # NOTE: when we do implement remote info, make sure we don't
52
+ # duplicate huge swabs of local data. If it's the same, just
53
+ # say it's the same.
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end