You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

createPluginJar.sh 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. # This script will create a plugin jar file for a given plugin.
  3. VALID_EXTS="class,png,exe,dll,html,css,js,gif,py"
  4. if [ "${1}" = "" -o "${2}" = "" ]; then
  5. echo "Usage Example: ${0} com.dmdirc.addons.windowstatus WindowStatusPlugin"
  6. echo "The above would create WindowStatusPlugin.jar in the plugins/ folder of the current dir"
  7. exit;
  8. fi
  9. destdir=${PWD}
  10. srcdir=${PWD}/modules/plugins/
  11. pluginname=${1}
  12. foldername=${pluginname//.//}
  13. newer=`find ${srcdir}/src/${foldername} -type f -newer ${destdir}/plugins/${2}.jar 2>&1 | wc -l`
  14. if [ $newer -eq 0 ]; then
  15. echo "${2}.jar appears to be up-to-date";
  16. exit 0;
  17. fi
  18. echo "Creating ${2}.jar for ${pluginname} (${foldername})"
  19. if [ ! -e modules/plugins/src/${foldername}/plugin.config ]; then
  20. echo "no plugin.config found";
  21. exit 0;
  22. fi
  23. #echo "looking for classes"
  24. TMPDIR=`mktemp -d`
  25. #echo "Using temp dir: ${TMPDIR}"
  26. cd $TMPDIR
  27. mkdir META-INF
  28. if [ -e "${srcdir}/src/${foldername}/plugin.config" ]; then
  29. cp "${srcdir}/src/${foldername}/plugin.config" META-INF/
  30. fi;
  31. if [ -d "${srcdir}/src/${foldername}/licences/" ]; then
  32. cp -r "${srcdir}/src/${foldername}/licences/" META-INF/licences/
  33. fi;
  34. # Do the same for plugin.config
  35. # This is rudimentary, it a version: section already exists (eg to specify
  36. # friendlyversion) then it won't add the number= key.
  37. if [ -e META-INF/plugin.config ]; then
  38. VERSIONLINE=`grep -n "version:$" META-INF/plugin.config | cut -f 1 -d ':'`
  39. if [ -z "$VERSIONLINE" ]; then
  40. sed 's/keysections:/keysections:\n version/g' META-INF/plugin.config > META-INF/plugin.config.temp
  41. rm -Rf META-INF/plugin.config
  42. mv META-INF/plugin.config.temp META-INF/plugin.config
  43. fi;
  44. GIT=`which git`
  45. REV=$(${GIT} --git-dir "${srcdir}/.git" describe --tags `${GIT} --git-dir "${srcdir}/.git" rev-list --max-count=1 HEAD -- "src/${foldername}"`);
  46. echo "" >> META-INF/plugin.config
  47. echo "" >> META-INF/plugin.config
  48. echo "version:" >> META-INF/plugin.config;
  49. echo " number=$REV" >> META-INF/plugin.config;
  50. fi;
  51. foo=`echo $foldername | sed -e 's/\/[^\/]*$//g'`
  52. mkdir -p "$foo"
  53. cd "${foo}"
  54. ln -s "${destdir}/build/classes/${foldername}" .
  55. cd "$TMPDIR"
  56. mkdir -p "${destdir}/plugins/"
  57. rm -Rf "${destdir}/plugins/${2}.jar"
  58. jar -cvf "${srcdir}/src/${foldername}/${2}.jar" META-INF >/dev/null
  59. bit=""
  60. while [ 1 -eq 1 ]; do
  61. bit=${bit}/*
  62. ls ${foo}${bit}/* >/dev/null 2>&1
  63. if [ ${?} -ne 0 ]; then
  64. break;
  65. else
  66. DIR="${PWD}"
  67. for prepackage in `ls "${srcdir}/src/${foldername}${bit}/prePackage.sh" 2>/dev/null`; do
  68. cd `dirname "${prepackage}"`
  69. /bin/sh "${prepackage}"
  70. cd ${DIR}
  71. done;
  72. FILES="ls -1 "${foo}${bit}/"*.{${VALID_EXTS}}"
  73. FILES=`eval ${FILES} 2>/dev/null`
  74. jar -uvf "${srcdir}/src/${foldername}/${2}.jar" ${FILES} >/dev/null
  75. fi
  76. done
  77. mv "${srcdir}/src/${foldername}/${2}.jar" "${destdir}/plugins/"
  78. cd "${srcdir}"
  79. rm -Rf ${TMPDIR}
  80. #echo "done";