2014-03-24 11:44:12 -04:00
|
|
|
#!/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.
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
acquire_rat_jar () {
|
|
|
|
|
2014-09-30 16:11:25 -04:00
|
|
|
URL="http://repo1.maven.org/maven2/org/apache/rat/apache-rat/${RAT_VERSION}/apache-rat-${RAT_VERSION}.jar"
|
2014-03-24 11:44:12 -04:00
|
|
|
|
2014-09-08 13:24:15 -04:00
|
|
|
JAR="$rat_jar"
|
2014-09-30 16:11:25 -04:00
|
|
|
|
2015-04-10 15:02:35 -04:00
|
|
|
# Download rat launch jar if it hasn't been downloaded yet
|
|
|
|
if [ ! -f "$JAR" ]; then
|
|
|
|
# Download
|
|
|
|
printf "Attempting to fetch rat\n"
|
|
|
|
JAR_DL="${JAR}.part"
|
|
|
|
if [ $(command -v curl) ]; then
|
|
|
|
curl -L --silent "${URL}" > "$JAR_DL" && mv "$JAR_DL" "$JAR"
|
|
|
|
elif [ $(command -v wget) ]; then
|
|
|
|
wget --quiet ${URL} -O "$JAR_DL" && mv "$JAR_DL" "$JAR"
|
|
|
|
else
|
|
|
|
printf "You do not have curl or wget installed, please install rat manually.\n"
|
2014-07-30 16:17:14 -04:00
|
|
|
exit -1
|
2014-03-24 11:44:12 -04:00
|
|
|
fi
|
2015-04-10 15:02:35 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
unzip -tq "$JAR" &> /dev/null
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
# We failed to download
|
|
|
|
rm "$JAR"
|
|
|
|
printf "Our attempt to download rat locally to ${JAR} failed. Please install rat manually.\n"
|
|
|
|
exit -1
|
2014-03-24 11:44:12 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Go to the Spark project root directory
|
2014-09-08 13:24:15 -04:00
|
|
|
FWDIR="$(cd "`dirname "$0"`"/..; pwd)"
|
2014-07-30 15:33:42 -04:00
|
|
|
cd "$FWDIR"
|
2014-03-24 11:44:12 -04:00
|
|
|
|
|
|
|
if test -x "$JAVA_HOME/bin/java"; then
|
|
|
|
declare java_cmd="$JAVA_HOME/bin/java"
|
2014-09-30 16:11:25 -04:00
|
|
|
else
|
2014-03-24 11:44:12 -04:00
|
|
|
declare java_cmd=java
|
|
|
|
fi
|
|
|
|
|
|
|
|
export RAT_VERSION=0.10
|
2014-09-08 13:24:15 -04:00
|
|
|
export rat_jar="$FWDIR"/lib/apache-rat-${RAT_VERSION}.jar
|
|
|
|
mkdir -p "$FWDIR"/lib
|
2014-03-24 11:44:12 -04:00
|
|
|
|
|
|
|
[[ -f "$rat_jar" ]] || acquire_rat_jar || {
|
|
|
|
echo "Download failed. Obtain the rat jar manually and place it at $rat_jar"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2014-09-08 13:24:15 -04:00
|
|
|
$java_cmd -jar "$rat_jar" -E "$FWDIR"/.rat-excludes -d "$FWDIR" > rat-results.txt
|
2014-03-24 11:44:12 -04:00
|
|
|
|
2015-04-10 15:02:35 -04:00
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
echo "RAT exited abnormally"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2014-09-08 13:24:15 -04:00
|
|
|
ERRORS="$(cat rat-results.txt | grep -e "??")"
|
2014-03-24 11:44:12 -04:00
|
|
|
|
|
|
|
if test ! -z "$ERRORS"; then
|
|
|
|
echo "Could not find Apache license headers in the following files:"
|
|
|
|
echo "$ERRORS"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo -e "RAT checks passed."
|
|
|
|
fi
|