build.sh 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #!/bin/bash
  2. export PATH=/home/jenkins/jdk/bin/:$PATH
  3. # Get the Eclipse launcher and build script to use
  4. set -x
  5. set -e
  6. TRUNK_HOME=$(cd $(pwd)/../../ ; pwd)
  7. #gives you the posibility to overwrite eclipse, if you do not use URL
  8. [ -n "${ECLIPSE_HOME}" ] || { echo "using default ECLIPSE_HOME=${TRUNK_HOME}/eclipse"; ECLIPSE_HOME=${TRUNK_HOME}/eclipse; }
  9. BUILD_RELEASE_ID_PREFIX=Linux_SGX_1.5
  10. if [ "$RELEASE_ID" != "${RELEASE_ID%$BUILD_RELEASE_ID_PREFIX*}" ]; then
  11. echo "$BUILD_RELEASE_ID_PREFIX IS in $RELEASE_ID, so it is an triggered build. Change the RELEASE_ID to an accepted form."
  12. temp=${RELEASE_ID#$BUILD_RELEASE_ID_PREFIX}
  13. RELEASE_ID=v`echo ${temp} | tr -d _ | tr -d -`
  14. else
  15. echo "$BUILD_RELEASE_ID_PREFIX is NOT in $RELEASE_ID. Keeping the user specified RELEASE_ID."
  16. fi
  17. function main() {
  18. validate-jenkins-parameters
  19. cleanupPreBuild
  20. checkEnvironment
  21. buildPlugin
  22. archivePlugin
  23. }
  24. function validate-jenkins-parameters {
  25. validate-parameter "DELETE_CURRENT_ECLIPSE" "$DELETE_CURRENT_ECLIPSE"
  26. [[ "ECLIPSE_DOWNLOAD_URL" != "" ]] &&
  27. echo "[WARNING] ECLIPSE_DOWNLOAD_URL is not set; assume eclipse archive is already downloaded"
  28. }
  29. function validate-parameter {
  30. local NAME="$1"
  31. local VALUE="$2"
  32. [[ ! -z "$VALUE" ]] || {
  33. echo "Mandatory Jenkins parameter '\$$NAME' not set !"
  34. exit 1
  35. }
  36. }
  37. function cleanupPreBuild() {
  38. ./clean.sh
  39. [[ "false" == "${DELETE_CURRENT_ECLIPSE}" ]] || {
  40. forceRemoveEclipse
  41. }
  42. }
  43. function forceRemoveEclipse() {
  44. pushd ${TRUNK_HOME}
  45. rm -fr eclipse
  46. popd
  47. }
  48. function checkEnvironment() {
  49. if [ ! -d "${ECLIPSE_HOME}" ]; then
  50. echo "Eclipse does not exist"
  51. echo "Downloading eclipse"
  52. getEclipse
  53. fi
  54. if [ -z "$RELEASE_ID" ]; then
  55. echo "Mandatory variable RELEASE_ID not defined; exiting"
  56. exit
  57. fi
  58. }
  59. function getEclipse() {
  60. local eclipseArchiveURL="${ECLIPSE_DOWNLOAD_URL}"
  61. pushd $TRUNK_HOME
  62. cleanupEclipseArchive
  63. downloadEclipse "${eclipseArchiveURL}"
  64. unzipEclipse
  65. installPDE
  66. cleanupEclipseArchive
  67. popd
  68. }
  69. function cleanupEclipseArchive() {
  70. find . -maxdepth 1 -mindepth 1 -name "*eclipse*.zip*" | xargs rm -f
  71. }
  72. function downloadEclipse() {
  73. local URL="$1"
  74. if [[ "$1" != "" ]] ; then
  75. echo " wget --no-proxy "$1""
  76. wget --no-proxy "$1"
  77. else
  78. echo "skip downloaded empty url"
  79. fi
  80. }
  81. function unzipEclipse() {
  82. pwd
  83. rm -fr eclipse
  84. local eclipseArchiveName="$(find . -maxdepth 1 -mindepth 1 -name "*eclipse*.zip*")"
  85. unzip "${eclipseArchiveName}"
  86. [[ -d eclipse ]] || {
  87. echo "Eclipse directory does not exist!"
  88. exit
  89. }
  90. # local eclipseFolderName=${eclipseArchiveName%.zip}
  91. # local eclipseArchiveName="eclipse"
  92. # mv "${eclipseFolderName}" eclipse
  93. }
  94. function installPDE() {
  95. echo "~~~~>"
  96. pwd
  97. ${ECLIPSE_HOME}/eclipse -nosplash \
  98. -application org.eclipse.equinox.p2.director \
  99. -repository http://download.eclipse.org/eclipse/updates/4.4 \
  100. -destination ${ECLIPSE_HOME} \
  101. -installIU org.eclipse.pde.source.feature.group \
  102. -installIU org.eclipse.pde.feature.group
  103. }
  104. function preBuild() {
  105. local BUILDDIR="$1"
  106. local BUILDDIRWORK="$2"
  107. local SITEFILE="$BUILDDIRWORK/sites/site.xml"
  108. local FEATUREDIR="$BUILDDIRWORK/features"
  109. local FEATUREFILE="feature.xml"
  110. local PLUGINDIR="$BUILDDIRWORK/plugins"
  111. local PLUGINFILE="META-INF/MANIFEST.MF"
  112. local ROOTDIR=$(dirname "$0")"/.."
  113. local VERSION=$(awk '/STRFILEVER/ {print $3}' ${ROOTDIR}/common/inc/internal/se_version.h|sed 's/^\"\(.*\)\"$/\1/')
  114. VERSION=$(echo "$VERSION" | awk -F'.' '{for(i=1; i<=NF&&i<=3; i++) if(i==1){version=$i} else{version=version"."$i}}; END{print version}')
  115. if [[ "$VERSION" =~ ^[0-9]{1,}(.[0-9]{1,}){2}$ ]]; then
  116. rm -fr "$BUILDDIRWORK"
  117. cp -fr "$BUILDDIR" "$BUILDDIRWORK"
  118. #site.xml
  119. sed -i "s#[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{0,2\}\.qualifier#$VERSION\.qualifier#g" "$SITEFILE"
  120. #feature
  121. for DIR in $(ls "$FEATUREDIR"); do
  122. sed -i "s#[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{0,2\}\.qualifier#$VERSION\.qualifier#g" "$FEATUREDIR/$DIR/$FEATUREFILE"
  123. done
  124. #plugin
  125. for DIR in $(ls "$PLUGINDIR"); do
  126. sed -i "s#[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{0,2\}\.qualifier#$VERSION\.qualifier#g" "$PLUGINDIR/$DIR/$PLUGINFILE"
  127. done
  128. fi
  129. }
  130. function postBuild() {
  131. local BUILDDIR="$1"
  132. local BUILDDIRWORK="$2"
  133. local UPDATESITEDIR="updatesite"
  134. if [[ -d "$BUILDDIRWORK" ]] && [[ -d "$BUILDDIRWORK/$UPDATESITEDIR" ]]; then
  135. rm -fr "$BUILDDIR/$UPDATESITEDIR"
  136. cp -fr "$BUILDDIRWORK/$UPDATESITEDIR" "$BUILDDIR/$UPDATESITEDIR"
  137. rm -fr "$BUILDDIRWORK"
  138. fi
  139. }
  140. function buildPlugin() {
  141. pwd
  142. echo "PWD=`pwd`"
  143. echo "ECLIPSE_HOME=$ECLIPSE_HOME"
  144. #BASELOCATION="$PWD/target_platform"
  145. BASELOCATION="$ECLIPSE_HOME"
  146. BUILDVERSION="$RELEASE_ID"
  147. BUILDDIR="$PWD/build_directory"
  148. BUILDDIRWORK="$PWD/.build_directory"
  149. BUILDCONFIG="$PWD/build_config"
  150. LAUNCHER=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.equinox.launcher_*.jar`
  151. BUILDFILE=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.pde.build_*/scripts/build.xml`
  152. # make sure we found valid files
  153. if [ ! -f "$LAUNCHER" ]; then
  154. echo "Installation Error: Eclipse plugin org.eclipse.equinox.launcher...jar not detected. " \
  155. "Found '$LAUNCHER'. Aborting."
  156. exit 1
  157. fi
  158. if [ ! -f "$BUILDFILE" ]; then
  159. echo "Installation Error: Eclipse build file org.eclipse.pde.build_.../scripts/build.xml " \
  160. "not detected. Found '$BUILDFILE'. Aborting."
  161. exit 1
  162. fi
  163. preBuild "$BUILDDIR" "$BUILDDIRWORK"
  164. #
  165. # -- Print configuration used and actually execute the build --
  166. #
  167. echo "Eclipse configuration found:"
  168. echo " Eclipse Home: $ECLIPSE_HOME"
  169. echo " Launcher: $LAUNCHER"
  170. echo " Build File: $BUILDFILE"
  171. echo " Build Config: $BUILDCONFIG"
  172. echo " Base Location: $BASELOCATION"
  173. echo " Build Directory: $BUILDDIRWORK"
  174. echo " Build Version: $BUILDVERSION"
  175. echo " Java: " $(which java)
  176. java -version
  177. # CURRENT_DIR=$(pwd)
  178. # ${ECLIPSE_HOME}/eclipse -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher -metadataRepository file:/${CURRENT_DIR}/build_directory/updatesite/sgx-eclipse-plugin -artifactRepository file:/${CURRENT_DIR}/build_directory/updatesite/featuresAndBundles -source ${CURRENT_DIR}/build_directory/ -config gtk.linux.x86 -compress -publishArtifacts
  179. # cp ./build_directory/updatesite/featuresAndBundles/artifacts.jar ./build_directory/updatesite/sgx-eclipse-plugin/
  180. java \
  181. -jar $LAUNCHER \
  182. -application org.eclipse.ant.core.antRunner \
  183. -buildfile $BUILDFILE \
  184. -DbuildDirectory=$BUILDDIRWORK \
  185. -DbaseLocation=$BASELOCATION \
  186. -Dbuilder=$BUILDCONFIG \
  187. -DforceContextQualifier=$BUILDVERSION \
  188. -v -v -v -v
  189. postBuild "$BUILDDIR" "$BUILDDIRWORK"
  190. }
  191. function findFirst() {
  192. echo "enter Find First, $@" 1>&2
  193. for i in "$@"; do
  194. if [ -f "$i" ]; then
  195. echo "found $i" 1>&2
  196. echo "$i"
  197. return
  198. fi
  199. done
  200. }
  201. function archivePlugin() {
  202. pushd build_directory/updatesite/sgx-eclipse-plugin
  203. zip -r Intel-sgx-eclipse-plugin.zip *
  204. popd
  205. }
  206. main