You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@yetus.apache.org by aw...@apache.org on 2022/05/02 16:07:27 UTC
[yetus] branch main updated: YETUS-1169. improve i18n support (#265)
This is an automated email from the ASF dual-hosted git repository.
aw pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/yetus.git
The following commit(s) were added to refs/heads/main by this push:
new 1ec17771 YETUS-1169. improve i18n support (#265)
1ec17771 is described below
commit 1ec17771a653acb310713ca966d2ade4099cb9c2
Author: Allen Wittenauer <aw...@apache.org>
AuthorDate: Mon May 2 09:07:23 2022 -0700
YETUS-1169. improve i18n support (#265)
Signed-off-by: Nick Dimiduk <nd...@apache.org>
---
precommit/pom.xml | 1 +
precommit/src/main/shell/core.d/change-analysis.sh | 2 +-
precommit/src/main/shell/plugins.d/codespell.sh | 17 ++++++++++-------
precommit/src/main/shell/plugins.d/detsecrets.sh | 14 ++------------
precommit/src/main/shell/plugins.d/jshint.sh | 12 +++++++-----
precommit/src/main/shell/smart-apply-patch.sh | 10 ++--------
"precommit/src/test/resources/i18n/\303\237.json" | 4 ++++
"precommit/src/test/resources/i18n/\303\244.xml" | 7 +++++++
"precommit/src/test/resources/i18n/\303\247.yaml" | 6 ++++++
9 files changed, 40 insertions(+), 33 deletions(-)
diff --git a/precommit/pom.xml b/precommit/pom.xml
index 7a1fc4a7..dde2564f 100644
--- a/precommit/pom.xml
+++ b/precommit/pom.xml
@@ -158,6 +158,7 @@
<excludes>
<exclude>src/main/python/unit-test-filter-file.example</exclude>
<exclude>src/test/resources/brokenfiles/**</exclude>
+ <exclude>src/test/resources/i18n/**</exclude>
</excludes>
</configuration>
</plugin>
diff --git a/precommit/src/main/shell/core.d/change-analysis.sh b/precommit/src/main/shell/core.d/change-analysis.sh
index d75cdb12..a5e1e946 100755
--- a/precommit/src/main/shell/core.d/change-analysis.sh
+++ b/precommit/src/main/shell/core.d/change-analysis.sh
@@ -118,7 +118,7 @@ function exclude_paths_from_changed_files
for p in "${EXCLUDE_PATHS[@]}"; do
if [[ "${f}" =~ ${p} ]]; then
strip=true
- echo "${f}" >> "${PATCH_DIR}/excluded.txt"
+ printf "%b\n" "${f}" >> "${PATCH_DIR}/excluded.txt"
break
fi
done
diff --git a/precommit/src/main/shell/plugins.d/codespell.sh b/precommit/src/main/shell/plugins.d/codespell.sh
index afddfde9..f4f75a3e 100755
--- a/precommit/src/main/shell/plugins.d/codespell.sh
+++ b/precommit/src/main/shell/plugins.d/codespell.sh
@@ -67,6 +67,9 @@ function codespell_logic
declare repostatus=$1
declare -a codespellargs
declare i
+ declare tmpfile
+
+ tmpfile="${PATCH_DIR}/codespell.$$"
pushd "${BASEDIR}" >/dev/null || return 1
@@ -74,22 +77,22 @@ function codespell_logic
codespellargs=("--exclude-file" "${CODESPELL_X_FILE}")
fi
+ printf "^%b:\n" "${CHANGED_FILES[@]}" > "${tmpfile}"
+
# specifically add ./ because otherwise the .codespellrc file gets weird
"${CODESPELL}" \
--disable-colors \
--interactive 0 \
--quiet-level 2 \
"${codespellargs[@]}" \
- "./${i}" \
+ "." \
| "${SED}" -e 's,^./,,g' \
>> "${PATCH_DIR}/${repostatus}-codespell-tmp.txt"
- for i in "${CHANGED_FILES[@]}"; do
- "${GREP}" -E "^${i}:" \
- "${PATCH_DIR}/${repostatus}-codespell-tmp.txt" \
- >> "${PATCH_DIR}/${repostatus}-codespell-result.txt"
- done
-
+ "${GREP}" -E -f "${tmpfile}" \
+ "${PATCH_DIR}/${repostatus}-codespell-tmp.txt" \
+ >> "${PATCH_DIR}/${repostatus}-codespell-result.txt"
+ rm "${tmpfile}"
popd > /dev/null || return 1
}
diff --git a/precommit/src/main/shell/plugins.d/detsecrets.sh b/precommit/src/main/shell/plugins.d/detsecrets.sh
index f97691c9..9950a88c 100755
--- a/precommit/src/main/shell/plugins.d/detsecrets.sh
+++ b/precommit/src/main/shell/plugins.d/detsecrets.sh
@@ -94,20 +94,11 @@ function detsecrets_calcdiffs
function detsecrets_convert_json_to_flat
{
declare repostatus=$1
- declare filename
declare tmpfile
tmpfile="${PATCH_DIR}/detsecrets.$$"
- for filename in "${CHANGED_FILES[@]}"; do
- echo "${filename}" >> "${tmpfile}"
- done
-
- if [[ -f "${PATCH_DIR}/excluded.txt" ]]; then
- stripcmd=("${GREP}" "-v" "-f" "${PATCH_DIR}/excluded.txt")
- else
- stripcmd=("cat")
- fi
+ printf "^%b:\n" "${CHANGED_FILES[@]}" > "${tmpfile}"
# rip apart the detect-secrets json and make it a colon delimited file
# to make it easier to parse. Theoretically, python or python3 should
@@ -117,8 +108,7 @@ function detsecrets_convert_json_to_flat
"${pythonexec}" "${BINDIR}/plugins.d/detsecrets_parse.py" \
"${PATCH_DIR}/${repostatus}-detsecrets-result.json" \
"${DETSECRETS_HASHFILE}" \
- | "${GREP}" "-f" "${tmpfile}" \
- | "${stripcmd[@]}" \
+ | "${GREP}" -E -f "${tmpfile}" \
> "${PATCH_DIR}/${repostatus}-detsecrets-result.txt"
rm "${tmpfile}"
diff --git a/precommit/src/main/shell/plugins.d/jshint.sh b/precommit/src/main/shell/plugins.d/jshint.sh
index b41aefbe..ec15cdd2 100755
--- a/precommit/src/main/shell/plugins.d/jshint.sh
+++ b/precommit/src/main/shell/plugins.d/jshint.sh
@@ -95,9 +95,11 @@ EOF
function jshint_logic
{
declare repostatus=$1
- declare j
declare full="${PATCH_DIR}/${repostatus}-jshint-result.full.txt"
declare filter="${PATCH_DIR}/${repostatus}-jshint-result.txt"
+ declare tmpfile
+
+ tmpfile="${PATCH_DIR}/jshint.$$"
pushd "${BASEDIR}" >/dev/null || return 1
"${JSHINT}" \
@@ -106,13 +108,13 @@ function jshint_logic
. \
> "${full}"
+ printf "^%b:\n" "${CHANGED_FILES[@]}" > "${tmpfile}"
+
# pull out the files we care about
- for j in "${CHANGED_FILES[@]}"; do
- "${GREP}" "^${j}:" "${full}" \
- >> "${filter}"
- done
+ "${GREP}" -E -f "${tmpfile}" "${full}" > "${filter}"
popd > /dev/null || return 1
+ rm "${tmpfile}"
}
function jshint_preapply
diff --git a/precommit/src/main/shell/smart-apply-patch.sh b/precommit/src/main/shell/smart-apply-patch.sh
index df318327..2853b316 100755
--- a/precommit/src/main/shell/smart-apply-patch.sh
+++ b/precommit/src/main/shell/smart-apply-patch.sh
@@ -265,10 +265,7 @@ function patch_reports
find_changed_files
if [[ -n "${FILEREPORT}" ]]; then
- : > "${FILEREPORT}"
- for i in "${CHANGED_FILES[@]}"; do
- echo "${i}" >> "${FILEREPORT}"
- done
+ printf "%b\n" "${CHANGED_FILES[@]}" > "${FILEREPORT}"
fi
if [[ -n "${MODULEREPORT}" ]] || [[ -n "${UNIONREPORT}" ]]; then
@@ -281,10 +278,7 @@ function patch_reports
find_changed_modules
if [[ -n "${MODULEREPORT}" ]]; then
- : > "${MODULEREPORT}"
- for i in "${CHANGED_MODULES[@]}"; do
- echo "${i}" >> "${MODULEREPORT}"
- done
+ printf "%b\n" "${CHANGED_MODULES[@]}" > "${MODULEREPORT}"
fi
if [[ -n "${UNIONREPORT}" ]]; then
diff --git "a/precommit/src/test/resources/i18n/\303\237.json" "b/precommit/src/test/resources/i18n/\303\237.json"
new file mode 100644
index 00000000..e035b110
--- /dev/null
+++ "b/precommit/src/test/resources/i18n/\303\237.json"
@@ -0,0 +1,4 @@
+{
+ "test1": "test1",
+ "test2": "test2"
+}
diff --git "a/precommit/src/test/resources/i18n/\303\244.xml" "b/precommit/src/test/resources/i18n/\303\244.xml"
new file mode 100644
index 00000000..63e1043a
--- /dev/null
+++ "b/precommit/src/test/resources/i18n/\303\244.xml"
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ test
+
+-->
+<test/>
diff --git "a/precommit/src/test/resources/i18n/\303\247.yaml" "b/precommit/src/test/resources/i18n/\303\247.yaml"
new file mode 100644
index 00000000..c0234d67
--- /dev/null
+++ "b/precommit/src/test/resources/i18n/\303\247.yaml"
@@ -0,0 +1,6 @@
+# test
+---
+
+test:
+ - 1
+ - 2