Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. #
  4. # Script combines given JUnit XML files into one.
  5. #
  6. # Script assumes that file begins with XML header.
  7. # Script will copy content between <testsuite> tags
  8. # to new file with XML header and <testsuites> tags.
  9. # Script will not affect original files, but it will
  10. # overwrite output file contents. Script searches all
  11. # *.xml files from input directory.
  12. #
  13. # -h - Help
  14. # -i [DIR] - Input directory
  15. # -o [FILE] - Output file
  16. #
  17. # Author: Jarno Tuovinen <[email protected]>
  18. #
  19. # License: MIT
  20. #
  21.  
  22. INPUTDIR=""
  23. OUTPUTFILE=""
  24.  
  25. # arg 1 = input file
  26. function striphead() {
  27. sed 1,$(expr $(grep -m1 -n "<testsuite" $1 | cut -f1 -d:) - 1)d $1
  28. }
  29.  
  30. function error() {
  31. echo "ERROR: $*"
  32. exit -1
  33. }
  34.  
  35. function help() {
  36. echo "$0"
  37. echo "HELP:"
  38. echo -e "\t-h\tHelp"
  39. echo -e "\t-i\tInput dir [mandatory]"
  40. echo -e "\t-o\tOutput file [mandatory]"
  41. exit 0
  42. }
  43.  
  44. # Handle parameters
  45. while getopts "hi:o:" opt; do
  46. case $opt in
  47. h) help ;;
  48. i) INPUTDIR="$OPTARG" ;;
  49. o) OUTPUTFILE="$OPTARG" ;;
  50. \?) error ;;
  51. esac
  52. done
  53.  
  54. # Input dir must be given
  55. if [[ -z ${INPUTDIR} ]]; then
  56. error "Input dir not given"
  57. fi
  58.  
  59. # Output file must be given
  60. if [[ -z ${OUTPUTFILE} ]]; then
  61. error "Output file not given"
  62. fi
  63.  
  64. echo '<?xml version="1.0" encoding="UTF-8"?>' > ${OUTPUTFILE}
  65. echo '<testsuites>' >> ${OUTPUTFILE}
  66. for f in ${INPUTDIR}/*.xml
  67. do
  68. echo $(striphead ${f}) >> ${OUTPUTFILE}
  69. done
  70.  
  71. echo '</testsuites>' >> ${OUTPUTFILE}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement