saveVersion.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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`
  24. date=`date`
  25. dir=`pwd`
  26. cwd=`dirname $dir`
  27. if git rev-parse HEAD 2>/dev/null > /dev/null ; then
  28. revision=`git log -1 --pretty=format:"%H" ../`
  29. hostname=`hostname`
  30. branch=`git branch | sed -n -e 's/^* //p'`
  31. url="git://${hostname}${cwd}"
  32. elif [ -d .svn ]; then
  33. revision=`svn info ../ | sed -n -e 's/Last Changed Rev: \(.*\)/\1/p'`
  34. url=`svn info ../ | sed -n -e 's/URL: \(.*\)/\1/p'`
  35. # Get canonical branch (branches/X, tags/X, or trunk)
  36. branch=`echo $url | sed -n -e 's,.*\(branches/.*\)$,\1,p' \
  37. -e 's,.*\(tags/.*\)$,\1,p' \
  38. -e 's,.*trunk$,trunk,p'`
  39. else
  40. revision="Unknown"
  41. branch="Unknown"
  42. url="file://$cwd"
  43. fi
  44. srcChecksum=`find ../ -name '*.java' | grep -v generated-sources | LC_ALL=C sort | xargs md5sum | md5sum | cut -d ' ' -f 1`
  45. mkdir -p $build_dir/generated-sources/version/org/apache/hadoop/yarn/
  46. cat << EOF | \
  47. sed -e "s/VERSION/$version/" -e "s/USER/$user/" -e "s/DATE/$date/" \
  48. -e "s|URL|$url|" -e "s/REV/$revision/" \
  49. -e "s|BRANCH|$branch|" -e "s/SRCCHECKSUM/$srcChecksum/" \
  50. > $build_dir/generated-sources/version/org/apache/hadoop/yarn/package-info.java
  51. /*
  52. * Generated by saveVersion.sh
  53. */
  54. @YarnVersionAnnotation(version="VERSION", revision="REV", branch="BRANCH",
  55. user="USER", date="DATE", url="URL",
  56. srcChecksum="SRCCHECKSUM")
  57. package org.apache.hadoop.yarn;
  58. EOF