dist-layout-stitching 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. function run()
  21. {
  22. declare res
  23. echo "\$ ${*}"
  24. "${@}"
  25. res=$?
  26. if [[ ${res} != 0 ]]; then
  27. echo
  28. echo "Failed!"
  29. echo
  30. exit "${res}"
  31. fi
  32. }
  33. function findfileindir()
  34. {
  35. declare file="$1"
  36. declare dir="${2:-./share}"
  37. declare count
  38. count=$(find "${dir}" -iname "${file}" | wc -l)
  39. #shellcheck disable=SC2086
  40. echo ${count}
  41. }
  42. function copyifnotexists()
  43. {
  44. declare src="$1"
  45. declare dest="$2"
  46. declare srcname
  47. declare destdir
  48. declare child
  49. declare childpath
  50. if [[ -f "${src}" ]]; then
  51. srcname=${src##*/}
  52. if [[ "${srcname}" != *.jar ||
  53. $(findfileindir "${srcname}") -eq "0" ]]; then
  54. destdir=$(dirname "${dest}")
  55. mkdir -p "${destdir}"
  56. cp -p "${src}" "${dest}"
  57. fi
  58. else
  59. for childpath in "${src}"/*; do
  60. child="${childpath##*/}"
  61. if [[ "${child}" == "doc" ||
  62. "${child}" == "webapps" ]]; then
  63. mkdir -p "${dest}/${child}"
  64. cp -r "${src}/${child}"/* "${dest}/${child}"
  65. continue;
  66. fi
  67. copyifnotexists "${src}/${child}" "${dest}/${child}"
  68. done
  69. fi
  70. }
  71. #Copy all contents as is except the lib.
  72. #for libs check for existence in share directory, if not exist then only copy.
  73. function copy()
  74. {
  75. declare src="$1"
  76. declare dest="$2"
  77. declare child
  78. declare childpath
  79. if [[ -d "${src}" ]]; then
  80. for childpath in "${src}"/*; do
  81. child="${childpath##*/}"
  82. if [[ "${child}" == "share" ]]; then
  83. copyifnotexists "${src}/${child}" "${dest}/${child}"
  84. else
  85. if [[ -d "${src}/${child}" ]]; then
  86. mkdir -p "${dest}/${child}"
  87. cp -pr "${src}/${child}"/* "${dest}/${child}"
  88. else
  89. cp -pr "${src}/${child}" "${dest}/${child}"
  90. fi
  91. fi
  92. done
  93. fi
  94. }
  95. # shellcheck disable=SC2164
  96. ROOT=$(cd "${BASEDIR}"/../..;pwd)
  97. echo
  98. echo "Current directory $(pwd)"
  99. echo
  100. run rm -rf "hadoop-${VERSION}"
  101. run mkdir "hadoop-${VERSION}"
  102. run cd "hadoop-${VERSION}"
  103. run cp -p "${ROOT}/LICENSE.txt" .
  104. run cp -p "${ROOT}/NOTICE.txt" .
  105. run cp -p "${ROOT}/README.txt" .
  106. # Copy hadoop-common first so that it have always have all dependencies.
  107. # Remaining projects will copy only libraries which are not present already in 'share' directory.
  108. run copy "${ROOT}/hadoop-common-project/hadoop-common/target/hadoop-common-${VERSION}" .
  109. run copy "${ROOT}/hadoop-common-project/hadoop-nfs/target/hadoop-nfs-${VERSION}" .
  110. run copy "${ROOT}/hadoop-hdfs-project/hadoop-hdfs/target/hadoop-hdfs-${VERSION}" .
  111. run copy "${ROOT}/hadoop-hdfs-project/hadoop-hdfs-nfs/target/hadoop-hdfs-nfs-${VERSION}" .
  112. run copy "${ROOT}/hadoop-hdfs-project/hadoop-hdfs-client/target/hadoop-hdfs-client-${VERSION}" .
  113. run copy "${ROOT}/hadoop-hdfs-project/hadoop-hdfs-native-client/target/hadoop-hdfs-native-client-${VERSION}" .
  114. run copy "${ROOT}/hadoop-hdfs-project/hadoop-hdfs-rbf/target/hadoop-hdfs-rbf-${VERSION}" .
  115. run copy "${ROOT}/hadoop-yarn-project/target/hadoop-yarn-project-${VERSION}" .
  116. run copy "${ROOT}/hadoop-mapreduce-project/target/hadoop-mapreduce-${VERSION}" .
  117. run copy "${ROOT}/hadoop-tools/hadoop-tools-dist/target/hadoop-tools-dist-${VERSION}" .
  118. #copy httpfs and kms as is
  119. run cp -pr "${ROOT}/hadoop-hdfs-project/hadoop-hdfs-httpfs/target/hadoop-hdfs-httpfs-${VERSION}"/* .
  120. run cp -pr "${ROOT}/hadoop-common-project/hadoop-kms/target/hadoop-kms-${VERSION}"/* .
  121. # copy client jars as-is
  122. run mkdir -p "share/hadoop/client"
  123. run cp -p "${ROOT}/hadoop-client-modules/hadoop-client-api/target/hadoop-client-api-${VERSION}.jar" share/hadoop/client/
  124. run cp -p "${ROOT}/hadoop-client-modules/hadoop-client-runtime/target/hadoop-client-runtime-${VERSION}.jar" share/hadoop/client/
  125. run cp -p "${ROOT}/hadoop-client-modules/hadoop-client-minicluster/target/hadoop-client-minicluster-${VERSION}.jar" share/hadoop/client/
  126. echo
  127. echo "Hadoop dist layout available at: ${BASEDIR}/hadoop-${VERSION}"
  128. echo