-
Notifications
You must be signed in to change notification settings - Fork 281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for source code analysis on Nemo #1211
Open
bellingard
wants to merge
1
commit into
restlet:2.4
Choose a base branch
from
bellingard:2.3
base: 2.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
language: java | ||
sudo: false | ||
install: true | ||
|
||
jdk: | ||
- oraclejdk7 | ||
|
||
script: | ||
- "cd build" | ||
- "ant rebuild" | ||
- "cd $TRAVIS_BUILD_DIR" | ||
- ./runSonarQubeAnalysis.sh | ||
|
||
cache: | ||
directories: | ||
- '$HOME/.sonar/cache' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/bin/sh | ||
# Exit on failure | ||
set -e | ||
|
||
# This assumes that the 2 following variables are defined: | ||
# - SONAR_HOST_URL => should point to the public URL of the SQ server (e.g. for Nemo: https://nemo.sonarqube.org) | ||
# - SONAR_TOKEN => token of a user who has the "Execute Analysis" permission on the SQ server | ||
|
||
installSonarQubeScanner() { | ||
export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-2.6 | ||
rm -rf $SONAR_SCANNER_HOME | ||
mkdir -p $SONAR_SCANNER_HOME | ||
curl -sSLo $HOME/.sonar/sonar-scanner.zip http://repo1.maven.org/maven2/org/sonarsource/scanner/cli/sonar-scanner-cli/2.6/sonar-scanner-cli-2.6.zip | ||
unzip $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/ | ||
rm $HOME/.sonar/sonar-scanner.zip | ||
export PATH=$SONAR_SCANNER_HOME/bin:$PATH | ||
export SONAR_SCANNER_OPTS="-server -Xmx1G -Xms128m" | ||
} | ||
|
||
# Install the SonarQube Scanner | ||
# TODO: Would be nice to have it pre-installed by Travis somehow | ||
installSonarQubeScanner | ||
|
||
# And run the analysis | ||
# It assumes that there's a sonar-project.properties file at the root of the repo | ||
if [ "$TRAVIS_BRANCH" = "2.3" ] && [ "$TRAVIS_PULL_REQUEST" = "false" ]; then | ||
# => This will run a full analysis of the project and push results to the SonarQube server. | ||
# | ||
# Analysis is done only on branch "2.3" (which seems to be the main developement branch for the moment) | ||
# so that build of branches don't push analyses to the same project and therefore "pollute" the results | ||
echo "Starting analysis by SonarQube..." | ||
sonar-scanner \ | ||
-Dsonar.host.url=$SONAR_HOST_URL \ | ||
-Dsonar.login=$SONAR_TOKEN | ||
|
||
elif [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ -n "${GITHUB_TOKEN-}" ]; then | ||
# => This will analyse the PR and display found issues as comments in the PR, but it won't push results to the SonarQube server | ||
# | ||
# For security reasons environment variables are not available on the pull requests | ||
# coming from outside repositories | ||
# http://docs.travis-ci.com/user/pull-requests/#Security-Restrictions-when-testing-Pull-Requests | ||
# That's why the analysis does not need to be executed if the variable GITHUB_TOKEN is not defined. | ||
echo "Starting Pull Request analysis by SonarQube..." | ||
sonar-scanner \ | ||
-Dsonar.host.url=$SONAR_HOST_URL \ | ||
-Dsonar.login=$SONAR_TOKEN \ | ||
-Dsonar.analysis.mode=preview \ | ||
-Dsonar.github.oauth=$GITHUB_TOKEN \ | ||
-Dsonar.github.repository=$TRAVIS_REPO_SLUG \ | ||
-Dsonar.github.pullRequest=$TRAVIS_PULL_REQUEST | ||
fi | ||
# When neither on master branch nor on a non-external pull request => nothing to do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
sonar.projectKey=restlet-framework-java | ||
sonar.projectVersion=2.3-SNAPSHOT | ||
sonar.projectName=Restlet Framework | ||
|
||
# Configuration of sources | ||
sonar.sources=modules | ||
# let's analyse only Java files for the moment | ||
sonar.inclusions=**/src/**/*.java | ||
# but exclude the code used for the examples | ||
sonar.exclusions=**/org.restlet.example*/** | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
# Other useful information for SonarQube | ||
sonar.links.homepage=http://restlet.com | ||
sonar.links.ci=https://travis-ci.org/restlet/restlet-framework-java | ||
sonar.links.scm=https://github.com/restlet/restlet-framework-java | ||
sonar.links.issue=https://github.com/restlet/restlet-framework-java/issues |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @bellingard , I've seen that the build failed. I don't see any relation to sonar.
Do you think the failure could be caused by the
sudo/install
configuration?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thboileau I've made several tests on this topic (as you can see on all the commits I've made on my fork of RF), and actually never managed to make the Ant build pass - even w/o the SonarQube analysis. TravisCI is always killing the Ant build process for some reason - this is why I had deactivated the Ant build on my fork (see this commit in which I added it again to prepare the PR). I hope you'll be able to figure that out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is related to this ticket: travis-ci/travis-ci#3396
Do you see any drawback to comment the
sudo: false
command?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@thboileau Might be related indeed. You can try w/o
sudo:false
to see if it works - this should not have too many impacts on SQ analysis. Maybe another solution is to increase the heap size when executing the unit tests (like mentioned here).