Skip to content

Commit

Permalink
escape -> split (minor)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewor14 committed Aug 7, 2014
1 parent 45a1eb9 commit aabfc7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
10 changes: 5 additions & 5 deletions bin/spark-class
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ if [ -e "$FWDIR/conf/java-opts" ] ; then
JAVA_OPTS="$JAVA_OPTS `cat $FWDIR/conf/java-opts`"
fi

# Escape JAVA_OPTS properly to handle whitespace, double quotes and backslashes
# This exports the escaped java options into ESCAPED_JAVA_OPTS
escape_java_options "$JAVA_OPTS"
# Split JAVA_OPTS properly to handle whitespace, double quotes and backslashes
# This exports the split java options into SPLIT_JAVA_OPTS
split_java_options "$JAVA_OPTS"

# Attention: when changing the way the JAVA_OPTS are assembled, the change must be reflected in CommandUtils.scala!

Expand Down Expand Up @@ -159,10 +159,10 @@ export CLASSPATH
if [ "$SPARK_PRINT_LAUNCH_COMMAND" == "1" ]; then
# Put quotes around system properties in case they contain spaces
# This exports the resulting list of java opts into QUOTED_JAVA_OPTS
quote_java_property "${ESCAPED_JAVA_OPTS[@]}"
quote_java_property "${SPLIT_JAVA_OPTS[@]}"
echo -n "Spark Command: " 1>&2
echo "$RUNNER" -cp "$CLASSPATH" "${QUOTED_JAVA_OPTS[@]}" "$@" 1>&2
echo -e "========================================\n" 1>&2
fi

exec "$RUNNER" -cp "$CLASSPATH" "${ESCAPED_JAVA_OPTS[@]}" "$@"
exec "$RUNNER" -cp "$CLASSPATH" "${SPLIT_JAVA_OPTS[@]}" "$@"
16 changes: 8 additions & 8 deletions bin/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ parse_java_property() {
export JAVA_PROPERTY_VALUE
}

# Properly escape java options, dealing with whitespace, double quotes and backslashes.
# This accepts a string and returns the escaped list through ESCAPED_JAVA_OPTS.
escape_java_options() {
ESCAPED_JAVA_OPTS=() # return value
option_buffer="" # buffer for collecting parts of an option
opened_quotes=0 # whether we are expecting a closing double quotes
# Properly split java options, dealing with whitespace, double quotes and backslashes.
# This accepts a string and returns the resulting list through SPLIT_JAVA_OPTS.
split_java_options() {
SPLIT_JAVA_OPTS=() # return value
option_buffer="" # buffer for collecting parts of an option
opened_quotes=0 # whether we are expecting a closing double quotes
for word in $1; do
contains_quote=$(echo "$word" | sed "s/\\\\\"//g" | grep "\"")
if [[ -n "$contains_quote" ]]; then
Expand All @@ -49,7 +49,7 @@ escape_java_options() {
fi
if [[ $opened_quotes == 0 ]]; then
# Remove all non-escaped quotes around the value
ESCAPED_JAVA_OPTS+=("$(
SPLIT_JAVA_OPTS+=("$(
echo "$option_buffer $word" | \
sed "s/^[[:space:]]*//" | \
sed "s/\([^\\]\)\"/\1/g" | \
Expand All @@ -66,7 +66,7 @@ escape_java_options() {
echo "Java options parse error! Expecting closing double quotes." 1>&2
exit 1
fi
export ESCAPED_JAVA_OPTS
export SPLIT_JAVA_OPTS
}

# Put double quotes around each of the given java options that is a system property.
Expand Down

0 comments on commit aabfc7e

Please sign in to comment.