0001 #!/usr/bin/env bash
0002
0003 #
0004 # Licensed to the Apache Software Foundation (ASF) under one or more
0005 # contributor license agreements. See the NOTICE file distributed with
0006 # this work for additional information regarding copyright ownership.
0007 # The ASF licenses this file to You under the Apache License, Version 2.0
0008 # (the "License"); you may not use this file except in compliance with
0009 # the License. You may obtain a copy of the License at
0010 #
0011 # http://www.apache.org/licenses/LICENSE-2.0
0012 #
0013 # Unless required by applicable law or agreed to in writing, software
0014 # distributed under the License is distributed on an "AS IS" BASIS,
0015 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 # See the License for the specific language governing permissions and
0017 # limitations under the License.
0018 #
0019
0020
0021 acquire_rat_jar () {
0022
0023 URL="https://repo.maven.apache.org/maven2/org/apache/rat/apache-rat/${RAT_VERSION}/apache-rat-${RAT_VERSION}.jar"
0024
0025 JAR="$rat_jar"
0026
0027 # Download rat launch jar if it hasn't been downloaded yet
0028 if [ ! -f "$JAR" ]; then
0029 # Download
0030 printf "Attempting to fetch rat\n"
0031 JAR_DL="${JAR}.part"
0032 if [ $(command -v curl) ]; then
0033 curl -L --silent "${URL}" > "$JAR_DL" && mv "$JAR_DL" "$JAR"
0034 elif [ $(command -v wget) ]; then
0035 wget --quiet ${URL} -O "$JAR_DL" && mv "$JAR_DL" "$JAR"
0036 else
0037 printf "You do not have curl or wget installed, please install rat manually.\n"
0038 exit -1
0039 fi
0040 fi
0041
0042 unzip -tq "$JAR" &> /dev/null
0043 if [ $? -ne 0 ]; then
0044 # We failed to download
0045 rm "$JAR"
0046 printf "Our attempt to download rat locally to ${JAR} failed. Please install rat manually.\n"
0047 exit -1
0048 fi
0049 }
0050
0051 # Go to the Spark project root directory
0052 FWDIR="$(cd "`dirname "$0"`"/..; pwd)"
0053 cd "$FWDIR"
0054
0055 if test -x "$JAVA_HOME/bin/java"; then
0056 declare java_cmd="$JAVA_HOME/bin/java"
0057 else
0058 declare java_cmd=java
0059 fi
0060
0061 export RAT_VERSION=0.13
0062 export rat_jar="$FWDIR"/lib/apache-rat-${RAT_VERSION}.jar
0063 mkdir -p "$FWDIR"/lib
0064
0065 [[ -f "$rat_jar" ]] || acquire_rat_jar || {
0066 echo "Download failed. Obtain the rat jar manually and place it at $rat_jar"
0067 exit 1
0068 }
0069
0070 mkdir target
0071 $java_cmd -jar "$rat_jar" -E "$FWDIR"/dev/.rat-excludes -d "$FWDIR" > target/rat-results.txt
0072
0073 if [ $? -ne 0 ]; then
0074 echo "RAT exited abnormally"
0075 exit 1
0076 fi
0077
0078 ERRORS="$(cat target/rat-results.txt | grep -e "??")"
0079
0080 if test ! -z "$ERRORS"; then
0081 echo "Could not find Apache license headers in the following files:"
0082 echo "$ERRORS"
0083 exit 1
0084 else
0085 echo -e "RAT checks passed."
0086 fi