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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. if [ -d "${srcdir}/src/${foldername}/identities/" ]; then
  35. cp -r "${srcdir}/src/${foldername}/identities/" META-INF/identities/
  36. fi;
  37. # Do the same for plugin.config
  38. # This is rudimentary, it a version: section already exists (eg to specify
  39. # friendlyversion) then it won't add the number= key.
  40. if [ -e META-INF/plugin.config ]; then
  41. VERSIONLINE=`grep -n "version:$" META-INF/plugin.config | cut -f 1 -d ':'`
  42. if [ -z "$VERSIONLINE" ]; then
  43. sed 's/keysections:/keysections:\n version/g' META-INF/plugin.config > META-INF/plugin.config.temp
  44. rm -Rf META-INF/plugin.config
  45. mv META-INF/plugin.config.temp META-INF/plugin.config
  46. fi;
  47. GIT=`which git`
  48. REV=$(${GIT} --git-dir "${srcdir}/.git" describe --tags `${GIT} --git-dir "${srcdir}/.git" rev-list --max-count=1 HEAD -- "src/${foldername}"`);
  49. echo "" >> META-INF/plugin.config
  50. echo "" >> META-INF/plugin.config
  51. echo "version:" >> META-INF/plugin.config;
  52. echo " number=$REV" >> META-INF/plugin.config;
  53. fi;
  54. foo=`echo $foldername | sed -e 's/\/[^\/]*$//g'`
  55. mkdir -p "$foo"
  56. cd "${foo}"
  57. ln -s "${destdir}/build/classes/${foldername}" .
  58. cd "$TMPDIR"
  59. mkdir -p "${destdir}/plugins/"
  60. rm -Rf "${destdir}/plugins/${2}.jar"
  61. jar -cvf "${srcdir}/src/${foldername}/${2}.jar" META-INF >/dev/null
  62. bit=""
  63. while [ 1 -eq 1 ]; do
  64. bit=${bit}/*
  65. ls ${foo}${bit}/* >/dev/null 2>&1
  66. if [ ${?} -ne 0 ]; then
  67. break;
  68. else
  69. DIR="${PWD}"
  70. for prepackage in `ls "${srcdir}/src/${foldername}${bit}/prePackage.sh" 2>/dev/null`; do
  71. cd `dirname "${prepackage}"`
  72. /bin/sh "${prepackage}"
  73. cd ${DIR}
  74. done;
  75. FILES="ls -1 "${foo}${bit}/"*.{${VALID_EXTS}}"
  76. FILES=`eval ${FILES} 2>/dev/null`
  77. jar -uvf "${srcdir}/src/${foldername}/${2}.jar" ${FILES} >/dev/null
  78. fi
  79. done
  80. mv "${srcdir}/src/${foldername}/${2}.jar" "${destdir}/plugins/"
  81. cd "${srcdir}"
  82. rm -Rf ${TMPDIR}
  83. #echo "done";