dist-layout-stitching 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # project.version
  17. VERSION=$1
  18. # project.build.directory
  19. BASEDIR=$2
  20. #hdds.version
  21. HDDS_VERSION=$3
  22. function run()
  23. {
  24. declare res
  25. echo "\$ ${*}"
  26. "${@}"
  27. res=$?
  28. if [[ ${res} != 0 ]]; then
  29. echo
  30. echo "Failed!"
  31. echo
  32. exit "${res}"
  33. fi
  34. }
  35. function findfileindir()
  36. {
  37. declare file="$1"
  38. declare dir="${2:-./share}"
  39. declare count
  40. count=$(find "${dir}" -iname "${file}" | wc -l)
  41. #shellcheck disable=SC2086
  42. echo ${count}
  43. }
  44. function copyifnotexists()
  45. {
  46. declare src="$1"
  47. declare dest="$2"
  48. declare srcname
  49. declare destdir
  50. declare child
  51. declare childpath
  52. if [[ -f "${src}" ]]; then
  53. srcname=${src##*/}
  54. if [[ "${srcname}" != *.jar ||
  55. $(findfileindir "${srcname}") -eq "0" ]]; then
  56. destdir=$(dirname "${dest}")
  57. mkdir -p "${destdir}"
  58. cp -p "${src}" "${dest}"
  59. fi
  60. else
  61. for childpath in "${src}"/*; do
  62. child="${childpath##*/}"
  63. if [[ "${child}" == "doc" ||
  64. "${child}" == "webapps" ]]; then
  65. mkdir -p "${dest}/${child}"
  66. cp -r "${src}/${child}"/* "${dest}/${child}"
  67. continue;
  68. fi
  69. copyifnotexists "${src}/${child}" "${dest}/${child}"
  70. done
  71. fi
  72. }
  73. #Copy all contents as is except the lib.
  74. #for libs check for existence in share directory, if not exist then only copy.
  75. function copy()
  76. {
  77. declare src="$1"
  78. declare dest="$2"
  79. declare child
  80. declare childpath
  81. if [[ -d "${src}" ]]; then
  82. for childpath in "${src}"/*; do
  83. child="${childpath##*/}"
  84. if [[ "${child}" == "share" ]]; then
  85. copyifnotexists "${src}/${child}" "${dest}/${child}"
  86. else
  87. if [[ -d "${src}/${child}" ]]; then
  88. mkdir -p "${dest}/${child}"
  89. cp -pr "${src}/${child}"/* "${dest}/${child}"
  90. else
  91. cp -pr "${src}/${child}" "${dest}/${child}"
  92. fi
  93. fi
  94. done
  95. fi
  96. }
  97. # shellcheck disable=SC2164
  98. ROOT=$(cd "${BASEDIR}"/../..;pwd)
  99. echo
  100. echo "Current directory $(pwd)"
  101. echo
  102. run rm -rf "hadoop-${VERSION}"
  103. run mkdir "hadoop-${VERSION}"
  104. run cd "hadoop-${VERSION}"
  105. run cp -p "${ROOT}/LICENSE.txt" .
  106. run cp -p "${ROOT}/NOTICE.txt" .
  107. run cp -p "${ROOT}/LICENSE-binary" .
  108. run mkdir licenses-binary
  109. run cp -p "${ROOT}/licenses-binary"/* licenses-binary/
  110. run cp -p "${ROOT}/NOTICE-binary" .
  111. run cp -p "${ROOT}/README.txt" .
  112. # Copy hadoop-common first so that it have always have all dependencies.
  113. # Remaining projects will copy only libraries which are not present already in 'share' directory.
  114. run copy "${ROOT}/hadoop-common-project/hadoop-common/target/hadoop-common-${VERSION}" .
  115. run copy "${ROOT}/hadoop-common-project/hadoop-nfs/target/hadoop-nfs-${VERSION}" .
  116. run copy "${ROOT}/hadoop-common-project/hadoop-registry/target/hadoop-registry-${VERSION}" .
  117. run copy "${ROOT}/hadoop-hdfs-project/hadoop-hdfs/target/hadoop-hdfs-${VERSION}" .
  118. run copy "${ROOT}/hadoop-hdfs-project/hadoop-hdfs-nfs/target/hadoop-hdfs-nfs-${VERSION}" .
  119. run copy "${ROOT}/hadoop-hdfs-project/hadoop-hdfs-client/target/hadoop-hdfs-client-${VERSION}" .
  120. run copy "${ROOT}/hadoop-hdfs-project/hadoop-hdfs-native-client/target/hadoop-hdfs-native-client-${VERSION}" .
  121. run copy "${ROOT}/hadoop-hdfs-project/hadoop-hdfs-rbf/target/hadoop-hdfs-rbf-${VERSION}" .
  122. run copy "${ROOT}/hadoop-yarn-project/target/hadoop-yarn-project-${VERSION}" .
  123. run copy "${ROOT}/hadoop-mapreduce-project/target/hadoop-mapreduce-${VERSION}" .
  124. #copy httpfs and kms as is
  125. run cp -pr "${ROOT}/hadoop-hdfs-project/hadoop-hdfs-httpfs/target/hadoop-hdfs-httpfs-${VERSION}"/* .
  126. run cp -pr "${ROOT}/hadoop-common-project/hadoop-kms/target/hadoop-kms-${VERSION}"/* .
  127. # copy client jars as-is
  128. run mkdir -p "share/hadoop/client"
  129. run cp -p "${ROOT}/hadoop-client-modules/hadoop-client-api/target/hadoop-client-api-${VERSION}.jar" share/hadoop/client/
  130. run cp -p "${ROOT}/hadoop-client-modules/hadoop-client-runtime/target/hadoop-client-runtime-${VERSION}.jar" share/hadoop/client/
  131. run cp -p "${ROOT}/hadoop-client-modules/hadoop-client-minicluster/target/hadoop-client-minicluster-${VERSION}.jar" share/hadoop/client/
  132. run copy "${ROOT}/hadoop-tools/hadoop-tools-dist/target/hadoop-tools-dist-${VERSION}" .
  133. run copy "${ROOT}/hadoop-tools/hadoop-dynamometer/hadoop-dynamometer-dist/target/hadoop-dynamometer-dist-${VERSION}" .
  134. echo
  135. echo "Hadoop dist layout available at: ${BASEDIR}/hadoop-${VERSION}"
  136. echo