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

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