1+ #! /usr/bin/env bash
2+
3+ # Licensed to the Apache Software Foundation (ASF) under one or more
4+ # contributor license agreements. See the NOTICE file distributed with
5+ # this work for additional information regarding copyright ownership.
6+ # The ASF licenses this file to You under the Apache License, Version 2.0
7+ # (the "License"); you may not use this file except in compliance with
8+ # the License. You may obtain a copy of the License at
9+ #
10+ # http://www.apache.org/licenses/LICENSE-2.0
11+ #
12+ # Unless required by applicable law or agreed to in writing, software
13+ # distributed under the License is distributed on an "AS IS" BASIS,
14+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+ # See the License for the specific language governing permissions and
16+ # limitations under the License.
17+
18+ acquire_rat_jar () {
19+
20+ URL=" https://repo.maven.apache.org/maven2/org/apache/rat/apache-rat/${RAT_VERSION} /apache-rat-${RAT_VERSION} .jar"
21+
22+ JAR=" $rat_jar "
23+
24+ # Download rat launch jar if it hasn't been downloaded yet
25+ if [ ! -f " $JAR " ]; then
26+ # Download
27+ printf " Attempting to fetch rat\n"
28+ JAR_DL=" ${JAR} .part"
29+ if [ $( command -v curl) ]; then
30+ curl -L --silent " ${URL} " > " $JAR_DL " && mv " $JAR_DL " " $JAR "
31+ elif [ $( command -v wget) ]; then
32+ wget --quiet ${URL} -O " $JAR_DL " && mv " $JAR_DL " " $JAR "
33+ else
34+ printf " You do not have curl or wget installed, please install rat manually.\n"
35+ exit -1
36+ fi
37+ fi
38+
39+ unzip -tq " $JAR " & > /dev/null
40+ if [ $? -ne 0 ]; then
41+ # We failed to download
42+ rm " $JAR "
43+ printf " Our attempt to download rat locally to ${JAR} failed. Please install rat manually.\n"
44+ exit -1
45+ fi
46+ }
47+
48+ # Go to the Spark project root directory
49+ FWDIR=" $( cd " ` dirname " $0 " ` " /..; pwd) "
50+ cd " $FWDIR "
51+
52+ if test -x " $JAVA_HOME /bin/java" ; then
53+ declare java_cmd=" $JAVA_HOME /bin/java"
54+ else
55+ declare java_cmd=java
56+ fi
57+
58+ export RAT_VERSION=0.16.1
59+ export rat_jar=" $FWDIR " /lib/apache-rat-${RAT_VERSION} .jar
60+ mkdir -p " $FWDIR " /lib
61+
62+ [[ -f " $rat_jar " ]] || acquire_rat_jar || {
63+ echo " Download failed. Obtain the rat jar manually and place it at $rat_jar "
64+ exit 1
65+ }
66+
67+ mkdir -p build
68+ $java_cmd -jar " $rat_jar " -E " $FWDIR " /dev/rat_exclude_files.txt -d " $FWDIR " > build/rat-results.txt
69+
70+ if [ $? -ne 0 ]; then
71+ echo " RAT exited abnormally"
72+ exit 1
73+ fi
74+
75+ ERRORS=" $( cat build/rat-results.txt | grep -e " ??" ) "
76+
77+ if test ! -z " $ERRORS " ; then
78+ echo " Could not find Apache license headers in the following files:"
79+ echo " $ERRORS "
80+ exit 1
81+ else
82+ echo -e " RAT checks passed."
83+ fi
0 commit comments