|
| 1 | +#!/usr/bin/env bash |
| 2 | +################################################################################ |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +# See the License for the specific language governing permissions and |
| 17 | +# limitations under the License. |
| 18 | +################################################################################ |
| 19 | + |
| 20 | +download_rat_jar () { |
| 21 | + URL="https://repo.maven.apache.org/maven2/org/apache/rat/apache-rat/${RAT_VERSION}/apache-rat-${RAT_VERSION}.jar" |
| 22 | + JAR="$rat_jar" |
| 23 | + |
| 24 | + # Download rat launch jar |
| 25 | + printf "Attempting to fetch rat\n" |
| 26 | + wget --quiet ${URL} -O "$JAR" |
| 27 | +} |
| 28 | + |
| 29 | +BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" |
| 30 | +PROJECT_ROOT="${BASE_DIR}/../" |
| 31 | + |
| 32 | +cd ${PROJECT_ROOT} |
| 33 | + |
| 34 | +mkdir -p ${PROJECT_ROOT}/rat |
| 35 | +export RAT_VERSION=0.15 |
| 36 | +export rat_jar=${PROJECT_ROOT}/rat/apache-rat-${RAT_VERSION}.jar |
| 37 | + |
| 38 | +download_rat_jar |
| 39 | + |
| 40 | +java -jar ${rat_jar} -E ${PROJECT_ROOT}/dev/.rat-excludes -d ${PROJECT_ROOT} > rat/rat-results.txt |
| 41 | + |
| 42 | +if [ $? -ne 0 ]; then |
| 43 | + echo "RAT exited abnormally" |
| 44 | + exit 1 |
| 45 | +fi |
| 46 | + |
| 47 | +ERRORS="$(cat rat/rat-results.txt | grep -e "??")" |
| 48 | + |
| 49 | +if [[ -n "${ERRORS}" ]]; then |
| 50 | + echo "Could not find Apache license headers in the following files:" |
| 51 | + echo ${ERRORS} |
| 52 | + exit 1 |
| 53 | +else |
| 54 | + echo -e "RAT checks passed." |
| 55 | +fi |
0 commit comments