# ----------------------------------------------------------------------------- # JENKINS BUILDOUT FOR CODE ANALYSIS # ----------------------------------------------------------------------------- # This buildout needs to be extended by overriding the # jenkins-test-directories variable. See README.txt for more details. # ----------------------------------------------------------------------------- [buildout] parts += pep8 jenkins-pep8 pyflakes jenkins-pyflakes flake8 jenkins-flake8 ohcount jenkins-ohcount clonedigger jenkins-clonedigger zptlint jenkins-zptlint i18ndude i18nreport jenkins-i18ndude jenkins-i18report jenkins-xmllint jenkins-jslint jenkins-jshint jenkins-coffeelint jenkins-csslint jenkins-utf8-header jenkins-code-analysis jenkins-directory = ${buildout:directory}/parts/jenkins-test # This value needs to be overridden in the buildout file that extends this # buildout. jenkins-test-directories = # List the pep8 checks that a buildout file that extends this buildout may # want to ignore. Add them as a comma separated list, i.e. E501,W602,E401 ignore-pep8 = # A comma-seperated list of CSSLint rules to check (+) or ignore (-) # Learn more about rules: https://github.com/stubbornella/csslint/wiki csslint-ignore = adjoining-classes,floats,font-faces,font-sizes,ids,qualified-headings,unique-headings # ----------------------------------------------------------------------------- # PEP 8 CODE ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-pep8" script in the bin directory of the # buildout that runs a PEP 8 code analysis and outputs the results in a # pep8.log file that the Jenkins violations plugin can process. # ----------------------------------------------------------------------------- [pep8] recipe = zc.recipe.egg eggs = pep8 entry-points = pep8=pep8:_main [jenkins-pep8] recipe = collective.recipe.template url = https://raw.github.com/plone/buildout.jenkins/master/templates/code-analysis.sh output = ${buildout:directory}/bin/jenkins-code-analysis-pep8 title = Pep8 bin = ${buildout:directory}/bin/pep8 log = pep8.log before = analyse = $(find -L ${buildout:directory}/$pkg -regex ".*\.py" | xargs -r ${:bin} --ignore=${buildout:ignore-pep8} >> ${buildout:jenkins-directory}/pep8.log.tmp) after = $(cat ${buildout:jenkins-directory}/pep8.log.tmp|sed 's:${buildout:directory}/::' > ${buildout:jenkins-directory}/pep8.log) mode = 755 # ----------------------------------------------------------------------------- # PYFLAKES CODE ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-pyflakes" script in the bin directory of the # buildout that runs a PyFlakes code analyisis and outputs the results in # a pyflakes.log file that the Jenkins warnings plugin can process. # ----------------------------------------------------------------------------- [pyflakes] recipe = zc.recipe.egg eggs = pyflakes entry-points = pyflakes=pyflakes.scripts.pyflakes:main [jenkins-pyflakes] recipe = collective.recipe.template url = https://raw.github.com/plone/buildout.jenkins/master/templates/code-analysis.sh output = ${buildout:directory}/bin/jenkins-code-analysis-pyflakes title = PyFlakes bin = ${buildout:directory}/bin/pyflakes log = pyflakes.log before = analyse = $(find -L ${buildout:directory}/$pkg -regex ".*\.py" | xargs -r ${:bin} >> ${buildout:jenkins-directory}/pyflakes.log.tmp) after = $(cat ${buildout:jenkins-directory}/pyflakes.log.tmp|sed 's:${buildout:directory}/::' > ${buildout:jenkins-directory}/pyflakes.log) mode = 755 # ----------------------------------------------------------------------------- # FLAKE8 CODE ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-flake8" script in the bin directory of the # buildout that runs a PEP8 / PyFlakes code analyisis and outputs the results # in a flake8.log file that the Jenkins warnings plugin can process. # ----------------------------------------------------------------------------- [flake8] recipe = zc.recipe.egg eggs = flake8 entry-points = flake8=flake8.run:main [jenkins-flake8] recipe = collective.recipe.template url = https://raw.github.com/plone/buildout.jenkins/master/templates/code-analysis.sh output = ${buildout:directory}/bin/jenkins-code-analysis-flake8 title = Flake8 bin = ${buildout:directory}/bin/flake8 log = flake8.log before = analyse = $(find -L ${buildout:directory}/$pkg -regex ".*\.py" | xargs -r ${:bin} --ignore=${buildout:ignore-pep8} >> ${buildout:jenkins-directory}/flake8.log.tmp) after = $(cat ${buildout:jenkins-directory}/flake8.log.tmp|sed 's:${buildout:directory}/::' > ${buildout:jenkins-directory}/flake8.log) mode = 755 # ----------------------------------------------------------------------------- # PYLINT CODE ANALYSIS # ----------------------------------------------------------------------------- # XXX: Commented out for now. Pylint consumes just too much resources. #[pylint] #recipe = zc.recipe.egg #eggs = logilab.pylintinstaller #extra-paths = ${instance:location}/lib/python #entry-points = pylint=pylint.lint:Run #arguments = sys.argv[1:] #arguments = [ # '--output-format=parseable', # '--zope=y', # '--reports=y', # '--disable-msg=E0611,F0401,W0232,E1101,C0103,C0111,R0201,W0201,R0911,R0904#,F0220,E1103,R0901,E0211,E0213,E1002,W0622', # '--generated-members=objects', # ] + sys.argv[1:] # Disable messages: # # E0611: No name %r in module %r. Used when a name cannot be found in a module. # F0401: Unable to import %r (%s). Used when pylint has been unable to import a module. # W0232: Class has no __init__ method. Used when a class has no __init__ method, neither its parent classes. # C0103: Invalid name "%s" (should match %s). Used when the name doesn't match the regular expression associated to its type (constant, variable, class...). # C0111: Message Missing docstring Description Used when a module, function, class or method has no docstring. Some special methods like init don't necessary require a docstring. Explanation… # R0201: Method could be a function # W0201: Attribute %r defined outside __init__ # R0911: Too many return statements (%s/%s) # E0211: Method has no argument # - Reason: raises an error on zope.interface definitions # E0213 Method should have "self" as first argument # - Reason: raises an error on zope.interface definitions # E1121 Too many positional arguments for function call # - Reason: ??? # E1002 Use super on an old style class # - Reason: super(CommentsViewlet, self).update() raises an error # W0622 total_comments: Redefining built-in 'object' # - Reason: top level def function will not work (e.g. for catalog indexers) # ... # See http://pylint-messages.wikidot.com/all-messages for a full list. # # #[pylint] #recipe = collective.recipe.template #input = inline: # #!/bin/sh # if [ -s pylint.log ]; then # rm pylint.log # echo "Removing old pylint.log file" # fi # echo "Start pylint" # PACKAGES="${buildout:jenkins-test-directories}" # for pkg in $PACKAGES # do # echo "Running pylint for $pkg" # find -L $pkg -regex ".*\.py" | xargs -r bin/pylint >> pylint.log # done # echo "finish" #output = ${buildout:directory}/bin/jenkins-code-analysis-pylint #mode = 755 # ----------------------------------------------------------------------------- # CLONEDIGGER CODE ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-clonedigger" script in the bin directory of # the buildout... # ----------------------------------------------------------------------------- [clonedigger] recipe = zc.recipe.egg eggs = clonedigger [jenkins-clonedigger] recipe = collective.recipe.template input = inline: #!/bin/sh report=${buildout:jenkins-directory}/xml-clonedigger if [ -d $report ]; then echo "Old clonedigger xml reports removed" rm -rf $report fi echo "Start CloneDigger code analysis:" PACKAGES="${buildout:jenkins-test-directories}" for pkg in $PACKAGES do echo "Analyse $pkg" mkdir -p $report/$pkg ${buildout:directory}/bin/clonedigger --cpd-output -o $report/$pkg/clonedigger.xml ${buildout:directory}/$pkg done echo "Finished." echo "" output = ${buildout:directory}/bin/jenkins-code-analysis-clonedigger mode = 775 # ---------------------------------------------------------------------------- # OHCOUNT # ---------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-ohcount" script in the bin directory of the # buildout that runs, ohcount, a source code line counter. This requires # ohcount to be installed on the server (see # http://pypi.python.org/pypi/ohconvert for more information.) # The results can be included into Jenkins with the SLOCCount plugin: # https://wiki.jenkins-ci.org/display/JENKINS/SLOCCount+Plugin # $ sudo apt-get install ohcount # ---------------------------------------------------------------------------- [ohcount] recipe = zc.recipe.egg eggs = ohconvert [jenkins-ohcount] recipe = collective.recipe.template url = https://raw.github.com/plone/buildout.jenkins/master/templates/code-analysis.sh title = OHCount bin = ${buildout:directory}/bin/ohconvert log = sloccount.sc before = analyse = $(${:bin} $pkg >> ${buildout:jenkins-directory}/sloccount.sc) after = output = ${buildout:directory}/bin/jenkins-code-analysis-ohcount mode = 755 # ----------------------------------------------------------------------------- # XML LINT CODE ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-xmllint" script in the bin directory of the # buildout. This requires xmllint to be installed on the system. # ----------------------------------------------------------------------------- [jenkins-xmllint] recipe = collective.recipe.template url = https://raw.github.com/plone/buildout.jenkins/master/templates/code-analysis.sh title = XMLLint bin = xmllint log = xmllint.log before = $(\ command -v xmllint >/dev/null 2>&1 || { \ echo >&2 "XMLLint not found!"; \ echo "Skip XMLLint code analysis. Please make sure XMLLint is installed on your machine."; \ exit 1; \ }) analyse = $(find -L $pkg -regex ".*\.[cz]?xml|zcml" | xargs -r ${:bin} --noout 2>> ${buildout:jenkins-directory}/xmllint.log >> ${buildout:jenkins-directory}/xmllint-errors.log) after = $(cat ${buildout:jenkins-directory}/flake8.log.tmp|sed 's:${buildout:directory}/::' > ${buildout:jenkins-directory}/flake8.log) output = ${buildout:directory}/bin/jenkins-code-analysis-xmllint mode = 755 # ----------------------------------------------------------------------------- # ZPT LINT CODE ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-zptlint" script in the bin directory of the # buildout...TODO # ----------------------------------------------------------------------------- [zptlint] recipe = zc.recipe.egg eggs = zptlint entry-points = zptlint=zptlint:run [jenkins-zptlint] recipe = collective.recipe.template url = https://raw.github.com/plone/buildout.jenkins/master/templates/code-analysis.sh title = ZPTLint bin = ${buildout:directory}/bin/zptlint log = zptlint.log before = analyse = $(find -L $pkg -regex ".*\.[cz]?pt" | xargs -r ${:bin} >> ${buildout:jenkins-directory}/zptlint.log) after = output = ${buildout:directory}/bin/jenkins-code-analysis-zptlint mode = 755 # ----------------------------------------------------------------------------- # JAVASCRIPT CODE ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-jslint" script in the bin directory of the # buildout that runs a jslint based code analysis on all javascript files. # # This requires jslint to be installed manually on the server. # $ sudo apt-get install nodejs npm # $ sudo npm install -g jslint # ----------------------------------------------------------------------------- [jenkins-jslint] recipe = collective.recipe.template url = https://raw.github.com/plone/buildout.jenkins/master/templates/code-analysis.sh title = JSLint bin = jslint log = jslint.log before = $(command -v ${:bin} >/dev/null 2>&1 || { echo >&2 "JSLint not found!"; echo "Skip JSLint code analysis. Please make sure JSLint is installed on your machine."; exit 1; }) analyse = $(find -L $pkg -regex ".*\.[cz]?js" | xargs -r ${:bin} --jslint-reporter >> ${buildout:jenkins-directory}/jslint.log) after = output = ${buildout:directory}/bin/jenkins-code-analysis-jslint mode = 755 # ----------------------------------------------------------------------------- # JAVASCRIPT CODE ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-jshint" script in the bin directory of the # buildout that runs a jshint based code analysis on all javascript files. # see: http://www.jshint.com/options/ # # jslint does not return xml format, so we switched to jshint # # This requires jshint to be installed manually on the server. # $ sudo apt-get install nodejs npm # $ sudo npm install -g jshint # ----------------------------------------------------------------------------- [jenkins-jshint] recipe = collective.recipe.template url = https://raw.github.com/plone/buildout.jenkins/master/templates/code-analysis.sh title = JSHint log = xml-jshint bin = jshint before = analyse = $(\ report=${buildout:jenkins-directory}/xml-jshint; \ mkdir -p $report/$pkg; \ for jsfile in `find -L $pkg -regex ".*\.js" | xargs -r `; do \ ${:bin} $jsfile >> ${buildout:jenkins-directory}/jshint.log; \ jsfilename=`echo $jsfile | awk -F\/ '{ print $NF }'`; \ ${:bin} --reporter jslint $jsfile > $report/$pkg/$jsfilename.xml; \ done) after = output = ${buildout:directory}/bin/jenkins-code-analysis-jshint mode = 755 # ----------------------------------------------------------------------------- # COFFEESCRIPT CODE ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-coffeelint" script in the bin directory of the # buildout that runs a coffeelint based code analysis on all javascript files. # see: http://www.coffeelint.org/ # # This requires coffeelint to be installed manually on the server. # $ sudo apt-get install nodejs npm # $ sudo npm install -g coffeelint # ----------------------------------------------------------------------------- [jenkins-coffeelint] recipe = collective.recipe.template input = inline: #!/bin/bash command -v coffeelint >/dev/null 2>&1 || { echo >&2 "coffeelint not found!"; echo "Skip coffeelint code analysis. Please make sure coffeelint is installed on your machine."; exit 1; } if [ -e ${buildout:jenkins-directory}/coffeelint.log ]; then echo "Old coffeelint.log file removed" rm ${buildout:jenkins-directory}/coffeelint.log fi report=${buildout:jenkins-directory}/xml-coffeelint if [ -d $report ]; then echo "Old coffeelint xml reports removed" rm -rf $report fi echo "Start coffeelint code analysis:" PACKAGES="${buildout:jenkins-test-directories}" for pkg in $PACKAGES do echo "Analyse $pkg" mkdir -p $report/$pkg for coffeefile in `find -L $pkg -regex ".*\.coffee" | xargs -r `; do coffeelint $coffeefile >> ${buildout:jenkins-directory}/coffeelint.log # XXX: dollar{coffeefile##*/} does not work in template recipe coffeefilename=`echo $coffeefile | awk -F\/ '{ print $NF }'` coffeelint --jslint=1 $coffeefile > $report/$pkg/$coffeefilename.xml done done echo "Write log to ${buildout:jenkins-directory}/coffeelint.log" echo "Finished." echo "" output = ${buildout:directory}/bin/jenkins-code-analysis-coffeelint mode = 755 # ----------------------------------------------------------------------------- # CSS CODE ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-csslint" script in the bin directory of the # buildout that runs a jshint based code analysis on all css files. # # This requires jshint to be installed manually on the server. # $ sudo apt-get install nodejs npm # $ sudo npm install -g csslint # # XXX: CSSLint outputs "csslint: No files specified." which breaks violations # plugin. It should return xml on --format=lint-xml as jshint does... # ----------------------------------------------------------------------------- [jenkins-csslint] recipe = collective.recipe.template url = https://raw.github.com/plone/buildout.jenkins/master/templates/code-analysis.sh title = CSSLint log = xml-csslint bin = csslint before = analyse = $(\ report=${buildout:jenkins-directory}/xml-csslint; \ mkdir -p $report/$pkg; \ for cssfile in `find -L $pkg -regex ".*\.css" | xargs -r `; do \ ${:bin} --ignore=${buildout:csslint-ignore} $cssfile >> ${buildout:jenkins-directory}/csslint.log; \ cssfilename=`echo $cssfile | awk -F\/ '{ print $NF }'`; \ ${:bin} --format=lint-xml --ignore=${buildout:csslint-ignore} $cssfile > $report/$pkg/$cssfilename.xml; \ done) after = output = ${buildout:directory}/bin/jenkins-code-analysis-csslint mode = 755 # ----------------------------------------------------------------------------- # TRANSLATION CODE ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-translations" script in the bin directory # of the buildout that runs a code analysis on all templates to find # untranslated strings. # ----------------------------------------------------------------------------- [i18ndude] recipe = zc.recipe.egg eggs = i18ndude [jenkins-i18ndude] recipe = collective.recipe.template url = https://raw.github.com/plone/buildout.jenkins/master/templates/code-analysis.sh title = Translations bin = ${buildout:directory}/bin/i18ndude log = i18ndude.log before = analyse = $(find -L $pkg -regex ".*\.[cz]?pt" | xargs -r ${:bin} find-untranslated >> ${buildout:jenkins-directory}/i18ndude.log) after = output = ${buildout:directory}/bin/jenkins-code-analysis-translations mode = 755 [i18nreport] recipe = zc.recipe.egg eggs = collective.i18nreport [jenkins-i18report] recipe = collective.recipe.template input = inline: #!/bin/sh echo "Run i18nreport" ${buildout:directory}/bin/i18nreport --path=${buildout:directory} --format=html --all-languages >> ${buildout:jenkins-directory}/i18report.html echo "Finished." echo "" output = ${buildout:directory}/bin/jenkins-code-analysis-i18nreport mode = 775 # ----------------------------------------------------------------------------- # PYTHON FILES ENCODING ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis-utf8check" script in the bin directory # of the buildout that runs a code analysis on all python files to find # missing coding: utf-8 headers # ----------------------------------------------------------------------------- [jenkins-utf8-header] recipe = collective.recipe.template url = https://raw.github.com/plone/buildout.jenkins/master/templates/code-analysis.sh title = UTF-8 Headers bin = sh log = missing-utf-8-headers.log before = analyse = $(find $pkg -regex ".*\.py" -exec grep -H -E -o -c "coding: utf-8" {} \; | grep 0 | cut -d":" -f1 >> ${buildout:jenkins-directory}/missing-utf8-header.log) after = output = ${buildout:directory}/bin/jenkins-code-analysis-utf8header mode = 755 # ----------------------------------------------------------------------------- # CODE ANALYSIS # ----------------------------------------------------------------------------- # Creates a "jenkins-code-analysis" script in the bin directory of the buildout # that runs all code analysis sections at once. # ----------------------------------------------------------------------------- [jenkins-code-analysis] recipe = collective.recipe.template input = inline: #!/bin/sh bin/jenkins-code-analysis-pep8 bin/jenkins-code-analysis-pyflakes bin/jenkins-code-analysis-flake8 bin/jenkins-code-analysis-ohcount bin/jenkins-code-analysis-xmllint bin/jenkins-code-analysis-zptlint # bin/jenkins-code-analysis-jslint bin/jenkins-code-analysis-jshint bin/jenkins-code-analysis-csslint bin/jenkins-code-analysis-translations # bin/jenkins-code-analysis-clonedigger bin/jenkins-code-analysis-i18nreport bin/jenkins-code-analysis-utf8header output = ${buildout:directory}/bin/jenkins-code-analysis mode = 755