diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-08-04 14:11:51 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2015-08-06 14:18:35 +0200 |
commit | 9b6151d1283f6a34f268c662e5e965f6dee25487 (patch) | |
tree | 5a1b8f65af21fa58339cd20da27e5deb7b4abbfd | |
parent | c31e0667170091488cfdaf1f4b7c576546832e11 (diff) | |
download | sonarqube-9b6151d1283f6a34f268c662e5e965f6dee25487.tar.gz sonarqube-9b6151d1283f6a34f268c662e5e965f6dee25487.zip |
[SCRIPTS] add support to set non existing property in property_utils
-rwxr-xr-x | scripts/property_utils.sh | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/scripts/property_utils.sh b/scripts/property_utils.sh index 43c7dcb2085..e301bb47165 100755 --- a/scripts/property_utils.sh +++ b/scripts/property_utils.sh @@ -19,24 +19,36 @@ function cnt_lines() { cat $1 | wc -l } -function set_property() { +function write_prop() { PROPERTY=$1 VALUE=$2 FILE=$3 # uncomment below to help debug calls to set_property - # echo "setting property $PROPERTY to value $VALUE in $FILE" + #echo "setting property $PROPERTY to value $VALUE in $FILE" + + echo "" >> $FILE + echo "${PROPERTY}=${VALUE}" >> $FILE +} - # delete line of specified property - LINE_COUNT=$(cnt_lines $FILE) - REGEXP="${1//\./\\\.}\s*=" - sed -i $SED_DISABLE_BACKUP "/${REGEXP}/d" $FILE +function set_property() { + PROPERTY=$1 + VALUE=$2 + FILE=$3 - # add property if at least one line deleted - NEW_LINE_COUNT=$(cnt_lines $FILE) - if [ $LINE_COUNT -gt $NEW_LINE_COUNT ]; then - echo "" >> $FILE - echo "${PROPERTY}=${VALUE}" >> $FILE + REGEXP="${1//\./\\\.}\s*=" + if [ $(grep $REGEXP $FILE | wc -l) -eq 0 ]; then + write_prop $1 $2 $3 + else + # delete line of specified property + LINE_COUNT=$(cnt_lines $FILE) + sed -i $SED_DISABLE_BACKUP "/${REGEXP}/d" $FILE + + # add property if at least one line deleted + NEW_LINE_COUNT=$(cnt_lines $FILE) + if [ $LINE_COUNT -gt $NEW_LINE_COUNT ]; then + write_prop $1 $2 $3 + fi fi } |