Reputation: 21
SAP Hybris Suite comes with integrated PMD Plugin and runs custom PMD Code rulesets.
The PMD Plugin is called through Hybris ANT build script.
But i would like to know if there is a way to integrate Hybris Suite with SonarQube
Upvotes: 2
Views: 7510
Reputation: 9126
The sonar
target is deprecated. Instead you should use the sonarcheck
target. This target by default scans all extensions added to the localextensions.xml
file, but you may overwrite this list. All parameters may be configured by using the local.properties
file or by passing them by the system properties (parameters prefixed with -D
).
Let's say you have 4 extensions in the bin/modules/custom
directory. They are named ext1
, ext2
, ext3
and ext4
. Bellow are steps which should be executed to perform SonarScanner analysis with a test code coverage.
SonarScanner requires the project to be built (binary files are required).
cd ${HYBRIS_HOME}/hybris/bin/platform
. ./setantenv.sh
localextensions.xml
ant extensionsxml \
-Dplatform.extensionsgen.filename=${HYBRIS_HOME}/hybris/config/localextensions.xml \
-Dplatform.extensions=ext1,ext2,ext3,ext4
ant all
The SAP Hybris suite provides two tasks to execute tests:
Both must be executed with additional parameters to generate test code coverage report.
cd /tmp
wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.agent/0.8.6/org.jacoco.agent-0.8.6-runtime.jar -O jacocoAgent.jar
cd ${HYBRIS_HOME}/hybris/bin/platform
alltests
ant alltests \
-Dtestclasses.extensions=ext1,ext2,ext3,ext4 \
-Dtestclasses.reportdir=/tmp/alltests \
-Dstandalone.javaoptions="-Djava.locale.providers=COMPAT,CLDR -javaagent:/tmp/jacocoAgent.jar=destfile=/tmp/jacocoAlltests.exec"
The java.locale.providers
parameter is required to not break tests which uses non ASCII characters in the impex
files. It is only needed when the JaCoCo agent is added.allwebtests
ant allwebtests \
-Dtestclasses.extensions=ext1,ext2,ext3,ext4 \
-Dtestclasses.reportdir=/tmp/allwebtests \
-Dstandalone.javaoptions="-Djava.locale.providers=COMPAT,CLDR -javaagent:/tmp/jacocoAgent.jar=destfile=/tmp/jacocoAllwebtests.exec"
When all tests are done we have to convert the JaCoCo exec
files to the XML format.
cd /tmp
wget https://repo1.maven.org/maven2/org/jacoco/org.jacoco.cli/0.8.6/org.jacoco.cli-0.8.6-nodeps.jar -O jacocoCli.jar
cd ${HYBRIS_HOME}/hybris/bin/platform
java -jar /tmp/jacocoCli.jar report \
/tmp/jacocoAlltests.exec \
/tmp/jacocoAllwebtests.exec \
--classfiles ${HYBRIS_HOME}/hybris/bin/modules/custom/ext1 \
--classfiles ${HYBRIS_HOME}/hybris/bin/modules/custom/ext2 \
--classfiles ${HYBRIS_HOME}/hybris/bin/modules/custom/ext3 \
--classfiles ${HYBRIS_HOME}/hybris/bin/modules/custom/ext4 \
--xml /tmp/jacocoTestReport.xml
There are a few parameters which should be set:
sonar.host.url
- the SonarQube/SonarCloud server URLsonar.login
- the user's token used to authorize to the serversonar.projectKey
- the project identifiersonar.projectName
- the project display namesonar.projectVersion
- the project versionsonar.java.source
- the Java version required to run the software (required only for versions older than 2105)sonar.extensions
- the extensions which should be analyzed (required only for versions older than 2105)sonar.junit.reportPaths
- the paths to the test resultssonar.test.exclusions
- the tests which should be excluded by SonarScannersonar.coverage.jacoco.xmlReportPaths
- the path to the JaCoCo XML reportant sonarcheck
-Dsonar.host.url=https://example.org/ \
-Dsonar.login=1234567890abcdefghijk \
-Dsonar.projectKey=my.company:custom-extensions \
-Dsonar.projectName="Custom Extensions" \
-Dsonar.projectVersion=1.0.0-SNAPSHOT \
-Dsonar.java.source=11 \
-Dsonar.extensions=ext1,ext2,ext3,ext4 \
-Dsonar.junit.reportPaths=/tmp/alltests,/tmp/allwebtests \
-Dsonar.test.exclusions= \
-Dsonar.coverage.jacoco.xmlReportPaths=/tmp/jacocoTestReport.xml
Upvotes: 0
Reputation: 1186
Depending on your hybris version, there's an already existing sonar
Ant task that will send the metrics to Sonar.
First go to your platform home:
cd $HYBRIS_HOME/hybris/bin/platform
Then, to initialize Ant correctly:
. ./setantenv.sh
Execute tests:
ant unittests
The send the results to Sonar:
ant sonar
Sonar Runner can be configured inside the platform in the config/local.properties
file. For example:
sonar.java.source=8
sonar.projectName=Example
sonar.projectKey=example
sonar.exclusions=file:**/gensrc/**, **/ws/axis/*
sonar.login=secret
sonar.password=evenmoresecret
sonar.excludedExtensions=core,testweb,scripting,paymentstandard,mediaweb,maintenanceweb,deliveryzone,commons,processing,impex,validation,catalog,europe1,platformservices,workflow,hac,comments,advancedsavedquery,springintegrationlibs,ldap,hmc,virtualjdbc,cockpit,admincockpit,reportcockpit,platformhmc,productcockpit,customerreview,sapcoretest,sapcoreodata,sapcore,sapcorejco,sapcorejcorec,sapcorebol,advancedexport,backoffice,datahubbackoffice,mcc,wishlist,mediaconversion,solrfacetsearch,solrfacetsearchhmc,voucher,promotions,basecommerce,ticketsystem,cms2,cms2lib,btg,cmscockpit,btgcockpit,b2bcommerce,payment,commerceservices,b2bapprovalprocess,commercewebservicescommons,cscockpit,acceleratorservices,b2bacceleratorservices,acceleratorcms,commercefacades,acceleratorfacades,acceleratorstorefrontcommons,b2bacceleratorfacades,addonsupport,sapcoreaddon,captchaaddon,liveeditaddon,commercesearch,commercesearchhmc,commercesearchbackoffice,datahubadapter,sapcoreconfiguration,sapmodel,sapproductavailability,sapproductavailabilityhmc,b2bsapproductavailability,sappricingbol,sappricinghmc,sappricing,sappricingproductcarouseladdon,b2bsappricing,sapcustomerb2c,sapcustomerb2b,sapmodelhmc,saporderexchange,saporderexchangeb2b,sapcoreconfigurationhmc,sapproducthmc,sapcoreconfigurationbackoffice,multipaymentmode,amazonpay,codpayment,bspay,paypalservice
This is also the place you might want to configure the Sonar instance results need to be sent to.
Upvotes: 4
Reputation: 22804
Assuming this is Java code we're talking about you can easily "analyze" it with SonarQube. As far as "integrating" it goes, if you mean that you want to run the "custom PMD Code rulesets" via SonarQube, that's should be just a matter of installing the SonarQube PMD plugin and setting up the Quality Profile.
Upvotes: 1