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 3.0KB

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