Skip to content

Instantly share code, notes, and snippets.

@kinow
Last active August 29, 2015 14:25
Show Gist options
  • Save kinow/90cbe1cc13343141912b to your computer and use it in GitHub Desktop.
Save kinow/90cbe1cc13343141912b to your computer and use it in GitHub Desktop.
review-jena-notice-license.sh
#!/bin/bash
# requirements: bash shell (not posix), tr, find, grep
BASEDIR=$(dirname $0)
YEAR=$(date +%G)
JENA_HOME=$(pwd -P $BASEDIR)
if [[ ! -z "$1" ]]
then
JENA_HOME=$1
fi
# Reviewing NOTICE and LICENSE files in $JENA_HOME. This script is case insensitive, and tries to find these files \
# in subdirectories without an extension, with .txt extension, or .md extension. If the file is missing and the directory \
# contains a pom.xml file (i.e. it is a Maven Module), it will raise an exception.
function reviewFileInModule() {
MODULE=$1
FILE_NAME=$2
ABSOLUTE_PATH="${JENA_HOME}/${MODULE}"
LE_FILE=$(find ${ABSOLUTE_PATH} -maxdepth 1 -iname "${FILE_NAME}*" -print)
if [[ -z "$LE_FILE" ]]
then
echo " --> Missing ${FILE_NAME}{.txt|.md|} file for $MODULE"
return 1
fi
return 0
}
function reviewYearInFileInModule() {
MODULE=$1
FILE_NAME=$2
ABSOLUTE_PATH="${JENA_HOME}/${MODULE}"
LE_FILE=$(find ${ABSOLUTE_PATH} -maxdepth 1 -iname "${FILE_NAME}*" -print)
if [[ ! -z "$LE_FILE" ]]
then
shopt -s nocasematch
if [[ "$LE_FILE" =~ "${FILE_NAME}.txt"$ || "$LE_FILE" =~ "${FILE_NAME}.md"$ ||"$LE_FILE" =~ "${FILE_NAME}"$ ]]
then
$(grep "$YEAR" $LE_FILE > /dev/null 2>&1)
if [[ "$?" -ne 0 ]]
then
echo " --> $MODULE $FILE_NAME file is not mentioning the year $YEAR"
return 1
fi
fi
shopt -u nocasematch
fi
return 0
}
echo "Reviewing files in $JENA_HOME. Current year is $YEAR"
DIRS=$(ls "${JENA_HOME}/")
echo "### NOTICE FILE"
for DIR in $DIRS
do
if [[ -d "$DIR" && -s "${DIR}/pom.xml" ]]
then
reviewFileInModule "${DIR}" "notice"
reviewYearInFileInModule "${DIR}" "notice"
fi
done
echo "### LICENSE FILE"
for DIR in $DIRS
do
if [[ -d "$DIR" && -s "${DIR}/pom.xml" ]]
then
reviewFileInModule "${DIR}" "license"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment