66 lines
2.0 KiB
Bash
Executable File
66 lines
2.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
# Description:
|
|
# Validates code for copy-paste, prints results to standard output and report file.
|
|
#
|
|
# Parameters:
|
|
# $1 $2 $3 $n - folders to exclude from code checking.
|
|
#
|
|
# Required environment variables:
|
|
# SRCROOT - project directory.
|
|
# SCRIPT_DIR - directory of current script.
|
|
#
|
|
# Optional environment variables:
|
|
# SCRIPT_INPUT_FILE_COUNT - number of files listed in "Input files" of build phase.
|
|
# SCRIPT_INPUT_FILE_{N} - file path to directory that should be checked.
|
|
#
|
|
# Modified files:
|
|
# ${SRCROOT}/code-quality-reports/CPDLog.txt - check report.
|
|
#
|
|
# Example of usage:
|
|
# copy_paste_detection.sh Generated Localization Pods
|
|
#
|
|
|
|
EXIT_SUCCESS=0
|
|
EXIT_FAILURE=1
|
|
|
|
if which pmd >/dev/null; then
|
|
REPORTS_DIR="${SRCROOT}/code-quality-reports"
|
|
|
|
SOURCES_DIRS=`. ${SCRIPT_DIR}/common/read_input_file_names.sh " " ${SRCROOT}`
|
|
|
|
COMMAND_LINE_ARGUMENTS=$@
|
|
|
|
FOLDERS_TO_EXCLUDE=""
|
|
|
|
for argument in ${COMMAND_LINE_ARGUMENTS}
|
|
do
|
|
FOLDERS_TO_EXCLUDE=${FOLDERS_TO_EXCLUDE}"-or -name ${argument} "
|
|
done
|
|
|
|
FOLDERS_TO_EXCLUDE=`echo ${FOLDERS_TO_EXCLUDE} | cut -c5-` # remove first "-or"
|
|
|
|
FILES_TO_EXCLUDE=`find ${SRCROOT} -type d ${FOLDERS_TO_EXCLUDE} | paste -sd " " -`
|
|
|
|
mkdir -p ${REPORTS_DIR}
|
|
|
|
DIRS_ARGUMENTS=""
|
|
|
|
for SOURCE_DIR in ${SOURCES_DIRS}; do
|
|
DIRS_ARGUMENTS=${DIRS_ARGUMENTS}" --dir "${SOURCE_DIR}
|
|
done
|
|
|
|
pmd cpd ${DIRS_ARGUMENTS} --exclude ${FILES_TO_EXCLUDE} --minimum-tokens 50 --language swift --encoding UTF-8 --format net.sourceforge.pmd.cpd.XMLRenderer --skip-lexical-errors true > ${REPORTS_DIR}/cpd-output.xml
|
|
|
|
php ${SCRIPT_DIR}/../aux_scripts/cpd_script.php ${REPORTS_DIR}/cpd-output.xml | tee ${REPORTS_DIR}/CPDLog.txt
|
|
|
|
# Make paths relative to SRCROOT, so different developers won't rewrite entire file
|
|
SED_REPLACEMENT_STRING=$(echo ${SRCROOT} | sed "s/\//\\\\\//g")
|
|
|
|
sed -i '' "s/${SED_REPLACEMENT_STRING}//g" "${REPORTS_DIR}/CPDLog.txt"
|
|
else
|
|
echo "warning: pmd not installed, install using 'brew install pmd'"
|
|
|
|
exit ${EXIT_FAILURE}
|
|
fi
|