Sonar Setup in Local windows machine for local Liferay
instances
Sonar is an open source platform to manage code quality. It
will helpful to follow some coding standards and to reduce code review
comments.
·
Sonar
installation steps
·
Download Sonar 3.0 from http://dist.sonar.codehaus.org or http://www.sonarqube.org/downloads/
·
Extract it in at your choice of directory
·
Create a database with the name as “sonar” in MySQL
database.
·
Open <Sonar Directory>/conf/sonar.properties
file
·
Provide your database username and password as shown
below
sonar.jdbc.username:
root
sonar.jdbc.password:
root
·
Uncomment the below lines of code by removing “#” for
mysql jdbc connection.
sonar.jdbc.url:
jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true
sonar.jdbc.driverClassName:
com.mysql.jdbc.Driver
sonar.jdbc.validationQuery:
select 1
·
Start tomcat by running “<Sonar-directory>/bin/windows-x86-64/StartSonar.bat (if you
are using 64 bit machine) or
·
Start tomcat by
running “<Sonar-directory>/bin/windows-x86-32/StartSonar.bat (if you
are using 32 bit machine).
·
In Console, “Started SelectChannelConnector@0.0.0.0:9000"
message will be displayed. It means your sonar server is up now.
·
Open Browser and access http://localhost:9000/
·
Login using admin/admin.
·
Go to configuration by clicking configuration link in
top menu
·
Click on Restore Profile link.
·
You can change the rules of the sonar if you want. If you
have created your own rules for your company (e.g. <Company_name>_Liferay_Projects.xml)
·
Then upload a file and click on “Restore Profile”
button. It will install <Company_Name>_Liferay_Projects rules in
Sonar.
·
Now you can see “<Company_Name>_Liferay_Projects” in Java
Profiles table.
·
Click on set as default button for “<Company_Name>_Liferay_Projects”
·
After
installation, we require a build setup
·
Download “sonar-ant-task-1.3.jar” and put it in
<Apache_Ant_home>/lib.
·
Open build.xml of your plugins-sdk and put the below
code just before ending the </project> tag and make the changes in properties
which given in bold.
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
</taskdef>
<!-- Add the target -->
<target name="sonar">
<property name="sonar.jdbc.url"
value="jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8"
/>
<property name="sonar.jdbc.driverClassName"
value="com.mysql.jdbc.Driver" />
<!-- the username and password of your
database -->
<property name="sonar.jdbc.username" value="root" />
<property name="sonar.jdbc.password" value="root" />
<!-- list of mandatories Sonar properties -->
<property name="sonar.sources"
value="portlets/sample-portlet/docroot/WEB-INF/src,portlets/new-sample-portlet/docroot/WEB-INF/src"
/>
<property name="sonar.projectName" value="“<Company_Name>-portal" />
<property name="sonar.binaries"
value="portlets/sample-portlet/docroot/WEB-INF/classes,portlets/new-sample-portlet/docroot/WEB-INF/classes"
/>
<property name="sonar.exclusions"
value="" />
<property name="sonar.libraries"
value="portlets/sample-portlet/docroot/WEB-INF/lib,portlets/new-sample-portlet/docroot/WEB-INF/lib"
/>
<sonar:sonar key=“<Company_Name>-portal: “<Company_Name>"
version="0.1-SNAPSHOT"
xmlns:sonar="antlib:org.sonar.ant"/>
</target>
·
Build your plugin (e.g. portlet, hook, etc.) using ant
command “ant deploy” or “ant compile”
·
Then generate sonar report using “ant sonar”
Congratulation! It’s done.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.