Commons component plugin - Macros - Substitute keys¶
Contents :
- # SUBSTITUTE KEYS IN {files} USING {key_value_list} AS {processed_files}
- # SUBSTITUTE KEYS IN {files} FOR FILES WHOSE NAMES MATCHING {regex} USING {key_value_list} AS {processed_files}
- # SUBSTITUTE KEYS IN {files} FOR FILES WHOSE NAMES NOT MATCHING {regex} USING {key_value_list} AS {processed_files}
# SUBSTITUTE KEYS IN {files} USING {key_value_list} AS {processed_files}¶
What ?
This macro allows to replace specific keys by selected values in a bundle of files.
Underlying instruction :
LOAD {key_value_list} AS placeholder{%%rand2}.file
CONVERT placeholder{%%rand2}.file TO properties(structured) AS placeholder{%%rand3}.properties
LOAD {files} AS __bundle{%%rand1}
CONVERT __bundle{%%rand1} TO file(param) USING placeholder{%%rand3}.properties AS {processed_files}
> Input :
{files}
: The bundle of files where you want to apply the substitution.{key_value_list}
: It can either be a path to a properties file or an inline command with keys and values.
Example of inline command : $(key1=value1 \n key2=value2).
> Output :
{processed_files}
: The bundle of filtered files that have been processed.
Examples :
# SUBSTITUTE KEYS IN resources_folder USING resources_folder/file.properties AS result_bundle
Or
# SUBSTITUTE KEYS IN resources_folder USING $(oneKey=oneValue \n anotherKey=anotherValue) AS result_bundle First file to process :
Second file to process :
.properties File :
The folder containing files to process which corresponds to
{files}
:SKF script :
In order to check that the macro worked properly, we added in this example, the instruction “LOAD result AS resultOutput” to be able to see the result output.
You can access to the result output in the following folder which contains temporary files :
C:\Users\*user name*\AppData\Local\Temp\Squash_TA\20190909_121048_957615127627872437436\tests\tests\substitute_keys.ta\myResources2594181966007652622639979916temp Result output for first file :
Result output for second file :
# SUBSTITUTE KEYS IN {files} FOR FILES WHOSE NAMES MATCHING {regex} USING {key_value_list} AS {processed_files}¶
What ?
This macro allows to replace specific keys by selected values in a bundle of files whose names are matching a selected regular expression.
Underlying instruction :
LOAD {key_value_list} AS placeholder{%%rand2}.file
CONVERT placeholder{%%rand2}.file TO properties(structured) AS placeholder{%%rand3}.properties
LOAD {files} AS __bundle{%%rand1}
CONVERT __bundle{%%rand1} TO file(param) USING placeholder{%%rand3}.properties,$(squashtest.ta.param.include:{regex}) AS {processed_files}
> Input :
{files}
: The bundle of files where you want to apply the substitution.{regex}
: The regular expression used to filter the files in the bundle.{key_value_list}
: It can either be a path to a properties file or an inline command with keys and values.
Example of inline command : $(key1=value1 \n key2=value2).
> Output :
{processed_files}
: The bundle of filtered files that have been processed.
Examples :
# SUBSTITUTE KEYS IN resources_folder FOR FILES WHOSE NAMES MATCHING .xml USING resources_folder/file.properties AS result_bundle Or
# SUBSTITUTE KEYS IN resources_folder FOR FILES WHOSE NAMES MATCHING .xml USING $(oneKey=oneValue \n anotherKey=anotherValue) AS result_bundle This example is based on the previous one. For more details, please check here.
SKF script :
Or
Console output :
The .txt and .properties files which don’t match the selected regex are properly excluded.
Result output for first file :
Result output for second file :
The .xml file is the only one that has been processed.
# SUBSTITUTE KEYS IN {files} FOR FILES WHOSE NAMES NOT MATCHING {regex} USING {key_value_list} AS {processed_files}¶
What ?
This macro allows to replace specific keys by selected values in a bundle of files whose names are not matching a selected regular expression.
Underlying instruction :
LOAD {key_value_list} AS placeholder{%%rand2}.file
CONVERT placeholder{%%rand2}.file TO properties(structured) AS placeholder{%%rand3}.properties
LOAD {files} AS __bundle{%%rand1}
CONVERT __bundle{%%rand1} TO file(param) USING placeholder{%%rand3}.properties,$(squashtest.ta.param.exclude:{regex}) AS {processed_files}
> Input :
{files}
: The bundle of files where you want to apply the substitution.{regex}
: The regular expression used to filter the files in the bundle.{key_value_list}
: It can either be a path to a properties file or an inline command with keys and values.
Example of inline command : $(key1=value1 \n key2=value2).
> Output :
{processed_files}
: The bundle of filtered files that have been processed.
Examples :
# SUBSTITUTE KEYS IN resources_folder FOR FILES WHOSE NAMES NOT MATCHING .xml USING resources_folder/file.properties AS result_bundle Or
# SUBSTITUTE KEYS IN resources_folder FOR FILES WHOSE NAMES NOT MATCHING .xml USING $(oneKey=oneValue,anotherKey \n anotherValue) AS result_bundle This example is based on the previous one. For more details, please check here.
SKF script :
Console output :
The .xml file which match the selected regex is properly excluded.
Result output for first file :
Result output for second file :
The .xml file is not processed whereas the .txt is.