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

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