diff --git a/.travis.yml b/.travis.yml index 167956e..dc8bf5c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,5 @@ env: cache: directories: - '$HOME/.m2/repository' - - '$HOME/.sonar/cache' script: ./travis.sh diff --git a/travis.sh b/travis.sh index c49f893..46dcd7e 100755 --- a/travis.sh +++ b/travis.sh @@ -4,18 +4,20 @@ set -euo pipefail mvn -B clean install -Pits -Dsonar.runtimeVersion=$SQ_VERSION -if [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ "$SQ_VERSION" == "LTS" ]; then - mvn -B sonar:sonar \ - -Dsonar.host.url=https://sonarcloud.io \ - -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST \ - -Dsonar.github.repository=$TRAVIS_REPO_SLUG \ - -Dsonar.github.oauth=$GITHUB_TOKEN \ - -Dsonar.login=$SONAR_TOKEN \ - -Dsonar.organization=racodond-github +if [ "$SQ_VERSION" == "LTS" ]; then + + mvnCommand='mvn -B sonar:sonar' + commonArgs="-Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dsonar.organization=racodond-github" + githubArgs="-Dsonar.analysis.mode=preview -Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST -Dsonar.github.repository=$TRAVIS_REPO_SLUG -Dsonar.github.oauth=$GITHUB_TOKEN" + branchArgs='' + + if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then + if [ "$TRAVIS_BRANCH" != "master" ]; then + branchArgs="-Dsonar.branch.name=$TRAVIS_BRANCH -Dsonar.branch.target=master" + fi + eval $mvnCommand $commonArgs $branchArgs + else + eval $mvnCommand $commonArgs $githubArgs + fi -elif [ "$TRAVIS_BRANCH" == "master" ] && [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$SQ_VERSION" == "LTS" ]; then - mvn -B sonar:sonar \ - -Dsonar.host.url=https://sonarcloud.io \ - -Dsonar.login=$SONAR_TOKEN \ - -Dsonar.organization=racodond-github fi