2011-08-24 68 views
1

我是一個初學者到SONAR,我只是需要一個樣本Ant構建文件幫助與SONAR的默認運行我的Java項目名稱的「Hello World」太陽檢查質量配置文件。我還沒有找到任何適當的螞蟻指南聲納。我正在使用SONAR 2.10。聲納Ant build.xml文件

請幫我在SONAR開始。

<project name="Example" default="Sonar" basedir="."> 
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml"> 
<classpath path="C:\Program Files\Apache Software Foundation\ant\lib\sonar-ant-task-1.0.jar" /> 
</taskdef> 
<!-- Out-of-the-box those parameters are optional --> 
<property name="sonar.jdbc.url" value="jdbc:mysql://localhost:3309/sonar" /> 
<property name="sonar.jdbc.driverClassName" value="com.mysql.jdbc.Driver" /> 
<property name="sonar.jdbc.username" value="root" /> 
<property name="sonar.jdbc.password" value="root" /> 
<!-- Additional Sonar configuration (PMD need 1.5 when using annotations)--> 
<property name="sonar.java.source" value="1.5"/> 
<property name="sonar.java.target" value="1.5"/> 
<property name="sonar.projectName" value="Example"/> 
<property name="sonar.binaries" value="C:\Documents and Settings\tausif\Feature2\Example\bin"/> 
<!-- SERVER ON A REMOTE HOST --> 
<property name="sonar.host.url" value="http://localhost:8080/sonar" /> 
<target name="Sonar"> 
<!-- The workDir directory is used by Sonar to store temporary files --> 
<sonar:sonar workDir="C:\Documents and Settings\tausif\Feature2\Sonar" key="com.example:example" xmlns:sonar="antlib:org.sonar.ant" > 
    <!-- source directories (required) --> 
    <sources> 
    <path location="C:\Documents and Settings\tausif\Feature2\Example" /> 
    </sources> 
</sonar:sonar> 
</target> 
</project> 

以上兩個答案真的有助於我創建這個XML文件。 這是我的示例build.xml。你可以請檢查我缺少的東西嗎? 我已經孫支票default.My項目名稱爲例子。

回答

1

您可能會發現this聲納2.6:增加了對螞蟻社區持續檢查支持)或this分析與Ant任務1.0)文檔很有幫助。

+0

謝謝,但我已經經歷了這一切,谷歌,並沒有太大的幫助,我瞭解如何運行太陽檢查我的Hello詞項目。非常感謝Sun檢查的任何示例build.xml。 –

+0

@Md Tausif Warsi讓太陽將檢查你的服務器的默認質量配置文件。然後,所有內容都將以此配置文件運行。或者使用在此規定的paramate sonar.profile: – oers

1

您可以參考以下ant腳本,專用於聲納。 你可以將它添加到你的build.xml中。 下面是詳細的腳本

<!-- Here you need to set the path which contains sonar specific jars required for ant e.g. path which contains sonar-ant-task-2.1.jar --> 
<path id="sonar.classpath"> 
    <fileset dir="${basedir}/sonar" includes="**/*.jar" /> 
</path> 

<!-- This taskdef represents your ant lib for sonar you have to specify jar location along with jar name in class path no need to change the uri and resource--> 
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml"> 
     <classpath path="${basedir}\sonar\sonar-ant-task-2.1.jar" /> 
</taskdef> 

<!-- This is the target we use to run sonar "depends" property is optional --> 
<target name="sonar" depends="clean, compile"> 
      <!-- specify your build version --> 
    <property name="build.version" value="0.0.0.1-Sonar"/> 

      <!-- specify your organization name its optional --> 
    <property name="mysonar.organizationName" value="XYZ"/> 

      <!-- specify your project Name --> 
    <property name="sonar.projectName" value="${project.name}" /> 

      <!-- database url which is used by the sonar --> 
    <property name="sonar.jdbc.url" value="jdbc:mysql://<IP>:<Port>/sonar?useUnicode=true&amp;characterEncoding=utf8" /> 

      <!-- Driver name--> 
    <property name="sonar.jdbc.driverClassName" value="com.mysql.jdbc.Driver" /> 

      <!-- database user name --> 
    <property name="sonar.jdbc.username" value="test" /> 

      <!-- database password --> 
    <property name="sonar.jdbc.password" value="test" /> 

      <!-- url on which sonar is running--> 
    <property name="sonar.host.url" value="http://<IP>:<Port>" /> 

      <!-- project key --> 
    <property name="sonar.projectKey" value="${mysonar.organizationName}:${sonar.projectName}" /> 

      <!-- project version--> 
    <property name="sonar.projectVersion" value="1.0" /> 

      <!-- location source files --> 
    <property name="sonar.sources" value="${src.home}/main/java" /> 

      <!-- location of binaries after compilation--> 
    <property name="sonar.binaries" value="${basedir}/output"/> 

      <!-- location of sonar library--> 
    <sonar:sonar xmlns:sonar="antlib:org.sonar.ant"> 

    </sonar:sonar> 
</target> 

注:請確保您指定的位置是正確的,你可以給絕對路徑爲好。

+0

您在註釋行中提到http://docs.codehaus.org/display/SONAR/Advanced+parameters,mySonar.organizationName是** **可選那麼爲什麼你使用它在sonar.projectkey上的值屬性。你能告訴我你爲什麼使用projectkey嗎?你在組織名稱中的含義。聲納整合。 –