|
| 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 | + echo "Attempting to fetch rat" |
| 26 | + wget --quiet ${URL} -O "$JAR" |
| 27 | +} |
| 28 | + |
| 29 | +CURR_DIR=`pwd` |
| 30 | +SOURCE_PACKAGE=${SOURCE_PACKAGE} |
| 31 | + |
| 32 | +export RAT_VERSION=0.15 |
| 33 | +export rat_jar=rat/apache-rat-${RAT_VERSION}.jar |
| 34 | + |
| 35 | +if [ -z "${SOURCE_PACKAGE}" ]; then |
| 36 | + BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" |
| 37 | + PROJECT_ROOT="${BASE_DIR}/../" |
| 38 | + cd ${PROJECT_ROOT} |
| 39 | + |
| 40 | + # Sanity check to ensure that resolved paths are valid; a LICENSE file should always exist in project root |
| 41 | + if [ ! -f ${PROJECT_ROOT}/LICENSE ]; then |
| 42 | + echo "Project root path ${PROJECT_ROOT} is not valid; script may be in the wrong directory." |
| 43 | + exit 1 |
| 44 | + fi |
| 45 | + |
| 46 | + RUN_RAT="java -jar ${rat_jar} -E ${PROJECT_ROOT}/dev/.rat-excludes -d ${PROJECT_ROOT}" |
| 47 | +else |
| 48 | + EXTENSION='.tar.gz' |
| 49 | + # get unzipped directory |
| 50 | + PACKAGE_DIR="${SOURCE_PACKAGE:0:$((${#SOURCE_PACKAGE} - ${#EXTENSION}))}" |
| 51 | + tar -xf ${SOURCE_PACKAGE} |
| 52 | + |
| 53 | + RUN_RAT="java -jar ${rat_jar} -e PKG-INFO -e setup.cfg -e pypaimon.egg-info/* -d ${PACKAGE_DIR}" |
| 54 | +fi |
| 55 | + |
| 56 | +mkdir -p rat |
| 57 | +download_rat_jar |
| 58 | + |
| 59 | +$RUN_RAT > rat/rat-results.txt |
| 60 | + |
| 61 | +if [ $? -ne 0 ]; then |
| 62 | + echo "RAT exited abnormally" |
| 63 | + exit 1 |
| 64 | +fi |
| 65 | + |
| 66 | +ERRORS="$(cat rat/rat-results.txt | grep -e "??")" |
| 67 | + |
| 68 | +# clean |
| 69 | +rm -rf rat |
| 70 | +if [ -d "$PACKAGE_DIR" ]; then |
| 71 | + rm -rf $PACKAGE_DIR |
| 72 | +fi |
| 73 | + |
| 74 | +if [[ -n "${ERRORS}" ]]; then |
| 75 | + echo "Could not find Apache license headers in the following files:" |
| 76 | + echo ${ERRORS} |
| 77 | + exit 1 |
| 78 | +else |
| 79 | + echo -e "RAT checks passed." |
| 80 | +fi |
0 commit comments