Skip to content

Commit e793e5f

Browse files
committed
Handle multi-line arguments
1 parent 5d8f8c4 commit e793e5f

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

bin/utils.sh

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,33 @@
2222

2323
# Parse the value of a config from a java properties file according to the specifications in
2424
# http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load(java.io.Reader).
25-
# This accepts the name of the config and returns the value through JAVA_PROPERTY_VALUE.
26-
# This currently does not support multi-line configs.
25+
# This accepts the name of the config as an argument, and expects the path of the property
26+
# file to be found in PROPERTIES_FILE. The value is returned through JAVA_PROPERTY_VALUE.
2727
parse_java_property() {
28+
JAVA_PROPERTY_VALUE="" # return value
29+
config_buffer="" # buffer for collecting parts of a config value
30+
multi_line=0 # whether this config is spanning multiple lines
31+
while read -r line; do
32+
# Strip leading and trailing whitespace
33+
line=$(echo "$line" | sed "s/^[[:space:]]\(.*\)[[:space:]]*$/\1/")
34+
contains_config=$(echo "$line" | grep -e "^$1")
35+
if [[ -n "$contains_config" || "$multi_line" == 1 ]]; then
36+
has_more_lines=$(echo "$line" | grep -e "\\\\$")
37+
if [[ -n "$has_more_lines" ]]; then
38+
# Strip trailing backslash
39+
line=$(echo "$line" | sed "s/\\\\$//")
40+
config_buffer="$config_buffer $line"
41+
multi_line=1
42+
else
43+
JAVA_PROPERTY_VALUE="$config_buffer $line"
44+
break
45+
fi
46+
fi
47+
done < "$PROPERTIES_FILE"
48+
49+
# Actually extract the value of the config
2850
JAVA_PROPERTY_VALUE=$( \
29-
sed "/^[#!]/ d" "conf/spark-defaults.conf" | \
30-
grep "$1" | \
51+
echo "$JAVA_PROPERTY_VALUE" | \
3152
sed "s/$1//" | \
3253
sed "s/^[[:space:]]*[:=]\{0,1\}//" | \
3354
sed "s/^[[:space:]]*\(.*\)[[:space:]]*$/\1/g" \
@@ -63,7 +84,8 @@ split_java_options() {
6384
done
6485
# Something is wrong if we ended with open double quotes
6586
if [[ $opened_quotes == 1 ]]; then
66-
echo "Java options parse error! Expecting closing double quotes." 1>&2
87+
echo -e "Java options parse error! Expecting closing double quotes:" 1>&2
88+
echo -e " ${SPLIT_JAVA_OPTS[@]}" 1>&2
6789
exit 1
6890
fi
6991
export SPLIT_JAVA_OPTS

0 commit comments

Comments
 (0)