Replacing Tokens in Files

This wraps the TokenCustomizer resources for modifying files by replacing tokens with values.

Usage with directory

Replace method returns a list of files that have been updated.

require 'mintpress-resources'

opts = {
  :host => MintPress::Infrastructure::LocalHost.new,
  'source' => '/tmp/download/extensionsodi',
  'include_files' => "**/*CONN*.xml",
  'exclude_files' => "*ORACLE*",
  'tokens' => { '{HOST_WEBLOGIC_USER}' => 'weblogic', '{HOST_WEBLOGIC_PWD}' => 'welcome1'}
}

files = MintPress::Resources::TokenCustomizer.new(opts).replace
raise "Failed to customize folder" if files.empty

The above example will replace tokens HOST_WEBLOGIC_USER and HOST_WEBLOGIC_PWD in every XML file within the specified folder with filenames containing ‘CONN’ and not containing ‘ORACLE’.

Usage with archive file

The TokenCustomizer can be used to modify the content of the Zip or Jar archive.

require 'mintpress-resources'

opts = {
  :host => MintPress::Infrastructure::LocalHost.new,
  'source' => '/tmp/download/extensionsodi.jar',
  'include_files' => "**/*CONN*.xml",
  'tokens' => { '{HOST_WEBLOGIC_USER}' => 'weblogic', '{HOST_WEBLOGIC_PWD}' => 'welcome1'}
}

files = MintPress::Resources::TokenCustomizer.new(opts).replace
raise "Failed to customize archive" if files.empty

Usage with tokens file

The TokenCustomizer can be used to modify the content archive of directory with tokens and values specified in a local file.

require 'mintpress-resources'

opts = {
  :host => MintPress::Infrastructure::LocalHost.new,
  'source' => '/tmp/download/extensionsodi.jar',
  'include_files' => "**/*CONN*.xml",
  'exclude_files' => "*JMS*",
  'tokens_file' => '/tmp/tokens/dev.properties'
}

files = MintPress::Resources::TokenCustomizer.new(opts).replace
raise "Failed to customize archive using tokens file" if files.empty