You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@yetus.apache.org by aw...@apache.org on 2020/02/18 19:17:00 UTC

[yetus] branch master updated: YETUS-936 test-patch.sh does not do gradle (#88)

This is an automated email from the ASF dual-hosted git repository.

aw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yetus.git


The following commit(s) were added to refs/heads/master by this push:
     new a18ce88  YETUS-936 test-patch.sh does not do gradle (#88)
a18ce88 is described below

commit a18ce885dc57c16ede438914d8e4e2e4b1d2186d
Author: Allen Wittenauer <aw...@apache.org>
AuthorDate: Tue Feb 18 11:16:53 2020 -0800

    YETUS-936 test-patch.sh does not do gradle (#88)
    
    Signed-off-by: Sean Busbey <bu...@apache.org>
---
 .../in-progress/precommit-advanced.html.md         |   3 +
 precommit/src/main/shell/core.d/01-common.sh       |  36 ++++++-
 .../src/main/shell/test-patch.d/checkstyle.sh      |  66 +++++++++++-
 precommit/src/main/shell/test-patch.d/gradle.sh    | 112 +++++----------------
 precommit/src/main/shell/test-patch.d/junit.sh     |  12 +--
 precommit/src/main/shell/test-patch.sh             |  28 ++++++
 6 files changed, 153 insertions(+), 104 deletions(-)

diff --git a/asf-site-src/source/documentation/in-progress/precommit-advanced.html.md b/asf-site-src/source/documentation/in-progress/precommit-advanced.html.md
index 4e5a68e..e0ff7bd 100644
--- a/asf-site-src/source/documentation/in-progress/precommit-advanced.html.md
+++ b/asf-site-src/source/documentation/in-progress/precommit-advanced.html.md
@@ -83,6 +83,9 @@ Similarly, there are other functions that may be defined during the test-patch r
 * pluginname\_precheck
   * executed prior to the patch being applied but after the git repository is setup.  Returning a fail status here will exit test-patch.
 
+* pluginname\_postcleanup
+  * executed on test-patch shutdown.
+
 * pluginname\_patchfile
   * executed prior to the patch being applied but after the git repository is setup. This step is intended to perform tests on the content of the patch itself.
 
diff --git a/precommit/src/main/shell/core.d/01-common.sh b/precommit/src/main/shell/core.d/01-common.sh
index 054d1cc..79d9fcd 100755
--- a/precommit/src/main/shell/core.d/01-common.sh
+++ b/precommit/src/main/shell/core.d/01-common.sh
@@ -857,4 +857,38 @@ function delete_parameter
   fi
 
   yetus_del_array_element PARAMETER_TRACKER "${i}"
-}
\ No newline at end of file
+}
+
+## @description  unescape common HTML entities
+## @audience     public
+## @stability    stable
+## @replaceable  no
+## @param        parameter
+function unescape_html
+{
+  declare str=$1
+
+  str="${str//&amp;/&}"
+  str="${str//&quot;/\"}"
+  str="${str//&lt;/<}"
+  str="${str//&gt;/>}"
+  str="${str//&apos;/\'}"
+  echo "${str}"
+}
+
+## @description  escape common HTML entities
+## @audience     public
+## @stability    stable
+## @replaceable  no
+## @param        parameter
+function escape_html
+{
+  declare str=$1
+
+  str="${str//&/&amp;}"
+  str="${str//\"/&quot;}"
+  str="${str//</&lt;}"
+  str="${str//>/&gt;}"
+  str="${str//\'/&apos;}"
+  echo "${str}"
+}
diff --git a/precommit/src/main/shell/test-patch.d/checkstyle.sh b/precommit/src/main/shell/test-patch.d/checkstyle.sh
index bec3efd..270f265 100755
--- a/precommit/src/main/shell/test-patch.d/checkstyle.sh
+++ b/precommit/src/main/shell/test-patch.d/checkstyle.sh
@@ -34,6 +34,14 @@ function checkstyle_filefilter
       add_test checkstyle
     fi
   fi
+
+  if [[ ${BUILDTOOL} == gradle ]]; then
+    if [[ ${filename} =~ \.java$
+       || ${filename} =~ config/checkstyle/checkstyle.xml
+       || ${filename} =~ config/checkstyle/suppressions.xml ]]; then
+      add_test checkstyle
+    fi
+  fi
 }
 
 ## @description  usage help for checkstyle
@@ -149,11 +157,14 @@ function checkstyle_runner
   declare logfile
   declare modulesuffix
   declare cmd
+  declare line
+  declare newline
   declare logline
   declare text
   declare linenum
   declare codeline
   declare cmdresult
+  declare -a filelist
 
   # first, let's clear out any previous run information
   modules_reset
@@ -167,7 +178,7 @@ function checkstyle_runner
     fn=$(module_file_fragment "${MODULE[${i}]}")
     modulesuffix=$(basename "${MODULE[${i}]}")
     output="${PATCH_DIR}/${repostatus}-checkstyle-${fn}.txt"
-    logfile="${PATCH_DIR}/maven-${repostatus}-checkstyle-${fn}.txt"
+    logfile="${PATCH_DIR}/buildtool-${repostatus}-checkstyle-${fn}.txt"
 
     buildtool_cwd "${i}"
 
@@ -186,6 +197,11 @@ function checkstyle_runner
           ${CHECKSTYLE_OPTIONS} \
           ${MODULEEXTRAPARAM[${i}]//@@@MODULEFN@@@/${fn}} -Ptest-patch"
       ;;
+      gradle)
+        cmd="${GRADLEW} ${GRADLEW_ARGS[*]} \
+           checkstyleMain checkstyleTest \
+          ${MODULEEXTRAPARAM[${i}]//@@@MODULEFN@@@/${fn}}"
+      ;;
       *)
         UNSUPPORTED_TEST=true
         return 0
@@ -202,10 +218,50 @@ function checkstyle_runner
     echo_and_redirect "${logfile}" ${cmd}
     cmdresult=$?
 
-    "${SED}" -e 's,^\[ERROR\] ,,g' -e 's,^\[WARN\] ,,g' "${logfile}" \
-      | ${GREP} ^/ \
-      | ${SED} -e "s,${BASEDIR},.,g" \
-      > "${tmp}"
+    case ${BUILDTOOL} in
+      ant)
+        "${SED}" -e 's,^\[ERROR\] ,,g' -e 's,^\[WARN\] ,,g' "${logfile}" \
+          | "${GREP}" ^/ \
+          | "${SED}" -e "s,${BASEDIR},.,g" \
+          > "${tmp}"
+        ;;
+      maven)
+        "${SED}" -e 's,^\[ERROR\] ,,g' -e 's,^\[WARN\] ,,g' "${logfile}" \
+          | "${GREP}" ^/ \
+          | "${SED}" -e "s,${BASEDIR},.,g" \
+          > "${tmp}"
+          ;;
+      gradle)
+         # find -path isn't quite everywhere yet...
+
+          while read -r line; do
+              if [[ ${line} =~ build/reports/checkstyle ]]; then
+                filelist+=("${line}")
+              fi
+          done < <(find "${BASEDIR}" -name 'main.xml' -o -name 'test.xml')
+
+          touch "${tmp}"
+
+          if [[ ${#filelist[@]} -gt 0 ]]; then
+            # convert xml to maven-like output
+            while read -r line; do
+              if [[ $line =~ ^\<file ]]; then
+                fn=$(echo "$line" | "${SED}" -E 's,^.+name="([^"]+)".+$,\1,' | "${SED}" -e "s,${BASEDIR},.,g")
+              elif [[ $line =~ ^\<error ]]; then
+                if [[ $line =~ column ]]; then
+                  newline=$(echo "$line" | "${SED}" -E 's,^.+line="([0-9]+)".*column="([0-9]+)".*severity="([a-z]+)".*message="([^"]+)".+$,__FN__:\1\:\2:\4,')
+                else
+                  newline=$(echo "$line" | "${SED}" -E 's,^.+line="([0-9]+)".*severity="([a-z]+)".*message="([^"]+)".+$,__FN__:\1:\3,')
+                fi
+
+                newline=$(unescape_html "${newline}")
+                newline=$(echo "$newline" | "${SED}" -e "s,__FN__,$fn,")
+                echo "$newline" >> "${tmp}"
+              fi
+            done < <(cat "${filelist[@]}")
+          fi
+          ;;
+    esac
 
     if [[ "${modulesuffix}" == . ]]; then
       modulesuffix=root
diff --git a/precommit/src/main/shell/test-patch.d/gradle.sh b/precommit/src/main/shell/test-patch.d/gradle.sh
index 4946360..81f9966 100755
--- a/precommit/src/main/shell/test-patch.d/gradle.sh
+++ b/precommit/src/main/shell/test-patch.d/gradle.sh
@@ -19,69 +19,48 @@
 
 add_build_tool gradle
 
-declare -a GRADLE_ARGS=()
-
-function gradle_usage
-{
-  yetus_add_option "--gradle-cmd=<cmd>" "The 'gradle' command to use (default 'gradle')"
-  yetus_add_option "--gradlew-cmd=<cmd>" "The 'gradlew' command to use (default 'basedir/gradlew')"
-}
+declare -a GRADLEW_ARGS=()
 
 function gradle_parse_args
 {
-  local i
-
-  for i in "$@"; do
-    case ${i} in
-      --gradle-cmd=*)
-        delete_parameter "${i}"
-        GRADLE=${i#*=}
-      ;;
-      --gradlew-cmd=*)
-        delete_parameter "${i}"
-        GRADLEW=${i#*=}
-      ;;
-    esac
-  done
-
-  # if we requested offline, pass that to mvn
+  # if we requested offline, pass that to gradle
   if [[ ${OFFLINE} == "true" ]]; then
-    GRADLE_ARGS=("${GRADLE_ARGS[@]}" --offline)
+    GRADLEW_ARGS+=("--offline")
   fi
 
-  GRADLE=${GRADLE:-gradle}
   GRADLEW=${GRADLEW:-"${BASEDIR}/gradlew"}
 }
 
 function gradle_precheck
 {
   declare gradle_version
-  if ! verify_command gradle "${GRADLE}"; then
-    add_vote_table -1 gradle "ERROR: gradle is not available."
-    return 1
+
+  pushd "${BASEDIR}" >/dev/null || return 1
+  if ! verify_command gradle "${GRADLEW}"; then
+      add_vote_table -1 gradle "ERROR: gradlew is not available."
+      popd >/dev/null || return 1
+      return 1
   fi
+
   # finally let folks know what version they'll be dealing with.
-  gradle_version=$("${GRADLE}" --version 2>/dev/null | grep Gradle 2>/dev/null)
+  gradle_version=$("${GRADLEW}" --version 2>/dev/null | grep ^Gradle 2>/dev/null)
+  popd >/dev/null || return 1
+
   add_version_data gradle "${gradle_version##* }"
   return 0
 }
 
-function gradle_initialize
+function gradle_postcleanup
 {
-  if [[ "${BUILDTOOL}" = gradle ]]; then
-    # shellcheck disable=SC2034
-    BUILDTOOLCWD=basedir
-  fi
 
-  # we need to do this before docker kicks in
-  if [[ -e "${HOME}/.gradle"
-     && ! -d "${HOME}/.gradle" ]]; then
-    yetus_error "ERROR: ${HOME}/.gradle is not a directory."
-    return 1
-  elif [[ ! -e "${HOME}/.gradle" ]]; then
-    yetus_debug "Creating ${HOME}/.gradle"
-    mkdir -p "${HOME}/.gradle"
-  fi
+  pushd "${BASEDIR}" >/dev/null || return 1
+  # shellcheck disable=SC2046
+  echo_and_redirect \
+      "${PATCH_DIR}/gradle-postcleanup-log.txt" \
+      $("${BUILDTOOL}_executor") \
+      --stop
+  popd >/dev/null || return 1
+  return 0
 }
 
 function gradle_filefilter
@@ -90,8 +69,7 @@ function gradle_filefilter
 
   if [[ ${filename} =~ build\.gradle$
      || ${filename} =~ gradlew$
-     || ${filename} =~ gradle\.properties$
-     || ${filename} =~ wrapper\.gradle$ ]]; then
+     || ${filename} =~ gradle\.properties$ ]]; then
     yetus_debug "tests/compile: ${filename}"
     add_test compile
   fi
@@ -104,44 +82,7 @@ function gradle_buildfile
 
 function gradle_executor
 {
-  echo "${GRADLEW}" "${GRADLE_ARGS[@]}"
-}
-
-## @description  Bootstrap gradle
-## @audience     private
-## @stability    evolving
-## @replaceable  no
-## @return       0 on success
-## @return       1 on failure
-function gradle_precompile
-{
-  declare repostatus=$1
-  declare result=0
-
-  if [[ ${BUILDTOOL} != gradle ]]; then
-    return 0
-  fi
-
-  if [[ "${repostatus}" = branch ]]; then
-    # shellcheck disable=SC2153
-    big_console_header "gradle boostrap: ${PATCH_BRANCH}"
-  else
-    big_console_header "gradle bootstrap: ${BUILDMODE}"
-  fi
-
-  personality_modules "${repostatus}" gradleboot
-
-  pushd "${BASEDIR}" >/dev/null || return 1
-  echo_and_redirect "${PATCH_DIR}/${repostatus}-gradle-bootstrap.txt" gradle -b bootstrap.gradle
-  popd >/dev/null || return 1
-
-  modules_workers "${repostatus}" gradleboot
-  result=$?
-  modules_messages "${repostatus}" gradleboot true
-  if [[ ${result} != 0 ]]; then
-    return 1
-  fi
-  return 0
+  echo "${GRADLEW}" "${GRADLEW_ARGS[@]}"
 }
 
 ## @description  Helper for generic_logfilter
@@ -290,8 +231,3 @@ function gradle_builtin_personality_file_tests
     add_test findbugs
   fi
 }
-
-function gradle_docker_support
-{
-  DOCKER_EXTRAARGS+=("-v" "${HOME}/.gradle:/home/${USER_NAME}/.gradle")
-}
diff --git a/precommit/src/main/shell/test-patch.d/junit.sh b/precommit/src/main/shell/test-patch.d/junit.sh
index 28fa60d..48b3b96 100755
--- a/precommit/src/main/shell/test-patch.d/junit.sh
+++ b/precommit/src/main/shell/test-patch.d/junit.sh
@@ -195,11 +195,7 @@ EOF
         "${failures}" \
         "${ela}"
       if [[ "${failures}" == 1 ]]; then
-        msg="${msg//&/&amp;}"
-        msg="${msg//</&lt;}"
-        msg="${msg//>/&gt;}"
-        msg="${msg//\"/&quot;}"
-        msg="${msg//\'/&apos;}"
+        msg=$(escape_html "${msg}")
         printf "<failure message=\"%s\">" "${msg}"
         j=0
         until [[ $j -eq ${#TP_FOOTER_TABLE[@]} ]]; do
@@ -214,11 +210,7 @@ EOF
                         "${SED}" -e "s,@@BASE@@,${url},g")
             fi
             if [[ "${footsub// }" == "${subs}" ]]; then
-              footcomment="${footcomment//&/&amp;}"
-              footcomment="${footcomment//</&lt;}"
-              footcomment="${footcomment//>/&gt;}"
-              footcomment="${footcomment//\"/&quot;}"
-              footcomment="${footcomment//\'/&apos;}"
+              footcomment=$(escape_html "${footcomment}")
               echo "${footcomment}"
             fi
           fi
diff --git a/precommit/src/main/shell/test-patch.sh b/precommit/src/main/shell/test-patch.sh
index 2ef5b07..58d011d 100755
--- a/precommit/src/main/shell/test-patch.sh
+++ b/precommit/src/main/shell/test-patch.sh
@@ -3220,6 +3220,32 @@ function prechecks
   done
 }
 
+## @description perform prechecks
+## @audience private
+## @stability evolving
+## @return   exits on failure
+function postcleanups
+{
+  declare plugin
+  declare result=0
+
+  for plugin in ${BUILDTOOL} "${NEEDED_TESTS[@]}" "${TESTFORMATS[@]}"; do
+    verify_patchdir_still_exists
+
+    if declare -f "${plugin}_postcleanup" >/dev/null 2>&1; then
+
+      yetus_debug "Running ${plugin}_postcleanup"
+      "${plugin}_postcleanup"
+
+      (( result = result + $? ))
+      if [[ ${result} != 0 ]] ; then
+        bugsystem_finalreport 1
+        cleanup_and_exit 1
+      fi
+    fi
+  done
+}
+
 ## @description import core library routines
 ## @audience private
 ## @stability evolving
@@ -3319,6 +3345,8 @@ runtests
 
 stop_coprocessors
 
+postcleanups
+
 finish_vote_table
 
 finish_footer_table