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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/bash
  2. set -euo pipefail
  3. function installTravisTools {
  4. mkdir ~/.local
  5. curl -sSL https://github.com/SonarSource/travis-utils/tarball/v21 | tar zx --strip-components 1 -C ~/.local
  6. source ~/.local/bin/install
  7. }
  8. function strongEcho {
  9. echo ""
  10. echo "================ $1 ================="
  11. }
  12. case "$TARGET" in
  13. CI)
  14. if [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "$SONAR_GITHUB_OAUTH" ]; then
  15. # For security reasons environment variables are not available on the pull requests
  16. # coming from outside repositories
  17. # http://docs.travis-ci.com/user/pull-requests/#Security-Restrictions-when-testing-Pull-Requests
  18. # That's why the analysis does not need to be executed if the variable SONAR_GITHUB_OAUTH is not defined.
  19. strongEcho 'Build and analyze pull request'
  20. # this pull request must be built and analyzed (without upload of report)
  21. mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify -Pcoverage-per-test,analysis -Dclirr=true -B -e -V
  22. # Switch to java 8 as the Dory HTTPS certificate is not supported by Java 7
  23. export JAVA_HOME=/usr/lib/jvm/java-8-oracle
  24. export PATH=$JAVA_HOME/bin:$PATH
  25. mvn sonar:sonar -B -e -V \
  26. -Dsonar.analysis.mode=issues \
  27. -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST \
  28. -Dsonar.github.repository=$TRAVIS_REPO_SLUG \
  29. -Dsonar.github.oauth=$SONAR_GITHUB_OAUTH \
  30. -Dsonar.host.url=$SONAR_HOST_URL \
  31. -Dsonar.login=$SONAR_LOGIN \
  32. -Dsonar.password=$SONAR_PASSWORD
  33. else
  34. strongEcho 'Build, no analysis'
  35. # Build branch, without any analysis
  36. # No need for Maven goal "install" as the generated JAR file does not need to be installed
  37. # in Maven local repository
  38. mvn verify -B -e -V
  39. fi
  40. ;;
  41. POSTGRES)
  42. installTravisTools
  43. psql -c 'create database sonar;' -U postgres
  44. runDatabaseCI "postgresql" "jdbc:postgresql://localhost/sonar" "postgres" ""
  45. ;;
  46. MYSQL)
  47. installTravisTools
  48. mysql -e "CREATE DATABASE sonar CHARACTER SET UTF8;" -uroot
  49. mysql -e "CREATE USER 'sonar'@'localhost' IDENTIFIED BY 'sonar';" -uroot
  50. mysql -e "GRANT ALL ON sonar.* TO 'sonar'@'localhost';" -uroot
  51. mysql -e "FLUSH PRIVILEGES;" -uroot
  52. runDatabaseCI "mysql" "jdbc:mysql://localhost/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance" "sonar" "sonar"
  53. ;;
  54. WEB)
  55. set +eu
  56. source ~/.nvm/nvm.sh && nvm install 4
  57. cd server/sonar-web && npm install && npm test
  58. ;;
  59. IT)
  60. if [ "$IT_CATEGORY" == "Plugins" ] && [ -n "$SONAR_GITHUB_OAUTH" ]; then
  61. echo "This job is ignored as it needs to access a private GitHub repository"
  62. else
  63. installTravisTools
  64. start_xvfb
  65. mvn install -Pit,dev -DskipTests -Dcategory=$IT_CATEGORY -Dmaven.test.redirectTestOutputToFile=false -e -Dsource.skip=true
  66. fi
  67. ;;
  68. *)
  69. echo "Unexpected TARGET value: $TARGET"
  70. exit 1
  71. ;;
  72. esac