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.
- checksums.yaml +7 -0
- data/.gitignore +140 -10
- data/CHANGELOG.md +181 -8
- data/README.md +63 -35
- data/Rakefile +1 -1
- data/docs/omnibus-build-cache.md b/data/docs/Build → Cache.md +0 -0
- data/docs/Building on Debian.md +59 -0
- data/docs/Building on OSX.md +61 -35
- data/docs/Building on RHEL.md +74 -0
- data/docs/Building on Windows.md +40 -81
- data/features/commands/build.feature +1 -2
- data/features/commands/clean.feature +1 -1
- data/lib/omnibus.rb +111 -204
- data/lib/omnibus/build_version.rb +3 -20
- data/lib/omnibus/build_version_dsl.rb +2 -3
- data/lib/omnibus/builder.rb +103 -211
- data/lib/omnibus/cleaner.rb +5 -7
- data/lib/omnibus/cli.rb +1 -4
- data/lib/omnibus/cli/base.rb +9 -16
- data/lib/omnibus/compressor.rb +60 -0
- data/{spec/data/complicated/config/software/version-manifest.rb → lib/omnibus/compressors/base.rb} +17 -12
- data/lib/omnibus/compressors/dmg.rb +312 -0
- data/lib/omnibus/{null_builder.rb → compressors/null.rb} +10 -4
- data/lib/omnibus/compressors/tgz.rb +141 -0
- data/lib/omnibus/config.rb +89 -83
- data/lib/omnibus/core_extensions.rb +1 -0
- data/lib/omnibus/core_extensions/open_uri.rb +58 -0
- data/lib/omnibus/digestable.rb +9 -3
- data/lib/omnibus/exceptions.rb +116 -175
- data/lib/omnibus/fetcher.rb +97 -138
- data/lib/omnibus/fetchers/git_fetcher.rb +130 -165
- data/lib/omnibus/fetchers/net_fetcher.rb +205 -164
- data/lib/omnibus/fetchers/{s3_cache_fetcher.rb → null_fetcher.rb} +27 -17
- data/lib/omnibus/fetchers/path_fetcher.rb +74 -32
- data/lib/omnibus/file_syncer.rb +149 -0
- data/lib/omnibus/generator.rb +103 -32
- data/lib/omnibus/generator_files/.kitchen.yml.erb +5 -1
- data/lib/omnibus/generator_files/Gemfile.erb +13 -7
- data/lib/omnibus/generator_files/config/projects/project.rb.erb +28 -0
- data/lib/omnibus/generator_files/config/software/zlib.rb.erb +55 -0
- data/lib/omnibus/generator_files/omnibus.rb.erb +5 -7
- data/lib/omnibus/git_cache.rb +11 -13
- data/lib/omnibus/logger.rb +76 -22
- data/lib/omnibus/logging.rb +1 -1
- data/lib/omnibus/metadata.rb +264 -0
- data/lib/omnibus/ohai.rb +0 -51
- data/lib/omnibus/package.rb +4 -228
- data/lib/omnibus/packager.rb +71 -0
- data/lib/omnibus/packagers/base.rb +118 -176
- data/lib/omnibus/packagers/bff.rb +136 -0
- data/lib/omnibus/packagers/deb.rb +389 -0
- data/lib/omnibus/packagers/makeself.rb +114 -0
- data/lib/omnibus/packagers/msi.rb +346 -0
- data/lib/omnibus/packagers/pkg.rb +278 -0
- data/lib/omnibus/packagers/rpm.rb +438 -0
- data/lib/omnibus/packagers/solaris.rb +110 -0
- data/lib/omnibus/project.rb +263 -666
- data/lib/omnibus/publisher.rb +3 -3
- data/lib/omnibus/s3_cache.rb +21 -30
- data/lib/omnibus/software.rb +132 -271
- data/lib/omnibus/templating.rb +66 -0
- data/lib/omnibus/thread_pool.rb +109 -0
- data/lib/omnibus/util.rb +137 -15
- data/lib/omnibus/version.rb +1 -1
- data/omnibus.gemspec +2 -2
- data/resources/bff/gen.template.erb +22 -0
- data/resources/bff/postinstall.sh +0 -0
- data/resources/bff/unpostinstall.sh +0 -0
- data/resources/deb/conffiles.erb +3 -0
- data/resources/deb/control.erb +25 -0
- data/resources/deb/md5sums.erb +3 -0
- data/{lib/omnibus/generator_files/mac_dmg → resources/dmg}/background.png +0 -0
- data/resources/dmg/create_dmg.osascript.erb +17 -0
- data/{lib/omnibus/generator_files/mac_dmg → resources/dmg}/icon.png +0 -0
- data/{bin → resources/makeself}/makeself-header.sh +0 -0
- data/{bin → resources/makeself}/makeself.sh +0 -0
- data/{lib/omnibus/generator_files/package_scripts/makeselfinst.erb → resources/makeself/post_extract.sh.erb} +4 -4
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/LICENSE.rtf +0 -0
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/banner_background.bmp +0 -0
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/dialog_background.bmp +0 -0
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/project.ico +0 -0
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/project_16x16.ico +0 -0
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/assets/project_32x32.ico +0 -0
- data/{spec/fixtures/sample/files/windows_msi/Resources/localization-en-us.wxl → resources/msi/localization-en-us.wxl.erb} +3 -4
- data/resources/msi/parameters.wxi.erb +9 -0
- data/{lib/omnibus/generator_files/windows_msi → resources/msi}/source.wxs.erb +14 -15
- data/{lib/omnibus/generator_files/mac_pkg → resources/pkg}/background.png +0 -0
- data/resources/pkg/distribution.xml.erb +21 -0
- data/resources/pkg/license.html.erb +3 -0
- data/resources/pkg/welcome.html.erb +7 -0
- data/resources/rpm/rpmmacros.erb +3 -0
- data/resources/rpm/signing.erb +40 -0
- data/resources/rpm/spec.erb +70 -0
- data/spec/functional/builder_spec.rb +90 -111
- data/spec/functional/fetchers/git_fetcher_spec.rb +130 -0
- data/spec/functional/fetchers/net_fetcher_spec.rb +110 -0
- data/spec/functional/fetchers/path_fetcher_spec.rb +97 -0
- data/spec/functional/file_syncer_spec.rb +206 -0
- data/spec/functional/templating_spec.rb +73 -0
- data/spec/spec_helper.rb +31 -94
- data/spec/support/env_helpers.rb +20 -0
- data/spec/support/examples.rb +56 -0
- data/spec/support/file_helpers.rb +46 -0
- data/spec/support/git_helpers.rb +107 -0
- data/spec/support/logging_helpers.rb +33 -0
- data/spec/support/matchers.rb +36 -0
- data/spec/support/ohai_helpers.rb +22 -0
- data/spec/support/path_helpers.rb +19 -0
- data/spec/support/shell_helpers.rb +14 -0
- data/spec/unit/build_version_dsl_spec.rb +0 -17
- data/spec/unit/build_version_spec.rb +1 -19
- data/spec/unit/builder_spec.rb +158 -46
- data/spec/unit/compressor_spec.rb +45 -0
- data/spec/unit/compressors/base_spec.rb +26 -0
- data/spec/unit/compressors/dmg_spec.rb +291 -0
- data/spec/unit/compressors/null_spec.rb +23 -0
- data/spec/unit/compressors/tgz_spec.rb +67 -0
- data/spec/unit/config_spec.rb +27 -34
- data/spec/unit/digestable_spec.rb +4 -4
- data/spec/unit/fetchers/git_fetcher_spec.rb +110 -39
- data/spec/unit/fetchers/net_fetcher_spec.rb +182 -72
- data/spec/unit/fetchers/path_fetcher_spec.rb +111 -0
- data/spec/unit/generator_spec.rb +137 -0
- data/spec/unit/git_cache_spec.rb +24 -34
- data/spec/unit/library_spec.rb +21 -82
- data/spec/unit/metadata_spec.rb +207 -0
- data/spec/unit/ohai_spec.rb +0 -7
- data/spec/unit/omnibus_spec.rb +41 -36
- data/spec/unit/package_spec.rb +1 -216
- data/spec/unit/packagers/base_spec.rb +76 -190
- data/spec/unit/packagers/bff_spec.rb +160 -0
- data/spec/unit/packagers/deb_spec.rb +324 -0
- data/spec/unit/packagers/makeself_spec.rb +80 -0
- data/spec/unit/packagers/msi_spec.rb +267 -0
- data/spec/unit/packagers/pkg_spec.rb +219 -0
- data/spec/unit/packagers/rpm_spec.rb +328 -0
- data/spec/unit/project_spec.rb +217 -80
- data/spec/unit/publisher_spec.rb +6 -2
- data/spec/unit/publishers/artifactory_publisher_spec.rb +1 -1
- data/spec/unit/publishers/s3_publisher_spec.rb +1 -1
- data/spec/unit/s3_cacher_spec.rb +22 -5
- data/spec/unit/software_spec.rb +89 -232
- data/spec/unit/util_spec.rb +188 -0
- metadata +159 -402
- data/features/commands/_deprecated.feature +0 -84
- data/lib/omnibus/cleanroom.rb +0 -141
- data/lib/omnibus/cli/deprecated.rb +0 -132
- data/lib/omnibus/generator_files/mac_pkg/license.html.erb +0 -1
- data/lib/omnibus/generator_files/mac_pkg/welcome.html.erb +0 -9
- data/lib/omnibus/generator_files/project.rb.erb +0 -20
- data/lib/omnibus/generator_files/software/c-example.rb.erb +0 -42
- data/lib/omnibus/generator_files/software/erlang-example.rb.erb +0 -38
- data/lib/omnibus/generator_files/software/ruby-example.rb.erb +0 -24
- data/lib/omnibus/generator_files/windows_msi/localization-en-us.wxl.erb +0 -20
- data/lib/omnibus/generator_files/windows_msi/parameters.wxi.erb +0 -9
- data/lib/omnibus/packagers/mac_dmg.rb +0 -235
- data/lib/omnibus/packagers/mac_pkg.rb +0 -176
- data/lib/omnibus/packagers/windows_msi.rb +0 -109
- data/spec/data/complicated/config/patches/bzip2/makefile_take_env_vars.patch +0 -15
- data/spec/data/complicated/config/patches/couchdb/patch_for_couchjs_stack.patch +0 -19
- data/spec/data/complicated/config/patches/gd/gd-2.0.33-configure-libpng.patch +0 -100
- data/spec/data/complicated/config/patches/keepalived/keepalived-1.2.9_opscode_centos_5.patch +0 -15
- data/spec/data/complicated/config/patches/libedit/freebsd-vi-fix.patch +0 -24
- data/spec/data/complicated/config/patches/libiconv/libiconv-1.14_srclib_stdio.in.h-remove-gets-declarations.patch +0 -29
- data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-makefile-dest-fix.patch +0 -35
- data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-malloc-fix.patch +0 -13
- data/spec/data/complicated/config/patches/libwrap/tcp_wrappers-7.6-shared_lib_plus_plus-1.patch +0 -1035
- data/spec/data/complicated/config/patches/logrotate/logrotate_basedir_override.patch +0 -12
- data/spec/data/complicated/config/patches/ncurses/ncurses-5.9-solaris-xopen_source_extended-detection.patch +0 -11
- data/spec/data/complicated/config/patches/ncurses/ncurses-clang.patch +0 -42
- data/spec/data/complicated/config/patches/ncurses/patch-aa +0 -23
- data/spec/data/complicated/config/patches/ncurses/patch-ab +0 -44
- data/spec/data/complicated/config/patches/ncurses/patch-ac +0 -40
- data/spec/data/complicated/config/patches/ncurses/patch-ad +0 -12
- data/spec/data/complicated/config/patches/ncurses/patch-aix-configure +0 -23
- data/spec/data/complicated/config/patches/ncurses/patch-cxx_cursesf.h +0 -22
- data/spec/data/complicated/config/patches/ncurses/patch-cxx_cursesm.h +0 -22
- data/spec/data/complicated/config/patches/nrpe/fix_for_runit.patch +0 -64
- data/spec/data/complicated/config/patches/openssl/openssl-1.0.1f-do-not-build-docs.patch +0 -101
- data/spec/data/complicated/config/patches/postgresql/postgresql-9.1.2-configure-ncurses-fix.patch +0 -12
- data/spec/data/complicated/config/patches/ruby/patch-configure +0 -103
- data/spec/data/complicated/config/patches/ruby/ruby-aix-configure.patch +0 -10
- data/spec/data/complicated/config/patches/ruby/ruby-openssl-1.0.1c.patch +0 -42
- data/spec/data/complicated/config/patches/ruby/ruby_aix_1_9_3_448_ssl_EAGAIN.patch +0 -57
- data/spec/data/complicated/config/patches/ruby/rvm-cflags.patch +0 -27
- data/spec/data/complicated/config/projects/angrychef.rb +0 -32
- data/spec/data/complicated/config/projects/chef-windows.rb +0 -32
- data/spec/data/complicated/config/projects/chef.rb +0 -32
- data/spec/data/complicated/config/projects/chefdk-windows.rb +0 -41
- data/spec/data/complicated/config/projects/chefdk.rb +0 -44
- data/spec/data/complicated/config/software/appbundler.rb +0 -25
- data/spec/data/complicated/config/software/autoconf.rb +0 -35
- data/spec/data/complicated/config/software/automake.rb +0 -39
- data/spec/data/complicated/config/software/berkshelf.rb +0 -44
- data/spec/data/complicated/config/software/bundler.rb +0 -25
- data/spec/data/complicated/config/software/bzip2.rb +0 -46
- data/spec/data/complicated/config/software/cacerts.rb +0 -44
- data/spec/data/complicated/config/software/chef-client-msi.rb +0 -87
- data/spec/data/complicated/config/software/chef-gem.rb +0 -26
- data/spec/data/complicated/config/software/chef-vault.rb +0 -43
- data/spec/data/complicated/config/software/chef-windows.rb +0 -158
- data/spec/data/complicated/config/software/chef.rb +0 -170
- data/spec/data/complicated/config/software/chefdk.rb +0 -103
- data/spec/data/complicated/config/software/couchdb.rb +0 -53
- data/spec/data/complicated/config/software/curl.rb +0 -48
- data/spec/data/complicated/config/software/erlang.rb +0 -65
- data/spec/data/complicated/config/software/expat.rb +0 -21
- data/spec/data/complicated/config/software/fcgi.rb +0 -56
- data/spec/data/complicated/config/software/fcgiwrap.rb +0 -41
- data/spec/data/complicated/config/software/gd.rb +0 -56
- data/spec/data/complicated/config/software/gdbm.rb +0 -40
- data/spec/data/complicated/config/software/gecode.rb +0 -48
- data/spec/data/complicated/config/software/git.rb +0 -40
- data/spec/data/complicated/config/software/help2man.rb +0 -30
- data/spec/data/complicated/config/software/icu.rb +0 -40
- data/spec/data/complicated/config/software/jre.rb +0 -48
- data/spec/data/complicated/config/software/keepalived.rb +0 -43
- data/spec/data/complicated/config/software/libarchive.rb +0 -50
- data/spec/data/complicated/config/software/libedit.rb +0 -69
- data/spec/data/complicated/config/software/libffi.rb +0 -71
- data/spec/data/complicated/config/software/libgcc.rb +0 -39
- data/spec/data/complicated/config/software/libiconv.rb +0 -55
- data/spec/data/complicated/config/software/libjpeg.rb +0 -39
- data/spec/data/complicated/config/software/libpng.rb +0 -38
- data/spec/data/complicated/config/software/libtool.rb +0 -52
- data/spec/data/complicated/config/software/libwrap.rb +0 -50
- data/spec/data/complicated/config/software/libxml2.rb +0 -51
- data/spec/data/complicated/config/software/libxslt.rb +0 -52
- data/spec/data/complicated/config/software/libyaml-windows.rb +0 -43
- data/spec/data/complicated/config/software/libyaml.rb +0 -62
- data/spec/data/complicated/config/software/logrotate.rb +0 -41
- data/spec/data/complicated/config/software/makedepend.rb +0 -73
- data/spec/data/complicated/config/software/mysql2.rb +0 -42
- data/spec/data/complicated/config/software/nagios-plugins.rb +0 -53
- data/spec/data/complicated/config/software/nagios.rb +0 -66
- data/spec/data/complicated/config/software/ncurses.rb +0 -149
- data/spec/data/complicated/config/software/nginx.rb +0 -40
- data/spec/data/complicated/config/software/nodejs.rb +0 -44
- data/spec/data/complicated/config/software/nokogiri.rb +0 -55
- data/spec/data/complicated/config/software/nrpe.rb +0 -61
- data/spec/data/complicated/config/software/ohai.rb +0 -64
- data/spec/data/complicated/config/software/omnibus-ctl.rb +0 -34
- data/spec/data/complicated/config/software/openresty.rb +0 -67
- data/spec/data/complicated/config/software/openssl.rb +0 -158
- data/spec/data/complicated/config/software/pcre.rb +0 -42
- data/spec/data/complicated/config/software/perl-extutils-embed.rb +0 -15
- data/spec/data/complicated/config/software/perl-extutils-makemaker.rb +0 -15
- data/spec/data/complicated/config/software/perl.rb +0 -48
- data/spec/data/complicated/config/software/perl_pg_driver.rb +0 -12
- data/spec/data/complicated/config/software/php.rb +0 -41
- data/spec/data/complicated/config/software/pip.rb +0 -30
- data/spec/data/complicated/config/software/pkg-config.rb +0 -66
- data/spec/data/complicated/config/software/popt.rb +0 -47
- data/spec/data/complicated/config/software/postgresql.rb +0 -51
- data/spec/data/complicated/config/software/preparation.rb +0 -30
- data/spec/data/complicated/config/software/pygments.rb +0 -25
- data/spec/data/complicated/config/software/python.rb +0 -49
- data/spec/data/complicated/config/software/rabbitmq.rb +0 -36
- data/spec/data/complicated/config/software/rebar.rb +0 -36
- data/spec/data/complicated/config/software/redis.rb +0 -33
- data/spec/data/complicated/config/software/rsync.rb +0 -48
- data/spec/data/complicated/config/software/ruby-windows-devkit.rb +0 -30
- data/spec/data/complicated/config/software/ruby-windows.rb +0 -30
- data/spec/data/complicated/config/software/ruby.rb +0 -162
- data/spec/data/complicated/config/software/rubygems-customization.rb +0 -57
- data/spec/data/complicated/config/software/rubygems.rb +0 -37
- data/spec/data/complicated/config/software/runit.rb +0 -118
- data/spec/data/complicated/config/software/server-jre.rb +0 -46
- data/spec/data/complicated/config/software/setuptools.rb +0 -30
- data/spec/data/complicated/config/software/spawn-fcgi.rb +0 -40
- data/spec/data/complicated/config/software/sphinx.rb +0 -26
- data/spec/data/complicated/config/software/spidermonkey.rb +0 -60
- data/spec/data/complicated/config/software/sqitch.rb +0 -24
- data/spec/data/complicated/config/software/test-kitchen.rb +0 -39
- data/spec/data/complicated/config/software/unicorn.rb +0 -27
- data/spec/data/complicated/config/software/util-macros.rb +0 -46
- data/spec/data/complicated/config/software/xproto.rb +0 -46
- data/spec/data/complicated/config/software/yajl.rb +0 -30
- data/spec/data/complicated/config/software/zlib.rb +0 -67
- data/spec/data/overrides/bad_line.overrides +0 -3
- data/spec/data/overrides/good.overrides +0 -5
- data/spec/data/overrides/with_dupes.overrides +0 -4
- data/spec/data/projects/chefdk.rb +0 -41
- data/spec/data/projects/sample.rb +0 -13
- data/spec/data/software/erchef.rb +0 -42
- data/spec/data/software/zlib.rb +0 -67
- data/spec/fixtures/sample/files/mac_dmg/Resources/background.png +0 -0
- data/spec/fixtures/sample/files/mac_dmg/Resources/icon.png +0 -0
- data/spec/fixtures/sample/files/mac_pkg/Resources/background.png +0 -0
- data/spec/fixtures/sample/files/mac_pkg/Resources/license.html +0 -1
- data/spec/fixtures/sample/files/mac_pkg/Resources/welcome.html +0 -9
- data/spec/fixtures/sample/files/windows_msi/Resources/assets/LICENSE.rtf +0 -8
- data/spec/fixtures/sample/files/windows_msi/Resources/assets/banner_background.bmp +0 -0
- data/spec/fixtures/sample/files/windows_msi/Resources/assets/dialog_background.bmp +0 -0
- data/spec/fixtures/sample/files/windows_msi/Resources/assets/project.ico +0 -0
- data/spec/fixtures/sample/files/windows_msi/Resources/assets/project_16x16.ico +0 -0
- data/spec/fixtures/sample/files/windows_msi/Resources/assets/project_32x32.ico +0 -0
- data/spec/fixtures/sample/files/windows_msi/Resources/parameters.wxi.erb +0 -9
- data/spec/fixtures/sample/files/windows_msi/Resources/source.wxs +0 -74
- data/spec/integration/packagers/mac_spec.rb +0 -58
- data/spec/integration/packagers/windows_spec.rb +0 -70
- data/spec/unit/packagers/mac_pkg_spec.rb +0 -151
@@ -1,5 +1,6 @@
|
|
1
1
|
driver:
|
2
2
|
name: vagrant
|
3
|
+
forward_agent: yes
|
3
4
|
customize:
|
4
5
|
cpus: 2
|
5
6
|
memory: 2048
|
@@ -7,9 +8,12 @@ driver:
|
|
7
8
|
- ['.', '/home/vagrant/<%= config[:name] %>']
|
8
9
|
|
9
10
|
provisioner:
|
10
|
-
|
11
|
+
name: chef_zero
|
12
|
+
require_chef_omnibus: 11.14.6
|
11
13
|
|
12
14
|
platforms:
|
15
|
+
- name: ubuntu-14.04
|
16
|
+
run_list: apt::default
|
13
17
|
- name: ubuntu-12.04
|
14
18
|
run_list: apt::default
|
15
19
|
- name: ubuntu-11.04
|
@@ -1,15 +1,21 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
#
|
4
|
-
gem 'berkshelf', '~> 3.0'
|
5
|
-
|
6
|
-
# Install omnibus software
|
3
|
+
# Install omnibus
|
7
4
|
gem 'omnibus', '~> <%= Omnibus::VERSION.split('.')[0...-1].join('.') %>'
|
8
5
|
|
9
6
|
# Use Chef's software definitions. It is recommended that you write your own
|
10
7
|
# software definitions, but you can clone/fork Chef's to get you started.
|
11
8
|
# gem 'omnibus-software', github: 'opscode/omnibus-software'
|
12
9
|
|
13
|
-
#
|
14
|
-
|
15
|
-
|
10
|
+
# This development group is installed by default when you run `bundle install`,
|
11
|
+
# but if you are using Omnibus in a CI-based infrastructure, you do not need
|
12
|
+
# the Test Kitchen-based build lab. You can skip these unnecessary dependencies
|
13
|
+
# by running `bundle install --without development` to speed up build times.
|
14
|
+
group :development do
|
15
|
+
# Use Berkshelf for resolving cookbook dependencies
|
16
|
+
gem 'berkshelf', '~> 3.0'
|
17
|
+
|
18
|
+
# Use Test Kitchen with Vagrant for converging the build environment
|
19
|
+
gem 'test-kitchen', '~> 1.2'
|
20
|
+
gem 'kitchen-vagrant', '~> 0.14'
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#
|
2
|
+
# Copyright <%= Time.now.year %> YOUR NAME
|
3
|
+
#
|
4
|
+
# All Rights Reserved.
|
5
|
+
#
|
6
|
+
|
7
|
+
name "<%= config[:name] %>"
|
8
|
+
maintainer "CHANGE ME"
|
9
|
+
homepage "https://CHANGE-ME.com"
|
10
|
+
|
11
|
+
# Defaults to C:/<%= config[:name] %> on Windows
|
12
|
+
# and /opt/<%= config[:name] %> on all other platforms
|
13
|
+
install_dir "#{default_root}/#{name}"
|
14
|
+
|
15
|
+
build_version Omnibus::BuildVersion.semver
|
16
|
+
build_iteration 1
|
17
|
+
|
18
|
+
# Creates required build directories
|
19
|
+
dependency "preparation"
|
20
|
+
|
21
|
+
# <%= config[:name] %> dependencies/components
|
22
|
+
# dependency "somedep"
|
23
|
+
|
24
|
+
# Version manifest file
|
25
|
+
dependency "version-manifest"
|
26
|
+
|
27
|
+
exclude "**/.git"
|
28
|
+
exclude "**/bundler/git"
|
@@ -0,0 +1,55 @@
|
|
1
|
+
#
|
2
|
+
# Copyright <%= Time.now.year %> YOUR NAME
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
# These options are required for all software definitions
|
18
|
+
name "<%= config[:name] %>-zlib"
|
19
|
+
default_version "1.2.6"
|
20
|
+
|
21
|
+
# A software can specify more than one version that is available for install
|
22
|
+
version("1.2.6") { source md5: "618e944d7c7cd6521551e30b32322f4a" }
|
23
|
+
version("1.2.8") { source md5: "44d667c142d7cda120332623eab69f40" }
|
24
|
+
|
25
|
+
# Sources may be URLs, git locations, or path locations
|
26
|
+
source url: "http://downloads.sourceforge.net/project/libpng/zlib/#{version}/zlib-#{version}.tar.gz"
|
27
|
+
|
28
|
+
# This is the path, inside the tarball, where the source resides
|
29
|
+
relative_path "zlib-#{version}"
|
30
|
+
|
31
|
+
build do
|
32
|
+
# Setup a default environment from Omnibus - you should use this Omnibus
|
33
|
+
# helper everywhere. It will become the default in the future.
|
34
|
+
env = with_standard_compiler_flags(with_embedded_path)
|
35
|
+
|
36
|
+
# Manipulate any configure flags you wish:
|
37
|
+
# For some reason zlib needs this flag on solaris
|
38
|
+
env["CFLAGS"] << " -DNO_VIZ" if solaris?
|
39
|
+
|
40
|
+
# "command" is part of the build DSL. There are a number of handy options
|
41
|
+
# available, such as "copy", "sync", "ruby", etc. For a complete list, please
|
42
|
+
# consult the Omnibus gem documentation.
|
43
|
+
#
|
44
|
+
# "install_dir" is exposed and refers to the top-level projects +install_dir+
|
45
|
+
command "./configure" \
|
46
|
+
" --prefix=#{install_dir}/embedded", env: env
|
47
|
+
|
48
|
+
# You can have multiple steps - they are executed in the order in which they
|
49
|
+
# are read.
|
50
|
+
#
|
51
|
+
# "workers" is a DSL method that returns the most suitable number of
|
52
|
+
# builders for the currently running system.
|
53
|
+
command "make -j #{workers}", env: env
|
54
|
+
command "make -j #{workers} install", env: env
|
55
|
+
end
|
@@ -9,9 +9,7 @@
|
|
9
9
|
# By default, Omnibus uses system folders (like +/var+ and +/opt+) to build and
|
10
10
|
# cache components. If you would to build everything internally, you can
|
11
11
|
# uncomment the following options. This will prevent the need for root
|
12
|
-
# permissions in most cases.
|
13
|
-
# project configuration to build at +./local/omnibus/build+ instead of
|
14
|
-
# +<%= config[:install_path] %>+
|
12
|
+
# permissions in most cases.
|
15
13
|
#
|
16
14
|
# Uncomment this line to change the default base directory to "local"
|
17
15
|
# -------------------------------------------------------------------
|
@@ -20,7 +18,7 @@
|
|
20
18
|
# Alternatively you can tune the individual values
|
21
19
|
# ------------------------------------------------
|
22
20
|
# cache_dir './local/omnibus/cache'
|
23
|
-
# git_cache_dir './local/omnibus/cache/
|
21
|
+
# git_cache_dir './local/omnibus/cache/git_cache'
|
24
22
|
# source_dir './local/omnibus/src'
|
25
23
|
# build_dir './local/omnibus/build'
|
26
24
|
# package_dir './local/omnibus/pkg'
|
@@ -33,9 +31,9 @@
|
|
33
31
|
# Enable S3 asset caching
|
34
32
|
# ------------------------------
|
35
33
|
# use_s3_caching true
|
36
|
-
# s3_access_key ENV['
|
37
|
-
# s3_secret_key ENV['
|
38
|
-
# s3_bucket ENV['
|
34
|
+
# s3_access_key ENV['AWS_ACCESS_KEY_ID']
|
35
|
+
# s3_secret_key ENV['AWS_SECRET_ACCESS_KEY']
|
36
|
+
# s3_bucket ENV['AWS_S3_BUCKET']
|
39
37
|
|
40
38
|
# Customize compiler bits
|
41
39
|
# ------------------------------
|
data/lib/omnibus/git_cache.rb
CHANGED
@@ -61,11 +61,9 @@ module Omnibus
|
|
61
61
|
#
|
62
62
|
def create_cache_path
|
63
63
|
if File.directory?(cache_path)
|
64
|
-
log.info(log_key) { "Cache path `#{cache_path}' exists, skipping creation" }
|
65
64
|
false
|
66
65
|
else
|
67
|
-
|
68
|
-
FileUtils.mkdir_p(File.dirname(cache_path))
|
66
|
+
create_directory(File.dirname(cache_path))
|
69
67
|
shellout!("git --git-dir=#{cache_path} init -q")
|
70
68
|
true
|
71
69
|
end
|
@@ -79,7 +77,7 @@ module Omnibus
|
|
79
77
|
def tag
|
80
78
|
return @tag if @tag
|
81
79
|
|
82
|
-
log.
|
80
|
+
log.internal(log_key) { "Calculating tag" }
|
83
81
|
|
84
82
|
# Accumulate an array of all the software projects that come before
|
85
83
|
# the name and version we are tagging. So if you have
|
@@ -95,7 +93,7 @@ module Omnibus
|
|
95
93
|
end
|
96
94
|
end
|
97
95
|
|
98
|
-
log.
|
96
|
+
log.internal(log_key) { "dep_list: #{dep_list.map(&:name).inspect}" }
|
99
97
|
|
100
98
|
# This is the list of all the unqiue shasums of all the software build
|
101
99
|
# dependencies, including the on currently being acted upon.
|
@@ -103,14 +101,14 @@ module Omnibus
|
|
103
101
|
suffix = Digest::SHA256.hexdigest(shasums.join('|'))
|
104
102
|
@tag = "#{software.name}-#{suffix}"
|
105
103
|
|
106
|
-
log.
|
104
|
+
log.internal(log_key) { "tag: #{@tag}" }
|
107
105
|
|
108
106
|
@tag
|
109
107
|
end
|
110
108
|
|
111
109
|
# Create an incremental install path cache for the software step
|
112
110
|
def incremental
|
113
|
-
log.
|
111
|
+
log.internal(log_key) { 'Performing incremental cache' }
|
114
112
|
|
115
113
|
create_cache_path
|
116
114
|
remove_git_dirs
|
@@ -119,7 +117,7 @@ module Omnibus
|
|
119
117
|
|
120
118
|
begin
|
121
119
|
shellout!(%Q(git --git-dir=#{cache_path} --work-tree=#{install_dir} commit -q -m "Backup of #{tag}"))
|
122
|
-
rescue
|
120
|
+
rescue CommandFailed => e
|
123
121
|
raise unless e.message.include?('nothing to commit')
|
124
122
|
end
|
125
123
|
|
@@ -127,7 +125,7 @@ module Omnibus
|
|
127
125
|
end
|
128
126
|
|
129
127
|
def restore
|
130
|
-
log.
|
128
|
+
log.internal(log_key) { 'Performing cache restoration' }
|
131
129
|
|
132
130
|
create_cache_path
|
133
131
|
|
@@ -139,11 +137,11 @@ module Omnibus
|
|
139
137
|
end
|
140
138
|
|
141
139
|
if restore_me
|
142
|
-
log.
|
140
|
+
log.internal(log_key) { "Detected tag `#{tag}' can be restored, restoring" }
|
143
141
|
shellout!(%Q(git --git-dir=#{cache_path} --work-tree=#{install_dir} checkout -f "#{tag}"))
|
144
142
|
true
|
145
143
|
else
|
146
|
-
log.
|
144
|
+
log.internal(log_key) { "Could not find tag `#{tag}', skipping restore" }
|
147
145
|
false
|
148
146
|
end
|
149
147
|
end
|
@@ -155,14 +153,14 @@ module Omnibus
|
|
155
153
|
#
|
156
154
|
# @return [true]
|
157
155
|
def remove_git_dirs
|
158
|
-
log.
|
156
|
+
log.internal(log_key) { "Removing git directories" }
|
159
157
|
|
160
158
|
Dir.glob("#{install_dir}/**/{,.*}/config").reject do |path|
|
161
159
|
REQUIRED_GIT_FILES.any? do |required_file|
|
162
160
|
!File.exist?(File.join(File.dirname(path), required_file))
|
163
161
|
end
|
164
162
|
end.each do |path|
|
165
|
-
log.
|
163
|
+
log.internal(log_key) { "Removing git dir `#{path}'" }
|
166
164
|
FileUtils.rm_rf(File.dirname(path))
|
167
165
|
end
|
168
166
|
|
data/lib/omnibus/logger.rb
CHANGED
@@ -14,10 +14,8 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
#
|
16
16
|
|
17
|
-
require 'logger'
|
18
|
-
|
19
17
|
module Omnibus
|
20
|
-
class Logger
|
18
|
+
class Logger
|
21
19
|
#
|
22
20
|
# The amount of padding on the left column.
|
23
21
|
#
|
@@ -25,20 +23,51 @@ module Omnibus
|
|
25
23
|
#
|
26
24
|
LEFT = 40
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
#
|
27
|
+
# Our custom log levels, in order of severity
|
28
|
+
#
|
29
|
+
# @return [Array]
|
30
|
+
#
|
31
|
+
LEVELS = %w(UNKNOWN INTERNAL DEBUG INFO WARN ERROR FATAL NOTHING).freeze
|
32
|
+
|
33
|
+
#
|
34
|
+
# The mutex lock for synchronizing IO writing.
|
35
|
+
#
|
36
|
+
# @return [Mutex]
|
37
|
+
#
|
38
|
+
MUTEX = Mutex.new
|
39
|
+
|
40
|
+
attr_reader :io
|
41
|
+
attr_reader :level
|
42
|
+
|
43
|
+
#
|
44
|
+
# Create a new logger object.
|
45
|
+
#
|
46
|
+
# @param [IO] io
|
47
|
+
# the IO object to read/write
|
48
|
+
#
|
49
|
+
def initialize(io = $stdout)
|
50
|
+
@io = io
|
51
|
+
@level = LEVELS.index('WARN')
|
52
|
+
end
|
53
|
+
|
54
|
+
LEVELS.each.with_index do |level, index|
|
55
|
+
class_eval <<-EOH, __FILE__, __LINE__
|
56
|
+
def #{level.downcase}(progname, &block)
|
57
|
+
add(#{index}, progname, &block)
|
58
|
+
end
|
59
|
+
EOH
|
31
60
|
end
|
32
61
|
|
33
62
|
#
|
34
|
-
# Print a deprecation warning.
|
63
|
+
# Print a deprecation warning. This actually outputs to +WARN+, but is
|
64
|
+
# prefixed with the string "DEPRECATED" first.
|
35
65
|
#
|
36
66
|
# @see (Logger#add)
|
37
67
|
#
|
38
|
-
def deprecated(progname
|
39
|
-
|
40
|
-
|
41
|
-
end
|
68
|
+
def deprecated(progname, &block)
|
69
|
+
meta = Proc.new { "DEPRECATED: #{block.call}" }
|
70
|
+
add(LEVELS.index('WARN'), progname, &meta)
|
42
71
|
end
|
43
72
|
|
44
73
|
#
|
@@ -50,9 +79,7 @@ module Omnibus
|
|
50
79
|
# @param [Symbol] level
|
51
80
|
#
|
52
81
|
def level=(level)
|
53
|
-
@level =
|
54
|
-
rescue NameError
|
55
|
-
raise "'#{level.inspect}' does not appear to be a valid log level!"
|
82
|
+
@level = LEVELS.index(level.to_s.upcase) || -1
|
56
83
|
end
|
57
84
|
|
58
85
|
#
|
@@ -67,6 +94,16 @@ module Omnibus
|
|
67
94
|
@live_streams[level.to_sym] ||= LiveStream.new(self, level)
|
68
95
|
end
|
69
96
|
|
97
|
+
#
|
98
|
+
# Add a message to the logger with the given severity and progname.
|
99
|
+
#
|
100
|
+
def add(severity, progname, &block)
|
101
|
+
return true if io.nil? || severity < level
|
102
|
+
message = format_message(severity, progname, yield)
|
103
|
+
MUTEX.synchronize { io.write(message) }
|
104
|
+
true
|
105
|
+
end
|
106
|
+
|
70
107
|
#
|
71
108
|
# The string representation of this object.
|
72
109
|
#
|
@@ -87,14 +124,31 @@ module Omnibus
|
|
87
124
|
|
88
125
|
private
|
89
126
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
127
|
+
#
|
128
|
+
# Format the log message.
|
129
|
+
#
|
130
|
+
# @return [String]
|
131
|
+
#
|
132
|
+
def format_message(severity, progname, message)
|
133
|
+
if progname
|
134
|
+
left = "[#{progname}] #{format_severity(severity)} | "
|
135
|
+
else
|
136
|
+
left = "#{format_severity(severity)} | "
|
137
|
+
end
|
138
|
+
"#{left.rjust(LEFT)}#{message}\n"
|
139
|
+
end
|
96
140
|
|
97
|
-
|
141
|
+
#
|
142
|
+
# Format the log severity.
|
143
|
+
#
|
144
|
+
# @return [String]
|
145
|
+
#
|
146
|
+
def format_severity(severity)
|
147
|
+
if severity == 0
|
148
|
+
'_'
|
149
|
+
else
|
150
|
+
(LEVELS[severity] || '?')[0]
|
151
|
+
end
|
98
152
|
end
|
99
153
|
|
100
154
|
#
|
@@ -172,7 +226,7 @@ module Omnibus
|
|
172
226
|
# @param [String] data
|
173
227
|
#
|
174
228
|
def log_line(data)
|
175
|
-
@log.public_send(@level) { data }
|
229
|
+
@log.public_send(@level, nil) { data }
|
176
230
|
end
|
177
231
|
end
|
178
232
|
end
|
data/lib/omnibus/logging.rb
CHANGED
@@ -0,0 +1,264 @@
|
|
1
|
+
#
|
2
|
+
# Copyright 2014 Chef Software, Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'json'
|
18
|
+
|
19
|
+
module Omnibus
|
20
|
+
class Metadata
|
21
|
+
class << self
|
22
|
+
#
|
23
|
+
# Render the metadata for the package at the given path, generated by the
|
24
|
+
# given project.
|
25
|
+
#
|
26
|
+
# @raise [NoPackageFile]
|
27
|
+
# if the given +path+ does not contain a package
|
28
|
+
#
|
29
|
+
# @param [String] path
|
30
|
+
# the path to the package (or compressed object) on disk
|
31
|
+
# @param [Project] project
|
32
|
+
# the project which generated the given package or compressed object
|
33
|
+
#
|
34
|
+
# @return [String]
|
35
|
+
# the path to the metadata on disk
|
36
|
+
#
|
37
|
+
def generate(path, project)
|
38
|
+
unless File.exist?(path)
|
39
|
+
raise NoPackageFile.new(path)
|
40
|
+
end
|
41
|
+
|
42
|
+
package = Package.new(path)
|
43
|
+
|
44
|
+
data = {
|
45
|
+
# Package
|
46
|
+
basename: package.name,
|
47
|
+
md5: package.md5,
|
48
|
+
sha1: package.sha1,
|
49
|
+
sha256: package.sha256,
|
50
|
+
sha512: package.sha512,
|
51
|
+
platform: platform_shortname,
|
52
|
+
platform_version: platform_version,
|
53
|
+
arch: arch,
|
54
|
+
|
55
|
+
# Project
|
56
|
+
name: project.name,
|
57
|
+
friendly_name: project.friendly_name,
|
58
|
+
homepage: project.homepage,
|
59
|
+
version: project.build_version,
|
60
|
+
iteration: project.build_iteration,
|
61
|
+
}
|
62
|
+
|
63
|
+
instance = new(package, data)
|
64
|
+
instance.save
|
65
|
+
instance.path
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Load the metadata from disk.
|
70
|
+
#
|
71
|
+
# @param [Package] package
|
72
|
+
# the package for this metadata
|
73
|
+
#
|
74
|
+
# @return [Metadata]
|
75
|
+
#
|
76
|
+
def for_package(package)
|
77
|
+
data = File.read(path_for(package))
|
78
|
+
hash = JSON.parse(data, symbolize_names: true)
|
79
|
+
|
80
|
+
# Ensure Platform version has been truncated
|
81
|
+
if hash[:platform_version] && hash[:platform]
|
82
|
+
hash[:platform_version] = truncate_platform_version(hash[:platform_version], hash[:platform])
|
83
|
+
end
|
84
|
+
|
85
|
+
# Ensure an interation exists
|
86
|
+
hash[:iteration] ||= 1
|
87
|
+
|
88
|
+
new(package, hash)
|
89
|
+
rescue Errno::ENOENT
|
90
|
+
raise NoPackageMetadataFile.new(package.path)
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# The metadata path that corresponds to the package.
|
95
|
+
#
|
96
|
+
# @param [Package] package
|
97
|
+
# the package for this metadata
|
98
|
+
#
|
99
|
+
# @return [String]
|
100
|
+
#
|
101
|
+
def path_for(package)
|
102
|
+
"#{package.path}.metadata.json"
|
103
|
+
end
|
104
|
+
|
105
|
+
#
|
106
|
+
# The architecture for this machine, as reported from Ohai.
|
107
|
+
#
|
108
|
+
# @return [String]
|
109
|
+
#
|
110
|
+
def arch
|
111
|
+
Ohai['kernel']['machine']
|
112
|
+
end
|
113
|
+
|
114
|
+
#
|
115
|
+
# Platform version to be used in package metadata.
|
116
|
+
#
|
117
|
+
# @return [String]
|
118
|
+
# the platform version
|
119
|
+
#
|
120
|
+
def platform_version
|
121
|
+
truncate_platform_version(Ohai['platform_version'], platform_shortname)
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# Platform name to be used when creating metadata for the artifact.
|
126
|
+
# rhel/centos become "el", all others are just platform
|
127
|
+
#
|
128
|
+
# @return [String]
|
129
|
+
# the platform family short name
|
130
|
+
#
|
131
|
+
def platform_shortname
|
132
|
+
if Ohai['platform_family'] == 'rhel'
|
133
|
+
'el'
|
134
|
+
else
|
135
|
+
Ohai['platform']
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
private
|
140
|
+
|
141
|
+
#
|
142
|
+
# On certain platforms we don't care about the full MAJOR.MINOR.PATCH platform
|
143
|
+
# version. This method will properly truncate the version down to a more human
|
144
|
+
# friendly version. This version can also be thought of as a 'marketing'
|
145
|
+
# version.
|
146
|
+
#
|
147
|
+
# @param [String] platform_version
|
148
|
+
# the platform version to truncate
|
149
|
+
# @param [String] platform
|
150
|
+
# the platform shortname. this might be an Ohai-returned platform or
|
151
|
+
# platform family but it also might be a shortname like `el`
|
152
|
+
#
|
153
|
+
def truncate_platform_version(platform_version, platform)
|
154
|
+
case platform
|
155
|
+
when 'centos', 'debian', 'el', 'fedora', 'freebsd', 'rhel', 'sles'
|
156
|
+
# Only want MAJOR (e.g. Debian 7)
|
157
|
+
platform_version.split('.').first
|
158
|
+
when 'aix', 'arch', 'gentoo', 'mac_os_x', 'openbsd', 'slackware', 'solaris2', 'suse', 'ubuntu'
|
159
|
+
# Only want MAJOR.MINOR (e.g. Mac OS X 10.9, Ubuntu 12.04)
|
160
|
+
platform_version.split('.')[0..1].join('.')
|
161
|
+
when 'omnios', 'smartos'
|
162
|
+
# Only want MAJOR (e.g OmniOS r151006, SmartOS 20120809T221258Z)
|
163
|
+
platform_version.split('.').first
|
164
|
+
when 'windows'
|
165
|
+
# Windows has this really awesome "feature", where their version numbers
|
166
|
+
# internally do not match the "marketing" name.
|
167
|
+
#
|
168
|
+
# Definitively computing the Windows marketing name actually takes more
|
169
|
+
# than the platform version. Take a look at the following file for the
|
170
|
+
# details:
|
171
|
+
#
|
172
|
+
# https://github.com/opscode/chef/blob/master/lib/chef/win32/version.rb
|
173
|
+
#
|
174
|
+
# As we don't need to be exact here the simple mapping below is based on:
|
175
|
+
#
|
176
|
+
# http://www.jrsoftware.org/ishelp/index.php?topic=winvernotes
|
177
|
+
#
|
178
|
+
case platform_version
|
179
|
+
when '5.0.2195', '2000' then '2000'
|
180
|
+
when '5.1.2600', 'xp' then 'xp'
|
181
|
+
when '5.2.3790', '2003r2' then '2003r2'
|
182
|
+
when '6.0.6001', '2008' then '2008'
|
183
|
+
when '6.1.7600', '7' then '7'
|
184
|
+
when '6.1.7601', '2008r2' then '2008r2'
|
185
|
+
when '6.2.9200', '8' then '8'
|
186
|
+
# The following `when` will never match since Windows 2012's platform
|
187
|
+
# version is the same as Windows 8. It's only here for completeness and
|
188
|
+
# documentation.
|
189
|
+
when '6.2.9200', '2012' then '2012'
|
190
|
+
when /6\.3\.\d+/, '8.1' then '8.1'
|
191
|
+
# The following `when` will never match since Windows 2012R2's platform
|
192
|
+
# version is the same as Windows 8.1. It's only here for completeness
|
193
|
+
# and documentation.
|
194
|
+
when /6\.3\.\d+/, '2012r2' then '2012r2'
|
195
|
+
else
|
196
|
+
raise UnknownPlatformVersion.new(platform, platform_version)
|
197
|
+
end
|
198
|
+
else
|
199
|
+
raise UnknownPlatform.new(platform)
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# Create a new metadata object for the given package and hash data.
|
206
|
+
#
|
207
|
+
# @param [Package] package
|
208
|
+
# the package for this metadata
|
209
|
+
# @param [Hash] data
|
210
|
+
# the hash of attributes to set in the metadata
|
211
|
+
#
|
212
|
+
def initialize(package, data = {})
|
213
|
+
@package = package
|
214
|
+
@data = data.dup.freeze
|
215
|
+
end
|
216
|
+
|
217
|
+
#
|
218
|
+
# Helper for accessing the information inside the metadata hash.
|
219
|
+
#
|
220
|
+
# @return [Object]
|
221
|
+
#
|
222
|
+
def [](key)
|
223
|
+
@data[key]
|
224
|
+
end
|
225
|
+
|
226
|
+
#
|
227
|
+
# The name of this metadata file.
|
228
|
+
#
|
229
|
+
# @return [String]
|
230
|
+
#
|
231
|
+
def name
|
232
|
+
@name ||= File.basename(path)
|
233
|
+
end
|
234
|
+
|
235
|
+
#
|
236
|
+
# @see (Metadata.path_for)
|
237
|
+
#
|
238
|
+
def path
|
239
|
+
@path ||= self.class.path_for(@package)
|
240
|
+
end
|
241
|
+
|
242
|
+
#
|
243
|
+
# Save the file to disk.
|
244
|
+
#
|
245
|
+
# @return [true]
|
246
|
+
#
|
247
|
+
def save
|
248
|
+
File.open(path, 'w+') do |f|
|
249
|
+
f.write(to_json)
|
250
|
+
end
|
251
|
+
|
252
|
+
true
|
253
|
+
end
|
254
|
+
|
255
|
+
#
|
256
|
+
# The JSON representation of this metadata.
|
257
|
+
#
|
258
|
+
# @return [String]
|
259
|
+
#
|
260
|
+
def to_json
|
261
|
+
JSON.pretty_generate(@data)
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|