bundler-prehistoric 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (284) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +3 -0
  4. data/.travis.yml +100 -0
  5. data/CHANGELOG.md +1640 -0
  6. data/CONTRIBUTING.md +32 -0
  7. data/DEVELOPMENT.md +117 -0
  8. data/Gemfile +3 -0
  9. data/ISSUES.md +96 -0
  10. data/LICENSE.md +23 -0
  11. data/README.md +46 -0
  12. data/Rakefile +256 -0
  13. data/UPGRADING.md +103 -0
  14. data/bin/bundle +21 -0
  15. data/bin/bundle_ruby +56 -0
  16. data/bin/bundler +21 -0
  17. data/bundler.gemspec +33 -0
  18. data/lib/bundler.rb +442 -0
  19. data/lib/bundler/backports/time.rb +7 -0
  20. data/lib/bundler/capistrano.rb +16 -0
  21. data/lib/bundler/cli.rb +395 -0
  22. data/lib/bundler/cli/binstubs.rb +38 -0
  23. data/lib/bundler/cli/cache.rb +34 -0
  24. data/lib/bundler/cli/check.rb +35 -0
  25. data/lib/bundler/cli/clean.rb +19 -0
  26. data/lib/bundler/cli/common.rb +54 -0
  27. data/lib/bundler/cli/config.rb +84 -0
  28. data/lib/bundler/cli/console.rb +39 -0
  29. data/lib/bundler/cli/exec.rb +37 -0
  30. data/lib/bundler/cli/gem.rb +101 -0
  31. data/lib/bundler/cli/init.rb +33 -0
  32. data/lib/bundler/cli/inject.rb +33 -0
  33. data/lib/bundler/cli/install.rb +133 -0
  34. data/lib/bundler/cli/open.rb +23 -0
  35. data/lib/bundler/cli/outdated.rb +80 -0
  36. data/lib/bundler/cli/package.rb +36 -0
  37. data/lib/bundler/cli/platform.rb +43 -0
  38. data/lib/bundler/cli/show.rb +48 -0
  39. data/lib/bundler/cli/update.rb +73 -0
  40. data/lib/bundler/cli/viz.rb +27 -0
  41. data/lib/bundler/constants.rb +5 -0
  42. data/lib/bundler/current_ruby.rb +155 -0
  43. data/lib/bundler/definition.rb +604 -0
  44. data/lib/bundler/dep_proxy.rb +43 -0
  45. data/lib/bundler/dependency.rb +106 -0
  46. data/lib/bundler/deployment.rb +59 -0
  47. data/lib/bundler/deprecate.rb +15 -0
  48. data/lib/bundler/dsl.rb +305 -0
  49. data/lib/bundler/endpoint_specification.rb +76 -0
  50. data/lib/bundler/env.rb +56 -0
  51. data/lib/bundler/environment.rb +42 -0
  52. data/lib/bundler/fetcher.rb +396 -0
  53. data/lib/bundler/friendly_errors.rb +42 -0
  54. data/lib/bundler/gem_helper.rb +169 -0
  55. data/lib/bundler/gem_helpers.rb +25 -0
  56. data/lib/bundler/gem_installer.rb +9 -0
  57. data/lib/bundler/gem_path_manipulation.rb +8 -0
  58. data/lib/bundler/gem_tasks.rb +2 -0
  59. data/lib/bundler/graph.rb +169 -0
  60. data/lib/bundler/index.rb +184 -0
  61. data/lib/bundler/injector.rb +64 -0
  62. data/lib/bundler/installer.rb +332 -0
  63. data/lib/bundler/lazy_specification.rb +83 -0
  64. data/lib/bundler/lockfile_parser.rb +146 -0
  65. data/lib/bundler/match_platform.rb +13 -0
  66. data/lib/bundler/parallel_workers.rb +18 -0
  67. data/lib/bundler/parallel_workers/thread_worker.rb +30 -0
  68. data/lib/bundler/parallel_workers/unix_worker.rb +101 -0
  69. data/lib/bundler/parallel_workers/worker.rb +69 -0
  70. data/lib/bundler/psyched_yaml.rb +26 -0
  71. data/lib/bundler/remote_specification.rb +57 -0
  72. data/lib/bundler/resolver.rb +534 -0
  73. data/lib/bundler/retry.rb +60 -0
  74. data/lib/bundler/ruby_dsl.rb +11 -0
  75. data/lib/bundler/ruby_version.rb +117 -0
  76. data/lib/bundler/rubygems_ext.rb +171 -0
  77. data/lib/bundler/rubygems_integration.rb +578 -0
  78. data/lib/bundler/runtime.rb +310 -0
  79. data/lib/bundler/settings.rb +176 -0
  80. data/lib/bundler/setup.rb +23 -0
  81. data/lib/bundler/shared_helpers.rb +110 -0
  82. data/lib/bundler/similarity_detector.rb +63 -0
  83. data/lib/bundler/source.rb +29 -0
  84. data/lib/bundler/source/git.rb +289 -0
  85. data/lib/bundler/source/git/git_proxy.rb +158 -0
  86. data/lib/bundler/source/path.rb +225 -0
  87. data/lib/bundler/source/path/installer.rb +38 -0
  88. data/lib/bundler/source/rubygems.rb +334 -0
  89. data/lib/bundler/source/svn.rb +260 -0
  90. data/lib/bundler/source/svn/svn_proxy.rb +110 -0
  91. data/lib/bundler/spec_set.rb +154 -0
  92. data/lib/bundler/ssl_certs/.document +1 -0
  93. data/lib/bundler/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +14 -0
  94. data/lib/bundler/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +23 -0
  95. data/lib/bundler/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +28 -0
  96. data/lib/bundler/ssl_certs/GeoTrustGlobalCA.pem +20 -0
  97. data/lib/bundler/ssl_certs/certificate_manager.rb +41 -0
  98. data/lib/bundler/templates/Executable +16 -0
  99. data/lib/bundler/templates/Executable.standalone +12 -0
  100. data/lib/bundler/templates/Gemfile +4 -0
  101. data/lib/bundler/templates/newgem/.travis.yml.tt +3 -0
  102. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  103. data/lib/bundler/templates/newgem/LICENSE.txt.tt +22 -0
  104. data/lib/bundler/templates/newgem/README.md.tt +31 -0
  105. data/lib/bundler/templates/newgem/Rakefile.tt +26 -0
  106. data/lib/bundler/templates/newgem/bin/newgem.tt +3 -0
  107. data/lib/bundler/templates/newgem/consolerc.tt +3 -0
  108. data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +3 -0
  109. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
  110. data/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
  111. data/lib/bundler/templates/newgem/gitignore.tt +16 -0
  112. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +12 -0
  113. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  114. data/lib/bundler/templates/newgem/newgem.gemspec.tt +38 -0
  115. data/lib/bundler/templates/newgem/rspec.tt +2 -0
  116. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +11 -0
  117. data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +2 -0
  118. data/lib/bundler/templates/newgem/test/minitest_helper.rb.tt +4 -0
  119. data/lib/bundler/templates/newgem/test/test_newgem.rb.tt +11 -0
  120. data/lib/bundler/ui.rb +7 -0
  121. data/lib/bundler/ui/rg_proxy.rb +21 -0
  122. data/lib/bundler/ui/shell.rb +98 -0
  123. data/lib/bundler/ui/silent.rb +44 -0
  124. data/lib/bundler/vendor/.document +0 -0
  125. data/lib/bundler/vendor/net/http/faster.rb +26 -0
  126. data/lib/bundler/vendor/net/http/persistent.rb +1230 -0
  127. data/lib/bundler/vendor/net/http/persistent/ssl_reuse.rb +128 -0
  128. data/lib/bundler/vendor/thor.rb +480 -0
  129. data/lib/bundler/vendor/thor/actions.rb +319 -0
  130. data/lib/bundler/vendor/thor/actions/create_file.rb +103 -0
  131. data/lib/bundler/vendor/thor/actions/create_link.rb +59 -0
  132. data/lib/bundler/vendor/thor/actions/directory.rb +118 -0
  133. data/lib/bundler/vendor/thor/actions/empty_directory.rb +135 -0
  134. data/lib/bundler/vendor/thor/actions/file_manipulation.rb +316 -0
  135. data/lib/bundler/vendor/thor/actions/inject_into_file.rb +107 -0
  136. data/lib/bundler/vendor/thor/base.rb +656 -0
  137. data/lib/bundler/vendor/thor/command.rb +133 -0
  138. data/lib/bundler/vendor/thor/core_ext/hash_with_indifferent_access.rb +77 -0
  139. data/lib/bundler/vendor/thor/core_ext/io_binary_read.rb +10 -0
  140. data/lib/bundler/vendor/thor/core_ext/ordered_hash.rb +98 -0
  141. data/lib/bundler/vendor/thor/error.rb +32 -0
  142. data/lib/bundler/vendor/thor/group.rb +281 -0
  143. data/lib/bundler/vendor/thor/invocation.rb +173 -0
  144. data/lib/bundler/vendor/thor/line_editor.rb +17 -0
  145. data/lib/bundler/vendor/thor/line_editor/basic.rb +35 -0
  146. data/lib/bundler/vendor/thor/line_editor/readline.rb +88 -0
  147. data/lib/bundler/vendor/thor/parser.rb +4 -0
  148. data/lib/bundler/vendor/thor/parser/argument.rb +73 -0
  149. data/lib/bundler/vendor/thor/parser/arguments.rb +175 -0
  150. data/lib/bundler/vendor/thor/parser/option.rb +121 -0
  151. data/lib/bundler/vendor/thor/parser/options.rb +218 -0
  152. data/lib/bundler/vendor/thor/rake_compat.rb +71 -0
  153. data/lib/bundler/vendor/thor/runner.rb +322 -0
  154. data/lib/bundler/vendor/thor/shell.rb +81 -0
  155. data/lib/bundler/vendor/thor/shell/basic.rb +420 -0
  156. data/lib/bundler/vendor/thor/shell/color.rb +149 -0
  157. data/lib/bundler/vendor/thor/shell/html.rb +126 -0
  158. data/lib/bundler/vendor/thor/util.rb +267 -0
  159. data/lib/bundler/vendor/thor/version.rb +3 -0
  160. data/lib/bundler/vendored_persistent.rb +3 -0
  161. data/lib/bundler/vendored_thor.rb +8 -0
  162. data/lib/bundler/version.rb +6 -0
  163. data/lib/bundler/vlad.rb +11 -0
  164. data/man/bundle-config.ronn +155 -0
  165. data/man/bundle-exec.ronn +136 -0
  166. data/man/bundle-install.ronn +372 -0
  167. data/man/bundle-package.ronn +59 -0
  168. data/man/bundle-platform.ronn +42 -0
  169. data/man/bundle-update.ronn +179 -0
  170. data/man/bundle.ronn +92 -0
  171. data/man/gemfile.5.ronn +369 -0
  172. data/man/index.txt +7 -0
  173. data/spec/bundler/bundler_spec.rb +74 -0
  174. data/spec/bundler/cli_spec.rb +16 -0
  175. data/spec/bundler/definition_spec.rb +21 -0
  176. data/spec/bundler/dsl_spec.rb +108 -0
  177. data/spec/bundler/friendly_errors_spec.rb +13 -0
  178. data/spec/bundler/gem_helper_spec.rb +225 -0
  179. data/spec/bundler/psyched_yaml_spec.rb +8 -0
  180. data/spec/bundler/retry_spec.rb +59 -0
  181. data/spec/bundler/settings_spec.rb +13 -0
  182. data/spec/bundler/source_spec.rb +25 -0
  183. data/spec/cache/gems_spec.rb +316 -0
  184. data/spec/cache/git_spec.rb +188 -0
  185. data/spec/cache/path_spec.rb +121 -0
  186. data/spec/cache/platform_spec.rb +53 -0
  187. data/spec/cache/svn_spec.rb +82 -0
  188. data/spec/commands/binstubs_spec.rb +246 -0
  189. data/spec/commands/check_spec.rb +278 -0
  190. data/spec/commands/clean_spec.rb +652 -0
  191. data/spec/commands/config_spec.rb +227 -0
  192. data/spec/commands/console_spec.rb +102 -0
  193. data/spec/commands/exec_spec.rb +367 -0
  194. data/spec/commands/help_spec.rb +39 -0
  195. data/spec/commands/init_spec.rb +39 -0
  196. data/spec/commands/inject_spec.rb +78 -0
  197. data/spec/commands/licenses_spec.rb +31 -0
  198. data/spec/commands/newgem_spec.rb +451 -0
  199. data/spec/commands/open_spec.rb +80 -0
  200. data/spec/commands/outdated_spec.rb +168 -0
  201. data/spec/commands/package_spec.rb +128 -0
  202. data/spec/commands/show_spec.rb +152 -0
  203. data/spec/install/binstubs_spec.rb +24 -0
  204. data/spec/install/bundler_spec.rb +146 -0
  205. data/spec/install/deploy_spec.rb +237 -0
  206. data/spec/install/gemfile/gemspec_spec.rb +170 -0
  207. data/spec/install/gemfile/git_spec.rb +967 -0
  208. data/spec/install/gemfile/path_spec.rb +480 -0
  209. data/spec/install/gemfile/svn_spec.rb +582 -0
  210. data/spec/install/gemfile_spec.rb +44 -0
  211. data/spec/install/gems/c_ext_spec.rb +48 -0
  212. data/spec/install/gems/dependency_api_spec.rb +580 -0
  213. data/spec/install/gems/env_spec.rb +107 -0
  214. data/spec/install/gems/flex_spec.rb +314 -0
  215. data/spec/install/gems/groups_spec.rb +308 -0
  216. data/spec/install/gems/mirror_spec.rb +39 -0
  217. data/spec/install/gems/platform_spec.rb +221 -0
  218. data/spec/install/gems/post_install_spec.rb +121 -0
  219. data/spec/install/gems/resolving_spec.rb +124 -0
  220. data/spec/install/gems/simple_case_spec.rb +386 -0
  221. data/spec/install/gems/standalone_spec.rb +260 -0
  222. data/spec/install/gems/sudo_spec.rb +136 -0
  223. data/spec/install/gems/win32_spec.rb +26 -0
  224. data/spec/install/gemspecs_spec.rb +50 -0
  225. data/spec/install/path_spec.rb +150 -0
  226. data/spec/install/post_bundle_message_spec.rb +142 -0
  227. data/spec/install/prereleases_spec.rb +43 -0
  228. data/spec/install/security_policy_spec.rb +77 -0
  229. data/spec/install/upgrade_spec.rb +26 -0
  230. data/spec/lock/git_spec.rb +34 -0
  231. data/spec/lock/lockfile_spec.rb +912 -0
  232. data/spec/lock/svn_spec.rb +35 -0
  233. data/spec/other/bundle_ruby_spec.rb +142 -0
  234. data/spec/other/cli_dispatch_spec.rb +21 -0
  235. data/spec/other/ext_spec.rb +60 -0
  236. data/spec/other/platform_spec.rb +1285 -0
  237. data/spec/other/ssl_cert_spec.rb +10 -0
  238. data/spec/quality_spec.rb +88 -0
  239. data/spec/realworld/dependency_api_spec.rb +60 -0
  240. data/spec/realworld/edgecases_spec.rb +177 -0
  241. data/spec/realworld/parallel_spec.rb +69 -0
  242. data/spec/resolver/basic_spec.rb +66 -0
  243. data/spec/resolver/platform_spec.rb +88 -0
  244. data/spec/runtime/executable_spec.rb +149 -0
  245. data/spec/runtime/load_spec.rb +107 -0
  246. data/spec/runtime/platform_spec.rb +90 -0
  247. data/spec/runtime/require_spec.rb +332 -0
  248. data/spec/runtime/setup_spec.rb +856 -0
  249. data/spec/runtime/with_clean_env_spec.rb +91 -0
  250. data/spec/spec_helper.rb +114 -0
  251. data/spec/support/artifice/endopint_marshal_fail_basic_authentication.rb +13 -0
  252. data/spec/support/artifice/endpoint.rb +71 -0
  253. data/spec/support/artifice/endpoint_500.rb +37 -0
  254. data/spec/support/artifice/endpoint_api_missing.rb +16 -0
  255. data/spec/support/artifice/endpoint_basic_authentication.rb +13 -0
  256. data/spec/support/artifice/endpoint_creds_diff_host.rb +38 -0
  257. data/spec/support/artifice/endpoint_extra.rb +31 -0
  258. data/spec/support/artifice/endpoint_extra_missing.rb +15 -0
  259. data/spec/support/artifice/endpoint_fallback.rb +17 -0
  260. data/spec/support/artifice/endpoint_host_redirect.rb +15 -0
  261. data/spec/support/artifice/endpoint_marshal_fail.rb +11 -0
  262. data/spec/support/artifice/endpoint_redirect.rb +15 -0
  263. data/spec/support/artifice/endpoint_strict_basic_authentication.rb +18 -0
  264. data/spec/support/artifice/endpoint_timeout.rb +13 -0
  265. data/spec/support/builders.rb +748 -0
  266. data/spec/support/fakeweb/rack-1.0.0.marshal +2 -0
  267. data/spec/support/fakeweb/windows.rb +23 -0
  268. data/spec/support/hax.rb +22 -0
  269. data/spec/support/helpers.rb +348 -0
  270. data/spec/support/indexes.rb +280 -0
  271. data/spec/support/less_than_proc.rb +14 -0
  272. data/spec/support/matchers.rb +77 -0
  273. data/spec/support/path.rb +81 -0
  274. data/spec/support/permissions.rb +10 -0
  275. data/spec/support/platforms.rb +94 -0
  276. data/spec/support/ruby_ext.rb +20 -0
  277. data/spec/support/rubygems_ext.rb +39 -0
  278. data/spec/support/streams.rb +13 -0
  279. data/spec/support/sudo.rb +16 -0
  280. data/spec/update/gems_spec.rb +201 -0
  281. data/spec/update/git_spec.rb +236 -0
  282. data/spec/update/source_spec.rb +63 -0
  283. data/spec/update/svn_spec.rb +100 -0
  284. metadata +486 -0
@@ -0,0 +1,158 @@
1
+ module Bundler
2
+ class Source
3
+ class Git < Path
4
+
5
+ class GitNotInstalledError < GitError
6
+ def initialize
7
+ msg = "You need to install git to be able to use gems from git repositories. "
8
+ msg << "For help installing git, please refer to GitHub's tutorial at https://help.github.com/articles/set-up-git"
9
+ super msg
10
+ end
11
+ end
12
+
13
+ class GitNotAllowedError < GitError
14
+ def initialize(command)
15
+ msg = "Bundler is trying to run a `git #{command}` at runtime. You probably need to run `bundle install`. However, "
16
+ msg << "this error message could probably be more useful. Please submit a ticket at http://github.com/bundler/bundler/issues "
17
+ msg << "with steps to reproduce as well as the following\n\nCALLER: #{caller.join("\n")}"
18
+ super msg
19
+ end
20
+ end
21
+
22
+ class GitCommandError < GitError
23
+ def initialize(command, path = nil)
24
+ msg = "Git error: command `git #{command}` in directory #{Dir.pwd} has failed."
25
+ msg << "\nIf this error persists you could try removing the cache directory '#{path}'" if path && path.exist?
26
+ super msg
27
+ end
28
+ end
29
+
30
+ # The GitProxy is responsible to interact with git repositories.
31
+ # All actions required by the Git source is encapsulated in this
32
+ # object.
33
+ class GitProxy
34
+ attr_accessor :path, :uri, :ref
35
+ attr_writer :revision
36
+
37
+ def initialize(path, uri, ref, revision = nil, git = nil)
38
+ @path = path
39
+ @uri = uri
40
+ @ref = ref
41
+ @revision = revision
42
+ @git = git
43
+ raise GitNotInstalledError.new if allow? && !Bundler.git_present?
44
+ end
45
+
46
+ def revision
47
+ @revision ||= allowed_in_path { git("rev-parse #{ref}").strip }
48
+ end
49
+
50
+ def branch
51
+ @branch ||= allowed_in_path do
52
+ git("branch") =~ /^\* (.*)$/ && $1.strip
53
+ end
54
+ end
55
+
56
+ def contains?(commit)
57
+ allowed_in_path do
58
+ result = git_null("branch --contains #{commit}")
59
+ $? == 0 && result =~ /^\* (.*)$/
60
+ end
61
+ end
62
+
63
+ def checkout
64
+ if path.exist?
65
+ return if has_revision_cached?
66
+ Bundler.ui.confirm "Updating #{uri}"
67
+ in_path do
68
+ git_retry %|fetch --force --quiet --tags #{uri_escaped} "refs/heads/*:refs/heads/*"|
69
+ end
70
+ else
71
+ Bundler.ui.info "Fetching #{uri}"
72
+ FileUtils.mkdir_p(path.dirname)
73
+ git_retry %|clone #{uri_escaped} "#{path}" --bare --no-hardlinks --quiet|
74
+ end
75
+ end
76
+
77
+ def copy_to(destination, submodules=false)
78
+ unless File.exist?(destination.join(".git"))
79
+ FileUtils.mkdir_p(destination.dirname)
80
+ FileUtils.rm_rf(destination)
81
+ git_retry %|clone --no-checkout --quiet "#{path}" "#{destination}"|
82
+ File.chmod((0777 & ~File.umask), destination)
83
+ end
84
+
85
+ SharedHelpers.chdir(destination) do
86
+ git_retry %|fetch --force --quiet --tags "#{path}"|
87
+ git "reset --hard #{@revision}"
88
+
89
+ if submodules
90
+ git_retry "submodule update --init --recursive"
91
+ end
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ # TODO: Do not rely on /dev/null.
98
+ # Given that open3 is not cross platform until Ruby 1.9.3,
99
+ # the best solution is to pipe to /dev/null if it exists.
100
+ # If it doesn't, everything will work fine, but the user
101
+ # will get the $stderr messages as well.
102
+ def git_null(command)
103
+ git("#{command} 2>#{Bundler::NULL}", false)
104
+ end
105
+
106
+ def git_retry(command)
107
+ Bundler::Retry.new("git #{command}", GitNotAllowedError).attempts do
108
+ git(command)
109
+ end
110
+ end
111
+
112
+ def git(command, check_errors=true)
113
+ raise GitNotAllowedError.new(command) unless allow?
114
+ out = SharedHelpers.with_clean_git_env { %x{git #{command}} }
115
+ raise GitCommandError.new(command, path) if check_errors && !$?.success?
116
+ out
117
+ end
118
+
119
+ def has_revision_cached?
120
+ return unless @revision
121
+ in_path { git("cat-file -e #{@revision}") }
122
+ true
123
+ rescue GitError
124
+ false
125
+ end
126
+
127
+ # Escape the URI for git commands
128
+ def uri_escaped
129
+ if Bundler::WINDOWS
130
+ # Windows quoting requires double quotes only, with double quotes
131
+ # inside the string escaped by being doubled.
132
+ '"' + uri.gsub('"') {|s| '""'} + '"'
133
+ else
134
+ # Bash requires single quoted strings, with the single quotes escaped
135
+ # by ending the string, escaping the quote, and restarting the string.
136
+ "'" + uri.gsub("'") {|s| "'\\''"} + "'"
137
+ end
138
+ end
139
+
140
+ def allow?
141
+ @git ? @git.allow_git_ops? : true
142
+ end
143
+
144
+ def in_path(&blk)
145
+ checkout unless path.exist?
146
+ SharedHelpers.chdir(path, &blk)
147
+ end
148
+
149
+ def allowed_in_path
150
+ return in_path { yield } if allow?
151
+ raise GitError, "The git source #{uri} is not yet checked out. Please run `bundle install` before trying to start your application"
152
+ end
153
+
154
+ end
155
+
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,225 @@
1
+ module Bundler
2
+ class Source
3
+
4
+ class Path < Source
5
+ autoload :Installer, 'bundler/source/path/installer'
6
+
7
+ attr_reader :path, :options
8
+ attr_writer :name
9
+ attr_accessor :version
10
+
11
+ DEFAULT_GLOB = "{,*,*/*}.gemspec"
12
+
13
+ def initialize(options)
14
+ @options = options
15
+ @glob = options["glob"] || DEFAULT_GLOB
16
+
17
+ @allow_cached = false
18
+ @allow_remote = false
19
+
20
+ if options["path"]
21
+ @path = Pathname.new(options["path"])
22
+ @path = expand(@path) unless @path.relative?
23
+ end
24
+
25
+ @name = options["name"]
26
+ @version = options["version"]
27
+
28
+ # Stores the original path. If at any point we move to the
29
+ # cached directory, we still have the original path to copy from.
30
+ @original_path = @path
31
+ end
32
+
33
+ def remote!
34
+ @allow_remote = true
35
+ end
36
+
37
+ def cached!
38
+ @allow_cached = true
39
+ end
40
+
41
+ def self.from_lock(options)
42
+ new(options.merge("path" => options.delete("remote")))
43
+ end
44
+
45
+ def to_lock
46
+ out = "PATH\n"
47
+ out << " remote: #{relative_path}\n"
48
+ out << " glob: #{@glob}\n" unless @glob == DEFAULT_GLOB
49
+ out << " specs:\n"
50
+ end
51
+
52
+ def to_s
53
+ "source at #{@path}"
54
+ end
55
+
56
+ def hash
57
+ self.class.hash
58
+ end
59
+
60
+ def eql?(o)
61
+ o.instance_of?(Path) &&
62
+ expand(path) == expand(o.path) &&
63
+ version == o.version
64
+ end
65
+
66
+ alias == eql?
67
+
68
+ def name
69
+ File.basename(expand(path).to_s)
70
+ end
71
+
72
+ def install(spec)
73
+ generate_bin(spec, :disable_extensions)
74
+ ["Using #{version_message(spec)} from #{to_s}", nil]
75
+ end
76
+
77
+ def cache(spec, custom_path = nil)
78
+ app_cache_path = app_cache_path(custom_path)
79
+ return unless Bundler.settings[:cache_all]
80
+ return if expand(@original_path).to_s.index(Bundler.root.to_s) == 0
81
+
82
+ unless @original_path.exist?
83
+ raise GemNotFound, "Can't cache gem #{version_message(spec)} because #{to_s} is missing!"
84
+ end
85
+
86
+ FileUtils.rm_rf(app_cache_path)
87
+ FileUtils.cp_r("#{@original_path}/.", app_cache_path)
88
+ FileUtils.touch(app_cache_path.join(".bundlecache"))
89
+ end
90
+
91
+ def local_specs(*)
92
+ @local_specs ||= load_spec_files
93
+ end
94
+
95
+ def specs
96
+ if has_app_cache?
97
+ @path = app_cache_path
98
+ end
99
+ local_specs
100
+ end
101
+
102
+ def app_cache_dirname
103
+ name
104
+ end
105
+
106
+ private
107
+
108
+ def expand(somepath)
109
+ somepath.expand_path(Bundler.root)
110
+ rescue ArgumentError => e
111
+ Bundler.ui.debug(e)
112
+ raise PathError, "There was an error while trying to use the path " \
113
+ "`#{somepath}`.\nThe error message was: #{e.message}."
114
+ end
115
+
116
+ def app_cache_path(custom_path = nil)
117
+ @app_cache_path ||= Bundler.app_cache(custom_path).join(app_cache_dirname)
118
+ end
119
+
120
+ def has_app_cache?
121
+ SharedHelpers.in_bundle? && app_cache_path.exist?
122
+ end
123
+
124
+ def load_spec_files
125
+ index = Index.new
126
+ expanded_path = expand(path)
127
+
128
+ if File.directory?(expanded_path)
129
+ Dir["#{expanded_path}/#{@glob}"].each do |file|
130
+ spec = Bundler.load_gemspec(file)
131
+ if spec
132
+ spec.loaded_from = file.to_s
133
+ spec.source = self
134
+ index << spec
135
+ end
136
+ end
137
+
138
+ if index.empty? && @name && @version
139
+ index << Gem::Specification.new do |s|
140
+ s.name = @name
141
+ s.source = self
142
+ s.version = Gem::Version.new(@version)
143
+ s.platform = Gem::Platform::RUBY
144
+ s.summary = "Fake gemspec for #{@name}"
145
+ s.relative_loaded_from = "#{@name}.gemspec"
146
+ s.authors = ["no one"]
147
+ if expanded_path.join("bin").exist?
148
+ executables = expanded_path.join("bin").children
149
+ executables.reject!{|p| File.directory?(p) }
150
+ s.executables = executables.map{|c| c.basename.to_s }
151
+ end
152
+ end
153
+ end
154
+ elsif File.exist?(expanded_path)
155
+ raise PathError, "The path `#{expanded_path}` is not a directory."
156
+ else
157
+ raise PathError, "The path `#{expanded_path}` does not exist."
158
+ end
159
+
160
+ index
161
+ end
162
+
163
+ def relative_path
164
+ if path.to_s.match(%r{^#{Regexp.escape Bundler.root.to_s}})
165
+ return path.relative_path_from(Bundler.root)
166
+ end
167
+ path
168
+ end
169
+
170
+ def generate_bin(spec, disable_extensions = false)
171
+ gem_dir = Pathname.new(spec.full_gem_path)
172
+
173
+ # Some gem authors put absolute paths in their gemspec
174
+ # and we have to save them from themselves
175
+ spec.files = spec.files.map do |p|
176
+ next if File.directory?(p)
177
+ begin
178
+ Pathname.new(p).relative_path_from(gem_dir).to_s
179
+ rescue ArgumentError
180
+ p
181
+ end
182
+ end.compact
183
+
184
+ gem_file = Bundler.rubygems.build_gem gem_dir, spec
185
+
186
+ installer = Path::Installer.new(spec, :env_shebang => false)
187
+ run_hooks(:pre_install, installer)
188
+ installer.build_extensions unless disable_extensions
189
+ run_hooks(:post_build, installer)
190
+ installer.generate_bin
191
+ run_hooks(:post_install, installer)
192
+ rescue Gem::InvalidSpecificationException => e
193
+ Bundler.ui.warn "\n#{spec.name} at #{spec.full_gem_path} did not have a valid gemspec.\n" \
194
+ "This prevents bundler from installing bins or native extensions, but " \
195
+ "that may not affect its functionality."
196
+
197
+ if !spec.extensions.empty? && !spec.email.empty?
198
+ Bundler.ui.warn "If you need to use this package without installing it from a gem " \
199
+ "repository, please contact #{spec.email} and ask them " \
200
+ "to modify their .gemspec so it can work with `gem build`."
201
+ end
202
+
203
+ Bundler.ui.warn "The validation message from Rubygems was:\n #{e.message}"
204
+ ensure
205
+ if gem_dir && gem_file
206
+ FileUtils.rm_rf(gem_dir.join gem_file)
207
+ end
208
+ end
209
+
210
+ def run_hooks(type, installer)
211
+ hooks_meth = "#{type}_hooks"
212
+ return unless Gem.respond_to?(hooks_meth)
213
+ Gem.send(hooks_meth).each do |hook|
214
+ result = hook.call(installer)
215
+ if result == false
216
+ location = " at #{$1}" if hook.inspect =~ /@(.*:\d+)/
217
+ message = "#{type} hook#{location} failed for #{installer.spec.full_name}"
218
+ raise InstallHookError, message
219
+ end
220
+ end
221
+ end
222
+ end
223
+
224
+ end
225
+ end
@@ -0,0 +1,38 @@
1
+ module Bundler
2
+ class Source
3
+ class Path
4
+
5
+ class Installer < Bundler::GemInstaller
6
+ def initialize(spec, options = {})
7
+ @spec = spec
8
+ @tmp_bin_dir = "#{Bundler.tmp(spec.full_name)}/bin"
9
+ @gem_bin_dir = "#{Bundler.rubygems.gem_dir}/bin"
10
+ @bin_dir = Bundler.requires_sudo? ? @tmp_bin_dir : @gem_bin_dir
11
+ @gem_dir = Bundler.rubygems.path(spec.full_gem_path)
12
+ @wrappers = options[:wrappers] || true
13
+ @env_shebang = options[:env_shebang] || true
14
+ @format_executable = options[:format_executable] || false
15
+ @build_args = options[:build_args] || Bundler.rubygems.build_args
16
+ end
17
+
18
+ def generate_bin
19
+ return if spec.executables.nil? || spec.executables.empty?
20
+
21
+ if Bundler.requires_sudo?
22
+ FileUtils.mkdir_p(@tmp_bin_dir) unless File.exist?(@tmp_bin_dir)
23
+ end
24
+
25
+ super
26
+
27
+ if Bundler.requires_sudo?
28
+ Bundler.mkdir_p @gem_bin_dir
29
+ spec.executables.each do |exe|
30
+ Bundler.sudo "cp -R #{@tmp_bin_dir}/#{exe} #{@gem_bin_dir}"
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,334 @@
1
+ require 'uri'
2
+ require 'rubygems/user_interaction'
3
+ require 'rubygems/spec_fetcher'
4
+
5
+ module Bundler
6
+ class Source
7
+ class Rubygems < Source
8
+ API_REQUEST_LIMIT = 100 # threshold for switching back to the modern index instead of fetching every spec
9
+
10
+ attr_reader :remotes, :caches
11
+ attr_accessor :dependency_names
12
+
13
+ def initialize(options = {})
14
+ @options = options
15
+ @remotes = (options["remotes"] || []).map { |r| normalize_uri(r) }
16
+ @fetchers = {}
17
+ @dependency_names = []
18
+ @allow_remote = false
19
+ @allow_cached = false
20
+ @caches = [Bundler.app_cache, *Bundler.rubygems.gem_cache]
21
+ end
22
+
23
+ def remote!
24
+ @allow_remote = true
25
+ end
26
+
27
+ def cached!
28
+ @allow_cached = true
29
+ end
30
+
31
+ def hash
32
+ Rubygems.hash
33
+ end
34
+
35
+ def eql?(o)
36
+ o.is_a?(Rubygems)
37
+ end
38
+
39
+ alias == eql?
40
+
41
+ def options
42
+ { "remotes" => @remotes.map { |r| r.to_s } }
43
+ end
44
+
45
+ def self.from_lock(options)
46
+ s = new(options)
47
+ Array(options["remote"]).each { |r| s.add_remote(r) }
48
+ s
49
+ end
50
+
51
+ def to_lock
52
+ out = "GEM\n"
53
+ out << remotes.map { |remote|
54
+ " remote: #{suppress_configured_credentials remote}\n"
55
+ }.join
56
+ out << " specs:\n"
57
+ end
58
+
59
+ def to_s
60
+ remote_names = self.remotes.map { |r| r.to_s }.join(', ')
61
+ "rubygems repository #{remote_names}"
62
+ end
63
+ alias_method :name, :to_s
64
+
65
+ def specs
66
+ @specs ||= fetch_specs
67
+ end
68
+
69
+ def install(spec)
70
+ return ["Using #{version_message(spec)}", nil] if installed_specs[spec].any?
71
+
72
+ # Download the gem to get the spec, because some specs that are returned
73
+ # by rubygems.org are broken and wrong.
74
+ if spec.source_uri
75
+ s = Bundler.rubygems.spec_from_gem(fetch_gem(spec), Bundler.settings["trust-policy"])
76
+ spec.__swap__(s)
77
+ end
78
+
79
+ unless Bundler.settings[:no_install]
80
+ path = cached_gem(spec)
81
+ if Bundler.requires_sudo?
82
+ install_path = Bundler.tmp(spec.full_name)
83
+ bin_path = install_path.join("bin")
84
+ else
85
+ install_path = Bundler.rubygems.gem_dir
86
+ bin_path = Bundler.system_bindir
87
+ end
88
+
89
+ installed_spec = nil
90
+ Bundler.rubygems.preserve_paths do
91
+ installed_spec = Bundler::GemInstaller.new(path,
92
+ :install_dir => install_path.to_s,
93
+ :bin_dir => bin_path.to_s,
94
+ :ignore_dependencies => true,
95
+ :wrappers => true,
96
+ :env_shebang => true
97
+ ).install
98
+ end
99
+
100
+ # SUDO HAX
101
+ if Bundler.requires_sudo?
102
+ Bundler.rubygems.repository_subdirectories.each do |name|
103
+ src = File.join(install_path, name, "*")
104
+ dst = File.join(Bundler.rubygems.gem_dir, name)
105
+ if name == "extensions" && Dir.glob(src).any?
106
+ src = File.join(src, "*/*")
107
+ ext_src = Dir.glob(src).first
108
+ ext_src.gsub!(src[0..-6], '')
109
+ dst = File.dirname(File.join(dst, ext_src))
110
+ end
111
+ Bundler.mkdir_p dst
112
+ Bundler.sudo "cp -R #{src} #{dst}" if Dir[src].any?
113
+ end
114
+
115
+ spec.executables.each do |exe|
116
+ Bundler.mkdir_p Bundler.system_bindir
117
+ Bundler.sudo "cp -R #{install_path}/bin/#{exe} #{Bundler.system_bindir}/"
118
+ end
119
+ end
120
+ installed_spec.loaded_from = loaded_from(spec)
121
+ end
122
+ spec.loaded_from = loaded_from(spec)
123
+ ["Installing #{version_message(spec)}", spec.post_install_message]
124
+ ensure
125
+ if install_path && Bundler.requires_sudo?
126
+ FileUtils.remove_entry_secure(install_path)
127
+ end
128
+ end
129
+
130
+ def cache(spec, custom_path = nil)
131
+ if builtin_gem?(spec)
132
+ cached_path = cached_built_in_gem(spec)
133
+ else
134
+ cached_path = cached_gem(spec)
135
+ end
136
+ raise GemNotFound, "Missing gem file '#{spec.full_name}.gem'." unless cached_path
137
+ return if File.dirname(cached_path) == Bundler.app_cache.to_s
138
+ Bundler.ui.info " * #{File.basename(cached_path)}"
139
+ FileUtils.cp(cached_path, Bundler.app_cache(custom_path))
140
+ end
141
+
142
+ def cached_built_in_gem(spec)
143
+ cached_path = cached_path(spec)
144
+ if cached_path.nil?
145
+ remote_spec = remote_specs.search(spec).first
146
+ cached_path = fetch_gem(remote_spec)
147
+ end
148
+ cached_path
149
+ end
150
+
151
+ def add_remote(source)
152
+ @remotes << normalize_uri(source)
153
+ end
154
+
155
+ def replace_remotes(source)
156
+ return false if source.remotes == @remotes
157
+
158
+ @remotes = []
159
+ source.remotes.each do |r|
160
+ add_remote r.to_s
161
+ end
162
+
163
+ true
164
+ end
165
+
166
+ private
167
+
168
+ def loaded_from(spec)
169
+ "#{Bundler.rubygems.gem_dir}/specifications/#{spec.full_name}.gemspec"
170
+ end
171
+
172
+ def cached_gem(spec)
173
+ cached_gem = cached_path(spec)
174
+ unless cached_gem
175
+ raise Bundler::GemNotFound, "Could not find #{spec.file_name} for installation"
176
+ end
177
+ cached_gem
178
+ end
179
+
180
+ def cached_path(spec)
181
+ possibilities = @caches.map { |p| "#{p}/#{spec.file_name}" }
182
+ possibilities.find { |p| File.exist?(p) }
183
+ end
184
+
185
+ def normalize_uri(uri)
186
+ uri = uri.to_s
187
+ uri = "#{uri}/" unless uri =~ %r'/$'
188
+ uri = URI(uri)
189
+ raise ArgumentError, "The source must be an absolute URI" unless uri.absolute?
190
+ uri
191
+ end
192
+
193
+ def suppress_configured_credentials(remote)
194
+ remote_nouser = remote.tap { |uri| uri.user = uri.password = nil }.to_s
195
+ if remote.userinfo && remote.userinfo == Bundler.settings[remote_nouser]
196
+ remote_nouser
197
+ else
198
+ remote
199
+ end
200
+ end
201
+
202
+ def fetch_specs
203
+ # remote_specs usually generates a way larger Index than the other
204
+ # sources, and large_idx.use small_idx is way faster than
205
+ # small_idx.use large_idx.
206
+ if @allow_remote
207
+ idx = remote_specs.dup
208
+ else
209
+ idx = Index.new
210
+ end
211
+ idx.use(cached_specs, :override_dupes) if @allow_cached || @allow_remote
212
+ idx.use(installed_specs, :override_dupes)
213
+ idx
214
+ end
215
+
216
+ def installed_specs
217
+ @installed_specs ||= begin
218
+ idx = Index.new
219
+ have_bundler = false
220
+ Bundler.rubygems.all_specs.reverse.each do |spec|
221
+ next if spec.name == 'bundler' && spec.version.to_s != VERSION
222
+ have_bundler = true if spec.name == 'bundler'
223
+ spec.source = self
224
+ idx << spec
225
+ end
226
+
227
+ # Always have bundler locally
228
+ unless have_bundler
229
+ # We're running bundler directly from the source
230
+ # so, let's create a fake gemspec for it (it's a path)
231
+ # gemspec
232
+ bundler = Gem::Specification.new do |s|
233
+ s.name = 'bundler'
234
+ s.version = VERSION
235
+ s.platform = Gem::Platform::RUBY
236
+ s.source = self
237
+ s.authors = ["bundler team"]
238
+ s.loaded_from = File.expand_path("..", __FILE__)
239
+ end
240
+ idx << bundler
241
+ end
242
+ idx
243
+ end
244
+ end
245
+
246
+ def cached_specs
247
+ @cached_specs ||= begin
248
+ idx = installed_specs.dup
249
+
250
+ path = Bundler.app_cache
251
+ Dir["#{path}/*.gem"].each do |gemfile|
252
+ next if gemfile =~ /^bundler\-[\d\.]+?\.gem/
253
+ s ||= Bundler.rubygems.spec_from_gem(gemfile)
254
+ s.source = self
255
+ idx << s
256
+ end
257
+ end
258
+
259
+ idx
260
+ end
261
+
262
+ def remote_specs
263
+ @remote_specs ||= begin
264
+ old = Bundler.rubygems.sources
265
+ idx = Index.new
266
+
267
+ fetchers = remotes.map { |uri| Bundler::Fetcher.new(uri) }
268
+ api_fetchers = fetchers.select { |f| f.use_api }
269
+ index_fetchers = fetchers - api_fetchers
270
+
271
+ # gather lists from non-api sites
272
+ index_fetchers.each do |f|
273
+ Bundler.ui.info "Fetching source index from #{f.uri}"
274
+ idx.use f.specs(nil, self)
275
+ end
276
+ return idx if api_fetchers.empty?
277
+
278
+ # because ensuring we have all the gems we need involves downloading
279
+ # the gemspecs of those gems, if the non-api sites contain more than
280
+ # about 100 gems, we just treat all sites as non-api for speed.
281
+ allow_api = idx.size < API_REQUEST_LIMIT && dependency_names.size < API_REQUEST_LIMIT
282
+
283
+ if allow_api
284
+ api_fetchers.each do |f|
285
+ Bundler.ui.info "Fetching gem metadata from #{f.uri}", Bundler.ui.debug?
286
+ idx.use f.specs(dependency_names, self)
287
+ Bundler.ui.info "" if !Bundler.ui.debug? # new line now that the dots are over
288
+ end
289
+
290
+ if api_fetchers.all?{|f| f.use_api }
291
+ # it's possible that gems from one source depend on gems from some
292
+ # other source, so now we download gemspecs and iterate over those
293
+ # dependencies, looking for gems we don't have info on yet.
294
+ unmet = idx.unmet_dependency_names
295
+
296
+ # if there are any cross-site gems we missed, get them now
297
+ api_fetchers.each do |f|
298
+ Bundler.ui.info "Fetching additional metadata from #{f.uri}", Bundler.ui.debug?
299
+ idx.use f.specs(unmet, self)
300
+ Bundler.ui.info "" if !Bundler.ui.debug? # new line now that the dots are over
301
+ end if unmet.any?
302
+ else
303
+ allow_api = false
304
+ end
305
+ end
306
+
307
+ if !allow_api
308
+ api_fetchers.each do |f|
309
+ Bundler.ui.info "Fetching source index from #{f.uri}"
310
+ idx.use f.specs(nil, self)
311
+ end
312
+ end
313
+
314
+ return idx
315
+ ensure
316
+ Bundler.rubygems.sources = old
317
+ end
318
+ end
319
+
320
+ def fetch_gem(spec)
321
+ return false unless spec.source_uri
322
+ Fetcher.download_gem_from_uri(spec, spec.source_uri)
323
+ end
324
+
325
+ def builtin_gem?(spec)
326
+ # Ruby 2.1, where all included gems have this summary
327
+ return true if spec.summary =~ /is bundled with Ruby/
328
+
329
+ # Ruby 2.0, where gemspecs are stored in specifications/default/
330
+ spec.loaded_from && spec.loaded_from.include?("specifications/default/")
331
+ end
332
+ end
333
+ end
334
+ end