-# We need to clean the build that was used for the tests before to ensure that everything gets rebuilt (sonarqube only use what's built throught its wrappers)
-# Plus, we need to activate MC so that it does not get throught the quality net :)
-./build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-outputs make VERBOSE=1
+./build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-outputs "$@"
+
+# Run ctest before sonar to gather coverage some information
+# EDIT: Don't run the tests on travis because they take too much time.
+#set +e
+#ctest -j2 --output-on-failure
+#outcome=$?
+#set -e
+outcome=0
+
+# Only run sonar on master (not on pull requests)
+if [ "$TRAVIS_PULL_REQUEST" != "false" ] ; then
+ exit $outcome
+fi
+
+# generate the gcov files
+#ctest -D ExperimentalCoverage
+
+# and finally execute the actual SonarQube analysis
+# (the SONAR_TOKEN is set from the travis web interface, to not expose it with an ongoing "set -x")
+# See https://docs.travis-ci.com/user/sonarqube/ for more info on tokens
+# don't show the token in the logs
+set +x
+sonar-scanner -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN 2>&1 \
+ | grep -v 'INFO: Parsing /home/travis/build/simgrid/simgrid/Testing/CoverageInfo' \
+ | grep -v 'WARN: File not analysed by Sonar, so ignoring coverage: /usr/include/'