Sonar is an open platform to manage code quality. Sonar can gather data from your Groovy projects and display them on a web interface or straight in SpringSource Toolkit via an eclipse plugin.
1. How to enable analysis of your Groovy projects
- If your project is not mavenised,you will need to create a pom.xml.
cd into your project folder and run:
mvn org.grails:grails-maven-plugin:1.3.7:create-pom -DgroupId=YOURGROUPID
mvn org.grails:grails-maven-plugin:1.3.7:create-pom -DgroupId=YOURGROUPID
- Edit your pom xml. Add:
<sourceDirectory>src/main/groovy</sourceDirectory>
<properties>
<sonar.language>grvy</sonar.language>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
</properties>
<sourceDirectory>src/main/groovy</sourceDirectory>
<properties>
<sonar.language>grvy</sonar.language>
<sonar.dynamicAnalysis>false</sonar.dynamicAnalysis>
</properties>
2. How to add your project to the sonar console
- You need to install the Flex plugin to enable analysis of AS3 and flex projects:
Go to System>Update Center:

- Under Available plugins find Groovy and click install:

- Restart sonar:
macosx-universal-64/sonar.sh stop
macosx-universal-64/sonar.sh console
..or the linux/windows equivalent...
macosx-universal-64/sonar.sh stop
macosx-universal-64/sonar.sh console
..or the linux/windows equivalent...
- Go to the sonar profiles page.
If you installed sonar locally,the default url is:
http://localhost:9000/profiles/projects/
http://localhost:9000/profiles/projects/
If the installation was successful,you should see a ‘Sonar Groovy Way ‘ section:

3. How to gather data from your Groovy project and analyse it in Sonar
- cd into your project folder. Clean and Install your project into your local maven repo:
- run the sonar analysis:
- Go to your Sonar profile page. For local installs the default url is: http://localhost:9000/profiles
- Click on +Create or ‘Sonar Groovy Way‘ and? add your project to the associated projects:

- Go back to your sonar web interface (http://localhost:9000) –? the reports on all gathered data should be displayed.
4. How to install and configure the Sonar Eclipse Plugin in STS
- Go to Help>Install New software
Enter the Sonar Update Site:
http://dist.sonar-ide.codehaus.org/eclipse/
http://dist.sonar-ide.codehaus.org/eclipse/

- Click Next,Accept T&C,Reboot STS when prompted
- go to preferences,type in sonar to the filter:
 If you are running sonar on http://localhost:9000/,then you don’t need to do anything. If your are running on a different host:port,click on add and and add a new Sonar Server URL.
- To verify the connection you can click on edit and click on Test Connection. In the console you should get:
[INFO] Connected to Sonar 2.8
[INFO] Connected to Sonar 2.8
- Right click on your project in the Project explorer,go to Configure > Associate with Sonar:

- 1. Select your Sonar server from the dropdown list
2. Copy the GroupID and ArtifactID from your pom.xml 3. Click on Find on Server
- Switch over to Sonar View:


- If the sonar analysis was successful,your Measures,Web,Hotspots and Violations panel will be populated with the gathered data.
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|