"Jar-Hell" - or how do I find a Java-Class in a folder full of Jar-Archives

There you go

  1. #!/bin/sh
  2.  
  3. ########################################################################
  4. ## Scans all jar files within a directory (recursively) for a class
  5. ## name
  6. ## Usage: findClass /tmp/ MyFunnyClass
  7. ########################################################################
  8.  
  9. black='\E[30;47m'
  10. red='\E[31;40m\033[1m'
  11. green='\E[32;47m'
  12. yellow='\E[33;40m'
  13. blue='\E[34;40m\033[1m'
  14. magenta='\E[35;47m'
  15. cyan='\E[36;47m'
  16. white='\E[37;47m'
  17. alias Reset="tput sgr0"
  18.  
  19. cecho ()
  20. {
  21. local default_msg=" "
  22. message=${1:-$default_msg} # Defaults to default message.
  23. color=${2:-$black} # Defaults to black, if not specified.
  24. echo -e -n "$color"
  25. echo -n "$message"
  26. Reset # Reset to normal.
  27. return
  28. }
  29.  
  30. clsln()
  31. {
  32. fillLine " ";
  33. }
  34.  
  35. fillLine()
  36. {
  37. let tw=$(tput cols)-1;
  38. for (( c=0 ; c < $tw; c++))
  39. do
  40. echo -n "$1";
  41. done
  42. echo -e -n '\r'
  43. }
  44.  
  45. echo
  46. echo -n Scanning Folder:
  47. cecho "$1" $yellow
  48. echo -n for Class:
  49. cecho "$2" $yellow
  50. echo
  51.  
  52. fillLine "."
  53. echo
  54. for i in $(find $1 -name '*jar');
  55. do
  56. clsln;
  57. echo -n -e "Scanning :";
  58. cecho $i $blue
  59. echo -n -e '\r';
  60.  
  61. out=$(jar vft $i | egrep $2);
  62.  
  63. if [ "$out" ]
  64. then
  65. clsln;
  66. fillLine "*"
  67. echo
  68. echo -n -e 'Possble hit in file:'
  69. cecho $i $blue
  70. echo
  71. echo "$out" $red
  72. echo
  73. fillLine "*"
  74. echo
  75. echo
  76. fi
  77. done;
  78. clsln;
  79. echo;