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

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