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.

travis.sh 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #!/bin/bash
  2. set -euo pipefail
  3. function installPhantomJs {
  4. echo "Setup PhantomJS 2.1"
  5. mkdir -p ~/phantomjs
  6. pushd ~/phantomjs > /dev/null
  7. if [ ! -d "phantomjs-2.1.1-linux-x86_64" ]; then
  8. echo "Download PhantomJS"
  9. wget https://repox.sonarsource.com/public-3rd-parties/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2 -O phantomjs-2.1.1-linux-x86_64.tar.bz2
  10. tar -xf phantomjs-2.1.1-linux-x86_64.tar.bz2
  11. rm phantomjs-2.1.1-linux-x86_64.tar.bz2
  12. fi
  13. popd > /dev/null
  14. export PHANTOMJS_HOME=~/phantomjs/phantomjs-2.1.1-linux-x86_64
  15. export PATH=$PHANTOMJS_HOME/bin:$PATH
  16. }
  17. #
  18. # A (too) old version of JDK8 is installed by default on Travis.
  19. # This method is preferred over Travis apt oracle-java8-installer because
  20. # JDK is kept in cache. It does not need to be downloaded from Oracle
  21. # at each build.
  22. #
  23. function installJdk8 {
  24. echo "Setup JDK 1.8u121"
  25. mkdir -p ~/jvm
  26. pushd ~/jvm > /dev/null
  27. if [ ! -d "jdk1.8.0_121" ]; then
  28. echo "Download JDK8"
  29. wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.tar.gz
  30. tar xzf jdk-8u121-linux-x64.tar.gz
  31. rm jdk-8u121-linux-x64.tar.gz
  32. fi
  33. popd > /dev/null
  34. export JAVA_HOME=~/jvm/jdk1.8.0_121
  35. export PATH=$JAVA_HOME/bin:$PATH
  36. }
  37. #
  38. # Maven 3.2.5 is installed by default on Travis. Maven 3.3.9 is preferred.
  39. #
  40. function installMaven {
  41. echo "Setup Maven"
  42. mkdir -p ~/maven
  43. pushd ~/maven > /dev/null
  44. if [ ! -d "apache-maven-3.3.9" ]; then
  45. echo "Download Maven 3.3.9"
  46. curl -sSL http://apache.mirrors.ovh.net/ftp.apache.org/dist/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz | tar zx -C ~/maven
  47. fi
  48. popd > /dev/null
  49. export M2_HOME=~/maven/apache-maven-3.3.9
  50. export PATH=$M2_HOME/bin:$PATH
  51. }
  52. #
  53. # Replaces the version defined in sources, usually x.y-SNAPSHOT,
  54. # by a version identifying the build.
  55. # The build version is composed of 4 fields, including the semantic version and
  56. # the build number provided by Travis.
  57. #
  58. # Exported variables:
  59. # - INITIAL_VERSION: version as defined in pom.xml
  60. # - BUILD_VERSION: version including the build number
  61. # - PROJECT_VERSION: target Maven version. The name of this variable is important because
  62. # it's used by QA when extracting version from Artifactory build info.
  63. #
  64. # Example of SNAPSHOT
  65. # INITIAL_VERSION=6.3-SNAPSHOT
  66. # BUILD_VERSION=6.3.0.12345
  67. # PROJECT_VERSION=6.3.0.12345
  68. #
  69. # Example of RC
  70. # INITIAL_VERSION=6.3-RC1
  71. # BUILD_VERSION=6.3.0.12345
  72. # PROJECT_VERSION=6.3-RC1
  73. #
  74. # Example of GA
  75. # INITIAL_VERSION=6.3
  76. # BUILD_VERSION=6.3.0.12345
  77. # PROJECT_VERSION=6.3
  78. #
  79. function fixBuildVersion {
  80. export INITIAL_VERSION=`maven_expression "project.version"`
  81. # remove suffix -SNAPSHOT or -RC
  82. without_suffix=`echo $INITIAL_VERSION | sed "s/-.*//g"`
  83. IFS=$'.'
  84. fields_count=`echo $without_suffix | wc -w`
  85. unset IFS
  86. if [ $fields_count -lt 3 ]; then
  87. export BUILD_VERSION="$without_suffix.0.$TRAVIS_BUILD_NUMBER"
  88. else
  89. export BUILD_VERSION="$without_suffix.$TRAVIS_BUILD_NUMBER"
  90. fi
  91. if [[ "${INITIAL_VERSION}" == *"-SNAPSHOT" ]]; then
  92. # SNAPSHOT
  93. export PROJECT_VERSION=$BUILD_VERSION
  94. mvn org.codehaus.mojo:versions-maven-plugin:2.2:set -DnewVersion=$PROJECT_VERSION -DgenerateBackupPoms=false -B -e
  95. else
  96. # not a SNAPSHOT: milestone, RC or GA
  97. export PROJECT_VERSION=$INITIAL_VERSION
  98. fi
  99. echo "Build Version : $BUILD_VERSION"
  100. echo "Project Version: $PROJECT_VERSION"
  101. }
  102. #
  103. # Configure Maven settings and install some script utilities
  104. #
  105. function configureTravis {
  106. mkdir ~/.local
  107. curl -sSL https://github.com/SonarSource/travis-utils/tarball/v33 | tar zx --strip-components 1 -C ~/.local
  108. source ~/.local/bin/install
  109. }
  110. configureTravis
  111. case "$TARGET" in
  112. BUILD)
  113. # Hack to keep job alive even if no logs during more than 10 minutes.
  114. # That can occur when uploading sonarqube.zip to Artifactory.
  115. ./clock.sh &
  116. installJdk8
  117. installMaven
  118. fixBuildVersion
  119. # Minimal Maven settings
  120. export MAVEN_OPTS="-Xmx1G -Xms128m"
  121. MAVEN_ARGS="-Dmaven.test.redirectTestOutputToFile=false -Dsurefire.useFile=false -B -e -V -DbuildVersion=$BUILD_VERSION"
  122. if [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  123. echo 'Build and analyze master'
  124. # Fetch all commit history so that SonarQube has exact blame information
  125. # for issue auto-assignment
  126. # This command can fail with "fatal: --unshallow on a complete repository does not make sense"
  127. # if there are not enough commits in the Git repository (even if Travis executed git clone --depth 50).
  128. # For this reason errors are ignored with "|| true"
  129. git fetch --unshallow || true
  130. mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy sonar:sonar \
  131. $MAVEN_ARGS \
  132. -Pdeploy-sonarsource,release \
  133. -Dsonar.host.url=$SONAR_HOST_URL \
  134. -Dsonar.login=$SONAR_TOKEN \
  135. -Dsonar.projectVersion=$INITIAL_VERSION
  136. elif [[ "$TRAVIS_BRANCH" == "branch-"* ]] && [ "$TRAVIS_PULL_REQUEST" == "false" ]; then
  137. echo 'Build release branch'
  138. mvn deploy $MAVEN_ARGS -Pdeploy-sonarsource,release
  139. elif [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "${GITHUB_TOKEN:-}" ]; then
  140. echo 'Build and analyze internal pull request'
  141. mvn org.jacoco:jacoco-maven-plugin:prepare-agent deploy sonar:sonar \
  142. $MAVEN_ARGS \
  143. -Dsource.skip=true \
  144. -Pdeploy-sonarsource \
  145. -Dsonar.analysis.mode=preview \
  146. -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST \
  147. -Dsonar.github.repository=$TRAVIS_REPO_SLUG \
  148. -Dsonar.github.oauth=$GITHUB_TOKEN \
  149. -Dsonar.host.url=$SONAR_HOST_URL \
  150. -Dsonar.login=$SONAR_TOKEN
  151. else
  152. echo 'Build feature branch or external pull request'
  153. mvn install $MAVEN_ARGS -Dsource.skip=true
  154. fi
  155. installPhantomJs
  156. ./run-integration-tests.sh "Lite" "" -Dorchestrator.browser=phantomjs
  157. ;;
  158. WEB_TESTS)
  159. set +u
  160. source ~/.nvm/nvm.sh && nvm install 6
  161. curl -o- -L https://yarnpkg.com/install.sh | bash
  162. export PATH=$HOME/.yarn/bin:$PATH
  163. cd server/sonar-web && yarn && yarn validate
  164. ;;
  165. *)
  166. echo "Unexpected TARGET value: $TARGET"
  167. exit 1
  168. ;;
  169. esac
  170. #stop the clock
  171. touch stop