|
22 | 22 |
|
23 | 23 | # Parse the value of a config from a java properties file according to the specifications in |
24 | 24 | # 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. |
27 | 27 | 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 |
28 | 50 | JAVA_PROPERTY_VALUE=$( \ |
29 | | - sed "/^[#!]/ d" "conf/spark-defaults.conf" | \ |
30 | | - grep "$1" | \ |
| 51 | + echo "$JAVA_PROPERTY_VALUE" | \ |
31 | 52 | sed "s/$1//" | \ |
32 | 53 | sed "s/^[[:space:]]*[:=]\{0,1\}//" | \ |
33 | 54 | sed "s/^[[:space:]]*\(.*\)[[:space:]]*$/\1/g" \ |
@@ -63,7 +84,8 @@ split_java_options() { |
63 | 84 | done |
64 | 85 | # Something is wrong if we ended with open double quotes |
65 | 86 | 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 |
67 | 89 | exit 1 |
68 | 90 | fi |
69 | 91 | export SPLIT_JAVA_OPTS |
|
0 commit comments