omnibus 3.2.2 → 4.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (302) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +140 -10
  3. data/CHANGELOG.md +181 -8
  4. data/README.md +63 -35
  5. data/Rakefile +1 -1
  6. data/docs/omnibus-build-cache.md b/data/docs/Build → Cache.md +0 -0
  7. data/docs/Building on Debian.md +59 -0
  8. data/docs/Building on OSX.md +61 -35
  9. data/docs/Building on RHEL.md +74 -0
  10. data/docs/Building on Windows.md +40 -81
  11. data/features/commands/build.feature +1 -2
  12. data/features/commands/clean.feature +1 -1
  13. data/lib/omnibus.rb +111 -204
  14. data/lib/omnibus/build_version.rb +3 -20
  15. data/lib/omnibus/build_version_dsl.rb +2 -3
  16. data/lib/omnibus/builder.rb +103 -211
  17. data/lib/omnibus/cleaner.rb +5 -7
  18. data/lib/omnibus/cli.rb +1 -4
  19. data/lib/omnibus/cli/base.rb +9 -16
  20. data/lib/omnibus/compressor.rb +60 -0
  21. data/{spec/data/complicated/config/software/version-manifest.rb → lib/omnibus/compressors/base.rb} +17 -12
  22. data/lib/omnibus/compressors/dmg.rb +312 -0
  23. data/lib/omnibus/{null_builder.rb → compressors/null.rb} +10 -4
  24. data/lib/omnibus/compressors/tgz.rb +141 -0
  25. data/lib/omnibus/config.rb +89 -83
  26. data/lib/omnibus/core_extensions.rb +1 -0
  27. data/lib/omnibus/core_extensions/open_uri.rb +58 -0
  28. data/lib/omnibus/digestable.rb +9 -3
  29. data/lib/omnibus/exceptions.rb +116 -175
  30. data/lib/omnibus/fetcher.rb +97 -138
  31. data/lib/omnibus/fetchers/git_fetcher.rb +130 -165
  32. data/lib/omnibus/fetchers/net_fetcher.rb +205 -164
  33. data/lib/omnibus/fetchers/{s3_cache_fetcher.rb → null_fetcher.rb} +27 -17
  34. data/lib/omnibus/fetchers/path_fetcher.rb +74 -32
  35. data/lib/omnibus/file_syncer.rb +149 -0
  36. data/lib/omnibus/generator.rb +103 -32
  37. data/lib/omnibus/generator_files/.kitchen.yml.erb +5 -1
  38. data/lib/omnibus/generator_files/Gemfile.erb +13 -7
  39. data/lib/omnibus/generator_files/config/projects/project.rb.erb +28 -0
  40. data/lib/omnibus/generator_files/config/software/zlib.rb.erb +55 -0
  41. data/lib/omnibus/generator_files/omnibus.rb.erb +5 -7
  42. data/lib/omnibus/git_cache.rb +11 -13
  43. data/lib/omnibus/logger.rb +76 -22
  44. data/lib/omnibus/logging.rb +1 -1
  45. data/lib/omnibus/metadata.rb +264 -0
  46. data/lib/omnibus/ohai.rb +0 -51
  47. data/lib/omnibus/package.rb +4 -228
  48. data/lib/omnibus/packager.rb +71 -0
  49. data/lib/omnibus/packagers/base.rb +118 -176
  50. data/lib/omnibus/packagers/bff.rb +136 -0
  51. data/lib/omnibus/packagers/deb.rb +389 -0
  52. data/lib/omnibus/packagers/makeself.rb +114 -0
  53. data/lib/omnibus/packagers/msi.rb +346 -0
  54. data/lib/omnibus/packagers/pkg.rb +278 -0
  55. data/lib/omnibus/packagers/rpm.rb +438 -0
  56. data/lib/omnibus/packagers/solaris.rb +110 -0
  57. data/lib/omnibus/project.rb +263 -666
  58. data/lib/omnibus/publisher.rb +3 -3
  59. data/lib/omnibus/s3_cache.rb +21 -30
  60. data/lib/omnibus/software.rb +132 -271
  61. data/lib/omnibus/templating.rb +66 -0
  62. data/lib/omnibus/thread_pool.rb +109 -0
  63. data/lib/omnibus/util.rb +137 -15
  64. data/lib/omnibus/version.rb +1 -1
  65. data/omnibus.gemspec +2 -2
  66. data/resources/bff/gen.template.erb +22 -0
  67. data/resources/bff/postinstall.sh +0 -0
  68. data/resources/bff/unpostinstall.sh +0 -0
  69. data/resources/deb/conffiles.erb +3 -0
  70. data/resources/deb/control.erb +25 -0
  71. data/resources/deb/md5sums.erb +3 -0
  72. data/{lib/omnibus/generator_files/mac_dmg → resources/dmg}/background.png +0 -0
  73. data/resources/dmg/create_dmg.osascript.erb +17 -0
  74. data/{lib/omnibus/generator_files/mac_dmg → resources/dmg}/icon.png +0 -0
  75. data/{bin → resources/makeself}/makeself-header.sh +0 -0
  76. data/{bin → resources/makeself}/makeself.sh +0 -0
  77. data/{lib/omnibus/generator_files/package_scripts/makeselfinst.erb → resources/makeself/post_extract.sh.erb} +4 -4
  78. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/LICENSE.rtf +0 -0
  79. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/banner_background.bmp +0 -0
  80. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/dialog_background.bmp +0 -0
  81. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/project.ico +0 -0
  82. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/project_16x16.ico +0 -0
  83. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/project_32x32.ico +0 -0
  84. data/{spec/fixtures/sample/files/windows_msi/Resources/localization-en-us.wxl → resources/msi/localization-en-us.wxl.erb} +3 -4
  85. data/resources/msi/parameters.wxi.erb +9 -0
  86. data/{lib/omnibus/generator_files/windows_msi → resources/msi}/source.wxs.erb +14 -15
  87. data/{lib/omnibus/generator_files/mac_pkg → resources/pkg}/background.png +0 -0
  88. data/resources/pkg/distribution.xml.erb +21 -0
  89. data/resources/pkg/license.html.erb +3 -0
  90. data/resources/pkg/welcome.html.erb +7 -0
  91. data/resources/rpm/rpmmacros.erb +3 -0
  92. data/resources/rpm/signing.erb +40 -0
  93. data/resources/rpm/spec.erb +70 -0
  94. data/spec/functional/builder_spec.rb +90 -111
  95. data/spec/functional/fetchers/git_fetcher_spec.rb +130 -0
  96. data/spec/functional/fetchers/net_fetcher_spec.rb +110 -0
  97. data/spec/functional/fetchers/path_fetcher_spec.rb +97 -0
  98. data/spec/functional/file_syncer_spec.rb +206 -0
  99. data/spec/functional/templating_spec.rb +73 -0
  100. data/spec/spec_helper.rb +31 -94
  101. data/spec/support/env_helpers.rb +20 -0
  102. data/spec/support/examples.rb +56 -0
  103. data/spec/support/file_helpers.rb +46 -0
  104. data/spec/support/git_helpers.rb +107 -0
  105. data/spec/support/logging_helpers.rb +33 -0
  106. data/spec/support/matchers.rb +36 -0
  107. data/spec/support/ohai_helpers.rb +22 -0
  108. data/spec/support/path_helpers.rb +19 -0
  109. data/spec/support/shell_helpers.rb +14 -0
  110. data/spec/unit/build_version_dsl_spec.rb +0 -17
  111. data/spec/unit/build_version_spec.rb +1 -19
  112. data/spec/unit/builder_spec.rb +158 -46
  113. data/spec/unit/compressor_spec.rb +45 -0
  114. data/spec/unit/compressors/base_spec.rb +26 -0
  115. data/spec/unit/compressors/dmg_spec.rb +291 -0
  116. data/spec/unit/compressors/null_spec.rb +23 -0
  117. data/spec/unit/compressors/tgz_spec.rb +67 -0
  118. data/spec/unit/config_spec.rb +27 -34
  119. data/spec/unit/digestable_spec.rb +4 -4
  120. data/spec/unit/fetchers/git_fetcher_spec.rb +110 -39
  121. data/spec/unit/fetchers/net_fetcher_spec.rb +182 -72
  122. data/spec/unit/fetchers/path_fetcher_spec.rb +111 -0
  123. data/spec/unit/generator_spec.rb +137 -0
  124. data/spec/unit/git_cache_spec.rb +24 -34
  125. data/spec/unit/library_spec.rb +21 -82
  126. data/spec/unit/metadata_spec.rb +207 -0
  127. data/spec/unit/ohai_spec.rb +0 -7
  128. data/spec/unit/omnibus_spec.rb +41 -36
  129. data/spec/unit/package_spec.rb +1 -216
  130. data/spec/unit/packagers/base_spec.rb +76 -190
  131. data/spec/unit/packagers/bff_spec.rb +160 -0
  132. data/spec/unit/packagers/deb_spec.rb +324 -0
  133. data/spec/unit/packagers/makeself_spec.rb +80 -0
  134. data/spec/unit/packagers/msi_spec.rb +267 -0
  135. data/spec/unit/packagers/pkg_spec.rb +219 -0
  136. data/spec/unit/packagers/rpm_spec.rb +328 -0
  137. data/spec/unit/project_spec.rb +217 -80
  138. data/spec/unit/publisher_spec.rb +6 -2
  139. data/spec/unit/publishers/artifactory_publisher_spec.rb +1 -1
  140. data/spec/unit/publishers/s3_publisher_spec.rb +1 -1
  141. data/spec/unit/s3_cacher_spec.rb +22 -5
  142. data/spec/unit/software_spec.rb +89 -232
  143. data/spec/unit/util_spec.rb +188 -0
  144. metadata +159 -402
  145. data/features/commands/_deprecated.feature +0 -84
  146. data/lib/omnibus/cleanroom.rb +0 -141
  147. data/lib/omnibus/cli/deprecated.rb +0 -132
  148. data/lib/omnibus/generator_files/mac_pkg/license.html.erb +0 -1
  149. data/lib/omnibus/generator_files/mac_pkg/welcome.html.erb +0 -9
  150. data/lib/omnibus/generator_files/project.rb.erb +0 -20
  151. data/lib/omnibus/generator_files/software/c-example.rb.erb +0 -42
  152. data/lib/omnibus/generator_files/software/erlang-example.rb.erb +0 -38
  153. data/lib/omnibus/generator_files/software/ruby-example.rb.erb +0 -24
  154. data/lib/omnibus/generator_files/windows_msi/localization-en-us.wxl.erb +0 -20
  155. data/lib/omnibus/generator_files/windows_msi/parameters.wxi.erb +0 -9
  156. data/lib/omnibus/packagers/mac_dmg.rb +0 -235
  157. data/lib/omnibus/packagers/mac_pkg.rb +0 -176
  158. data/lib/omnibus/packagers/windows_msi.rb +0 -109
  159. data/spec/data/complicated/config/patches/bzip2/makefile_take_env_vars.patch +0 -15
  160. data/spec/data/complicated/config/patches/couchdb/patch_for_couchjs_stack.patch +0 -19
  161. data/spec/data/complicated/config/patches/gd/gd-2.0.33-configure-libpng.patch +0 -100
  162. data/spec/data/complicated/config/patches/keepalived/keepalived-1.2.9_opscode_centos_5.patch +0 -15
  163. data/spec/data/complicated/config/patches/libedit/freebsd-vi-fix.patch +0 -24
  164. data/spec/data/complicated/config/patches/libiconv/libiconv-1.14_srclib_stdio.in.h-remove-gets-declarations.patch +0 -29
  165. data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-makefile-dest-fix.patch +0 -35
  166. data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-malloc-fix.patch +0 -13
  167. data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-shared_lib_plus_plus-1.patch +0 -1035
  168. data/spec/data/complicated/config/patches/logrotate/logrotate_basedir_override.patch +0 -12
  169. data/spec/data/complicated/config/patches/ncurses/ncurses-5.9-solaris-xopen_source_extended-detection.patch +0 -11
  170. data/spec/data/complicated/config/patches/ncurses/ncurses-clang.patch +0 -42
  171. data/spec/data/complicated/config/patches/ncurses/patch-aa +0 -23
  172. data/spec/data/complicated/config/patches/ncurses/patch-ab +0 -44
  173. data/spec/data/complicated/config/patches/ncurses/patch-ac +0 -40
  174. data/spec/data/complicated/config/patches/ncurses/patch-ad +0 -12
  175. data/spec/data/complicated/config/patches/ncurses/patch-aix-configure +0 -23
  176. data/spec/data/complicated/config/patches/ncurses/patch-cxx_cursesf.h +0 -22
  177. data/spec/data/complicated/config/patches/ncurses/patch-cxx_cursesm.h +0 -22
  178. data/spec/data/complicated/config/patches/nrpe/fix_for_runit.patch +0 -64
  179. data/spec/data/complicated/config/patches/openssl/openssl-1.0.1f-do-not-build-docs.patch +0 -101
  180. data/spec/data/complicated/config/patches/postgresql/postgresql-9.1.2-configure-ncurses-fix.patch +0 -12
  181. data/spec/data/complicated/config/patches/ruby/patch-configure +0 -103
  182. data/spec/data/complicated/config/patches/ruby/ruby-aix-configure.patch +0 -10
  183. data/spec/data/complicated/config/patches/ruby/ruby-openssl-1.0.1c.patch +0 -42
  184. data/spec/data/complicated/config/patches/ruby/ruby_aix_1_9_3_448_ssl_EAGAIN.patch +0 -57
  185. data/spec/data/complicated/config/patches/ruby/rvm-cflags.patch +0 -27
  186. data/spec/data/complicated/config/projects/angrychef.rb +0 -32
  187. data/spec/data/complicated/config/projects/chef-windows.rb +0 -32
  188. data/spec/data/complicated/config/projects/chef.rb +0 -32
  189. data/spec/data/complicated/config/projects/chefdk-windows.rb +0 -41
  190. data/spec/data/complicated/config/projects/chefdk.rb +0 -44
  191. data/spec/data/complicated/config/software/appbundler.rb +0 -25
  192. data/spec/data/complicated/config/software/autoconf.rb +0 -35
  193. data/spec/data/complicated/config/software/automake.rb +0 -39
  194. data/spec/data/complicated/config/software/berkshelf.rb +0 -44
  195. data/spec/data/complicated/config/software/bundler.rb +0 -25
  196. data/spec/data/complicated/config/software/bzip2.rb +0 -46
  197. data/spec/data/complicated/config/software/cacerts.rb +0 -44
  198. data/spec/data/complicated/config/software/chef-client-msi.rb +0 -87
  199. data/spec/data/complicated/config/software/chef-gem.rb +0 -26
  200. data/spec/data/complicated/config/software/chef-vault.rb +0 -43
  201. data/spec/data/complicated/config/software/chef-windows.rb +0 -158
  202. data/spec/data/complicated/config/software/chef.rb +0 -170
  203. data/spec/data/complicated/config/software/chefdk.rb +0 -103
  204. data/spec/data/complicated/config/software/couchdb.rb +0 -53
  205. data/spec/data/complicated/config/software/curl.rb +0 -48
  206. data/spec/data/complicated/config/software/erlang.rb +0 -65
  207. data/spec/data/complicated/config/software/expat.rb +0 -21
  208. data/spec/data/complicated/config/software/fcgi.rb +0 -56
  209. data/spec/data/complicated/config/software/fcgiwrap.rb +0 -41
  210. data/spec/data/complicated/config/software/gd.rb +0 -56
  211. data/spec/data/complicated/config/software/gdbm.rb +0 -40
  212. data/spec/data/complicated/config/software/gecode.rb +0 -48
  213. data/spec/data/complicated/config/software/git.rb +0 -40
  214. data/spec/data/complicated/config/software/help2man.rb +0 -30
  215. data/spec/data/complicated/config/software/icu.rb +0 -40
  216. data/spec/data/complicated/config/software/jre.rb +0 -48
  217. data/spec/data/complicated/config/software/keepalived.rb +0 -43
  218. data/spec/data/complicated/config/software/libarchive.rb +0 -50
  219. data/spec/data/complicated/config/software/libedit.rb +0 -69
  220. data/spec/data/complicated/config/software/libffi.rb +0 -71
  221. data/spec/data/complicated/config/software/libgcc.rb +0 -39
  222. data/spec/data/complicated/config/software/libiconv.rb +0 -55
  223. data/spec/data/complicated/config/software/libjpeg.rb +0 -39
  224. data/spec/data/complicated/config/software/libpng.rb +0 -38
  225. data/spec/data/complicated/config/software/libtool.rb +0 -52
  226. data/spec/data/complicated/config/software/libwrap.rb +0 -50
  227. data/spec/data/complicated/config/software/libxml2.rb +0 -51
  228. data/spec/data/complicated/config/software/libxslt.rb +0 -52
  229. data/spec/data/complicated/config/software/libyaml-windows.rb +0 -43
  230. data/spec/data/complicated/config/software/libyaml.rb +0 -62
  231. data/spec/data/complicated/config/software/logrotate.rb +0 -41
  232. data/spec/data/complicated/config/software/makedepend.rb +0 -73
  233. data/spec/data/complicated/config/software/mysql2.rb +0 -42
  234. data/spec/data/complicated/config/software/nagios-plugins.rb +0 -53
  235. data/spec/data/complicated/config/software/nagios.rb +0 -66
  236. data/spec/data/complicated/config/software/ncurses.rb +0 -149
  237. data/spec/data/complicated/config/software/nginx.rb +0 -40
  238. data/spec/data/complicated/config/software/nodejs.rb +0 -44
  239. data/spec/data/complicated/config/software/nokogiri.rb +0 -55
  240. data/spec/data/complicated/config/software/nrpe.rb +0 -61
  241. data/spec/data/complicated/config/software/ohai.rb +0 -64
  242. data/spec/data/complicated/config/software/omnibus-ctl.rb +0 -34
  243. data/spec/data/complicated/config/software/openresty.rb +0 -67
  244. data/spec/data/complicated/config/software/openssl.rb +0 -158
  245. data/spec/data/complicated/config/software/pcre.rb +0 -42
  246. data/spec/data/complicated/config/software/perl-extutils-embed.rb +0 -15
  247. data/spec/data/complicated/config/software/perl-extutils-makemaker.rb +0 -15
  248. data/spec/data/complicated/config/software/perl.rb +0 -48
  249. data/spec/data/complicated/config/software/perl_pg_driver.rb +0 -12
  250. data/spec/data/complicated/config/software/php.rb +0 -41
  251. data/spec/data/complicated/config/software/pip.rb +0 -30
  252. data/spec/data/complicated/config/software/pkg-config.rb +0 -66
  253. data/spec/data/complicated/config/software/popt.rb +0 -47
  254. data/spec/data/complicated/config/software/postgresql.rb +0 -51
  255. data/spec/data/complicated/config/software/preparation.rb +0 -30
  256. data/spec/data/complicated/config/software/pygments.rb +0 -25
  257. data/spec/data/complicated/config/software/python.rb +0 -49
  258. data/spec/data/complicated/config/software/rabbitmq.rb +0 -36
  259. data/spec/data/complicated/config/software/rebar.rb +0 -36
  260. data/spec/data/complicated/config/software/redis.rb +0 -33
  261. data/spec/data/complicated/config/software/rsync.rb +0 -48
  262. data/spec/data/complicated/config/software/ruby-windows-devkit.rb +0 -30
  263. data/spec/data/complicated/config/software/ruby-windows.rb +0 -30
  264. data/spec/data/complicated/config/software/ruby.rb +0 -162
  265. data/spec/data/complicated/config/software/rubygems-customization.rb +0 -57
  266. data/spec/data/complicated/config/software/rubygems.rb +0 -37
  267. data/spec/data/complicated/config/software/runit.rb +0 -118
  268. data/spec/data/complicated/config/software/server-jre.rb +0 -46
  269. data/spec/data/complicated/config/software/setuptools.rb +0 -30
  270. data/spec/data/complicated/config/software/spawn-fcgi.rb +0 -40
  271. data/spec/data/complicated/config/software/sphinx.rb +0 -26
  272. data/spec/data/complicated/config/software/spidermonkey.rb +0 -60
  273. data/spec/data/complicated/config/software/sqitch.rb +0 -24
  274. data/spec/data/complicated/config/software/test-kitchen.rb +0 -39
  275. data/spec/data/complicated/config/software/unicorn.rb +0 -27
  276. data/spec/data/complicated/config/software/util-macros.rb +0 -46
  277. data/spec/data/complicated/config/software/xproto.rb +0 -46
  278. data/spec/data/complicated/config/software/yajl.rb +0 -30
  279. data/spec/data/complicated/config/software/zlib.rb +0 -67
  280. data/spec/data/overrides/bad_line.overrides +0 -3
  281. data/spec/data/overrides/good.overrides +0 -5
  282. data/spec/data/overrides/with_dupes.overrides +0 -4
  283. data/spec/data/projects/chefdk.rb +0 -41
  284. data/spec/data/projects/sample.rb +0 -13
  285. data/spec/data/software/erchef.rb +0 -42
  286. data/spec/data/software/zlib.rb +0 -67
  287. data/spec/fixtures/sample/files/mac_dmg/Resources/background.png +0 -0
  288. data/spec/fixtures/sample/files/mac_dmg/Resources/icon.png +0 -0
  289. data/spec/fixtures/sample/files/mac_pkg/Resources/background.png +0 -0
  290. data/spec/fixtures/sample/files/mac_pkg/Resources/license.html +0 -1
  291. data/spec/fixtures/sample/files/mac_pkg/Resources/welcome.html +0 -9
  292. data/spec/fixtures/sample/files/windows_msi/Resources/assets/LICENSE.rtf +0 -8
  293. data/spec/fixtures/sample/files/windows_msi/Resources/assets/banner_background.bmp +0 -0
  294. data/spec/fixtures/sample/files/windows_msi/Resources/assets/dialog_background.bmp +0 -0
  295. data/spec/fixtures/sample/files/windows_msi/Resources/assets/project.ico +0 -0
  296. data/spec/fixtures/sample/files/windows_msi/Resources/assets/project_16x16.ico +0 -0
  297. data/spec/fixtures/sample/files/windows_msi/Resources/assets/project_32x32.ico +0 -0
  298. data/spec/fixtures/sample/files/windows_msi/Resources/parameters.wxi.erb +0 -9
  299. data/spec/fixtures/sample/files/windows_msi/Resources/source.wxs +0 -74
  300. data/spec/integration/packagers/mac_spec.rb +0 -58
  301. data/spec/integration/packagers/windows_spec.rb +0 -70
  302. data/spec/unit/packagers/mac_pkg_spec.rb +0 -151
@@ -22,16 +22,16 @@ module Omnibus
22
22
  let(:io) { StringIO.new }
23
23
 
24
24
  it 'inspects the file types of glob entries' do
25
- expect(Dir).to receive(:glob).with(glob).and_return([subdir])
25
+ expect(FileSyncer).to receive(:glob).with(glob).and_return([subdir])
26
26
  expect(File).to receive(:ftype).with(subdir).and_return('directory')
27
- expect(subject.digest_directory(path)).to eq('d4635f6b4c2a85ba603e1f9e6a65bd68')
27
+ expect(subject.digest_directory(path)).to eq('8b91792e7917b1152d8494670caaeb85')
28
28
  end
29
29
 
30
30
  it 'inspects the contents of the files' do
31
- expect(Dir).to receive(:glob).with(glob).and_return([subfile])
31
+ expect(FileSyncer).to receive(:glob).with(glob).and_return([subfile])
32
32
  expect(File).to receive(:ftype).with(subfile).and_return('file')
33
33
  expect(File).to receive(:open).with(subfile).and_yield(io)
34
- expect(subject.digest_directory(path)).to eq('73d045a78027e674811c36f3dbd09433')
34
+ expect(subject.digest_directory(path)).to eq('c8f023976b95ace2ae3678540fd3b4f1')
35
35
  end
36
36
  end
37
37
  end
@@ -2,77 +2,148 @@ require 'spec_helper'
2
2
 
3
3
  module Omnibus
4
4
  describe GitFetcher do
5
+ let(:source_path) { '/local/path' }
6
+ let(:project_dir) { '/project/dir' }
7
+
5
8
  let(:software) do
6
9
  double(Software,
7
- name: 'project',
8
- source: { git: 'git@example.com:test/project.git' },
9
- version: '0.0.1',
10
- project_dir: '/tmp/project',
10
+ name: 'software',
11
+ source: { path: source_path },
12
+ project_dir: project_dir,
11
13
  )
12
14
  end
13
15
 
14
16
  subject { described_class.new(software) }
15
17
 
16
- describe '#fetch' do
17
- context 'when the project is cloned' do
18
- before do
19
- allow(subject).to receive(:existing_git_clone?).and_return(true)
20
- allow(subject).to receive(:fetch_updates)
18
+ describe '#fetch_required?' do
19
+ context 'when the repository is not cloned' do
20
+ before { allow(subject).to receive(:cloned?).and_return(false) }
21
+
22
+ it 'returns true' do
23
+ expect(subject.fetch_required?).to be_truthy
21
24
  end
25
+ end
22
26
 
23
- context 'when the rev matches' do
24
- before { allow(subject).to receive(:current_rev_matches_target_rev?).and_return(true) }
27
+ context 'when the repository is cloned' do
28
+ before { allow(subject).to receive(:cloned?).and_return(true) }
25
29
 
26
- it 'does not fetch updates' do
27
- expect(subject).to_not receive(:fetch_updates)
28
- subject.fetch
30
+ context 'when the revision is difference' do
31
+ before { allow(subject).to receive(:same_revision?).and_return(false) }
32
+
33
+ it 'returns true' do
34
+ expect(subject.fetch_required?).to be_truthy
29
35
  end
30
36
  end
31
37
 
32
- context 'when the rev does not match' do
33
- before { allow(subject).to receive(:current_rev_matches_target_rev?).and_return(false) }
38
+ context 'when the same revision is checked out' do
39
+ before { allow(subject).to receive(:same_revision?).and_return(true) }
34
40
 
35
- it 'fetches the updates' do
36
- expect(subject).to receive(:fetch_updates).once
37
- subject.fetch
41
+ it 'returns false' do
42
+ expect(subject.fetch_required?).to be(false)
38
43
  end
39
44
  end
40
45
  end
46
+ end
47
+
48
+ describe '#version_guid' do
49
+ let(:revision) { 'abcd1234' }
50
+
51
+ before do
52
+ allow(subject).to receive(:current_revision).and_return(revision)
53
+ end
41
54
 
42
- context 'when the project is not cloned' do
55
+ it 'returns the revision' do
56
+ expect(subject.version_guid).to eq("git:#{revision}")
57
+ end
58
+ end
59
+
60
+ describe '#clean' do
61
+ before { allow(subject).to receive(:git) }
62
+
63
+ context 'when the repository is cloned' do
43
64
  before do
44
- allow(subject).to receive(:existing_git_clone?).and_return(false)
45
- allow(subject).to receive(:clone)
46
- allow(subject).to receive(:checkout)
65
+ allow(subject).to receive(:cloned?).and_return(true)
47
66
  end
48
67
 
49
- it 'clones the project' do
50
- expect(subject).to receive(:clone).once
51
- subject.fetch
68
+ it 'gleans the directory' do
69
+ expect(subject).to receive(:git).with('clean -fdx')
70
+ subject.clean
52
71
  end
53
72
 
54
- it 'checkouts the ref' do
55
- expect(subject).to receive(:checkout).once
56
- subject.fetch
73
+ it 'returns true' do
74
+ expect(subject.clean).to be_truthy
57
75
  end
58
76
  end
59
77
 
60
- context 'when something fails' do
61
- let(:error_reporter) { double(Fetcher::ErrorReporter, explain: nil) }
62
-
78
+ context 'when the repository is not cloned' do
63
79
  before do
64
- allow(subject).to receive(:existing_git_clone?).and_return(false)
65
- allow(subject).to receive(:clone).and_raise(RuntimeError)
80
+ allow(subject).to receive(:cloned?).and_return(false)
81
+ end
66
82
 
67
- allow(Fetcher::ErrorReporter).to receive(:new).and_return(error_reporter)
83
+ it 'does not clean the repository' do
84
+ expect(subject).to_not receive(:git)
85
+ subject.clean
68
86
  end
69
87
 
70
- it 'retries 4 times' do
71
- allow(subject).to receive(:sleep)
72
- expect(subject).to receive(:clone).exactly(4).times
73
- expect { subject.fetch }.to raise_error(RuntimeError)
88
+ it 'returns false' do
89
+ expect(subject.clean).to be(false)
74
90
  end
75
91
  end
76
92
  end
93
+
94
+ describe '#fetch' do
95
+ before do
96
+ allow(subject).to receive(:create_required_directories)
97
+ allow(subject).to receive(:git_fetch)
98
+ allow(subject).to receive(:git_clone)
99
+ allow(subject).to receive(:git_checkout)
100
+ end
101
+
102
+ context 'when the repository is cloned' do
103
+ before { allow(subject).to receive(:cloned?).and_return(true) }
104
+
105
+ context 'when the revision is different' do
106
+ before { allow(subject).to receive(:same_revision?).and_return(false) }
107
+
108
+ it 'fetches and resets' do
109
+ expect(subject).to receive(:git_fetch)
110
+ subject.fetch
111
+ end
112
+ end
113
+
114
+ context 'when the revision is the same' do
115
+ before { allow(subject).to receive(:same_revision?).and_return(true) }
116
+
117
+ it 'does not fetch or reset' do
118
+ expect(subject).to_not receive(:git_fetch)
119
+ subject.fetch
120
+ end
121
+ end
122
+ end
123
+
124
+ context 'when the repository is not cloned' do
125
+ before { allow(subject).to receive(:cloned?).and_return(false) }
126
+
127
+ it 'clones the repository' do
128
+ expect(subject).to receive(:git_clone).once
129
+ subject.fetch
130
+ end
131
+
132
+ it 'checks out the correct revision' do
133
+ expect(subject).to receive(:git_checkout).once
134
+ subject.fetch
135
+ end
136
+ end
137
+ end
138
+
139
+ describe '#version_for_cache' do
140
+ let(:revision) { 'abcd1234' }
141
+
142
+ before { allow(subject).to receive(:current_revision).and_return(revision) }
143
+
144
+ it 'returns the shasum of the project_dir' do
145
+ expect(subject.version_for_cache).to eq("revision:#{revision}")
146
+ end
147
+ end
77
148
  end
78
149
  end
@@ -2,116 +2,226 @@ require 'spec_helper'
2
2
 
3
3
  module Omnibus
4
4
  describe NetFetcher do
5
- let(:software_mock) do
5
+ let(:project_dir) { '/tmp/project' }
6
+
7
+ let(:software) do
6
8
  double(Software,
7
- project_file: 'file.tar.gz',
9
+ downloaded_file: 'file.tar.gz',
8
10
  name: 'file',
9
- source: '/tmp/out',
11
+ source: { url: 'https://get.example.com/file.tar.gz', md5: 'abcd1234' },
10
12
  checksum: 'abc123',
11
13
  source_uri: 'http://example.com/file.tar.gz',
12
- project_dir: '/tmp/project',
14
+ project_dir: project_dir,
13
15
  )
14
16
  end
15
17
 
18
+ let(:cache_dir) { '/cache' }
19
+
16
20
  before do
17
- Config.source_dir('/tmp/out')
21
+ Config.cache_dir(cache_dir)
18
22
  end
19
23
 
20
- shared_examples 'an extractor' do |extension, command|
21
- context "when the file is a .#{extension}" do
22
- before do
23
- allow(software_mock).to receive(:project_file).and_return("file.#{extension}")
24
- allow(software_mock).to receive(:source_uri).and_return("http://example.com/file.#{extension}")
24
+ subject { described_class.new(software) }
25
+
26
+ describe '#fetch_required?' do
27
+ context 'when file is not downloaded' do
28
+ before { allow(File).to receive(:exist?).and_return(false) }
29
+
30
+ it 'returns true' do
31
+ expect(subject.fetch_required?).to be_truthy
25
32
  end
33
+ end
26
34
 
27
- it 'has the correct extract command' do
28
- expect(subject.extract_cmd).to eq(command)
35
+ context 'when the file is downloaded' do
36
+ before { allow(File).to receive(:exist?).and_return(true) }
37
+
38
+ context 'when the shasums differ' do
39
+ before do
40
+ allow(subject).to receive(:digest).and_return('abcd1234')
41
+ allow(subject).to receive(:checksum).and_return('efgh5678')
42
+ end
43
+
44
+ it 'returns true' do
45
+ expect(subject.fetch_required?).to be_truthy
46
+ end
29
47
  end
48
+
49
+ context 'when the shasums are the same' do
50
+ before do
51
+ allow(subject).to receive(:digest).and_return('abcd1234')
52
+ allow(subject).to receive(:checksum).and_return('abcd1234')
53
+ end
54
+
55
+ it 'returns true' do
56
+ expect(subject.fetch_required?).to be(false)
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '#version_guid' do
63
+ it 'returns the shasum' do
64
+ expect(subject.version_guid).to eq('md5:abcd1234')
30
65
  end
31
66
  end
32
67
 
33
- subject { described_class.new(software_mock) }
68
+ describe '#clean' do
69
+ before do
70
+ allow(FileUtils).to receive(:rm_rf)
71
+ allow(subject).to receive(:extract)
72
+ end
73
+
74
+ context 'when the project directory exists' do
75
+ before { allow(File).to receive(:exist?).and_return(true) }
34
76
 
35
- describe '#extract_cmd' do
36
- context 'on Windows' do
37
- before { stub_ohai(platform: 'windows', version: '2012') }
38
-
39
- it_behaves_like 'an extractor', '7z', '7z.exe x file.7z -o/tmp/out -r -y'
40
- it_behaves_like 'an extractor', 'zip', '7z.exe x file.zip -o/tmp/out -r -y'
41
- it_behaves_like 'an extractor', 'tar', 'tar xf file.tar -C/tmp/out'
42
- it_behaves_like 'an extractor', 'tgz', 'tar zxf file.tgz -C/tmp/out'
43
- it_behaves_like 'an extractor', 'tar.gz', 'tar zxf file.tar.gz -C/tmp/out'
44
- it_behaves_like 'an extractor', 'bz2', 'tar jxf file.bz2 -C/tmp/out'
45
- it_behaves_like 'an extractor', 'tar.bz2', 'tar jxf file.tar.bz2 -C/tmp/out'
46
- it_behaves_like 'an extractor', 'txz', 'tar Jxf file.txz -C/tmp/out'
47
- it_behaves_like 'an extractor', 'tar.xz', 'tar Jxf file.tar.xz -C/tmp/out'
77
+ it 'extracts the archive' do
78
+ expect(subject).to receive(:extract)
79
+ subject.clean
80
+ end
81
+
82
+ it 'returns true' do
83
+ expect(subject.clean).to be_truthy
84
+ end
85
+
86
+ it 'removes the project directory' do
87
+ expect(FileUtils).to receive(:rm_rf).with(project_dir)
88
+ subject.clean
89
+ end
48
90
  end
49
91
 
50
- context 'on Linux' do
51
- before { stub_ohai(platform: 'ubuntu', version: '12.04') }
52
-
53
- it_behaves_like 'an extractor', '7z', '7z x file.7z -o/tmp/out -r -y'
54
- it_behaves_like 'an extractor', 'zip', 'unzip file.zip -d /tmp/out'
55
- it_behaves_like 'an extractor', 'tar', 'tar xf file.tar -C/tmp/out'
56
- it_behaves_like 'an extractor', 'tgz', 'tar zxf file.tgz -C/tmp/out'
57
- it_behaves_like 'an extractor', 'tar.gz', 'tar zxf file.tar.gz -C/tmp/out'
58
- it_behaves_like 'an extractor', 'bz2', 'tar jxf file.bz2 -C/tmp/out'
59
- it_behaves_like 'an extractor', 'tar.bz2', 'tar jxf file.tar.bz2 -C/tmp/out'
60
- it_behaves_like 'an extractor', 'txz', 'tar Jxf file.txz -C/tmp/out'
61
- it_behaves_like 'an extractor', 'tar.xz', 'tar Jxf file.tar.xz -C/tmp/out'
92
+ context 'when the project directory does not exist' do
93
+ before { allow(File).to receive(:exist?).and_return(false) }
94
+
95
+ it 'extracts the archive' do
96
+ expect(subject).to receive(:extract)
97
+ subject.clean
98
+ end
99
+
100
+ it 'returns false' do
101
+ expect(subject.clean).to be(false)
102
+ end
62
103
  end
63
104
  end
64
105
 
65
- describe '#get_env' do
66
- it 'handles upper via lower' do
67
- stub_env('lower', 'abc')
68
- expect(subject.get_env('LOWER')).to eq('abc')
69
- expect(subject.get_env('lower')).to eq('abc')
106
+ describe '#version_for_cache' do
107
+ before do
108
+ allow(software).to receive(:source).and_return({
109
+ url: 'https://url',
110
+ md5: 'abcd1234',
111
+ })
70
112
  end
71
113
 
72
- it 'handles lower via upper' do
73
- stub_env('UPPER', 'abc')
74
- expect(subject.get_env('upper')).to eq('abc')
75
- expect(subject.get_env('UPPER')).to eq('abc')
114
+ it 'returns the download URL and md5' do
115
+ expect(subject.version_for_cache).to eq('download_url:https://url|md5:abcd1234')
76
116
  end
77
117
  end
78
118
 
79
- describe '#http_proxy' do
80
- it 'returns nil when no proxy is set in env' do
81
- expect(subject.http_proxy).to be_nil
119
+ shared_examples 'an extractor' do |extension, command|
120
+ context "when the file is a .#{extension}" do
121
+ before do
122
+ software.source[:url] = "https://example.com/file.#{extension}"
123
+ end
124
+
125
+ it 'is the right command' do
126
+ expect(subject.send(:extract_command)).to eq(command)
127
+ end
82
128
  end
129
+ end
83
130
 
84
- it 'returns a URI object when HTTP_PROXY is set' do
85
- stub_env('HTTP_PROXY', 'http://my.proxy')
86
- expect(subject.http_proxy).to eq(URI.parse('http://my.proxy'))
131
+ describe '#extract' do
132
+ before do
133
+ described_class.send(:public, :extract)
87
134
  end
88
135
 
89
- it 'sets user and pass from env when set' do
90
- stub_env('HTTP_PROXY', 'my.proxy')
91
- stub_env('HTTP_PROXY_USER', 'alex')
92
- stub_env('HTTP_PROXY_PASS', 'sesame')
93
- expect(subject.http_proxy).to eq(URI.parse('http://alex:sesame@my.proxy'))
136
+ context 'when the downloaded file is a folder' do
137
+ before do
138
+ allow(FileUtils).to receive(:cp_r)
139
+ allow(File).to receive(:directory?).and_return(true)
140
+ allow(subject).to receive(:extract_command)
141
+ software.source[:url] = 'https://example.com/folder'
142
+ end
143
+
144
+ it 'copies the entire directory to project_dir' do
145
+ expect(FileUtils).to receive(:cp_r).with("#{cache_dir}/folder", project_dir)
146
+ subject.extract
147
+ end
94
148
  end
95
149
 
96
- it 'uses user and pass in URL before those in env' do
97
- stub_env('HTTP_PROXY', 'sally:peanut@my.proxy')
98
- stub_env('HTTP_PROXY_USER', 'alex')
99
- stub_env('HTTP_PROXY_PASS', 'sesame')
100
- expect(subject.http_proxy).to eq(URI.parse('http://sally:peanut@my.proxy'))
150
+ context 'when the downloaded file is a regular file' do
151
+ before do
152
+ allow(FileUtils).to receive(:mkdir_p)
153
+ allow(FileUtils).to receive(:cp)
154
+ allow(File).to receive(:directory?).and_return(false)
155
+ allow(subject).to receive(:extract_command)
156
+ software.source[:url] = 'https://example.com/file'
157
+ end
158
+
159
+ it 'copies the file into the project_dir' do
160
+ expect(FileUtils).to receive(:cp).with("#{cache_dir}/file", "#{project_dir}/")
161
+ subject.extract
162
+ end
101
163
  end
102
164
  end
103
165
 
104
- describe '#excluded_from_proxy?' do
105
- it 'proxies if host does not match exclude list' do
106
- stub_env('NO_PROXY', 'google.com,www.buz.org')
107
- expect(subject.excluded_from_proxy?('should.proxy.com')).to be_falsey
108
- expect(subject.excluded_from_proxy?('www.buzz.org')).to be_falsey
166
+ describe '#extract_command' do
167
+ before { Config.source_dir('/tmp/out') }
168
+
169
+ context 'on Windows' do
170
+ before do
171
+ Config.cache_dir('C:')
172
+ stub_ohai(platform: 'windows', version: '2012')
173
+ end
174
+
175
+ it_behaves_like 'an extractor', '7z', '7z.exe x C:\\file.7z -o/tmp/out -r -y'
176
+ it_behaves_like 'an extractor', 'zip', '7z.exe x C:\\file.zip -o/tmp/out -r -y'
177
+ it_behaves_like 'an extractor', 'tar', 'tar xf C:\\file.tar -C/tmp/out'
178
+ it_behaves_like 'an extractor', 'tgz', 'tar zxf C:\\file.tgz -C/tmp/out'
179
+ it_behaves_like 'an extractor', 'tar.gz', 'tar zxf C:\\file.tar.gz -C/tmp/out'
180
+ it_behaves_like 'an extractor', 'bz2', 'tar jxf C:\\file.bz2 -C/tmp/out'
181
+ it_behaves_like 'an extractor', 'tar.bz2', 'tar jxf C:\\file.tar.bz2 -C/tmp/out'
182
+ it_behaves_like 'an extractor', 'txz', 'tar Jxf C:\\file.txz -C/tmp/out'
183
+ it_behaves_like 'an extractor', 'tar.xz', 'tar Jxf C:\\file.tar.xz -C/tmp/out'
109
184
  end
110
185
 
111
- it 'does not proxy if host matches exclude list' do
112
- stub_env('NO_PROXY', 'google.com,www.buz.org')
113
- expect(subject.excluded_from_proxy?('http://google.com')).to be_truthy
114
- expect(subject.excluded_from_proxy?('www.buz.org')).to be_truthy
186
+ context 'on Linux' do
187
+ before do
188
+ Config.cache_dir('/')
189
+ stub_ohai(platform: 'ubuntu', version: '12.04')
190
+ stub_const('File::ALT_SEPARATOR', nil)
191
+ end
192
+
193
+ it_behaves_like 'an extractor', '7z', '7z x /file.7z -o/tmp/out -r -y'
194
+ it_behaves_like 'an extractor', 'zip', 'unzip /file.zip -d /tmp/out'
195
+ it_behaves_like 'an extractor', 'tar', 'tar xf /file.tar -C/tmp/out'
196
+ it_behaves_like 'an extractor', 'tgz', 'tar zxf /file.tgz -C/tmp/out'
197
+ it_behaves_like 'an extractor', 'tar.gz', 'tar zxf /file.tar.gz -C/tmp/out'
198
+ it_behaves_like 'an extractor', 'bz2', 'tar jxf /file.bz2 -C/tmp/out'
199
+ it_behaves_like 'an extractor', 'tar.bz2', 'tar jxf /file.tar.bz2 -C/tmp/out'
200
+ it_behaves_like 'an extractor', 'txz', 'tar Jxf /file.txz -C/tmp/out'
201
+ it_behaves_like 'an extractor', 'tar.xz', 'tar Jxf /file.tar.xz -C/tmp/out'
202
+ end
203
+
204
+ context 'when gtar is present' do
205
+ before do
206
+ Config.cache_dir('/')
207
+
208
+ stub_ohai(platform: 'ubuntu', version: '12.04')
209
+ stub_const('File::ALT_SEPARATOR', nil)
210
+
211
+ allow(Omnibus).to receive(:which)
212
+ .with('gtar')
213
+ .and_return('/path/to/gtar')
214
+ end
215
+
216
+ it_behaves_like 'an extractor', '7z', '7z x /file.7z -o/tmp/out -r -y'
217
+ it_behaves_like 'an extractor', 'zip', 'unzip /file.zip -d /tmp/out'
218
+ it_behaves_like 'an extractor', 'tar', 'gtar xf /file.tar -C/tmp/out'
219
+ it_behaves_like 'an extractor', 'tgz', 'gtar zxf /file.tgz -C/tmp/out'
220
+ it_behaves_like 'an extractor', 'tar.gz', 'gtar zxf /file.tar.gz -C/tmp/out'
221
+ it_behaves_like 'an extractor', 'bz2', 'gtar jxf /file.bz2 -C/tmp/out'
222
+ it_behaves_like 'an extractor', 'tar.bz2', 'gtar jxf /file.tar.bz2 -C/tmp/out'
223
+ it_behaves_like 'an extractor', 'txz', 'gtar Jxf /file.txz -C/tmp/out'
224
+ it_behaves_like 'an extractor', 'tar.xz', 'gtar Jxf /file.tar.xz -C/tmp/out'
115
225
  end
116
226
  end
117
227
  end