Sonar-Scanner for Ant问题

时间:2017-09-20 07:11:59

标签: ant sonarqube sonar-runner

我目前正在将sonar-ant-task 1.4支持的build.xml文件更改为针对Ant 2.5的SonarQube Scanner的build.xml,以解决与命名相关的问题。 SonarQube 5.6.3。     我们为salesforce语言自定义插件创建了一个自定义插件,以便将旧版本升级到最新版本。 Build.xml如下所示

`           

      <!-- Define the Sonar task -->
      <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
        <classpath path="sonar-ant-task-2.5.jar" />
      </taskdef>

      <!-- define the force versions task -->
        <taskdef name='scm' classname='com.villagechief.codescan.versions.ant.ScmCommitterTask'>
        <classpath path="force-versions-0.2-SNAPSHOT.jar" />
      </taskdef>

      <!-- Define the Salesforce task -->
      <taskdef uri="salesforce" resource="com/salesforce/antlib.xml">
        <classpath path="ant-salesforce.jar" />
      </taskdef>
       <!-- Add the target -->
      <target name="sonar">
      <!--java srcdir="sonar-project-template\src" target="sonar-project-template\src" bootclasspath="C:\Program Files\Java\jdk1.8.0_145\jre\lib\rt.jar"/-->
         <property name="sonar.host.url" value="Link to another server/" />

        <property Name="sonar.login" value="****"/>
        <property Name="sonar.password" value="****"/>

        <!-- db properties -->
        <property name="sonar.jdbc.url" value="jdbc:sqlserver://<serverip>;databaseName=sonar" />
        <property name="sonar.jdbc.username" value="****" />
        <property name="sonar.jdbc.password" value="****" />


        <!-- location properties -->
        <property name="sonar.sources" value="${user.dir}/src" />
        <property name="sonar.binaries" value="${user.dir}/bin" />
        <property name="sonar.tests" value="${user.dir}/tests" />
        <property name="sonar.libraries" value="${user.dir}/" />

        <!-- define if not already defined properties -->
        <property name="sonar.language" value="sf" />
        <property name="salesforce.url" value="https://www.salesforce.com" />
        <property name="sonar.projectVersion" value="1.0-SNAPSHOT" />
        <sonar:sonar key="${sonar.projectKey}" version="${sonar.projectVersion}" xmlns:sonar="antlib:org.sonar.ant"/>
      </target>

      <target name="commit">
        <scm username="${salesforce.username}" password="${salesforce.password}" serverurl="${salesforce.url}" repository="${scm}" >
                <fileset dir="${user.dir}/src">
                    <include name="**/*"/>
                </fileset>
            </scm>
      </target>

      <target name="deletesrc">
        <delete dir="${user.dir}/src">
            <include name="**/*"/>
            <exclude name="package.xml"/>
        </delete>

      </target>
      <target name="download">
        <!-- Retrieve the contents listed in the file codepkg/package.xml into the codepkg directory -->
        <sf:retrieve username="${salesforce.username}" password="${salesforce.password}" serverurl="${salesforce.url}" 
          retrieveTarget="src" unpackaged="src/package.xml"/>
        <!--   
        <sf:retrieve username="${salesforce.username}" password="${salesforce.password}" serverurl="${salesforce.url}" 
          retrieveTarget="src" packageNames=""/>-->
      </target>

      <target name="deploy">
        <!-- Retrieve the contents listed in the file codepkg/package.xml into the codepkg directory -->
        <sf:deploy username="${salesforce.username}" password="${salesforce.password}" serverurl="${salesforce.url}" 
          deployroot="src"/>
      </target>

      <target name="commitall">
        <exec executable="git" dir="${user.dir}">
          <arg value="add"/>
          <arg value="-A"/>
        </exec>
        <exec executable="git" dir="${user.dir}">
          <arg value="commit"/>
          <arg value="-a"/>
          <arg value="-m"/>
          <arg value="&lt;automcommit: all&gt;"/>
        </exec>
      </target>
      <!-- <target name="analyse" depends="deletesrc, download, commit, commitall, sonar" /> -->
      <!--target name="analyse" depends="deletesrc, download, sonar" /-->
    <target name="analyse" depends=" download, sonar" />
    </project>
    `

请让我知道我哪里弄错了。问题是当我运行命令时:#!/ bin / sh ant -f ../build.xml analyze 分析未发送到它显示在日志中正确执行的服务器。所以我认为build.xml有问题。所以我需要帮助。

这是运行命令后得到的日志:ant -f build.xml analyze

Buildfile: C:\runner\runner\antbuild.xml

deletesrc:

download:
[sf:retrieve] Request for a retrieve submitted successfully.
[sf:retrieve] Request Id for the current retrieve task: 04s90000003elivAAA
[sf:retrieve] Waiting for server to finish processing the request...
[sf:retrieve] Request Status: Completed
[sf:retrieve] Finished request 04s90000003elivAAA successfully.

sonar:

analyse:

BUILD SUCCESSFUL
Total time: 15 seconds

提前致谢!

1 个答案:

答案 0 :(得分:0)

我不知道吞下你的错误是什么,但是当我使用build.xml的简化版本跑步时,我得到了:

sonar:sonar doesn't support the "key" attribute

事实上,sonar:sonar代码并不支持任何属性。好吧删除所有属性,然后重试:

You must define the following mandatory properties for 'Unknown': sonar.projectKey

所以添加

<property name="sonar.projectKey" value="foo"/>

分析运行得非常好。

那就是说,我对我还没有提到的任务做了一些其他修改。首先,假设SonarQube的现代版本(> 5.2),不需要为分析提供数据库凭证,因此应该将其剥离。其次,从5.3开始,你不应该提供SonarQube登录名和密码,而是generating a token并将其作为登录值传递。最后,sonar.binaries很久以后就被弃用了。请改用sonar.java.binaries

相关问题