libgems 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. data/ChangeLog +5811 -0
  2. data/History.txt +887 -0
  3. data/LICENSE.txt +51 -0
  4. data/README.md +87 -0
  5. data/Rakefile +113 -0
  6. data/lib/gauntlet_libgems.rb +50 -0
  7. data/lib/libgems.rb +1246 -0
  8. data/lib/libgems/builder.rb +102 -0
  9. data/lib/libgems/command.rb +534 -0
  10. data/lib/libgems/command_manager.rb +182 -0
  11. data/lib/libgems/commands/build_command.rb +53 -0
  12. data/lib/libgems/commands/cert_command.rb +86 -0
  13. data/lib/libgems/commands/check_command.rb +80 -0
  14. data/lib/libgems/commands/cleanup_command.rb +106 -0
  15. data/lib/libgems/commands/contents_command.rb +98 -0
  16. data/lib/libgems/commands/dependency_command.rb +195 -0
  17. data/lib/libgems/commands/environment_command.rb +133 -0
  18. data/lib/libgems/commands/fetch_command.rb +67 -0
  19. data/lib/libgems/commands/generate_index_command.rb +133 -0
  20. data/lib/libgems/commands/help_command.rb +172 -0
  21. data/lib/libgems/commands/install_command.rb +178 -0
  22. data/lib/libgems/commands/list_command.rb +35 -0
  23. data/lib/libgems/commands/lock_command.rb +110 -0
  24. data/lib/libgems/commands/mirror_command.rb +111 -0
  25. data/lib/libgems/commands/outdated_command.rb +33 -0
  26. data/lib/libgems/commands/owner_command.rb +75 -0
  27. data/lib/libgems/commands/pristine_command.rb +93 -0
  28. data/lib/libgems/commands/push_command.rb +56 -0
  29. data/lib/libgems/commands/query_command.rb +280 -0
  30. data/lib/libgems/commands/rdoc_command.rb +91 -0
  31. data/lib/libgems/commands/search_command.rb +31 -0
  32. data/lib/libgems/commands/server_command.rb +86 -0
  33. data/lib/libgems/commands/sources_command.rb +157 -0
  34. data/lib/libgems/commands/specification_command.rb +125 -0
  35. data/lib/libgems/commands/stale_command.rb +27 -0
  36. data/lib/libgems/commands/uninstall_command.rb +83 -0
  37. data/lib/libgems/commands/unpack_command.rb +121 -0
  38. data/lib/libgems/commands/update_command.rb +160 -0
  39. data/lib/libgems/commands/which_command.rb +86 -0
  40. data/lib/libgems/config_file.rb +345 -0
  41. data/lib/libgems/custom_require.rb +44 -0
  42. data/lib/libgems/defaults.rb +101 -0
  43. data/lib/libgems/dependency.rb +227 -0
  44. data/lib/libgems/dependency_installer.rb +286 -0
  45. data/lib/libgems/dependency_list.rb +208 -0
  46. data/lib/libgems/doc_manager.rb +242 -0
  47. data/lib/libgems/errors.rb +35 -0
  48. data/lib/libgems/exceptions.rb +91 -0
  49. data/lib/libgems/ext.rb +18 -0
  50. data/lib/libgems/ext/builder.rb +56 -0
  51. data/lib/libgems/ext/configure_builder.rb +25 -0
  52. data/lib/libgems/ext/ext_conf_builder.rb +24 -0
  53. data/lib/libgems/ext/rake_builder.rb +39 -0
  54. data/lib/libgems/format.rb +81 -0
  55. data/lib/libgems/gem_openssl.rb +92 -0
  56. data/lib/libgems/gem_path_searcher.rb +100 -0
  57. data/lib/libgems/gem_runner.rb +79 -0
  58. data/lib/libgems/gemcutter_utilities.rb +49 -0
  59. data/lib/libgems/indexer.rb +720 -0
  60. data/lib/libgems/install_update_options.rb +125 -0
  61. data/lib/libgems/installer.rb +604 -0
  62. data/lib/libgems/local_remote_options.rb +135 -0
  63. data/lib/libgems/old_format.rb +153 -0
  64. data/lib/libgems/package.rb +97 -0
  65. data/lib/libgems/package/f_sync_dir.rb +23 -0
  66. data/lib/libgems/package/tar_header.rb +266 -0
  67. data/lib/libgems/package/tar_input.rb +222 -0
  68. data/lib/libgems/package/tar_output.rb +144 -0
  69. data/lib/libgems/package/tar_reader.rb +106 -0
  70. data/lib/libgems/package/tar_reader/entry.rb +141 -0
  71. data/lib/libgems/package/tar_writer.rb +241 -0
  72. data/lib/libgems/package_task.rb +126 -0
  73. data/lib/libgems/platform.rb +183 -0
  74. data/lib/libgems/remote_fetcher.rb +414 -0
  75. data/lib/libgems/require_paths_builder.rb +18 -0
  76. data/lib/libgems/requirement.rb +153 -0
  77. data/lib/libgems/security.rb +814 -0
  78. data/lib/libgems/server.rb +872 -0
  79. data/lib/libgems/source_index.rb +597 -0
  80. data/lib/libgems/source_info_cache.rb +395 -0
  81. data/lib/libgems/source_info_cache_entry.rb +56 -0
  82. data/lib/libgems/spec_fetcher.rb +337 -0
  83. data/lib/libgems/specification.rb +1487 -0
  84. data/lib/libgems/test_utilities.rb +147 -0
  85. data/lib/libgems/text.rb +65 -0
  86. data/lib/libgems/uninstaller.rb +278 -0
  87. data/lib/libgems/user_interaction.rb +527 -0
  88. data/lib/libgems/validator.rb +240 -0
  89. data/lib/libgems/version.rb +316 -0
  90. data/lib/libgems/version_option.rb +65 -0
  91. data/lib/rbconfig/datadir.rb +20 -0
  92. data/test/bogussources.rb +8 -0
  93. data/test/data/gem-private_key.pem +27 -0
  94. data/test/data/gem-public_cert.pem +20 -0
  95. data/test/fake_certlib/openssl.rb +7 -0
  96. data/test/foo/discover.rb +0 -0
  97. data/test/gem_installer_test_case.rb +97 -0
  98. data/test/gem_package_tar_test_case.rb +132 -0
  99. data/test/gemutilities.rb +605 -0
  100. data/test/insure_session.rb +43 -0
  101. data/test/mockgemui.rb +56 -0
  102. data/test/plugin/exception/libgems_plugin.rb +2 -0
  103. data/test/plugin/load/libgems_plugin.rb +1 -0
  104. data/test/plugin/standarderror/libgems_plugin.rb +2 -0
  105. data/test/private_key.pem +27 -0
  106. data/test/public_cert.pem +20 -0
  107. data/test/rubygems_plugin.rb +21 -0
  108. data/test/simple_gem.rb +66 -0
  109. data/test/test_config.rb +12 -0
  110. data/test/test_gem.rb +780 -0
  111. data/test/test_gem_builder.rb +27 -0
  112. data/test/test_gem_command.rb +178 -0
  113. data/test/test_gem_command_manager.rb +207 -0
  114. data/test/test_gem_commands_build_command.rb +74 -0
  115. data/test/test_gem_commands_cert_command.rb +124 -0
  116. data/test/test_gem_commands_check_command.rb +18 -0
  117. data/test/test_gem_commands_contents_command.rb +156 -0
  118. data/test/test_gem_commands_dependency_command.rb +216 -0
  119. data/test/test_gem_commands_environment_command.rb +144 -0
  120. data/test/test_gem_commands_fetch_command.rb +76 -0
  121. data/test/test_gem_commands_generate_index_command.rb +135 -0
  122. data/test/test_gem_commands_install_command.rb +315 -0
  123. data/test/test_gem_commands_list_command.rb +36 -0
  124. data/test/test_gem_commands_lock_command.rb +68 -0
  125. data/test/test_gem_commands_mirror_command.rb +60 -0
  126. data/test/test_gem_commands_outdated_command.rb +40 -0
  127. data/test/test_gem_commands_owner_command.rb +105 -0
  128. data/test/test_gem_commands_pristine_command.rb +108 -0
  129. data/test/test_gem_commands_push_command.rb +81 -0
  130. data/test/test_gem_commands_query_command.rb +426 -0
  131. data/test/test_gem_commands_server_command.rb +59 -0
  132. data/test/test_gem_commands_sources_command.rb +209 -0
  133. data/test/test_gem_commands_specification_command.rb +139 -0
  134. data/test/test_gem_commands_stale_command.rb +38 -0
  135. data/test/test_gem_commands_uninstall_command.rb +83 -0
  136. data/test/test_gem_commands_unpack_command.rb +199 -0
  137. data/test/test_gem_commands_update_command.rb +207 -0
  138. data/test/test_gem_commands_which_command.rb +66 -0
  139. data/test/test_gem_config_file.rb +287 -0
  140. data/test/test_gem_dependency.rb +149 -0
  141. data/test/test_gem_dependency_installer.rb +661 -0
  142. data/test/test_gem_dependency_list.rb +230 -0
  143. data/test/test_gem_doc_manager.rb +31 -0
  144. data/test/test_gem_ext_configure_builder.rb +84 -0
  145. data/test/test_gem_ext_ext_conf_builder.rb +173 -0
  146. data/test/test_gem_ext_rake_builder.rb +81 -0
  147. data/test/test_gem_format.rb +70 -0
  148. data/test/test_gem_gem_path_searcher.rb +78 -0
  149. data/test/test_gem_gem_runner.rb +45 -0
  150. data/test/test_gem_gemcutter_utilities.rb +103 -0
  151. data/test/test_gem_indexer.rb +673 -0
  152. data/test/test_gem_install_update_options.rb +68 -0
  153. data/test/test_gem_installer.rb +857 -0
  154. data/test/test_gem_local_remote_options.rb +97 -0
  155. data/test/test_gem_package_tar_header.rb +130 -0
  156. data/test/test_gem_package_tar_input.rb +112 -0
  157. data/test/test_gem_package_tar_output.rb +97 -0
  158. data/test/test_gem_package_tar_reader.rb +46 -0
  159. data/test/test_gem_package_tar_reader_entry.rb +109 -0
  160. data/test/test_gem_package_tar_writer.rb +144 -0
  161. data/test/test_gem_package_task.rb +59 -0
  162. data/test/test_gem_platform.rb +264 -0
  163. data/test/test_gem_remote_fetcher.rb +740 -0
  164. data/test/test_gem_requirement.rb +292 -0
  165. data/test/test_gem_server.rb +356 -0
  166. data/test/test_gem_silent_ui.rb +113 -0
  167. data/test/test_gem_source_index.rb +461 -0
  168. data/test/test_gem_spec_fetcher.rb +410 -0
  169. data/test/test_gem_specification.rb +1334 -0
  170. data/test/test_gem_stream_ui.rb +218 -0
  171. data/test/test_gem_text.rb +43 -0
  172. data/test/test_gem_uninstaller.rb +146 -0
  173. data/test/test_gem_validator.rb +63 -0
  174. data/test/test_gem_version.rb +181 -0
  175. data/test/test_gem_version_option.rb +89 -0
  176. data/test/test_kernel.rb +59 -0
  177. metadata +402 -0
@@ -0,0 +1,91 @@
1
+ ##
2
+ # Base exception class for #{LibGems::NAME}. All exception raised by SlimGems are a
3
+ # subclass of this one.
4
+ class LibGems::Exception < RuntimeError; end
5
+
6
+ class LibGems::CommandLineError < LibGems::Exception; end
7
+
8
+ class LibGems::DependencyError < LibGems::Exception; end
9
+
10
+ class LibGems::DependencyRemovalException < LibGems::Exception; end
11
+
12
+ ##
13
+ # Raised when attempting to uninstall a gem that isn't in GEM_HOME.
14
+
15
+ class LibGems::GemNotInHomeException < LibGems::Exception
16
+ attr_accessor :spec
17
+ end
18
+
19
+ class LibGems::DocumentError < LibGems::Exception; end
20
+
21
+ ##
22
+ # Potentially raised when a specification is validated.
23
+ class LibGems::EndOfYAMLException < LibGems::Exception; end
24
+
25
+ ##
26
+ # Signals that a file permission error is preventing the user from
27
+ # installing in the requested directories.
28
+ class LibGems::FilePermissionError < LibGems::Exception
29
+ def initialize(path)
30
+ super("You don't have write permissions into the #{path} directory.")
31
+ end
32
+ end
33
+
34
+ ##
35
+ # Used to raise parsing and loading errors
36
+ class LibGems::FormatException < LibGems::Exception
37
+ attr_accessor :file_path
38
+ end
39
+
40
+ class LibGems::GemNotFoundException < LibGems::Exception
41
+ def initialize(msg, name=nil, version=nil, errors=nil)
42
+ super msg
43
+ @name = name
44
+ @version = version
45
+ @errors = errors
46
+ end
47
+
48
+ attr_reader :name, :version, :errors
49
+ end
50
+
51
+ class LibGems::InstallError < LibGems::Exception; end
52
+
53
+ ##
54
+ # Potentially raised when a specification is validated.
55
+ class LibGems::InvalidSpecificationException < LibGems::Exception; end
56
+
57
+ class LibGems::OperationNotSupportedError < LibGems::Exception; end
58
+
59
+ ##
60
+ # Signals that a remote operation cannot be conducted, probably due to not
61
+ # being connected (or just not finding host).
62
+ #--
63
+ # TODO: create a method that tests connection to the preferred gems server.
64
+ # All code dealing with remote operations will want this. Failure in that
65
+ # method should raise this error.
66
+ class LibGems::RemoteError < LibGems::Exception; end
67
+
68
+ class LibGems::RemoteInstallationCancelled < LibGems::Exception; end
69
+
70
+ class LibGems::RemoteInstallationSkipped < LibGems::Exception; end
71
+
72
+ ##
73
+ # Represents an error communicating via HTTP.
74
+ class LibGems::RemoteSourceException < LibGems::Exception; end
75
+
76
+ class LibGems::VerificationError < LibGems::Exception; end
77
+
78
+ ##
79
+ # Raised to indicate that a system exit should occur with the specified
80
+ # exit_code
81
+
82
+ class LibGems::SystemExitException < SystemExit
83
+ attr_accessor :exit_code
84
+
85
+ def initialize(exit_code)
86
+ @exit_code = exit_code
87
+
88
+ super "Exiting #{LibGems::NAME} with exit_code #{exit_code}"
89
+ end
90
+
91
+ end
@@ -0,0 +1,18 @@
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 'libgems'
8
+
9
+ ##
10
+ # Classes for building C extensions live here.
11
+
12
+ module LibGems::Ext; end
13
+
14
+ require 'libgems/ext/builder'
15
+ require 'libgems/ext/configure_builder'
16
+ require 'libgems/ext/ext_conf_builder'
17
+ require 'libgems/ext/rake_builder'
18
+
@@ -0,0 +1,56 @@
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
+ class LibGems::Ext::Builder
8
+
9
+ def self.class_name
10
+ name =~ /Ext::(.*)Builder/
11
+ $1.downcase
12
+ end
13
+
14
+ def self.make(dest_path, results)
15
+ unless File.exist? 'Makefile' then
16
+ raise LibGems::InstallError, "Makefile not found:\n\n#{results.join "\n"}"
17
+ end
18
+
19
+ mf = File.read('Makefile')
20
+ mf = mf.gsub(/^RUBYARCHDIR\s*=\s*\$[^$]*/, "RUBYARCHDIR = #{dest_path}")
21
+ mf = mf.gsub(/^RUBYLIBDIR\s*=\s*\$[^$]*/, "RUBYLIBDIR = #{dest_path}")
22
+
23
+ File.open('Makefile', 'wb') {|f| f.print mf}
24
+
25
+ # try to find make program from Ruby configue arguments first
26
+ RbConfig::CONFIG['configure_args'] =~ /with-make-prog\=(\w+)/
27
+ make_program = $1 || ENV['make']
28
+ unless make_program then
29
+ make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
30
+ end
31
+
32
+ ['', ' install'].each do |target|
33
+ cmd = "#{make_program}#{target}"
34
+ results << cmd
35
+ results << `#{cmd} #{redirector}`
36
+
37
+ raise LibGems::InstallError, "make#{target} failed:\n\n#{results}" unless
38
+ $?.success?
39
+ end
40
+ end
41
+
42
+ def self.redirector
43
+ '2>&1'
44
+ end
45
+
46
+ def self.run(command, results)
47
+ results << command
48
+ results << `#{command} #{redirector}`
49
+
50
+ unless $?.success? then
51
+ raise LibGems::InstallError, "#{class_name} failed:\n\n#{results.join "\n"}"
52
+ end
53
+ end
54
+
55
+ end
56
+
@@ -0,0 +1,25 @@
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 'libgems/ext/builder'
8
+
9
+ class LibGems::Ext::ConfigureBuilder < LibGems::Ext::Builder
10
+
11
+ def self.build(extension, directory, dest_path, results)
12
+ unless File.exist?('Makefile') then
13
+ cmd = "sh ./configure --prefix=#{dest_path}"
14
+ cmd << " #{LibGems::Command.build_args.join ' '}" unless LibGems::Command.build_args.empty?
15
+
16
+ run cmd, results
17
+ end
18
+
19
+ make dest_path, results
20
+
21
+ results
22
+ end
23
+
24
+ end
25
+
@@ -0,0 +1,24 @@
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 'libgems/ext/builder'
8
+ require 'libgems/command'
9
+
10
+ class LibGems::Ext::ExtConfBuilder < LibGems::Ext::Builder
11
+
12
+ def self.build(extension, directory, dest_path, results)
13
+ cmd = "#{LibGems.ruby} #{File.basename extension}"
14
+ cmd << " #{LibGems::Command.build_args.join ' '}" unless LibGems::Command.build_args.empty?
15
+
16
+ run cmd, results
17
+
18
+ make dest_path, results
19
+
20
+ results
21
+ end
22
+
23
+ end
24
+
@@ -0,0 +1,39 @@
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 'libgems/ext/builder'
8
+ require 'libgems/command'
9
+
10
+ class LibGems::Ext::RakeBuilder < LibGems::Ext::Builder
11
+
12
+ def self.build(extension, directory, dest_path, results)
13
+ if File.basename(extension) =~ /mkrf_conf/i then
14
+ cmd = "#{LibGems.ruby} #{File.basename extension}"
15
+ cmd << " #{LibGems::Command.build_args.join " "}" unless LibGems::Command.build_args.empty?
16
+ run cmd, results
17
+ end
18
+
19
+ # Deal with possible spaces in the path, e.g. C:/Program Files
20
+ dest_path = '"' + dest_path + '"' if dest_path.include?(' ')
21
+
22
+ rake = ENV['rake']
23
+
24
+ rake ||= begin
25
+ "\"#{LibGems.ruby}\" -rubygems #{LibGems.bin_path('rake')}"
26
+ rescue LibGems::Exception
27
+ end
28
+
29
+ rake ||= LibGems.default_exec_format % 'rake'
30
+
31
+ cmd = "#{rake} RUBYARCHDIR=#{dest_path} RUBYLIBDIR=#{dest_path}" # ENV is frozen
32
+
33
+ run cmd, results
34
+
35
+ results
36
+ end
37
+
38
+ end
39
+
@@ -0,0 +1,81 @@
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 'fileutils'
8
+
9
+ require 'libgems/package'
10
+
11
+ ##
12
+ # LibGems::Format knows the guts of the RubyGem .gem file format and provides the
13
+ # capability to read gem files
14
+
15
+ class LibGems::Format
16
+
17
+ attr_accessor :spec
18
+ attr_accessor :file_entries
19
+ attr_accessor :gem_path
20
+
21
+ extend LibGems::UserInteraction
22
+
23
+ ##
24
+ # Constructs a Format representing the gem's data which came from +gem_path+
25
+
26
+ def initialize(gem_path)
27
+ @gem_path = gem_path
28
+ end
29
+
30
+ ##
31
+ # Reads the gem +file_path+ using +security_policy+ and returns a Format
32
+ # representing the data in the gem
33
+
34
+ def self.from_file_by_path(file_path, security_policy = nil)
35
+ unless File.exist?(file_path)
36
+ raise LibGems::Exception, "Cannot load gem at [#{file_path}] in #{Dir.pwd}"
37
+ end
38
+
39
+ start = File.read file_path, 20
40
+
41
+ if start.nil? or start.length < 20 then
42
+ nil
43
+ elsif start.include?("MD5SUM =") # old version gems
44
+ require 'libgems/old_format'
45
+
46
+ LibGems::OldFormat.from_file_by_path file_path
47
+ else
48
+ open file_path, LibGems.binary_mode do |io|
49
+ from_io io, file_path, security_policy
50
+ end
51
+ end
52
+ end
53
+
54
+ ##
55
+ # Reads a gem from +io+ at +gem_path+ using +security_policy+ and returns a
56
+ # Format representing the data from the gem
57
+
58
+ def self.from_io(io, gem_path="(io)", security_policy = nil)
59
+ format = new gem_path
60
+
61
+ LibGems::Package.open io, 'r', security_policy do |pkg|
62
+ format.spec = pkg.metadata
63
+ format.file_entries = []
64
+
65
+ pkg.each do |entry|
66
+ size = entry.header.size
67
+ mode = entry.header.mode
68
+
69
+ format.file_entries << [{
70
+ "size" => size, "mode" => mode, "path" => entry.full_name,
71
+ },
72
+ entry.read
73
+ ]
74
+ end
75
+ end
76
+
77
+ format
78
+ end
79
+
80
+ end
81
+
@@ -0,0 +1,92 @@
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
+ #--
8
+ # Some system might not have OpenSSL installed, therefore the core
9
+ # library file openssl might not be available. We localize testing
10
+ # for the presence of OpenSSL in this file.
11
+ #++
12
+
13
+ module LibGems
14
+ class << self
15
+ ##
16
+ # Is SSL (used by the signing commands) available on this
17
+ # platform?
18
+
19
+ def ssl_available?
20
+ @ssl_available
21
+ end
22
+
23
+ ##
24
+ # Is SSL available?
25
+
26
+ attr_writer :ssl_available
27
+
28
+ ##
29
+ # Ensure that SSL is available. Throw an exception if it is not.
30
+
31
+ def ensure_ssl_available
32
+ unless ssl_available?
33
+ raise LibGems::Exception, "SSL is not installed on this system"
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ begin
40
+ require 'openssl'
41
+
42
+ # Reference a constant defined in the .rb portion of ssl (just to
43
+ # make sure that part is loaded too).
44
+
45
+ LibGems.ssl_available = !!OpenSSL::Digest::SHA1
46
+
47
+ class OpenSSL::X509::Certificate # :nodoc:
48
+ # Check the validity of this certificate.
49
+ def check_validity(issuer_cert = nil, time = Time.now)
50
+ ret = if @not_before && @not_before > time
51
+ [false, :expired, "not valid before '#@not_before'"]
52
+ elsif @not_after && @not_after < time
53
+ [false, :expired, "not valid after '#@not_after'"]
54
+ elsif issuer_cert && !verify(issuer_cert.public_key)
55
+ [false, :issuer, "#{issuer_cert.subject} is not issuer"]
56
+ else
57
+ [true, :ok, 'Valid certificate']
58
+ end
59
+
60
+ # return hash
61
+ { :is_valid => ret[0], :error => ret[1], :desc => ret[2] }
62
+ end
63
+ end
64
+
65
+ rescue LoadError, StandardError
66
+ LibGems.ssl_available = false
67
+ end
68
+
69
+ # :stopdoc:
70
+
71
+ module LibGems::SSL
72
+
73
+ # We make our own versions of the constants here. This allows us
74
+ # to reference the constants, even though some systems might not
75
+ # have SSL installed in the Ruby core package.
76
+ #
77
+ # These constants are only used during load time. At runtime, any
78
+ # method that makes a direct reference to SSL software must be
79
+ # protected with a LibGems.ensure_ssl_available call.
80
+
81
+ if LibGems.ssl_available? then
82
+ PKEY_RSA = OpenSSL::PKey::RSA
83
+ DIGEST_SHA1 = OpenSSL::Digest::SHA1
84
+ else
85
+ PKEY_RSA = :rsa
86
+ DIGEST_SHA1 = :sha1
87
+ end
88
+
89
+ end
90
+
91
+ # :startdoc:
92
+
@@ -0,0 +1,100 @@
1
+ ##
2
+ # LibGemsPathSearcher has the capability to find loadable files inside
3
+ # gems. It generates data up front to speed up searches later.
4
+
5
+ class LibGems::GemPathSearcher
6
+
7
+ ##
8
+ # Initialise the data we need to make searches later.
9
+
10
+ def initialize
11
+ # We want a record of all the installed gemspecs, in the order we wish to
12
+ # examine them.
13
+ @gemspecs = init_gemspecs
14
+
15
+ # Map gem spec to glob of full require_path directories. Preparing this
16
+ # information may speed up searches later.
17
+ @lib_dirs = {}
18
+
19
+ @gemspecs.each do |spec|
20
+ @lib_dirs[spec.object_id] = lib_dirs_for spec
21
+ end
22
+ end
23
+
24
+ ##
25
+ # Look in all the installed gems until a matching _path_ is found.
26
+ # Return the _gemspec_ of the gem where it was found. If no match
27
+ # is found, return nil.
28
+ #
29
+ # The gems are searched in alphabetical order, and in reverse
30
+ # version order.
31
+ #
32
+ # For example:
33
+ #
34
+ # find('log4r') # -> (log4r-1.1 spec)
35
+ # find('log4r.rb') # -> (log4r-1.1 spec)
36
+ # find('rake/rdoctask') # -> (rake-0.4.12 spec)
37
+ # find('foobarbaz') # -> nil
38
+ #
39
+ # Matching paths can have various suffixes ('.rb', '.so', and
40
+ # others), which may or may not already be attached to _file_.
41
+ # This method doesn't care about the full filename that matches;
42
+ # only that there is a match.
43
+
44
+ def find(path)
45
+ @gemspecs.find do |spec| matching_file? spec, path end
46
+ end
47
+
48
+ ##
49
+ # Works like #find, but finds all gemspecs matching +path+.
50
+
51
+ def find_all(path)
52
+ @gemspecs.select do |spec|
53
+ matching_file? spec, path
54
+ end
55
+ end
56
+
57
+ ##
58
+ # Attempts to find a matching path using the require_paths of the given
59
+ # +spec+.
60
+
61
+ def matching_file?(spec, path)
62
+ !matching_files(spec, path).empty?
63
+ end
64
+
65
+ ##
66
+ # Returns files matching +path+ in +spec+.
67
+ #--
68
+ # Some of the intermediate results are cached in @lib_dirs for speed.
69
+
70
+ def matching_files(spec, path)
71
+ return [] unless @lib_dirs[spec.object_id] # case no paths
72
+ glob = File.join @lib_dirs[spec.object_id], "#{path}#{LibGems.suffix_pattern}"
73
+ Dir[glob].select { |f| File.file? f.untaint }
74
+ end
75
+
76
+ ##
77
+ # Return a list of all installed gemspecs, sorted by alphabetical order and
78
+ # in reverse version order. (bar-2, bar-1, foo-2)
79
+
80
+ def init_gemspecs
81
+ specs = LibGems.source_index.map { |_, spec| spec }
82
+
83
+ specs.sort { |a, b|
84
+ names = a.name <=> b.name
85
+ next names if names.nonzero?
86
+ b.version <=> a.version
87
+ }
88
+ end
89
+
90
+ ##
91
+ # Returns library directories glob for a gemspec. For example,
92
+ # '/usr/local/lib/ruby/gems/1.8/gems/foobar-1.0/{lib,ext}'
93
+
94
+ def lib_dirs_for(spec)
95
+ "#{spec.full_gem_path}/{#{spec.require_paths.join(',')}}" if
96
+ spec.require_paths
97
+ end
98
+
99
+ end
100
+