Skip to content

Commit

Permalink
Analyze code quality with Sonar during Travis CI build
Browse files Browse the repository at this point in the history
Sonar analysis is only run when the branch belongs to the pitest/pitclipse
repository. Indeed, sending the results of the the analysis to SonarCloud
requires the encrypted SONAR token which is not provided by Travis CI when
the build comes from a fork.

The code checking whether the analysis can be run is located in .travis/build.sh
and is called by the .travis.yml configuration file.

I also struggled a bit to encrypt the token because encryption on travis-ci.com
is different from encryption on travis-ci.org. For the record here is what I did:
 > travis login --pro
 > travis encrypt --pro <token> -r pitest/pitclipse
  • Loading branch information
echebbi committed Aug 15, 2019
1 parent da2bede commit 5440931
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 6 deletions.
22 changes: 17 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,37 @@ jdk:
# Prevent "mvn install" default step
install: true

env: DISPLAY=:99.0

addons:
sonarcloud:
organization: "echebbi-github"
token:
secure: "YQklJf56eYXw36/OAbJGQ85qNXrYqR1D8MjicMNtg7oB3+lKvCVVaTx+NnS35Gp//TbOuOs7TMyLFENKFxhLBMDbBpDF4FGMOShgCbUpiuep+kkRj5G9c5PRSyjT+Q/UehOI3zmc16RV3RtJQPXDp1mY97gcWCJPonbteteSZCvrvZycJG6BwxrFLNir2rpHgt/SvGGknj9cJKZHwPy7Co838dqVr5fVa9WzElkcEgw5B9rt8o9gkKAdOpO/7JJijyVYuPBDS9DzJ6t7XurVT6nIpufqwVob8xv2uxyyN4icjKA4qcuXIwZBOD00lrhXoIkE7uK8VFEY0WbpMn6HuorqD6NFfpan4hxrrOTr5E19K6OneyaZtums04p9lf0Ev5t7vsx+ai1rZSzhIokZrvd0qZItUPJMRqeZ054kR+TMnkgOv5j77jGOi4bPz71BYB7JQgF8I3S8QcxfFMtgPRBYqHl61+HidNqPb2IfdLAEFG7bPpE+ll12D/CrcYUVtlegcrYX1Fks+KThyK6mbEhYNvNP86GpSBBf807c406XwzYchybdljEPV7Y5wJljdzvx7IksugiTe7SAyibTyFTPqbNxUBvSzT7UcM28y27P81XQEpwVORy2uI6nqtESr0VT3wk8JQAea3fON0HNlXE1+p7mUxY1tJWFIBvlnR8="
apt:
packages:
# Required by XVFB
- metacity

# Allow UI tests
dist: trusty

before_script:
- sh -e /etc/init.d/xvfb start
# Prepare the environment for UI tests
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start
- metacity --sm-disable --replace 2> metacity.err &
# Prevent installed packages from being used during build
- rm -rfv "$HOME/.m2/repository/org/pitest/"

script: mvn verify -P jacoco
# build.sh is responsible of checking whether Sonar analysis can be run
script: bash .travis/build.sh


after_success:
- bash <(curl -s https://codecov.io/bash)

# Keep p2 information
cache:
directories:
- "$HOME/.m2/repository"
- "$HOME/.m2/repository"
- "$HOME/.sonar/cache"
17 changes: 17 additions & 0 deletions .travis/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# IF the variable is set, we can run Sonar analysis.
# Indeed, that means that the build is performed on a branch of the
# pitest/pitclipse repository and that Travis CI allows us to use
# encrypted variables (e.g. Sonar's token)
if [ "${SONAR_SCANNER_HOME}" != "" ]; then
COMMAND="mvn verify -P jacoco sonar:sonar";

# ELSE we cannot run Sonar analysis because the branch is coming
# from a fork and Travis CI does not allow use to use encrypted variables.
else
COMMAND="mvn verify -P jacoco";
fi

echo ${COMMAND}
${COMMAND}
17 changes: 16 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,27 @@
<!-- DEPENDENCIES -->
<tycho-version>1.4.0</tycho-version>
<jacoco-version>0.8.1</jacoco-version>

<!-- SONARQUBE -->
<sonar.projectName>Pitclipse</sonar.projectName>

<sonar.organization>echebbi-github</sonar.organization>
<sonar.links.ci>https://travis-ci.com/pitest/pitclipse</sonar.links.ci>
<sonar.links.scm>https://github.com/pitest/pitclipse</sonar.links.scm>
<sonar.links.issue>https://github.com/pitest/pitclipse/issues</sonar.links.issue>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
<sonar.java.source>8</sonar.java.source>
<!-- Ignore :
- Exceptions,
- untestable activators -->
<sonar.exclusions>**/*Exception.java,**/Activator.java</sonar.exclusions>
<sonar.jacoco.reportPaths>../../tests/${project.artifactId}.tests/target/jacoco.exec</sonar.jacoco.reportPaths>
</properties>

<!-- COMMANDS:
* Build project:
mvn clean verify
* Change project's version:
mvn org.eclipse.tycho:tycho-versions-plugin:set-version -DnewVersion=major.minor.bug
-->
Expand Down
4 changes: 4 additions & 0 deletions releng/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
<module>org.pitest.pitclipse.target</module>
<module>org.pitest.pitclipse.p2</module>
</modules>

<properties>
<sonar.skip>true</sonar.skip>
</properties>
</project>
23 changes: 23 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
sonar.projectName=Pitclipse
sonar.projectKey=org.pitest:org.pitest.pitclipse

# =====================================================
# Meta-data for the project
# =====================================================

sonar.links.ci=https://travis-ci.com/pitest/pitclipse
sonar.links.scm=https://github.com/pitest/pitclipse
sonar.links.issue=https://github.com/pitest/pitclipse/issues


# =====================================================
# Properties that will be shared amongst all modules
# =====================================================

sonar.host.url=https://sonarcloud.io

# =====================================================
# Java config
# =====================================================

sonar.java.source=8
18 changes: 18 additions & 0 deletions tests/io.cucumber/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.pitest</groupId>
<artifactId>org.pitest.pitclipse.tests</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>io.cucumber</artifactId>
<packaging>eclipse-plugin</packaging>
<version>4.3.0</version>

<properties>
<sonar.skip>true</sonar.skip>
</properties>
</project>

0 comments on commit 5440931

Please sign in to comment.