Class: Omnibus::Packager::MSI

Inherits:
Base
  • Object
show all
Defined in:
lib/omnibus/packagers/msi.rb

Constant Summary

Constants included from Util

Util::SHELLOUT_OPTIONS

Constants included from NullArgumentable

NullArgumentable::NULL

Instance Attribute Summary

Attributes inherited from Base

#project

DSL methods collapse

Instance Method Summary collapse

Methods inherited from Base

build, #exclusions, id, #id, #initialize, #install_dir, #package_path, #resource_path, #resources_path, #run!, setup, #staging_dir

Methods included from Util

#copy_file, #create_directory, #create_file, #create_link, included, #remove_directory, #remove_file, #shellout, #shellout!, #windows_safe_path

Methods included from Templating

included, #render_template

Methods included from NullArgumentable

included, #null?

Methods included from Logging

included

Methods included from Digestable

#digest, #digest_directory

Constructor Details

This class inherits a constructor from Omnibus::Packager::Base

Instance Method Details

#msi_display_versionString

The display version calculated from the Omnibus::Project#build_version.


309
310
311
312
# File 'lib/omnibus/packagers/msi.rb', line 309

def msi_display_version
  versions = project.build_version.split(/[.+-]/)
  "#{versions[0]}.#{versions[1]}.#{versions[2]}"
end

#msi_versionString

Parse and return the MSI version from the Omnibus::Project#build_version.

A project's build_version looks something like:

dev builds => 11.14.0-alpha.1+20140501194641.git.94.561b564
           => 0.0.0+20140506165802.1

rel builds => 11.14.0.alpha.1 || 11.14.0

The MSI version spec expects a version that looks like X.Y.Z.W where X, Y, Z & W are all 32 bit integers.


297
298
299
300
# File 'lib/omnibus/packagers/msi.rb', line 297

def msi_version
  versions = project.build_version.split(/[.+-]/)
  "#{versions[0]}.#{versions[1]}.#{versions[2]}.#{project.build_iteration}"
end

#package_nameObject

See Also:


185
186
187
# File 'lib/omnibus/packagers/msi.rb', line 185

def package_name
  "#{project.package_name}-#{project.build_version}-#{project.build_iteration}.msi"
end

#parameters(val = NULL) ⇒ Hash

Set or retrieve the custom msi building parameters.

Examples:

parameters {
  'MagicParam' => 'ABCD-1234'
}

125
126
127
128
129
130
131
132
133
134
135
# File 'lib/omnibus/packagers/msi.rb', line 125

def parameters(val = NULL)
  if null?(val)
    @parameters || {}
  else
    unless val.is_a?(Hash)
      raise InvalidValue.new(:parameters, 'be a Hash')
    end

    @parameters = val
  end
end

#resources_dirString

The path where the MSI resources will live.


194
195
196
# File 'lib/omnibus/packagers/msi.rb', line 194

def resources_dir
  File.expand_path("#{staging_dir}/Resources")
end

#upgrade_code(val = NULL) ⇒ Hash

Set or retrieve the upgrade code.

Examples:

upgrade_code 'ABCD-1234'

98
99
100
101
102
103
104
105
106
107
108
# File 'lib/omnibus/packagers/msi.rb', line 98

def upgrade_code(val = NULL)
  if null?(val)
    @upgrade_code || raise(MissingRequiredAttribute.new(self, :upgrade_code, '2CD7259C-776D-4DDB-A4C8-6E544E580AA1'))
  else
    unless val.is_a?(String)
      raise InvalidValue.new(:parameters, 'be a String')
    end

    @upgrade_code = val
  end
end

#wix_candle_extension(extension) ⇒ Array

Set the wix candle extensions to load

Examples:

wix_candle_extension 'WixUtilExtension'

171
172
173
174
175
176
177
# File 'lib/omnibus/packagers/msi.rb', line 171

def wix_candle_extension(extension)
  unless extension.is_a?(String)
    raise InvalidValue.new(:wix_candle_extension, 'be an String')
  end

  wix_candle_extensions << extension
end

#wix_candle_extensionsArray

Returns the extensions to use for candle


330
331
332
# File 'lib/omnibus/packagers/msi.rb', line 330

def wix_candle_extensions
  @wix_candle_extensions ||= []
end

#wix_extension_switches(arr) ⇒ String

Takes an array of wix extension names and creates a string that can be passed to wix to load those.

for example,

'a', 'b'

> “-ext 'a' -ext 'b'”


343
344
345
# File 'lib/omnibus/packagers/msi.rb', line 343

def wix_extension_switches(arr)
  "#{arr.map {|e| "-ext '#{e}'"}.join(' ')}"
end

#wix_light_extension(extension) ⇒ Array

Set the wix light extensions to load

Examples:

wix_light_extension 'WixUtilExtension'

150
151
152
153
154
155
156
# File 'lib/omnibus/packagers/msi.rb', line 150

def wix_light_extension(extension)
  unless extension.is_a?(String)
    raise InvalidValue.new(:wix_light_extension, 'be an String')
  end

  wix_light_extensions << extension
end

#wix_light_extensionsArray

Returns the extensions to use for light


320
321
322
# File 'lib/omnibus/packagers/msi.rb', line 320

def wix_light_extensions
  @wix_light_extensions ||= []
end

#write_localization_filevoid

This method returns an undefined value.

Write the localization file into the staging directory.


203
204
205
206
207
208
209
210
211
212
# File 'lib/omnibus/packagers/msi.rb', line 203

def write_localization_file
  render_template(resource_path('localization-en-us.wxl.erb'),
    destination: "#{staging_dir}/localization-en-us.wxl",
    variables: {
      name:          project.package_name,
      friendly_name: project.friendly_name,
      maintainer:    project.maintainer,
    }
  )
end

#write_parameters_filevoid

This method returns an undefined value.

Write the parameters file into the staging directory.


219
220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'lib/omnibus/packagers/msi.rb', line 219

def write_parameters_file
  render_template(resource_path('parameters.wxi.erb'),
    destination: "#{staging_dir}/parameters.wxi",
    variables: {
      name:            project.package_name,
      friendly_name:   project.friendly_name,
      maintainer:      project.maintainer,
      upgrade_code:    upgrade_code,
      parameters:      parameters,
      version:         msi_version,
      display_version: msi_display_version,
    }
  )
end

#write_source_filevoid

This method returns an undefined value.

Write the source file into the staging directory.


239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/omnibus/packagers/msi.rb', line 239

def write_source_file
  paths = []

  # Remove C:/
  install_dir = project.install_dir.split('/')[1..-1].join('/')

  # Grab all parent paths
  Pathname.new(install_dir).ascend do |path|
    paths << path.to_s
  end

  # Create the hierarchy
  hierarchy = paths.reverse.inject({}) do |hash, path|
    hash[File.basename(path)] = path.gsub(/[^[:alnum:]]/, '').upcase + 'LOCATION'
    hash
  end

  # The last item in the path MUST be named PROJECTLOCATION or else space
  # robots will cause permanent damage to you and your family.
  hierarchy[hierarchy.keys.last] = 'PROJECTLOCATION'

  # If the path hierarchy is > 1, the customizable installation directory
  # should default to the second-to-last item in the hierarchy. If the
  # hierarchy is smaller than that, then just use the system drive.
  wix_install_dir = if hierarchy.size > 1
    hierarchy.to_a[-2][1]
  else
    'WINDOWSVOLUME'
  end

  render_template(resource_path('source.wxs.erb'),
    destination: "#{staging_dir}/source.wxs",
    variables: {
      name:          project.package_name,
      friendly_name: project.friendly_name,
      maintainer:    project.maintainer,
      hierarchy:     hierarchy,

      wix_install_dir: wix_install_dir,
    }
  )
end