使用 Ant 配置 Sonar 模块的 build.xml 文件 [英] Configuration of build.xml file for Sonar modules with Ant

查看:33
本文介绍了使用 Ant 配置 Sonar 模块的 build.xml 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个 Sonar 项目(使用 delphi 插件),为简单起见,假设我想报告两个模块.

I am setting up a Sonar project (using the delphi plugin), for simplicity sake assume there are two modules I want to report on.

每个模块都在自己的子文件夹中,每个模块都有自己的 build.xml 文件.

Each module is in it's own sub-folder and each has it's own build.xml file.

此时我可以成功运行声纳任务并为每个模块作为独立项目生成报告.

At this point I can successfully run the sonar tasks and generate reports for each module as an independent project.

我的问题是配置master"build.xml 文件.

My problem is with configuring the "master" build.xml file.

模块 build.xml 文件如下所示:

The module build.xml file looks like this:

<?xml version="1.0"?>
<project name = "CRM" default = "sonar" basedir = ".">
    <!-- Add the Sonar task -->
    <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
        <classpath path="c:/ANT/lib" />
    </taskdef>

    <target name="sonar">
        <property name="sonar.projectKey" value="EXO:CRM" />
        <property name="sonar.host.url" value="http://localhost:9000" />
        <sonar:sonar workDir="." key="CRM.key" version="0.1" xmlns:sonar="antlib:org.sonar.ant">
            <property key="sonar.sources" value="." />      <!-- project sources directories (required) -->
            <property key="sonar.language" value="delph" />                             <!-- project language -->
            <property key="sonar.delphi.codecoverage.excluded" value=".\tests" />           <!-- code coverage excluded directories -->
            <property key="sonar.importSources" value="true" />                         <!-- should we show sources or not? -->     
            <property key="sonar.delphi.sources.excluded" value="" />                       <!-- excluded directories -->
            <property key="sonar.delphi.sources.include" value=".\includes" />              <!-- include directories, "," separated -->
            <property key="sonar.delphi.sources.include.extend" value="true" />         <!-- should we extend includes in files? -->
        </sonar:sonar>
    </target>
</project>

Master" build.xml 如下所示:

The "Master" build.xml looks like this:

<?xml version="1.0"?>
<project name = "EXO" default = "sonar" basedir = ".">
    <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
        <classpath path="c:/ANT/lib" />
    </taskdef>

    <target name="sonar">
        <property name="sonar.modules" value="exonet6000/build.xml,CRM/build.xml" />
        <sonar:sonar workDir="." key="EXO.key" version="0.1" xmlns:sonar="antlib:org.sonar.ant">
            <!-- project sources directories (required) --> 
            <property key="sonar.sources" value="." />      
            <property key="sonar.language" value="delph" />
            <property key="sonar.importSources" value="true" /> 
            <property key="sonar.delphi.sources.excluded" value="" />                       
            <property key="sonar.delphi.sources.include" value=".\includes" />      
            <property key="sonar.delphi.sources.include.extend" value="true" />         
        </sonar:sonar>
    </target>
</project>

它总是扫描所有来源(必需值),即它不尊重我的模块.我目前可以让它工作的唯一方法是限制这样的源代码

It is always scanning all sources (required value) i.e. it is not respecting my modules. The only way I can get this to work currently is by limiting the source code like this

<property key="sonar.sources" value="./crm/,./exonet6000/" />   

我确定我在这里配置了一些明显的东西.

I'm sure I must be mis-configuring something obvious here.

我现在有我认为基于此处示例的更一致的文件集https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/java-ant-modules

I have now what I believe is a more consistent set of files based on examples here https://github.com/SonarSource/sonar-examples/tree/master/projects/languages/java/java-ant-modules

主构建文件:

<?xml version="1.0" encoding="UTF-8"?>
<project name = "EXO" default = "sonar" basedir = "." xmlns:sonar="antlib:org.sonar.ant">
    <echo>Root Project</echo>

    <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
        <classpath path="c:/ANT/lib" />
    </taskdef>

    <property name="sonar.host.url" value="http://localhost:9000" />
    <property name="sonar.modules" value="exonet6000/build.xml,CRM/build.xml" />

    <target name="sonar">
        <sonar:sonar key="EXO.key" version="0.1">   
        </sonar:sonar>
    </target>
</project>

和子模块文件之一

<?xml version="1.0" encoding="UTF-8"?>
<project name="CRM" default="all" basedir=".">
    <echo>CRM Module</echo>

    <property name="sonar.language" value="delph" />
    <property name="sonar.projectKey" value="EXO:CRM" />
    <property name="sonar.sources" value="." /> 

    <target name="all" />
</project>

此时声纳过程已成功完成,但没有进行实际分析.一个关键点是我没有看到子模块的回声,所以我怀疑这些构建任务实际上没有运行.

At this point the sonar process is completing successfully BUT no actual anlysis is being done. A key point is that I am not seeing the echo of the submodule so I suspect these build tasks are not actually running.

推荐答案

如果你看看 这个使用 Ant 和多模块的示例项目,我想说你不应该在你的主 bu​​ild.xml 文件的标签内指定任何属性,并让子模块指定这些属性.

If you look at this sample project using Ant and multimodules, I'd say that you should not specify any property inside the tag in your master build.xml file, and let the submodules specify those properties.

这篇关于使用 Ant 配置 Sonar 模块的 build.xml 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆