verify-license-files 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. #!/usr/bin/env bash
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements. See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. ## @description check a file
  18. ## @audience private
  19. ## @stability evolving
  20. ## @replaceable no
  21. ## @param filename
  22. ## @param jarfile
  23. ## @return 0 = destroy verify dir
  24. ## @return 1 = keep verify dir
  25. function process_file
  26. {
  27. declare check=$1
  28. declare fqfn=$2
  29. declare fn
  30. declare keepdir
  31. declare tf
  32. declare count
  33. declare valid
  34. fn=$(basename "${fqfn}")
  35. keepdir=false
  36. valid=0
  37. count=0
  38. unzip -o -d "${WORK_DIR}/${fn}" "${fqfn}" '*'"${check}"'*' >/dev/null 2>&1
  39. while read -r tf; do
  40. ((count = count + 1))
  41. if diff -q "${DIST_DIR}/${check}.txt" "${tf}" >/dev/null 2>&1; then
  42. ((valid = valid + 1))
  43. fi
  44. done < <(find "${WORK_DIR}/${fn}" -name "${check}"'*')
  45. if [[ "${count}" -eq 0 ]]; then
  46. hadoop_error "ERROR: ${fn}: Missing a ${check} file"
  47. elif [[ "${count}" -gt 1 ]]; then
  48. hadoop_error "WARNING: ${fn}: Found ${count} ${check} files (${valid} were valid)"
  49. keepdir=true
  50. fi
  51. if [[ "${valid}" -eq 0 ]] && [[ "${count}" -gt 0 ]]; then
  52. hadoop_error "ERROR: ${fn}: No valid ${check} found"
  53. keepdir=true
  54. fi
  55. if [[ "${keepdir}" = "false" ]]; then
  56. return 0
  57. else
  58. return 1
  59. fi
  60. }
  61. ## @description check a jar
  62. ## @audience private
  63. ## @stability evolving
  64. ## @replaceable no
  65. ## @param jarfile
  66. ## @return 0 - success
  67. ## @return 1 - errors
  68. function process_jar
  69. {
  70. declare fqfn=$1
  71. declare fn
  72. declare keepwork
  73. fn=$(basename "${fqfn}")
  74. keepwork=false
  75. if [[ ! ${fn} =~ hadoop-.*-${PROJ_VERSION} ]]; then
  76. return
  77. fi
  78. mkdir -p "${WORK_DIR}/${fn}"
  79. if ! process_file LICENSE "${fqfn}"; then
  80. keepwork=true
  81. fi
  82. if ! process_file NOTICE "${fqfn}"; then
  83. keepwork=true
  84. fi
  85. if [[ "${keepwork}" = "false" ]]; then
  86. rm -rf "${WORK_DIR:?}/${fn}"
  87. return 0
  88. else
  89. hadoop_error ""
  90. return 1
  91. fi
  92. }
  93. MYNAME="${BASH_SOURCE-$0}"
  94. #shellcheck disable=SC2034
  95. HADOOP_SHELL_EXECNAME="${MYNAME##*/}"
  96. BINDIR=$(cd -P -- "$(dirname -- "${MYNAME}")" >/dev/null && pwd -P)
  97. #shellcheck disable=SC2034
  98. HADOOP_LIBEXEC_DIR="${BINDIR}/../../hadoop-common-project/hadoop-common/src/main/bin"
  99. #shellcheck disable=SC1090
  100. . "${HADOOP_LIBEXEC_DIR}/hadoop-functions.sh"
  101. HADOOP_LIBEXEC_DIR=$(hadoop_abs "${HADOOP_LIBEXEC_DIR}")
  102. BINDIR=$(hadoop_abs "${BINDIR}")
  103. BASEDIR=$(hadoop_abs "${BINDIR}/../..")
  104. pushd "${BASEDIR}" >/dev/null
  105. #shellcheck disable=SC2016
  106. PROJ_VERSION=$(mvn -q -Dexec.executable="echo" -Dexec.args='${project.version}' --non-recursive exec:exec)
  107. popd >/dev/null
  108. DIST_DIR="${BASEDIR}/hadoop-dist/target/hadoop-${PROJ_VERSION}"
  109. WORK_DIR="${BASEDIR}/patchprocess/verify"
  110. rm -rf "${WORK_DIR:?}"
  111. mkdir -p "${WORK_DIR}"
  112. while read -r filename; do
  113. process_jar "${filename}"
  114. ((ret = ret + $? ))
  115. done < <(find "${DIST_DIR}" \
  116. -name "hadoop-*${PROJ_VERSION}*.jar" -or \
  117. -name "hadoop-*${PROJ_VERSION}*.war")
  118. if [[ ${ret} -gt 0 ]]; then
  119. exit 1
  120. fi
  121. exit 0