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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. srcdir=${PWD}
  9. pluginname=${1}
  10. foldername=${pluginname//.//}
  11. newer=`find src/${foldername} -type f -newer ${srcdir}/plugins/${2}.jar 2>&1 | wc -l`
  12. if [ $newer -eq 0 ]; then
  13. echo "${2}.jar appears to be up-to-date";
  14. exit 0;
  15. fi
  16. echo "Creating ${2}.jar for ${pluginname} (${foldername})"
  17. if [ ! -e src/${foldername}/plugin.info -a ! -e src/${foldername}/plugin.config ]; then
  18. echo "no plugin.info or plugin.config found";
  19. exit 0;
  20. fi
  21. #echo "looking for classes"
  22. TMPDIR=`mktemp -d`
  23. #echo "Using temp dir: ${TMPDIR}"
  24. cd $TMPDIR
  25. mkdir META-INF
  26. if [ -e ${srcdir}/src/${foldername}/plugin.info ]; then
  27. cp ${srcdir}/src/${foldername}/plugin.info META-INF/
  28. fi;
  29. if [ -e ${srcdir}/src/${foldername}/plugin.config ]; then
  30. cp ${srcdir}/src/${foldername}/plugin.config META-INF/
  31. fi;
  32. # Add the SVN version if there's no version specified and we know the SVN rev
  33. if [ -e META-INF/plugin.info ]; then
  34. if ! grep "^version=" META-INF/plugin.info >/dev/null; then
  35. SVN=`which svn`
  36. SVNREV=`$SVN info $srcdir/src/$foldername 2>&1 | grep "Last Changed Rev"`
  37. SVNREV=${SVNREV##*: }
  38. echo "" >> META-INF/plugin.info
  39. if [ -n "$SVNREV" ]; then
  40. echo "version=$SVNREV" >> META-INF/plugin.info;
  41. else
  42. echo "version=0" >> META-INF/plugin.info;
  43. fi
  44. if ! grep "^friendlyversion=" META-INF/plugin.info >/dev/null; then
  45. echo "friendlyversion=$SVNREV" >> META-INF/plugin.info
  46. fi
  47. fi
  48. fi;
  49. # Do the same for plugin.config
  50. # This is rudimentary, it a version: section already exists (eg to specify
  51. # friendlyversion) then it won't add the number= key.
  52. if [ -e META-INF/plugin.config ]; then
  53. if ! grep "^version:" META-INF/plugin.config >/dev/null; then
  54. SVN=`which svn`
  55. SVNREV=`$SVN info $srcdir/src/$foldername 2>&1 | grep "Last Changed Rev"`
  56. SVNREV=${SVNREV##*: }
  57. echo "" >> META-INF/plugin.config
  58. echo "" >> META-INF/plugin.config
  59. echo "version:" >> META-INF/plugin.config;
  60. if [ -n "$SVNREV" ]; then
  61. echo " number=$SVNREV" >> META-INF/plugin.config;
  62. else
  63. echo " number=0" >> META-INF/plugin.config;
  64. fi
  65. # Add to keysections list
  66. sed 's/keysections:/keysections:\n version/g' META-INF/plugin.config > META-INF/plugin.config.temp
  67. rm -Rf META-INF/plugin.config
  68. mv META-INF/plugin.config.temp META-INF/plugin.config
  69. fi
  70. fi;
  71. foo=`echo $foldername | sed -e 's/\/[^\/]*$//g'`
  72. mkdir -p $foo
  73. cd ${foo}
  74. ln -s ${srcdir}/build/classes/${foldername} .
  75. cd $TMPDIR
  76. mkdir -p ${srcdir}/plugins/
  77. rm -Rf ${srcdir}/plugins/${2}.jar
  78. jar -cvf ${srcdir}/src/${foldername}/${2}.jar META-INF >/dev/null
  79. bit=""
  80. while [ 1 -eq 1 ]; do
  81. bit=${bit}/*
  82. ls ${foo}${bit}/* >/dev/null 2>&1
  83. if [ ${?} -ne 0 ]; then
  84. break;
  85. else
  86. DIR=${PWD}
  87. for prepackage in `ls ${srcdir}/src/${foldername}${bit}/prePackage.sh 2>/dev/null`; do
  88. cd `dirname ${prepackage}`
  89. /bin/sh ${prepackage}
  90. cd ${DIR}
  91. done;
  92. 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
  93. fi
  94. done
  95. mv ${srcdir}/src/${foldername}/${2}.jar ${srcdir}/plugins/
  96. cd ${srcdir}
  97. rm -Rf ${TMPDIR}
  98. #echo "done";