Synchronization with CheckStyle (Java)

CheckStyle is a parser for Java code. You may use Checkstyle in embedded mode or else pass your  Checkstyle reports to Themis.

Analysis embedded in Themis

To delegate to Themis the analysis of your JavaScript code to EsLint, you should configure first the embedded linters mode for your source. You may then add a sub-plugin for Checkstyle.

Themis uses a default configuration of CheckStyle appointed google_checks. You may at any one time modify this content at the XML format.

In the case in which you have already a XML configuration file on your source code repository, you may indicate to Themis to use this configuration. To this end, you have to specify the combination of the two following parameters:

  • Use the file present on your repository (true/false): Indicate true to use your configuration file.
  • Relative way of the file on your repository: Indicate here the relative way on your source code repository of the configuration file. Example: src/my_checks.xml.

If you activate the use of your own configuration file, the "Configuration file" parameter is not taken into account in the analysis. It does not reflect also in no way the content of the configuration file on your source code repository.

Information and installed versions

Website: http://checkstyle.sourceforge.net/

Extensions of the analyzed files: .java.

Version of Themis Version of Checkstyle
2.6.0 8.15
1.0.4 7.5.1

 

Mailing of Checkstyle reports to Themis

If you use Checkstyle outside Themis, you have the possibility to synchronize the reports produced by Checkstyle at the XML format to Themis.

Preparation of the source in the source in Themis

The produced Checkstyle reports are tied to one of your code repositories. You have to indicate to your Themis source that the data tied to the code coverage will come from external reports.

Pour cela, rendez-vous dans la partie Administration, puis Projets et identifiez la Source concernée. Ajoutez ensuite un plugin pour la pratique "Dette technique", en indiquant Rapports externe - Checkstyle. Pour rappel, l'ajout d'un plugin se fait en ouvrant la liste des plugins de la source, puis en cliquant sur Ajout un plugin.

Use of the Jenkins plugin

In Jenkins, add a step in the Actions following the build part, by cliking on the Add an action following the build drop-down. Select Send report files to Themis.

On adding this step, the XML report produced by Checkstyle has to be available in the Jenkins work directory. You have therefore already performed Checkstyle on adding this step in your pipeline.

Select the Themis body and indicate the key of the source tied to the code repository in current analysis in Jenkins.

In the Report Files section, select for Type the Checkstyle value. Then in Path, indicate one or several expressions (separated by commas) allowing to access to the XML files produced by Checkstyle.

For example, checkstyle-result.xml or**/target/**/checkstyle-result.xml

Mailing of files by the REST API

If you do not use Jenkins, or do not wish to use the Jenkins plugin, it is possible to use the API of Themis to synchronize the Checkstyle reports. Here is an example of BASH script that you may implement in an other language if you wish (the variables at first are to adapt in your context).

Note that the type of reports to specify is checkstyle in the payload of the JSON request.

#!/bin/bash

#TOCHANGE THEMIS_URL="http://mythemis.com" SOURCE_KEY="da4e11f4-5489-4b2a-a028-20d071b1c671" API_KEY="NWJjZWQ3ZmNhYTJhYzkwMWRmNGZhYTYx" CHECKSTYLE_REPORT_FILE="checkstyle-result.xml" CURRENT_COMMIT=$(git rev-parse HEAD) #Current GIT commit
#For SVN : $(svn info --show-item last-changed-revision) CURRENT_DATE=$(date +%s)"000" WORKSPACE=$(pwd) #the root directory of the source code repository REPORT_ARCHIVE="themis_report.zip" #First of all, create a directory with all Checkstyle reports REPORT_DIR=$(mktemp -d -p /tmp) find . -name $CHECKSTYLE_REPORT_FILE -exec cp --parents \{\} $REPORT_DIR \; if [ -e $REPORT_ARCHIVE ];then echo "Remove existing archive" rm $REPORT_ARCHIVE else echo "File "$REPORT_ARCHIVE" does not exist" fi #Create archive to send to Themis zip -r $REPORT_ARCHIVE $REPORT_DIR curl -i \ -H "Content-Type: multipart/form-data" \ -H "Accept: application/json,application/zip" \ -H "themis-api-key:$API_KEY" \ -X POST \ -F 'metadata={ "executionDate" : "'$CURRENT_DATE'", "dataType" : "checkstyle", "commit" : "'$CURRENT_COMMIT'", "dataWorkspace" : "'$WORKSPACE'"};type=application/json' \ -F "archive=@"$REPORT_ARCHIVE";type=application/zip" \ $THEMIS_URL/api/reportFiles/$SOURCE_KEY rm -rf $REPORT_DIR
rm $REPORT_ARCHIVE
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.