packaging 0.88.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +17 -0
  3. data/README-Solaris.md +117 -0
  4. data/README.md +977 -0
  5. data/lib/packaging.rb +32 -0
  6. data/lib/packaging/archive.rb +126 -0
  7. data/lib/packaging/artifactory.rb +651 -0
  8. data/lib/packaging/artifactory/extensions.rb +94 -0
  9. data/lib/packaging/config.rb +492 -0
  10. data/lib/packaging/config/params.rb +387 -0
  11. data/lib/packaging/config/validations.rb +13 -0
  12. data/lib/packaging/deb.rb +28 -0
  13. data/lib/packaging/deb/repo.rb +264 -0
  14. data/lib/packaging/gem.rb +70 -0
  15. data/lib/packaging/metrics.rb +15 -0
  16. data/lib/packaging/nuget.rb +39 -0
  17. data/lib/packaging/paths.rb +376 -0
  18. data/lib/packaging/platforms.rb +507 -0
  19. data/lib/packaging/repo.rb +155 -0
  20. data/lib/packaging/retrieve.rb +75 -0
  21. data/lib/packaging/rpm.rb +5 -0
  22. data/lib/packaging/rpm/repo.rb +254 -0
  23. data/lib/packaging/sign.rb +8 -0
  24. data/lib/packaging/sign/deb.rb +9 -0
  25. data/lib/packaging/sign/dmg.rb +41 -0
  26. data/lib/packaging/sign/ips.rb +57 -0
  27. data/lib/packaging/sign/msi.rb +124 -0
  28. data/lib/packaging/sign/rpm.rb +115 -0
  29. data/lib/packaging/tar.rb +163 -0
  30. data/lib/packaging/util.rb +146 -0
  31. data/lib/packaging/util/date.rb +20 -0
  32. data/lib/packaging/util/execution.rb +85 -0
  33. data/lib/packaging/util/file.rb +125 -0
  34. data/lib/packaging/util/git.rb +174 -0
  35. data/lib/packaging/util/git_tags.rb +73 -0
  36. data/lib/packaging/util/gpg.rb +66 -0
  37. data/lib/packaging/util/jenkins.rb +95 -0
  38. data/lib/packaging/util/misc.rb +69 -0
  39. data/lib/packaging/util/net.rb +410 -0
  40. data/lib/packaging/util/os.rb +17 -0
  41. data/lib/packaging/util/platform.rb +40 -0
  42. data/lib/packaging/util/rake_utils.rb +112 -0
  43. data/lib/packaging/util/serialization.rb +19 -0
  44. data/lib/packaging/util/ship.rb +300 -0
  45. data/lib/packaging/util/tool.rb +41 -0
  46. data/lib/packaging/util/version.rb +334 -0
  47. data/spec/fixtures/config/ext/build_defaults.yaml +2 -0
  48. data/spec/fixtures/config/ext/project_data.yaml +2 -0
  49. data/spec/fixtures/configs/components/test_file.json +1 -0
  50. data/spec/fixtures/configs/components/test_file_2.json +0 -0
  51. data/spec/fixtures/configs/components/test_file_not_tagged.json +1 -0
  52. data/spec/fixtures/configs/components/test_file_wrong_ext.txt +0 -0
  53. data/spec/fixtures/configs/components/test_file_wrong_ext.wrong +0 -0
  54. data/spec/fixtures/util/pre_tasks.yaml +4 -0
  55. data/spec/lib/packaging/artifactory_spec.rb +221 -0
  56. data/spec/lib/packaging/config_spec.rb +576 -0
  57. data/spec/lib/packaging/deb/repo_spec.rb +157 -0
  58. data/spec/lib/packaging/deb_spec.rb +52 -0
  59. data/spec/lib/packaging/gem_spec.rb +86 -0
  60. data/spec/lib/packaging/paths_spec.rb +418 -0
  61. data/spec/lib/packaging/platforms_spec.rb +178 -0
  62. data/spec/lib/packaging/repo_spec.rb +135 -0
  63. data/spec/lib/packaging/retrieve_spec.rb +100 -0
  64. data/spec/lib/packaging/rpm/repo_spec.rb +133 -0
  65. data/spec/lib/packaging/sign_spec.rb +133 -0
  66. data/spec/lib/packaging/tar_spec.rb +116 -0
  67. data/spec/lib/packaging/util/execution_spec.rb +56 -0
  68. data/spec/lib/packaging/util/file_spec.rb +139 -0
  69. data/spec/lib/packaging/util/git_spec.rb +160 -0
  70. data/spec/lib/packaging/util/git_tag_spec.rb +36 -0
  71. data/spec/lib/packaging/util/gpg_spec.rb +64 -0
  72. data/spec/lib/packaging/util/jenkins_spec.rb +112 -0
  73. data/spec/lib/packaging/util/misc_spec.rb +31 -0
  74. data/spec/lib/packaging/util/net_spec.rb +259 -0
  75. data/spec/lib/packaging/util/os_spec.rb +31 -0
  76. data/spec/lib/packaging/util/rake_utils_spec.rb +70 -0
  77. data/spec/lib/packaging/util/ship_spec.rb +199 -0
  78. data/spec/lib/packaging/util/version_spec.rb +123 -0
  79. data/spec/lib/packaging_spec.rb +19 -0
  80. data/spec/spec_helper.rb +22 -0
  81. data/static_artifacts/PackageInfo.plist +3 -0
  82. data/tasks/00_utils.rake +214 -0
  83. data/tasks/30_metrics.rake +33 -0
  84. data/tasks/apple.rake +268 -0
  85. data/tasks/archive.rake +69 -0
  86. data/tasks/build.rake +12 -0
  87. data/tasks/clean.rake +5 -0
  88. data/tasks/config.rake +35 -0
  89. data/tasks/deb.rake +129 -0
  90. data/tasks/deb_repos.rake +28 -0
  91. data/tasks/deprecated.rake +130 -0
  92. data/tasks/doc.rake +20 -0
  93. data/tasks/education.rake +57 -0
  94. data/tasks/fetch.rake +60 -0
  95. data/tasks/gem.rake +159 -0
  96. data/tasks/jenkins.rake +538 -0
  97. data/tasks/jenkins_dynamic.rake +202 -0
  98. data/tasks/load_extras.rake +21 -0
  99. data/tasks/mock.rake +348 -0
  100. data/tasks/nightly_repos.rake +286 -0
  101. data/tasks/pe_deb.rake +12 -0
  102. data/tasks/pe_rpm.rake +13 -0
  103. data/tasks/pe_ship.rake +226 -0
  104. data/tasks/pe_sign.rake +13 -0
  105. data/tasks/pe_tar.rake +5 -0
  106. data/tasks/retrieve.rake +52 -0
  107. data/tasks/rpm.rake +66 -0
  108. data/tasks/rpm_repos.rake +29 -0
  109. data/tasks/ship.rake +692 -0
  110. data/tasks/sign.rake +154 -0
  111. data/tasks/tag.rake +8 -0
  112. data/tasks/tar.rake +28 -0
  113. data/tasks/update.rake +16 -0
  114. data/tasks/vanagon.rake +35 -0
  115. data/tasks/vendor_gems.rake +117 -0
  116. data/tasks/version.rake +33 -0
  117. data/tasks/z_data_dump.rake +65 -0
  118. data/templates/README +1 -0
  119. data/templates/downstream.xml.erb +47 -0
  120. data/templates/msi.xml.erb +197 -0
  121. data/templates/packaging.xml.erb +346 -0
  122. data/templates/repo.xml.erb +117 -0
  123. metadata +287 -0
@@ -0,0 +1,3 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <pkg-info followSymLinks="true" minimumSystemVersion="10.6" auth="root"/>
3
+
@@ -0,0 +1,214 @@
1
+ #######################################################################
2
+ # #
3
+ # #
4
+ # #
5
+ # #
6
+ # #
7
+ # #
8
+ # ! DO NOT ADD TO THIS FILE ! #
9
+ # #
10
+ # Usage of this file to store utilities is deprecated. Any new #
11
+ # utilities should be added to new or existing classes in #
12
+ # lib/packaging/util. Any modified utilities should be migrated #
13
+ # to new or existing classes in lib/packaging/util as well. #
14
+ # #
15
+ # #
16
+ # #
17
+ # #
18
+ # #
19
+ # #
20
+ #######################################################################
21
+
22
+
23
+
24
+
25
+
26
+ # Utility methods used by the various rake tasks
27
+
28
+ #######################################################################
29
+ # #
30
+ # DEPRECATED METHODS: Please move any newly depreacted #
31
+ # methods into the following section so that we can easily #
32
+ # see what methods are left to librarify. #
33
+ # #
34
+ #######################################################################
35
+
36
+ def invoke_task(task, *args)
37
+ Pkg::Util.deprecate('invoke_task', 'Pkg::Util::RakeUtils.invoke_task')
38
+ Pkg::Util::RakeUtils.invoke_task(task, *args)
39
+ end
40
+
41
+ def rsync_to(*args)
42
+ Pkg::Util.deprecate('rsync_to', 'Pkg::Util::Net.rsync_to')
43
+ Pkg::Util::Net.rsync_to(args[0], args[1], args[2])
44
+ end
45
+
46
+ def rsync_from(*args)
47
+ Pkg::Util.deprecate('rsync_from', 'Pkg::Util::Net.rsync_from')
48
+ Pkg::Util::Net.rsync_from(args[0], args[1], args[2])
49
+ end
50
+
51
+ def mkdir_pr(*args)
52
+ Pkg::Util.deprecate('mkdir_pr', 'FileUtils.mkdir_p')
53
+ FileUtils.mkdir_p args
54
+ end
55
+
56
+ def ln(target, name)
57
+ Pkg::Util.deprecate('ln', 'FileUtils.ln')
58
+ FileUtils.ln(name, target, :force => true, :verbose => true)
59
+ end
60
+
61
+ def ln_sfT(src, dest)
62
+ Pkg::Util.deprecate('ln_sfT')
63
+ sh "ln -sfT #{src} #{dest}"
64
+ end
65
+
66
+ def git_commit_file(file, message = nil)
67
+ Pkg::Util.deprecate('git_commit_file', 'Pkg::Util::Git.git_commit_file')
68
+ Pkg::Util::Git.git_commit_file(file, message)
69
+ end
70
+
71
+ def git_bundle(treeish, appendix = nil, output_dir = nil)
72
+ Pkg::Util.deprecate('git_bundle', 'Pkg::Util::Git.git_bundle')
73
+ Pkg::Util::Git.git_bundle(treeish, appendix, output_dir)
74
+ end
75
+
76
+ def git_tag(version)
77
+ Pkg::Util.deprecate('git_tag', 'Pkg::Util::Git.git_tag')
78
+ Pkg::Util::Git.git_tag(version)
79
+ end
80
+
81
+ def git_pull(remote, branch)
82
+ Pkg::Util.deprecate('git_pull', 'Pkg::Util::Git.git_pull')
83
+ Pkg::Util::Git.git_pull(remote, branch)
84
+ end
85
+
86
+ def curl_form_data(uri, form_data = [], options = {})
87
+ Pkg::Util.deprecate("curl_form_data", "Pkg::Util::Net.curl_form_data")
88
+ Pkg::Util::Net.curl_form_data(uri, form_data, options)
89
+ end
90
+
91
+ def create_jenkins_job(name, xml_file)
92
+ Pkg::Util.deprecate("create_jenkins_job", "Pkg::Util::Jenkins.create_jenkins_job")
93
+ Pkg::Util::Jenkins.create_jenkins_job(name, xml_file)
94
+ end
95
+
96
+ def jenkins_job_exists?(name)
97
+ Pkg::Util.deprecate("jenkins_job_exists", "Pkg::Util::Jenkins.jenkins_job_exists?")
98
+ Pkg::Util::Jenkins.jenkins_job_exists?(name)
99
+ end
100
+
101
+ def print_url_info(url_string)
102
+ Pkg::Util.deprecate("print_url_info", "Pkg::Util::Net.print_url_info")
103
+ Pkg::Util::Net.print_url_info(url_string)
104
+ end
105
+
106
+ def retry_on_fail(args, &block)
107
+ Pkg::Util.deprecate("retry_on_fail", "Pkg::Util::Execution.retry_on_fail")
108
+ Pkg::Util::Execution.retry_on_fail(args, &block)
109
+ end
110
+
111
+ # ex combines the behavior of `%x{cmd}` and rake's `sh "cmd"`. `%x{cmd}` has
112
+ # the benefit of returning the standard out of an executed command, enabling us
113
+ # to query the file system, e.g. `contents = %x{ls}`. The drawback to `%x{cmd}`
114
+ # is that on failure of a command (something returned non-zero) the return of
115
+ # `%x{cmd}` is just an empty string. As such, we can't know if we succeeded.
116
+ # Rake's `sh "cmd"`, on the other hand, will raise a RuntimeError if a command
117
+ # does not return 0, but doesn't return any of the stdout from the command -
118
+ # only true or false depending on its success or failure. With `ex(cmd)` we
119
+ # purport to both return the results of the command execution (ala `%x{cmd}`)
120
+ # while also raising an exception if a command does not succeed (ala `sh "cmd"`).
121
+ def ex(command)
122
+ # We haven't done anything about this deprecation and our log files
123
+ # have too many warnings from this.
124
+ # Turn off the notice for now until packaging is refactored.
125
+ # Pkg::Util.deprecate("ex", "Pkg::Util::Execution.ex")
126
+ Pkg::Util::Execution.ex(command)
127
+ end
128
+
129
+ def load_keychain
130
+ Pkg::Util.deprecate("load_keychain", "Pkg::Util::Gpg.load_keychain")
131
+ Pkg::Util::Gpg.load_keychain
132
+ end
133
+
134
+ def kill_keychain
135
+ Pkg::Util.deprecate("kill_keychain", "Pkg::Util::Gpg.kill_keychain")
136
+ Pkg::Util::Gpg.kill_keychain
137
+ end
138
+
139
+ def start_keychain
140
+ Pkg::Util.deprecate("start_keychain", "Pkg::Util::Gpg.start_keychain")
141
+ Pkg::Util::Gpg.start_keychain
142
+ end
143
+
144
+ def gpg_sign_file(file)
145
+ Pkg::Util.deprecate("gpg_sign_file", "Pkg::Util::Gpg.sign_file")
146
+ Pkg::Util::Gpg.sign_file(file)
147
+ end
148
+
149
+ def check_var(varname, var)
150
+ Pkg::Util.deprecate('check_var', 'Pkg::Util.check_var')
151
+ Pkg::Util.check_var(varname, var)
152
+ end
153
+
154
+ def rand_string
155
+ Pkg::Util.deprecate('invoke_task', 'Pkg::Util.rand_string')
156
+ Pkg::Util.rand_string
157
+ end
158
+
159
+ def escape_html(uri)
160
+ Pkg::Util.deprecate('escape_html', 'Pkg::Util::Net.escape_html')
161
+ Pkg::Util::Net.escape_html(uri)
162
+ end
163
+
164
+ def add_param_to_uri(uri, param)
165
+ Pkg::Util.deprecate('add_param_to_uri', 'Pkg::Util::Net.add_param_to_uri')
166
+ Pkg::Util::Net.add_param_to_uri(uri, param)
167
+ end
168
+
169
+ def cp_pr(src, dest, options = {})
170
+ Pkg::Util.deprecate('cp_pr', 'FileUtils.cp_r')
171
+ mandatory = { :preserve => true }
172
+ FileUtils.cp_r(src, dest, options.merge(mandatory))
173
+ end
174
+
175
+ def cp_p(src, dest, options = {})
176
+ Pkg::Util.deprecate('cp_p', 'FileUtils.cp')
177
+ mandatory = { :preserve => true }
178
+ FileUtils.cp(src, dest, options.merge(mandatory))
179
+ end
180
+
181
+ def remote_set_immutable(host, files)
182
+ Pkg::Util.deprecate('remote_set_immutable', 'Pkg::Util::Net.remote_set_immutable')
183
+ Pkg::Util::Net.remote_set_immutable(host, files)
184
+ end
185
+
186
+ def ask_yes_or_no
187
+ Pkg::Util.deprecate('ask_yes_or_no', 'Pkg::Util.ask_yes_or_no')
188
+ Pkg::Util.ask_yes_or_no
189
+ end
190
+
191
+ def confirm_ship(files)
192
+ Pkg::Util.deprecate('confirm_ship', 'Pkg::Util.confirm_ship')
193
+ Pkg::Util.confirm_ship(files)
194
+ end
195
+
196
+ def deprecate(old_cmd, new_cmd = nil)
197
+ Pkg::Util.deprecate('deprecate', 'Pkg::Util.deprecate')
198
+ Pkg::Util.deprecate(old_cmd, new_cmd)
199
+ end
200
+
201
+ def remote_buildparams(host, build)
202
+ Pkg::Util.deprecate('remote_buildparams', 'Pkg::Util::Net.remote_buildparams')
203
+ Pkg::Util::Net.remote_buildparams(host, build)
204
+ end
205
+
206
+ def ship_gem(file)
207
+ Pkg::Util.deprecate('ship_gem', 'Pkg::Gem.ship')
208
+ Pkg::Gem.ship(file)
209
+ end
210
+
211
+ def set_cow_envs(cow)
212
+ Pkg::Util.deprecate('set_cow_envs', 'Pkg::Deb.set_cow_envs')
213
+ Pkg::Deb.set_cow_envs(cow)
214
+ end
@@ -0,0 +1,33 @@
1
+ @metrics = []
2
+ def add_shipped_metrics(args)
3
+ @metrics << {
4
+ :type => 'shipped',
5
+ :package => (args[:package] || Pkg::Config.project),
6
+ :version => (args[:version] || Pkg::Config.version),
7
+ :pe_version => (args[:pe_version] || Pkg::Config.pe_version),
8
+ :is_rc => (args[:is_rc] || false),
9
+ }
10
+ end
11
+
12
+ def post_shipped_metrics
13
+ require 'net/http'
14
+ @metrics.each do |metric|
15
+ type = metric[:type]
16
+ package = metric[:package]
17
+ version = metric[:version]
18
+ pe_version = metric[:pe_version]
19
+ is_rc = metric[:is_rc]
20
+
21
+ uri = URI(Pkg::Config.metrics_url)
22
+ res = Net::HTTP.post_form(
23
+ uri,
24
+ {
25
+ 'type' => type,
26
+ 'package' => package,
27
+ 'version' => version,
28
+ 'pe_version' => pe_version,
29
+ 'is_rc' => is_rc,
30
+ }
31
+ )
32
+ end
33
+ end
data/tasks/apple.rake ADDED
@@ -0,0 +1,268 @@
1
+ # Title: Rake task to build Apple packages for #{@project}.
2
+ # Author: Gary Larizza
3
+ # Date: 05/18/2012
4
+ # Description: This task will create a DMG-encapsulated package that will
5
+ # install a package on OS X systems. This happens by building
6
+ # a directory tree of files that will then be fed to the
7
+ # packagemaker binary (can be installed by installing the
8
+ # XCode Tools) which will create the .pkg file.
9
+ #
10
+
11
+ # Path to Binaries (Constants)
12
+ CP = '/bin/cp'
13
+ INSTALL = '/usr/bin/install'
14
+ DITTO = '/usr/bin/ditto'
15
+ PKGBUILD = '/usr/bin/pkgbuild'
16
+
17
+ # Setup task to populate all the variables
18
+ task :setup do
19
+ # Read the Apple file-mappings
20
+ begin
21
+ @source_files = Pkg::Util::Serialization.load_yaml('ext/osx/file_mapping.yaml')
22
+ rescue => e
23
+ fail "Could not load Apple file mappings from 'ext/osx/file_mapping.yaml'\n#{e}"
24
+ end
25
+ @package_name = Pkg::Config.project
26
+ @title = "#{Pkg::Config.project}-#{Pkg::Config.version}"
27
+ @reverse_domain = "com.#{Pkg::Config.packager}.#{@package_name}"
28
+ @package_major_version = Pkg::Config.version.split('.')[0]
29
+ @package_minor_version = Pkg::Config.version.split('.')[1] +
30
+ Pkg::Config.version.split('.')[2].split('-')[0].split('rc')[0]
31
+ @pm_restart = 'None'
32
+ @build_date = Time.new.strftime("%Y-%m-%dT%H:%M:%SZ")
33
+ @apple_bindir = File.join('/', @source_files['directories']['bin']['path'])
34
+ @apple_sbindir = '/usr/sbin'
35
+ @apple_libdir = File.join('/', @source_files['directories']['lib']['path'])
36
+ @apple_old_libdir = '/usr/lib/ruby/site_ruby/1.8'
37
+ @apple_docdir = '/usr/share/doc'
38
+ end
39
+
40
+ # method: make_directory_tree
41
+ # description: This method sets up the directory structure that packagemaker
42
+ # needs to build a package. A prototype.plist file (holding
43
+ # package-specific options) is built from an ERB template located
44
+ # in the ext/osx directory.
45
+ def make_directory_tree
46
+ project_tmp = "#{Pkg::Util::File.mktemp}/#{@package_name}"
47
+ @scratch = "#{project_tmp}/#{@title}"
48
+ @working_tree = {
49
+ 'scripts' => "#{@scratch}/scripts",
50
+ 'resources' => "#{@scratch}/resources",
51
+ 'working' => "#{@scratch}/root",
52
+ 'payload' => "#{@scratch}/payload",
53
+ }
54
+ puts "Cleaning Tree: #{project_tmp}"
55
+ rm_rf(project_tmp)
56
+ @working_tree.each do |key, val|
57
+ mkdir_p(val)
58
+ end
59
+
60
+ if File.exists?('ext/osx/postflight.erb')
61
+ Pkg::Util::File.erb_file 'ext/osx/postflight.erb', "#{@working_tree["scripts"]}/postinstall", false, :binding => binding
62
+ end
63
+
64
+ if File.exists?('ext/osx/preflight.erb')
65
+ Pkg::Util::File.erb_file 'ext/osx/preflight.erb', "#{@working_tree["scripts"]}/preinstall", false, :binding => binding
66
+ end
67
+
68
+ if File.exists?('ext/osx/prototype.plist.erb')
69
+ Pkg::Util::File.erb_file 'ext/osx/prototype.plist.erb', "#{@scratch}/prototype.plist", false, :binding => binding
70
+ end
71
+
72
+ if File.exists?('ext/packaging/static_artifacts/PackageInfo.plist')
73
+ cp 'ext/packaging/static_artifacts/PackageInfo.plist', "#{@scratch}/PackageInfo.plist"
74
+ end
75
+
76
+ end
77
+
78
+ # method: build_dmg
79
+ # description: This method builds a package from the directory structure in
80
+ # /tmp/#{@project} and puts it in the
81
+ # /tmp/#{@project}/#{@project}-#{version}/payload directory. A DMG is
82
+ # created, using hdiutil, based on the contents of the
83
+ # /tmp/#{@project}/#{@project}-#{version}/payload directory. The resultant
84
+ # DMG is placed in the pkg/apple directory.
85
+ #
86
+ def build_dmg
87
+ # Local Variables
88
+ dmg_format_code = 'UDZO'
89
+ dmg_filesystem = 'HFS+'
90
+ zlib_level = '9'
91
+ dmg_format_option = "-imagekey zlib-level=#{zlib_level}"
92
+ dmg_format = "#{dmg_format_code} #{dmg_format_option}"
93
+ dmg_file = "#{@title}.dmg"
94
+ package_file = "#{@title}.pkg"
95
+
96
+ # Build .pkg file
97
+ system("sudo #{PKGBUILD} --root #{@working_tree['working']} \
98
+ --scripts #{@working_tree['scripts']} \
99
+ --identifier #{@reverse_domain} \
100
+ --version #{Pkg::Config.version} \
101
+ --install-location / \
102
+ --ownership preserve \
103
+ --info #{@scratch}/PackageInfo.plist \
104
+ #{@working_tree['payload']}/#{package_file}")
105
+
106
+ # Build .dmg file
107
+ system("sudo hdiutil create -volname #{@title} \
108
+ -srcfolder #{@working_tree['payload']} \
109
+ -uid 99 \
110
+ -gid 99 \
111
+ -ov \
112
+ -fs #{dmg_filesystem} \
113
+ -format #{dmg_format} \
114
+ #{dmg_file}")
115
+
116
+ if File.directory?("#{pwd}/pkg/apple")
117
+ sh "sudo mv #{pwd}/#{dmg_file} #{pwd}/pkg/apple/#{dmg_file}"
118
+ puts "moved: #{dmg_file} has been moved to #{pwd}/pkg/apple/#{dmg_file}"
119
+ else
120
+ mkdir_p("#{pwd}/pkg/apple")
121
+ sh "sudo mv #{pwd}/#{dmg_file} #{pwd}/pkg/apple/#{dmg_file}"
122
+ puts "moved: #{dmg_file} has been moved to #{pwd}/pkg/apple/#{dmg_file}"
123
+ end
124
+ end
125
+
126
+ # method: pack_source
127
+ # description: This method copies the #{@project} source into a directory
128
+ # structure in /tmp/#{@project}/#{@project}-#{version}/root mirroring the
129
+ # structure on the target system for which the package will be
130
+ # installed. Anything installed into /tmp/#{@project}/root will be
131
+ # installed as the package's payload.
132
+ #
133
+ def pack_source
134
+ work = "#{@working_tree['working']}"
135
+ source = pwd
136
+
137
+ # Make all necessary directories
138
+ @source_files.each_value do |files|
139
+ files.each_value do |params|
140
+ mkdir_p "#{work}/#{params['path']}"
141
+ end
142
+ end
143
+
144
+ # Install directory contents into place
145
+ unless @source_files['directories'].nil?
146
+ @source_files['directories'].each do |dir, params|
147
+ unless FileList["#{source}/#{dir}/*"].empty?
148
+ cmd = "#{DITTO} #{source}/#{dir}/ #{work}/#{params['path']}"
149
+ puts cmd
150
+ system(cmd)
151
+ end
152
+ end
153
+ end
154
+
155
+ # Setup a preinstall script and replace variables in the files with
156
+ # the correct paths.
157
+ if File.exists?("#{@working_tree['scripts']}/preinstall")
158
+ chmod(0755, "#{@working_tree['scripts']}/preinstall")
159
+ sh "sudo chown root:wheel #{@working_tree['scripts']}/preinstall"
160
+ end
161
+
162
+ # Setup a postinstall from from the erb created earlier
163
+ if File.exists?("#{@working_tree['scripts']}/postinstall")
164
+ chmod(0755, "#{@working_tree['scripts']}/postinstall")
165
+ sh "sudo chown root:wheel #{@working_tree['scripts']}/postinstall"
166
+ end
167
+
168
+ # Do a run through first setting the specified permissions then
169
+ # making sure 755 is set for all directories
170
+ unless @source_files['directories'].nil?
171
+ @source_files['directories'].each do |dir, params|
172
+ owner = params['owner']
173
+ group = params['group']
174
+ perms = params['perms']
175
+ path = params['path']
176
+ ##
177
+ # Before setting our default permissions for all subdirectories/files of
178
+ # each directory listed in directories, we have to get a list of the
179
+ # directories. Otherwise, when we set the default perms (most likely
180
+ # 0644) we'll lose traversal on subdirectories, and later when we want to
181
+ # ensure they're 755 we won't be able to find them.
182
+ #
183
+ directories = []
184
+ Dir["#{work}/#{path}/**/*"].each do |file|
185
+ directories << file if File.directory?(file)
186
+ end
187
+
188
+ ##
189
+ # Here we're setting the default permissions for all files as described
190
+ # in file_mapping.yaml. Since we have a listing of directories, it
191
+ # doesn't matter if we remove executable permission on directories, we'll
192
+ # reset it later.
193
+ #
194
+ sh "sudo chmod -R #{perms} #{work}/#{path}"
195
+
196
+ ##
197
+ # We know at least one directory, the one listed in file_mapping.yaml, so
198
+ # we set it executable.
199
+ #
200
+ sh "sudo chmod 0755 #{work}/#{path}"
201
+
202
+ ##
203
+ # Now that default perms are set, we go in and reset executable perms on
204
+ # directories
205
+ #
206
+ directories.each { |d| sh "sudo chmod 0755 #{d}" }
207
+
208
+ ##
209
+ # Finally we set the owner/group as described in file_mapping.yaml
210
+ #
211
+ sh "sudo chown -R #{owner}:#{group} #{work}/#{path}"
212
+ end
213
+ end
214
+
215
+ # Install any files
216
+ unless @source_files['files'].nil?
217
+ @source_files['files'].each do |file, params|
218
+ owner = params['owner']
219
+ group = params['group']
220
+ perms = params['perms']
221
+ dest = params['path']
222
+ # Allow for regexs like [A-Z]*
223
+ FileList[file].each do |f|
224
+ cmd = "sudo #{INSTALL} -o #{owner} -g #{group} -m #{perms} #{source}/#{f} #{work}/#{dest}"
225
+ puts cmd
226
+ system(cmd)
227
+ end
228
+ end
229
+ end
230
+
231
+ # Hackery here. Our packages were using /usr/bin/env ruby and installing to
232
+ # system ruby loadpath, which breaks horribly in a multi-ruby (rbenv, etc)
233
+ # environment. This goes into the workdir and looks for any files dropped in
234
+ # bin, and "seds" the shebang to /usr/bin/ruby. I would love to be using a
235
+ # ruby approach to this instead of shelling out to sed, but the problem is
236
+ # we've already set ownership on these files, almost exclusively to root, and
237
+ # thus we need to sudo out.
238
+ if @source_files['directories'] and @source_files['directories']['bin']
239
+ if bindir = @source_files['directories']['bin']['path']
240
+ Dir[File.join(work, bindir, '*')].each do |binfile|
241
+ sh "sudo /usr/bin/sed -E -i '' '1 s,^#![[:space:]]*/usr/bin/env[[:space:]]+ruby$,#!/usr/bin/ruby,' #{binfile}"
242
+ end
243
+ end
244
+ end
245
+ end
246
+
247
+ namespace :package do
248
+ desc "Task for building an Apple Package"
249
+ task :apple => [:setup] do
250
+ if Pkg::Config.build_dmg
251
+ bench = Benchmark.realtime do
252
+ # Test for pkgbuild binary
253
+ fail "pkgbuild must be installed." unless \
254
+ File.exists?(PKGBUILD)
255
+
256
+ make_directory_tree
257
+ pack_source
258
+ build_dmg
259
+ end
260
+ puts "Finished building in: #{bench}"
261
+ end
262
+ end
263
+ end
264
+
265
+ # An alias task to simplify our remote logic in jenkins.rake
266
+ namespace :pl do
267
+ task :dmg => "package:apple"
268
+ end