build.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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 buildPlugin() {
  105. pwd
  106. echo "PWD=`pwd`"
  107. echo "ECLIPSE_HOME=$ECLIPSE_HOME"
  108. #BASELOCATION="$PWD/target_platform"
  109. BASELOCATION="$ECLIPSE_HOME"
  110. BUILDVERSION="$RELEASE_ID"
  111. BUILDDIR="$PWD/build_directory"
  112. BUILDCONFIG="$PWD/build_config"
  113. LAUNCHER=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.equinox.launcher_*.jar`
  114. BUILDFILE=`findFirst "$ECLIPSE_HOME"/plugins/org.eclipse.pde.build_*/scripts/build.xml`
  115. # make sure we found valid files
  116. if [ ! -f "$LAUNCHER" ]; then
  117. echo "Installation Error: Eclipse plugin org.eclipse.equinox.launcher...jar not detected. " \
  118. "Found '$LAUNCHER'. Aborting."
  119. exit 1
  120. fi
  121. if [ ! -f "$BUILDFILE" ]; then
  122. echo "Installation Error: Eclipse build file org.eclipse.pde.build_.../scripts/build.xml " \
  123. "not detected. Found '$BUILDFILE'. Aborting."
  124. exit 1
  125. fi
  126. #
  127. # -- Print configuration used and actually execute the build --
  128. #
  129. echo "Eclipse configuration found:"
  130. echo " Eclipse Home: $ECLIPSE_HOME"
  131. echo " Launcher: $LAUNCHER"
  132. echo " Build File: $BUILDFILE"
  133. echo " Build Config: $BUILDCONFIG"
  134. echo " Base Location: $BASELOCATION"
  135. echo " Build Directory: $BUILDDIR"
  136. echo " Build Version: $BUILDVERSION"
  137. echo " Java: " $(which java)
  138. java -version
  139. # CURRENT_DIR=$(pwd)
  140. # ${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
  141. # cp ./build_directory/updatesite/featuresAndBundles/artifacts.jar ./build_directory/updatesite/sgx-eclipse-plugin/
  142. java \
  143. -jar $LAUNCHER \
  144. -application org.eclipse.ant.core.antRunner \
  145. -buildfile $BUILDFILE \
  146. -DbuildDirectory=$BUILDDIR \
  147. -DbaseLocation=$BASELOCATION \
  148. -Dbuilder=$BUILDCONFIG \
  149. -DforceContextQualifier=$BUILDVERSION \
  150. -v -v -v -v
  151. }
  152. function findFirst() {
  153. echo "enter Find First, $@" 1>&2
  154. for i in "$@"; do
  155. if [ -f "$i" ]; then
  156. echo "found $i" 1>&2
  157. echo "$i"
  158. return
  159. fi
  160. done
  161. }
  162. function archivePlugin() {
  163. pushd build_directory/updatesite/sgx-eclipse-plugin
  164. zip -r Intel-sgx-eclipse-plugin.zip *
  165. popd
  166. }
  167. main