saveVersion.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  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. # This file is used to generate the package-info.java class that
  17. # records the version, revision, branch, user, timestamp, and url
  18. unset LANG
  19. unset LC_CTYPE
  20. unset LC_TIME
  21. version=$1
  22. build_dir=$2
  23. user=`whoami | tr '\n\r' '\n'`
  24. date=`date`
  25. cwd=`pwd`
  26. if git rev-parse HEAD 2>/dev/null > /dev/null ; then
  27. revision=`git log -1 --pretty=format:"%H"`
  28. hostname=`hostname`
  29. branch=`git branch | sed -n -e 's/^* //p'`
  30. url="git://${hostname}${cwd}"
  31. elif [ -d .svn ]; then
  32. revision=`svn info | sed -n -e 's/Last Changed Rev: \(.*\)/\1/p'`
  33. url=`svn info | sed -n -e 's/^URL: \(.*\)/\1/p'`
  34. # Get canonical branch (branches/X, tags/X, or trunk)
  35. branch=`echo $url | sed -n -e 's,.*\(branches/.*\)$,\1,p' \
  36. -e 's,.*\(tags/.*\)$,\1,p' \
  37. -e 's,.*trunk$,trunk,p'`
  38. else
  39. revision="Unknown"
  40. branch="Unknown"
  41. url="file://$cwd"
  42. fi
  43. which md5sum > /dev/null
  44. if [ "$?" = "0" ] ; then
  45. srcChecksum=`find src/main/java -name '*.java' | LC_ALL=C sort | xargs md5sum | md5sum | cut -d ' ' -f 1`
  46. else
  47. srcChecksum="Not Available"
  48. fi
  49. mkdir -p $build_dir/org/apache/hadoop
  50. cat << EOF | \
  51. sed -e "s/VERSION/$version/" -e "s/USER/$user/" -e "s/DATE/$date/" \
  52. -e "s|URL|$url|" -e "s/REV/$revision/" \
  53. -e "s|BRANCH|$branch|" -e "s/SRCCHECKSUM/$srcChecksum/" \
  54. > $build_dir/org/apache/hadoop/package-info.java
  55. /*
  56. * Generated by src/saveVersion.sh
  57. */
  58. @HadoopVersionAnnotation(version="VERSION", revision="REV", branch="BRANCH",
  59. user="USER", date="DATE", url="URL",
  60. srcChecksum="SRCCHECKSUM")
  61. package org.apache.hadoop;
  62. EOF