-
Notifications
You must be signed in to change notification settings - Fork 28.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move parsing and escaping logic to utils.sh
This commit also fixes a deadly typo.
- Loading branch information
1 parent
dec2343
commit a4df3c4
Showing
3 changed files
with
82 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# Parse the value of a config from a java properties file according to the specifications in | ||
# http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load(java.io.Reader). | ||
# This accepts the name of the config and returns the value through JAVA_PROPERTY_VALUE. | ||
parse_java_property() { | ||
JAVA_PROPERTY_VALUE=$( \ | ||
sed "/^[#!]/ d" "conf/spark-defaults.conf" | \ | ||
grep "$1" | \ | ||
sed "s/$1//" | \ | ||
sed "s/^[[:space:]]*[:=]\{0,1\}//" | \ | ||
sed "s/^[[:space:]]*\(.*\)[[:space:]]*$/\1/g" \ | ||
) | ||
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 | ||
for word in $1; do | ||
contains_quote=$(echo "$word" | grep \" | grep -v \\\\\") | ||
if [ -n "$contains_quote" ]; then | ||
# Flip the bit | ||
opened_quotes=$(((opened_quotes + 1) % 2)) | ||
fi | ||
if [[ $opened_quotes == 0 ]]; then | ||
ESCAPED_JAVA_OPTS+=("$(echo "$option_buffer $word" | sed "s/^[[:space:]]*//" | sed "s/\([^\\]\)\"/\1/g")") | ||
option_buffer="" | ||
else | ||
option_buffer="$option_buffer $word" | ||
fi | ||
done | ||
# Something is wrong if we ended with open double quotes | ||
if [[ $opened_quotes == 1 ]]; then | ||
echo "Java options parse error! Expecting closing double quotes." 1>&2 | ||
exit 1 | ||
fi | ||
export ESCAPED_JAVA_OPTS | ||
} | ||
|