Skip to content

Commit

Permalink
#85 IFS=
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Oct 2, 2023
1 parent 142892a commit 2db8de9
Show file tree
Hide file tree
Showing 17 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion filters/01-delete-non-java-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fi

mkdir -p "$(dirname "${list}")"
find "${home}" -type f -not -name '*.java' -print > "${list}"
while read -r f; do
while IFS= read -r f; do
rm -f "${f}"
done < "${list}"

Expand Down
2 changes: 1 addition & 1 deletion filters/02-delete-package-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fi

mkdir -p "$(dirname "${list}")"
find "${home}" -type f -a -name 'package-info.java' -print > "${list}"
while read -r f; do
while IFS= read -r f; do
rm -f "${f}"
done < "${list}"

Expand Down
2 changes: 1 addition & 1 deletion filters/03-delete-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ mkdir -p "$(dirname "${list}")"
find "${home}" -type f -name '*Tests.java' -print;
find "${home}" -type f -path '**/src/test/java/**/*.java' -print
} > "${list}"
while read -r f; do
while IFS= read -r f; do
rm -f "${f}"
done < "${list}"

Expand Down
2 changes: 1 addition & 1 deletion filters/04-delete-unparseable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ candidates=${temp}/files-to-parse.txt
mkdir -p "$(dirname "${candidates}")"
find "${home}" -type f -name '*.java' -print > "${candidates}"
py=${LOCAL}/filters/delete-unparseable.py
while read -r f; do
while IFS= read -r f; do
printf "python3 %s %s %s\n" "${py@Q}" "${f@Q}" "${list@Q}" >> "${jobs}"
done < "${candidates}"
"${LOCAL}/help/parallel.sh" "${jobs}"
Expand Down
2 changes: 1 addition & 1 deletion filters/05-delete-long-lines.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ touch "${list}"

candidates=${temp}/files-to-check-line-lengths.txt
find "${home}" -type f -name '*.java' -print > "${candidates}"
while read -r f; do
while IFS= read -r f; do
length=$(LC_ALL=C awk '{ print length($0) }' < "${f}" | sort -n | tail -1)
if [ -z "${length}" ]; then continue; fi
if [ "${length}" -gt "${max}" ]; then
Expand Down
2 changes: 1 addition & 1 deletion filters/06-delete-non-classes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ candidates=${temp}/classes-to-challenge.txt
mkdir -p "$(dirname "${candidates}")"
find "${home}" -type f -name '*.java' -print > "${candidates}"
py=${LOCAL}/filters/delete-non-classes.py
while read -r f; do
while IFS= read -r f; do
printf "python3 %s %s %s\n" "${py@Q}" "${f@Q}" "${list@Q}" >> "${jobs}"
done < "${candidates}"
"${LOCAL}/help/parallel.sh" "${jobs}"
Expand Down
2 changes: 1 addition & 1 deletion filters/07-delete-invalid-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ candidates=${temp}/classes-to-filter.txt
mkdir -p "$(dirname "${candidates}")"
find "${home}" -type f -name '*.java' -print > "${candidates}"
py=${LOCAL}/filters/delete-invalid-files.py
while read -r f; do
while IFS= read -r f; do
printf "python3 %s %s %s\n" "${py@Q}" "${f@Q}" "${list@Q}" >> "${jobs}"
done < "${candidates}"
"${LOCAL}/help/parallel.sh" "${jobs}"
Expand Down
4 changes: 2 additions & 2 deletions steps/aggregate-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ if [ -e "${ddir}" ]; then
exit
fi

find "${dir}" -name '*.m' | while read -r m; do
ls "${m}".* | while read -r v; do
find "${dir}" -name '*.m' | while IFS= read -r m; do
ls "${m}".* | while IFS= read -r v; do
java=$(echo "${v}" | sed "s|${dir}||" | sed "s|\.m\..*$||")
metric=$(echo "${v}" | sed "s|${dir}${java}.m.||")
csv=${ddir}/${metric}.csv
Expand Down
10 changes: 5 additions & 5 deletions steps/aggregate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ touch "${jobs}"

declare -i repo=0
sh="$(dirname "$0")/aggregate-repo.sh"
echo "${repos}" | while read -r r; do
echo "${repos}" | while IFS= read -r r; do
repo=$((repo+1))
printf "%s %s %s %s\n" "${sh@Q}" "${r@Q}" "${repo@Q}" "${total@Q}" >> "${jobs}"
done
Expand All @@ -48,15 +48,15 @@ wait
mkdir -p "${TARGET}/data"
rm -rf "${TARGET}/data/*.csv"
printf "repository,file" >> "${TARGET}/data/all.csv"
echo "${all}" | while read -r a; do
echo "${all}" | while IFS= read -r a; do
printf ',%s' "${a}" >> "${TARGET}/data/all.csv"
done
printf "\n" >> "${TARGET}/data/all.csv"

find "${TARGET}/data" -maxdepth 2 -mindepth 2 -type d -print | while read -r d; do
find "${TARGET}/data" -maxdepth 2 -mindepth 2 -type d -print | while IFS= read -r d; do
r=$(realpath --relative-to="${TARGET}/data" "$d" )
find "${d}" -name '*.csv' -maxdepth 1 -exec basename {} \; | while read -r csv; do
while read -r t; do
find "${d}" -name '*.csv' -maxdepth 1 -exec basename {} \; | while IFS= read -r csv; do
while IFS= read -r t; do
echo "${r},${t}" >> "${TARGET}/data/${csv}"
done < "${d}/${csv}"
done
Expand Down
4 changes: 2 additions & 2 deletions steps/filter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set -e
set -o pipefail

mkdir -p "${TARGET}/temp/reports"
find "${LOCAL}/filters" -name '*.sh' -exec realpath --relative-to="${LOCAL}/filters" {} \; | sort | while read -r filter; do
find "${LOCAL}/filters" -name '*.sh' -exec realpath --relative-to="${LOCAL}/filters" {} \; | sort | while IFS= read -r filter; do
tex=${TARGET}/temp/reports/${filter}.tex
if [ -e "${tex}" ]; then
echo "The ${filter} filter was already completed earlier, see report in '${tex}'"
Expand All @@ -45,7 +45,7 @@ and published its results to ${TARGET}/temp/reports/${filter}.tex "
done


find "${TARGET}/temp/reports" -type f -exec basename {} \; | while read -r f; do
find "${TARGET}/temp/reports" -type f -exec basename {} \; | while IFS= read -r f; do
echo "${f}:"
cat "${TARGET}/temp/reports/${f}"
echo ""
Expand Down
2 changes: 1 addition & 1 deletion steps/jpeek-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ for type in all cvc; do
echo "No files generated by jpeek in ${dir}"
continue
fi
find "${dir}" -type f -maxdepth 1 -print | while read -r report; do
find "${dir}" -type f -maxdepth 1 -print | while IFS= read -r report; do
echo "${report}" >> "${files}"
if echo "${report}" | grep -q "${accept}"; then
packages=$(xmlstarlet sel -t -v 'count(/metric/app/package/@id)' "${report}")
Expand Down
4 changes: 2 additions & 2 deletions steps/measure-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ start=$(date +%s%N)

mkdir -p "$(dirname "${javam}")"
metrics=$(find "${LOCAL}/metrics/" -type f -exec basename {} \;)
echo "${metrics}" | while read -r m; do
echo "${metrics}" | while IFS= read -r m; do
# @todo #74 This metric doesn't work, because when we run it,
# the directory already doesn't have the ".git" folder --- it was filtered out
# by one of the filters in the "filters/" directory. Probably, we should avoid shallow clones
# and then get an opportunity to have more Git-based metrics.
if [ "${m}" = "authors.sh" ]; then continue; fi
if timeout 30m "metrics/${m}" "${java}" "${javam}"; then
while read -r t; do
while IFS= read -r t; do
IFS=' ' read -r -ra M <<< "${t}"
echo "${M[1]}" > "${javam}.${M[0]}"
done < "${javam}"
Expand Down
2 changes: 1 addition & 1 deletion steps/measure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ touch "${jobs}"

declare -i file=0
sh="$(dirname "$0")/measure-file.sh"
echo "${javas}" | while read -r java; do
echo "${javas}" | while IFS= read -r java; do
file=$((file+1))
rel=$(realpath --relative-to="${TARGET}/github" "${java}")
javam=${TARGET}/measurements/${rel}.m
Expand Down
4 changes: 2 additions & 2 deletions steps/polish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if [ ! -e "${dir}" ]; then
fi

repos=$(find "${dir}" -maxdepth 2 -mindepth 2 -type d -exec realpath --relative-to="${dir}" {} \;)
echo "${repos}" | while read -r repo; do
echo "${repos}" | while IFS= read -r repo; do
if [ -z "${repo}" ]; then continue; fi
if grep -Fxq "${repo}" "${TARGET}/repositories.csv"; then
echo "Directory of ${repo} is already here"
Expand All @@ -42,7 +42,7 @@ done
echo "All $(echo "${repos}" | wc -l | xargs) repo directories inside ${dir} look good"

orgs=$(find "${dir}" -maxdepth 1 -mindepth 1 -type d -exec realpath --relative-to="${dir}" {} \;)
echo "${orgs}" | while read -r org; do
echo "${orgs}" | while IFS= read -r org; do
if [ "$(find "${dir}/${org}" | wc -l | xargs)" == '0' ]; then
rm -rf "${dir:?}/${org}"
echo "Organization ${org} is empty and was deleted"
Expand Down
2 changes: 1 addition & 1 deletion steps/report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ rm -f "${TARGET}/temp/list-of-metrics.tex"

java=${TARGET}/temp/Foo.java
mkdir -p "$(dirname "${java}")"
find "${LOCAL}/metrics" -type f -exec basename {} \; | while read -r m; do
find "${LOCAL}/metrics" -type f -exec basename {} \; | while IFS= read -r m; do
echo "class Foo {}" > "${java}"
metric=${TARGET}/temp/Foo.${m}.m
rm -f "${metric}"
Expand Down
2 changes: 1 addition & 1 deletion steps/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ set -o pipefail
temp=${LOCAL}/test-zone
mkdir -p "${temp}"

find "${LOCAL}/tests" -name '*.sh' | sort | while read -r test; do
find "${LOCAL}/tests" -name '*.sh' | sort | while IFS= read -r test; do
name=$(realpath --relative-to="${LOCAL}/tests" "${test}")
if [ -n "${TEST}" ] && [ ! "${TEST}" = "${name}" ]; then
continue
Expand Down
4 changes: 2 additions & 2 deletions tests/steps/test-aggregate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ set -o pipefail

temp=$1

repo="foo/bar test"
repo="foo/bar test ; "
dir="${TARGET}/measurements/${repo}/a"
mkdir -p "${dir}"
touch "${dir}/Foo.java.m"
echo "42" > "${dir}/Foo.java.m.loc"
"${LOCAL}/steps/aggregate.sh"
"${LOCAL}/steps/aggregate.sh" >/dev/null
test -e "${TARGET}/data/${repo}/all.csv"
test -e "${TARGET}/data/${repo}/loc.csv"
cat "${TARGET}/data/${repo}/loc.csv" | grep ",42" >/dev/null
Expand Down

0 comments on commit 2db8de9

Please sign in to comment.