Created
November 7, 2012 20:57
-
-
Save StevenLooman/4034389 to your computer and use it in GitHub Desktop.
Wrapper script to analyze Python (Plone) egg or sources with Sonar
This file contains hidden or 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
#!/usr/bin/env bash | |
for D in *; do | |
if [ -d "${D}" ]; then | |
cd ${D} | |
~/src/plone-sonar-runner.sh | |
cd .. | |
fi | |
done |
This file contains hidden or 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
#!/usr/bin/env bash | |
BASE_NAME=`basename \`pwd\`` | |
SCRIPT_BASE_DIR=`dirname $0` | |
# detect egg name/version | |
if [ -f setup.py ]; then | |
PROJECT_NAME=`python setup.py --name` | |
PROJECT_VERSION=`python setup.py --version` | |
elif [ -f EGG-INFO/PKG-INFO ]; then | |
PROJECT_NAME=`awk '/^Name:/ { print $2 }' EGG-INFO/PKG-INFO` | |
PROJECT_VERSION=`awk '/^Version:/ { print $2 }' EGG-INFO/PKG-INFO` | |
fi | |
# sanity checks | |
if [ "$PROJECT_NAME"x == "x" ]; then | |
echo Unable to detect name of package | |
exit 1 | |
fi | |
if [ "$PROJECT_VERSION"x == "x" ] ; then | |
echo Unable to detect version of package | |
exit 1 | |
fi | |
echo Detected egg $PROJECT_NAME, version $PROJECT_VERSION | |
PROJECT_KEY="plone:"$PROJECT_NAME | |
# find sources directory | |
PROJECT_SRC="src" | |
if [ ! -d src ]; then | |
PROJECT_SRC=${BASE_NAME} | |
PROJECT_SRC=${PROJECT_SRC%%-*} | |
PROJECT_SRC=${PROJECT_SRC%%.*} | |
fi | |
PROJECT_SCM="true" | |
if [ ! -d .git -a ! -d .svn ]; then | |
PROJECT_SCM="false" | |
fi | |
# get project date | |
PROJECT_DATE=`date "+%Y-%m-%d"` | |
if [ -d EGG-INFO ]; then | |
ESCAPED_PROJECT_VERSION=`echo $PROJECT_VERSION | sed 's/\./\\\\./'` | |
AWK_PROG="/$ESCAPED_PROJECT_VERSION.*[0-9]{4}-[0-9]{2}-[0-9]{2}/{print\$3}" | |
PROJECT_DATE=`awk $AWK_PROG EGG-INFO/PKG-INFO | head -1 | xargs` | |
fi | |
# make sure sonar-runner can find a sonar-project.properties file | |
if [ ! -f sonar-project.properties ]; then | |
DO_DELETE_PROPS_FILE="yes" | |
cp $SCRIPT_BASE_DIR/sonar-project.properties . | |
fi | |
# run it | |
echo sonar-runner \ | |
-Dsonar.language=py \ | |
-Dsonar.projectKey=$PROJECT_KEY \ | |
-Dsonar.projectVersion=$PROJECT_VERSION \ | |
-Dsonar.projectDate=$PROJECT_DATE \ | |
-Dsonar.projectName=$PROJECT_NAME \ | |
-Dsonar.sources=$PROJECT_SRC \ | |
-Dsonar.scm.enabled=$PROJECT_SCM | |
# -Dsonar.projectDate=$PROJECT_DATE | |
# cleaning up | |
if [ "$DO_DELETE_PROPS_FILE"x != "x" ]; then | |
rm sonar-project.properties | |
fi |
This file contains hidden or 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
# project metadata (required) | |
sonar.projectKey=parameter | |
sonar.projectName=parameter | |
sonar.projectVersion=parameter | |
# path to source directories (required) | |
sonar.sources=parameter | |
# The value of the property must be the key of the language. | |
sonar.language=py |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment