Skip to content

Commit

Permalink
Set tokens to empty values if not set. (#48)
Browse files Browse the repository at this point in the history
* Set tokens to empty values if not set.
Fixes #24

* Add option for defining if empty values should be replaced.
  • Loading branch information
pascalberger authored and Harshil Lodhi committed Oct 21, 2016
1 parent 9165104 commit 09ccc04
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
17 changes: 16 additions & 1 deletion Utilites/Tokenizer/task.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
},
"demands": [
],

"groups": [
{
"name": "advanced",
"displayName": "Advanced",
"isExpanded": false
}
],
"inputs": [
{
"name": "SourcePath",
Expand All @@ -42,6 +48,15 @@
"defaultValue": "",
"helpMarkDown": "Json file that contains environment specific settings in the form XPath, Attribute, Value and values for user-defined variables.",
"required": false
},
{
"name": "ReplaceUndefinedValuesWithEmpty",
"type": "boolean",
"label": "Replace undefined values with empty",
"defaultValue": false,
"groupName": "advanced",
"helpMarkDown": "If set tokens will be set to an empty value if neither environment variable was set nor the value be found in the configuration. Otherwise the token will be skipped.",
"required": false
}
],
"instanceNameFormat": "Tokenizer: Transform Source filename",
Expand Down
7 changes: 6 additions & 1 deletion Utilites/Tokenizer/tokenize-ps3.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,12 @@ try {
$variableValue = $Configuration.$environmentName.CustomVariables.$matchedItem
Write-Verbose "Found variable '$matchedItem' in configuration with value '$variableValue"
} else {
Write-Host "No value found for token '$match'"
Write-Host "No value found for token '$match'"
if ($ReplaceUndefinedValuesWithEmpty) {
Write-Host "Setting '$match' to an empty value."
# Explicitely set token to empty value if neither environment variable was set nor the value be found in the configuration.
$variableValue = [string]::Empty
}
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions Utilites/Tokenizer/tokenize.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ param
#DestinationFile that will have the transformed $SourcePath, if empty then $SourcePath will be used as $DestinationPath
[String] [Parameter(Mandatory = $false)] $DestinationPath,
#ConfigurationJsonFile contains the environment specific configuration values, XPath key value pairs that will be used for XML documents passed as $SourcePath
[String] [Parameter(Mandatory = $false)] $ConfigurationJsonFile
[String] [Parameter(Mandatory = $false)] $ConfigurationJsonFile,
#Replace undefined values with empty
[Boolean] [Parameter(Mandatory = $false)] $ReplaceUndefinedValuesWithEmpty
)

Write-Verbose "Entering script tokenize.ps1"
Write-Verbose "SourcePath = $SourcePath"
Write-Verbose "DestinationPath = $DestinationPath"
Write-Verbose "ConfigurationJsonFile = $ConfigurationJsonFile"
Write-Verbose "ReplaceUndefinedValuesWithEmpty = $ReplaceUndefinedValuesWithEmpty"

. $PSScriptRoot\Helpers.ps1

Expand Down Expand Up @@ -98,7 +101,12 @@ ForEach ($match in $matches) {
Write-Verbose "Found variable '$matchedItem' in configuration with value '$variableValue"
}
else {
Write-Host "No value found for token '$match'"
Write-Host "No value found for token '$match'"
if ($ReplaceUndefinedValuesWithEmpty) {
Write-Host "Setting '$match' to an empty value."
# Explicitely set token to empty value if neither environment variable was set nor the value be found in the configuration.
$variableValue = [string]::Empty
}
}
}
}
Expand Down

0 comments on commit 09ccc04

Please sign in to comment.