Skip to content

Commit

Permalink
Issue checkstyle#11637: Used Shellcheck to resolve SC2086 in Shell Sc…
Browse files Browse the repository at this point in the history
…ript
  • Loading branch information
Rahulkhinchi03 authored and romani committed May 21, 2022
1 parent 384719c commit 5ea26d6
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 149 deletions.
14 changes: 7 additions & 7 deletions .ci/bump-license-year-in-all-projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ set -e
CURR_YEAR=$(date +"%Y")
JAVA_FILE=$(find ./src/main -type f -name *.java -print -quit)
echo "Current year will be taken from $JAVA_FILE"
PREV_YEAR=$(grep "Copyright" $JAVA_FILE | cut -d " " -f 4 | cut -d '-' -f 2)
PREV_YEAR=$(grep "Copyright" "$JAVA_FILE" | cut -d " " -f 4 | cut -d '-' -f 2)
echo "CURR_YEAR=$CURR_YEAR"
echo "PREV_YEAR=$PREV_YEAR"

./.ci/bump-license-year.sh $PREV_YEAR $CURR_YEAR .
./.ci/bump-license-year.sh "$PREV_YEAR" "$CURR_YEAR" .
git add . && git commit -m "minor: bump year to $CURR_YEAR" && git push origin master

mkdir -p .ci-temp/bump-year
Expand All @@ -21,11 +21,11 @@ git clone git@github.com:checkstyle/regression-tool.git
git clone git@github.com:sevntu-checkstyle/sevntu.checkstyle.git
git clone git@github.com:sevntu-checkstyle/methods-distance.git

./../../.ci/bump-license-year.sh $PREV_YEAR $CURR_YEAR contribution
./../../.ci/bump-license-year.sh $PREV_YEAR $CURR_YEAR sonar-checkstyle
./../../.ci/bump-license-year.sh $PREV_YEAR $CURR_YEAR regression-tool
./../../.ci/bump-license-year.sh $PREV_YEAR $CURR_YEAR sevntu.checkstyle
./../../.ci/bump-license-year.sh $PREV_YEAR $CURR_YEAR methods-distance
./../../.ci/bump-license-year.sh "$PREV_YEAR" "$CURR_YEAR" contribution
./../../.ci/bump-license-year.sh "$PREV_YEAR" "$CURR_YEAR" sonar-checkstyle
./../../.ci/bump-license-year.sh "$PREV_YEAR" "$CURR_YEAR" regression-tool
./../../.ci/bump-license-year.sh "$PREV_YEAR" "$CURR_YEAR" sevntu.checkstyle
./../../.ci/bump-license-year.sh "$PREV_YEAR" "$CURR_YEAR" methods-distance

cd contribution
git add . && git commit -m "minor: bump year to $CURR_YEAR" && git push origin master
Expand Down
6 changes: 3 additions & 3 deletions .ci/bump-license-year.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ DIR=$3
OLD_VALUE="// Copyright (C) 2001-$PREV_YEAR the original author or authors."
NEW_VALUE="// Copyright (C) 2001-$CURR_YEAR the original author or authors."

find $DIR -type f \( -name *.java -o -name *.header -o -name *.g4 \) \
find "$DIR" -type f \( -name *.java -o -name *.header -o -name *.g4 \) \
-exec sed -i "s|$OLD_VALUE|$NEW_VALUE|g" {} +

BASEDIR=$(pwd)
echo "Distinct Diff in $DIR is:"
cd $DIR
cd "$DIR"
git diff | grep -Eh "^\+" | grep -v "+++ b" | sort | uniq
cd $BASEDIR
cd "$BASEDIR"
4 changes: 2 additions & 2 deletions .ci/checkchmod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [[ ! -z $CHMOD ]]; then
echo "Files that violates this rule:"
for NAMEFILE in $CHMOD
do
echo $NAMEFILE;
echo "$NAMEFILE";
done
exit 1;
fi
Expand All @@ -25,7 +25,7 @@ if [[ ! -z $CHMOD ]]; then
echo "Files that violates this rule:"
for NAMEFILE in $CHMOD
do
echo $NAMEFILE;
echo "$NAMEFILE";
done
exit 1;
fi
14 changes: 7 additions & 7 deletions .ci/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ function should_run_job {

if [[ $DEBUG == "true" ]]; then
echo "Head commit: $HEAD"
OUT=$(git branch -a --contains $HEAD)
OUT=$(git branch -a --contains "$HEAD")
echo "Master contains head commit: $OUT"
OUT=$(git branch -a --contains $HEAD | grep " origin/master$" || true)
OUT=$(git branch -a --contains "$HEAD" | grep " origin/master$" || true)
echo "Master contains head commit (filtered): $OUT"
fi

# We are not in master if master does not contain the head commit
if [[ $(git branch -a --contains $HEAD | grep " origin/master$" \
if [[ $(git branch -a --contains "$HEAD" | grep " origin/master$" \
| wc -c ) == 0 ]]; then
PREVIOUS_COMMIT=`git merge-base origin/master $HEAD`
PREVIOUS_COMMIT=`git merge-base origin/master "$HEAD"`
fi

echo "Previous Commit to start with: $PREVIOUS_COMMIT"
Expand All @@ -66,15 +66,15 @@ function should_run_job {
fi

if [[ $DEBUG == "true" ]]; then
OUT=`git diff --name-only $HEAD $PREVIOUS_COMMIT`
OUT=`git diff --name-only "$HEAD" "$PREVIOUS_COMMIT"`
echo "Files between top commit and previous: $OUT"
OUT=`git diff --name-only $HEAD $PREVIOUS_COMMIT | grep -vE "$SKIP_FILES" | cat`
OUT=`git diff --name-only "$HEAD" "$PREVIOUS_COMMIT" | grep -vE "$SKIP_FILES" | cat`
echo "Files should not skip: $OUT"
fi

# Identifies if the files involved in the commits between head and previous
# is more than the list of skippable files
if [[ $(git diff --name-only $HEAD $PREVIOUS_COMMIT \
if [[ $(git diff --name-only "$HEAD" "$PREVIOUS_COMMIT" \
| grep -vE "$SKIP_FILES" | cat | wc -c | sed 's/^ *//' ) > 0 ]]; then
SKIP_JOB_BY_FILES="false"
else
Expand Down
4 changes: 2 additions & 2 deletions .ci/copy-site-to-sourceforge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ set -e
PREV_RELEASE=$1
RELEASE=$2

echo "PREVIOUS RELEASE version:"$PREV_RELEASE
echo "RELEASE version:"$RELEASE
echo "PREVIOUS RELEASE version:""$PREV_RELEASE"
echo "RELEASE version:""$RELEASE"

if [[ -z $RELEASE ]]; then
echo "Problem to calculate release version."
Expand Down
14 changes: 7 additions & 7 deletions .ci/eclipse-compiler-javac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ echo "Latest eclipse release is $ECJ_MAVEN_VERSION"
ECJ_JAR=$(wget --quiet -O- "$ECLIPSE_URL/$ECJ_MAVEN_VERSION/" | grep -o "ecj-[^\"]*" | head -n1)
ECJ_PATH=~/.m2/repository/$ECJ_MAVEN_VERSION/$ECJ_JAR

if [ ! -f $ECJ_PATH ]; then
if [ ! -f "$ECJ_PATH" ]; then
echo "$ECJ_PATH is not found, downloading ..."
cd target
wget $ECLIPSE_URL/$ECJ_MAVEN_VERSION/$ECJ_JAR
wget $ECLIPSE_URL/"$ECJ_MAVEN_VERSION"/"$ECJ_JAR"
echo "test jar after download:"
jar -tvf $ECJ_JAR > /dev/null
jar -tvf "$ECJ_JAR" > /dev/null
echo "check compiler options"
ECJ_OPTIONS=org/eclipse/jdt/internal/compiler/impl/CompilerOptions.class
ECJ_OPTIONS_PATTERN='org.eclipse.jdt.core.compiler.problem.[^"]*'
jar -xf $ECJ_JAR $ECJ_OPTIONS
jar -xf "$ECJ_JAR" $ECJ_OPTIONS
javap -constants $ECJ_OPTIONS | grep -o "$ECJ_OPTIONS_PATTERN" | sort > ecj.opt
grep -o "^[^=#]*" ../config/org.eclipse.jdt.core.prefs | sort > cs.opt
OPTIONS_DIFF=$(diff --unified cs.opt ecj.opt | cat)
Expand All @@ -37,7 +37,7 @@ if [ ! -f $ECJ_PATH ]; then
exit 1
fi
mkdir -p $(dirname "$ECJ_PATH")
cp $ECJ_JAR $ECJ_PATH
cp "$ECJ_JAR" "$ECJ_PATH"
cd ..
fi

Expand All @@ -49,7 +49,7 @@ echo "Executing eclipse compiler, output is redirected to $RESULT_FILE..."
echo "java -jar $ECJ_PATH -target ${JAVA_RELEASE} -source ${JAVA_RELEASE} -cp $1 ..."

set +e
java -jar $ECJ_PATH -target ${JAVA_RELEASE} -source ${JAVA_RELEASE} -encoding UTF-8 -cp $1 \
java -jar "$ECJ_PATH" -target "${JAVA_RELEASE}" -source "${JAVA_RELEASE}" -encoding UTF-8 -cp "$1" \
-d target/eclipse-compile \
-properties config/org.eclipse.jdt.core.prefs \
-enableJavadoc \
Expand All @@ -69,7 +69,7 @@ if [[ $EXIT_CODE != 0 ]]; then
else
# check compilation of resources, all WARN and INFO are ignored
set +e
java -jar $ECJ_PATH -target ${JAVA_RELEASE} -source ${JAVA_RELEASE} -cp $1 \
java -jar "$ECJ_PATH" -target "${JAVA_RELEASE}" -source "${JAVA_RELEASE}" -cp "$1" \
-d target/eclipse-compile \
-nowarn \
src/main/java \
Expand Down
16 changes: 8 additions & 8 deletions .ci/fast-forward-merge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,27 @@ REPO=${FORK_USER_NAME}-fork
LOCAL_USER_BRANCH=${FORK_USER_NAME}-${USER_BRANCH}

echo "removing remote ${REPO} if present ..."
git remote rm ${REPO} | true
git remote rm "${REPO}" | true

echo "adding remote ..."
git remote add ${REPO} https://github.com/${FORK_USER_NAME}/${GIT_REPO}.git
git fetch ${REPO}
git remote add "${REPO}" https://github.com/"${FORK_USER_NAME}"/${GIT_REPO}.git
git fetch "${REPO}"

echo "removing remote ${LOCAL_USER_BRANCH} if present ..."
git branch -D ${LOCAL_USER_BRANCH} | true
git branch -D "${LOCAL_USER_BRANCH}" | true

echo "creating local branch ..."
git checkout -b ${LOCAL_USER_BRANCH} ${REPO}/${USER_BRANCH}
git checkout -b "${LOCAL_USER_BRANCH}" "${REPO}"/"${USER_BRANCH}"

echo "rebasing over master ..."
git rebase master

echo "merge to master ..."
git checkout master
git merge ${LOCAL_USER_BRANCH} --ff-only
git merge "${LOCAL_USER_BRANCH}" --ff-only

echo "removing local branch ..."
git branch -D ${LOCAL_USER_BRANCH}
git branch -D "${LOCAL_USER_BRANCH}"

echo "removing remote ..."
git remote rm ${REPO}
git remote rm "${REPO}"
13 changes: 7 additions & 6 deletions .ci/idea_inspection.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ if [[ -z $IDEA_PATH ]]; then
echo "IDEA_PATH variable not found."
# Try to search in path
IDEA_PATH="$(which idea)"
if [ -z $IDEA_PATH ]; then
if [ -z "$IDEA_PATH" ]; then
echo "IntelliJ IDEA was not found in path."
exit -1
fi
Expand All @@ -31,22 +31,23 @@ fi
# Execute compilation of Checkstyle to generate all source files
mvn -e --no-transfer-progress clean compile

mkdir -p $RESULTS_DIR
rm -rf $RESULTS_DIR/*
mkdir -p "$RESULTS_DIR"
rm -rf "$RESULTS_DIR"/*

echo "Intellij Idea validation is about to start"
echo "Progress output will be flushed at end. Validation is in progress ..."
IDEA_OUTPUT=`$IDEA_PATH/bin/inspect.sh $PROJECT_DIR $INSPECTIONS_PATH $RESULTS_DIR -$NOISE_LVL`
IDEA_OUTPUT=`"$IDEA_PATH"/bin/inspect.sh "$PROJECT_DIR" "$INSPECTIONS_PATH" "$RESULTS_DIR" \
-$NOISE_LVL`

if [[ $IDEA_OUTPUT == "Already running" ]]; then
echo "It might be that Intellij Idea is running, please close it."
exit 1;
fi

echo "Checking results ..."
if [[ $(grep -R "<problems" $RESULTS_DIR/ | cat | wc -l ) > 0 ]]; then
if [[ $(grep -R "<problems" "$RESULTS_DIR"/ | cat | wc -l ) > 0 ]]; then
echo "There are inspection problems. Review results at $RESULTS_DIR folder. Files:"
grep -Rl "<problems" $RESULTS_DIR/
grep -Rl "<problems" "$RESULTS_DIR"/
exit 1;
else
echo "Inspection did not found any problems"
Expand Down
12 changes: 6 additions & 6 deletions .ci/no-exception-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ case $1 in
guava-with-google-checks)
CS_POM_VERSION="$(getCheckstylePomVersion)"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo CS_version: $CS_POM_VERSION
echo CS_version: "$CS_POM_VERSION"
checkout_from https://github.com/checkstyle/contribution
cd .ci-temp/contribution/checkstyle-tester
sed -i.'' 's/^guava/#guava/' projects-to-test-on.properties
Expand All @@ -30,7 +30,7 @@ guava-with-google-checks)
guava-with-sun-checks)
CS_POM_VERSION="$(getCheckstylePomVersion)"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo CS_version: $CS_POM_VERSION
echo CS_version: "$CS_POM_VERSION"
checkout_from https://github.com/checkstyle/contribution
cd .ci-temp/contribution/checkstyle-tester
sed -i.'' 's/^guava/#guava/' projects-to-test-on.properties
Expand Down Expand Up @@ -72,7 +72,7 @@ openjdk17-with-checks-nonjavadoc-error)
no-exception-lucene-and-others-javadoc)
CS_POM_VERSION="$(getCheckstylePomVersion)"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo 'CS_POM_VERSION='${CS_POM_VERSION}
echo 'CS_POM_VERSION='"${CS_POM_VERSION}"
checkout_from https://github.com/checkstyle/contribution
cp .ci/projects-for-no-exception-javadoc.config .ci-temp/contribution/checkstyle-tester
cd .ci-temp/contribution/checkstyle-tester
Expand All @@ -92,7 +92,7 @@ no-exception-lucene-and-others-javadoc)

no-exception-cassandra-storm-tapestry-javadoc)
CS_POM_VERSION="$(getCheckstylePomVersion)"
echo 'CS_POM_VERSION='${CS_POM_VERSION}
echo 'CS_POM_VERSION='"${CS_POM_VERSION}"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
checkout_from https://github.com/checkstyle/contribution
cp .ci/projects-for-no-exception-javadoc.config .ci-temp/contribution/checkstyle-tester
Expand All @@ -112,7 +112,7 @@ no-exception-cassandra-storm-tapestry-javadoc)

no-exception-hadoop-apache-groovy-scouter-javadoc)
CS_POM_VERSION="$(getCheckstylePomVersion)"
echo 'CS_POM_VERSION='${CS_POM_VERSION}
echo 'CS_POM_VERSION='"${CS_POM_VERSION}"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
checkout_from https://github.com/checkstyle/contribution
cp .ci/projects-for-no-exception-javadoc.config .ci-temp/contribution/checkstyle-tester
Expand All @@ -133,7 +133,7 @@ no-exception-hadoop-apache-groovy-scouter-javadoc)

no-exception-only-javadoc)
CS_POM_VERSION="$(getCheckstylePomVersion)"
echo 'CS_POM_VERSION='${CS_POM_VERSION}
echo 'CS_POM_VERSION='"${CS_POM_VERSION}"
BRANCH=$(git rev-parse --abbrev-ref HEAD)
checkout_from https://github.com/checkstyle/contribution
cd .ci-temp/contribution/checkstyle-tester
Expand Down
2 changes: 1 addition & 1 deletion .ci/no_old_refs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ for MENTIONED_ISSUES_GREP_OUTPUT_LINE in $(cat $MENTIONED_ISSUES_GREP_OUTPUT); d
echo "$LINK" >> $CLOSED_ISSUES
fi
if [ ! -z "$LINKED_ISSUES" ]; then
for LINKED_ISSUE in $(cat $LINKED_ISSUES); do
for LINKED_ISSUE in $(cat "$LINKED_ISSUES"); do
if [ "$LINKED_ISSUE" = "$GITHUB_HOST/$ISSUE" ]; then
echo "$LINK" >> $LINKED_ISSUES_MENTIONED
fi
Expand Down
18 changes: 9 additions & 9 deletions .ci/pitest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,22 @@ pitest-annotation|pitest-design \
|pitest-tree-walker \
|pitest-utils \
|pitest-java-ast-visitor)
mvn --no-transfer-progress -e -P$1 clean test-compile org.pitest:pitest-maven:mutationCoverage;
mvn --no-transfer-progress -e -P"$1" clean test-compile org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=();
checkPitestReport ignoredItems
;;

# till #9351
pitest-main)
mvn --no-transfer-progress -e -P$1 clean test-compile org.pitest:pitest-maven:mutationCoverage;
mvn --no-transfer-progress -e -P"$1" clean test-compile org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"Main.java.html:<td class='uncovered'><pre><span class=''> }</span></pre></td></tr>"
);
checkPitestReport ignoredItems
;;

pitest-header)
mvn --no-transfer-progress -e -P$1 clean test-compile org.pitest:pitest-maven:mutationCoverage;
mvn --no-transfer-progress -e -P"$1" clean test-compile org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"RegexpHeaderCheck.java.html:<td class='covered'><pre><span class='survived'> isMatch = headerLineNo == headerSize</span></pre></td></tr>"
"RegexpHeaderCheck.java.html:<td class='covered'><pre><span class='survived'> || isMatch(line, headerLineNo);</span></pre></td></tr>"
Expand All @@ -77,7 +77,7 @@ pitest-header)
;;

pitest-imports)
mvn --no-transfer-progress -e -P$1 clean test-compile org.pitest:pitest-maven:mutationCoverage;
mvn --no-transfer-progress -e -P"$1" clean test-compile org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"ImportControlLoader.java.html:<td class='covered'><pre><span class='survived'> else if (ALLOW_ELEMENT_NAME.equals(qName) || &#34;disallow&#34;.equals(qName)) {</span></pre></td></tr>"
"PkgImportControl.java.html:<td class='covered'><pre><span class='survived'> if (regex || parent.regex) {</span></pre></td></tr>"
Expand All @@ -87,7 +87,7 @@ pitest-imports)
;;

pitest-common)
mvn --no-transfer-progress -e -P$1 clean test-compile org.pitest:pitest-maven:mutationCoverage;
mvn --no-transfer-progress -e -P"$1" clean test-compile org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"Checker.java.html:<td class='covered'><pre><span class='survived'> if (cacheFile != null &#38;&#38; cacheFile.isInCache(fileName, timestamp)</span></pre></td></tr>"
"DefaultLogger.java.html:<td class='covered'><pre><span class='survived'> closeError = errorStreamOptions == OutputStreamOptions.CLOSE;</span></pre></td></tr>"
Expand All @@ -104,7 +104,7 @@ pitest-common)


pitest-ant)
mvn --no-transfer-progress -e -P$1 clean test-compile org.pitest:pitest-maven:mutationCoverage;
mvn --no-transfer-progress -e -P"$1" clean test-compile org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"CheckstyleAntTask.java.html:<td class='covered'><pre><span class='survived'> if (toFile == null || !useFile) {</span></pre></td></tr>"
"CheckstyleAntTask.java.html:<td class='covered'><pre><span class='survived'> if (toFile == null || !useFile) {</span></pre></td></tr>"
Expand All @@ -116,7 +116,7 @@ pitest-ant)
;;

pitest-indentation)
mvn --no-transfer-progress -e -P$1 clean test-compile org.pitest:pitest-maven:mutationCoverage;
mvn --no-transfer-progress -e -P"$1" clean test-compile org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"AbstractExpressionHandler.java.html:<td class='covered'><pre><span class='survived'> &#38;&#38; curNode.getColumnNo() &#60; realStart.getColumnNo()) {</span></pre></td></tr>"
"AbstractExpressionHandler.java.html:<td class='covered'><pre><span class='survived'> if (colNum == null || thisLineColumn &#60; colNum) {</span></pre></td></tr>"
Expand Down Expand Up @@ -146,7 +146,7 @@ pitest-indentation)
;;

pitest-javadoc)
mvn --no-transfer-progress -e -P$1 clean test-compile org.pitest:pitest-maven:mutationCoverage;
mvn --no-transfer-progress -e -P"$1" clean test-compile org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"AbstractJavadocCheck.java.html:<td class='covered'><pre><span class='survived'> beginJavadocTree(root);</span></pre></td></tr>"
"AbstractJavadocCheck.java.html:<td class='covered'><pre><span class='survived'> finishJavadocTree(root);</span></pre></td></tr>"
Expand All @@ -156,7 +156,7 @@ pitest-javadoc)
;;

pitest-coding)
mvn --no-transfer-progress -e -P$1 clean test-compile org.pitest:pitest-maven:mutationCoverage;
mvn --no-transfer-progress -e -P"$1" clean test-compile org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"FinalLocalVariableCheck.java.html:<td class='covered'><pre><span class='survived'> &#38;&#38; isSameVariables(storedVariable, variable)</span></pre></td></tr>"
"FinalLocalVariableCheck.java.html:<td class='covered'><pre><span class='survived'> == ast.getParent()) {</span></pre></td></tr>"
Expand Down

0 comments on commit 5ea26d6

Please sign in to comment.