Wednesday, September 13, 2017

Sonar In Hybris


  • Download SonarQube from https://www.sonarqube.org/downloads/
  • Install/Unzip the SonarQube in a directory
  • Create a new mysql db "CREATE DATABASE sonar"
  • Set the db properties in sonar.properties file 
    • sonar.jdbc.username=
    • sonar.jdbc.password=
    • sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance&useSSL=false
  • Put the mysql driver in the directory sonarqube-6.5\extensions\jdbc-driver
  • Set the following properties in sonar.properties file
    • sonar.web.context=/sonar
    • sonar.web.javaOpts=-server -Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError
    • sonar.search.port=0
  • Start sonar qube via >StartSonar.bat and access localhost:9000/sonar 
  • login using admin/admin
  • Go to http://localhost:9000/sonar/profiles and restore the hybris official profile java-hybris-profile-public.xml
  • Set Hybris Official profile as the default java profile
  • Download the ant task jar sonarqube-ant-task-2.5.jar and put it in  config/customize/platform/resources/ant/sonar/lib
  • Now there are two ways to run sonar profiler using 1)  a new sonar build file and 2)existing hybris sonar build file
    • 1)  a new sonar build file
      • Create an ant file with the following contents
   
   
        value="jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8" />
   
   
   
   
   
        value="Hybris Java Project analyzed with the Sonar Ant Task" />
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
       
           
       
       
       
   
      • Go to the directory and run the above ant file. You will see the sonar is updated with a new project with name "Sonar Build for Hybris"
    • 2)existing hybris sonar build file
      • Add the following properties to local.properties file
        • sonar.language=java
        • sonar.projectName=HYB SONAR
        • sonar.projectKey=HYB SONAR
        • sonar.projectVersion=1.0
        • sonar.excludedExtensions=acceleratorcms,acceleratorfacades,acceleratorservices,acceleratorstorefrontcommons,addonsupport,captchaaddon,commercefacades,platformservices
        • sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true&useConfigs=maxPerformance
      • Copy platform/resources/ant/sonar.xml into /config/customize/platform/resources/ant and change the following references in the file
        • replace the existing sonarqube-ant-task jar file wih the new sonarqube-ant-task-2.5.jar file
        • replace all "sonar.binaries" with "sonar.java.binaries"
        • replace all "sonar.libraries" with "sonar.java.libraries"
      • In hybris/bin/platform execute "ant customize sonar" to apply the above customisations
      • In hybris/bin/platform execute "ant customize sonar" to apply the above customisations
      • Now a project named HYB SONAR is created in sonar
Ref : https://wiki.hybris.com/display/hybrisALF/Measuring+Code+Quality+with+Sonar