声纳蚂蚁任务或 Hudson 集成覆盖范围报告

发布于 2024-12-12 00:14:30 字数 7526 浏览 0 评论 0原文

早上好,我有一个关于声纳中 cobertura 报告集成的问题。 我尝试了两种方式:来自哈德森和来自蚂蚁任务。 如果我使用 Hudson 来配置声纳集成,cobertura 报告会很好地集成到我的声纳仪表板中,但我收到一些警告,例如

Java bytecode scan... 
[WARN]  Class 'javax/mail/Folder' is not accessible through the ClassLoader.
[WARN]  Class 'javax/mail/Folder' is not accessible through the ClassLoader.
[WARN]  Class 'javax/mail/Folder' is not accessible through the ClassLoader.
[WARN]  Class 'javax/mail/Folder' is not accessible through the ClassLoader.
[WARN]  Class 'com/sun/mail/imap/IMAPFolder' is not accessible through the ClassLoader.

但是,我的 cobertura 报告集成得很好:

 [INFO]  Sensor CoberturaSensor...
 [INFO]  parsing C:\hudson\jobs\Client Mail\workspace\cobertura\reports\coverage.xml
 [INFO]  Sensor CoberturaSensor done: 1218 ms

所以,我决定使用 ant 任务,以便我可以管理我的librairies,这是我的 ant 任务:

 <target name="sonar" depends="cover-report">
<!-- The workDir directory is used by Sonar to store temporary files -->
<sonar:sonar workDir="./" key="fr.simscorps:client.mail" version="0.1-SNAPSHOT" xmlns:sonar="antlib:org.sonar.ant">
<property key="sonar.host.url" value="http://172.30.3.55:1234/sonar/" />
  <!-- source directories (required) -->
  <sources>
    <path location="./src" />
  </sources>

  <!-- list of properties (optional) -->
  <property key="sonar.dynamicAnalysis" value="reuseReports" />
  <property key="sonar.projectName" value="client mail" />
  <property key="sonar.java.source" value="1.5" />
  <property key="sonar.projectVersion" value="0.1-SNAPSHOT" /> 
  <property key="sonar.phase" value="generate-sources"/>
  <property key="sonar.cobertura.reportsPath" value="${reports.xml.dir}/coverage.xml"/>
  <property key="sonar.surefire.reportsPath" value="${reports.xml.dir}/TESTS-test.TestSuiteClientMail.xml" />



  <!-- test source directories (optional) -->
  <tests>
    <path location="./test" />
  </tests>

  <!-- binaries directories, which contain for example the compiled Java bytecode (optional) -->
  <binaries>
    <path location="./bin" />
  </binaries>

  <!-- path to libraries (optional). These libraries are for example used by the Java Findbugs plugin -->
  <libraries>
    <path location="./lib/activation.jar" />
    <path location="./lib/deltasync.jar" />
    <path location="./lib/jaybird_full_2_1_6.jar" />
    <path location="./lib/junit.jar" />
    <path location="./lib/mail.jar" />
    <path location="./lib/libdeltasync/apache-mime4j-0.5.jar"/>
    <path location="./lib/libdeltasync/commons-codec-1.5.jar"/>
    <path location="./lib/libdeltasync/commons-codec-1.5-javadoc.jar"/>
    <path location="./lib/libdeltasync/commons-codec-1.5-sources.jar"/>
    <path location="./lib/libdeltasync/commons-logging-1.1.1.jar"/>
    <path location="./lib/libdeltasync/httpclient-4.1.1.jar"/>
    <path location="./lib/libdeltasync/httpclient-cache-4.1.1.jar"/>
    <path location="./lib/libdeltasync/httpcore-4.1.jar"/>
    <path location="./lib/libdeltasync/httpmime-4.1.1.jar"/>
    <path location="./lib/libdeltasync/logback-classic-0.9.29.jar"/>
    <path location="./lib/libdeltasync/logback-classic-0.9.29-sources.jar"/>
    <path location="./lib/libdeltasync/logback-core-0.9.29.jar"/>
    <path location="./lib/libdeltasync/logback-core-0.9.29-sources.jar"/>
    <path location="./lib/libdeltasync/slf4j-api-1.6.1.jar"/>
    <path location="./lib/libdeltasync/slf4j-api-1.6.1-sources.jar"/>
  </libraries>
</sonar:sonar>
</target>

我的报告生成得很好(大约 700ko),在 Hudson 的日志中我看到了 cobertura 传感器,但就像他没有做任何事情:

[sonar:sonar] [INFO]  Sensor CoberturaSensor...
[sonar:sonar] [INFO]  Sensor CoberturaSensor done: 0 ms

在这里,我的另一个ant 任务依赖性:

 <property name="junit.output.dir" value="junit"/>
<property name="instrumented.dir" value="cobertura/instrumented"/>
<property name="classes.dir" value="bin"/>
<property name="jars.dir" value="lib"/>
<property name="test.dir" value="test"/>
<property name="cobertura.dir" value="${jars.dir}/cobertura"/>
<property name="reports.xml.dir" value="cobertura/reports"/>
<property name="cob.ser.file" value="cobertura.ser" />

 <!-- Define the Sonar task if this hasn't been done in a common script -->
   <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
   <classpath path="C:\hudson\tools\my_ant\lib" />
   </taskdef>

<path id="cobertura.classpath">
    <fileset dir="${cobertura.dir}">
        <include name="cobertura.jar" />
        <include name="lib/**/*.jar" />
    </fileset>
    <fileset dir="${jars.dir}">
        <include name="**/*.jar"/>
    </fileset>
</path>

<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
<target name="clean" >
    <delete dir="${instrumented.dir}" />
    <delete dir="${reports.xml.dir}" />
    <delete file="${cob.ser.file}" />
</target>

<target name="prepare" depends="clean">
        <mkdir dir="${instrumented.dir}" />
        <mkdir dir="${reports.xml.dir}" />
</target>
<target name="instrument" depends="prepare">
    <cobertura-instrument todir="${instrumented.dir}">
            <ignore regex="org.apache.log4j.*" />
            <fileset dir="${classes.dir}">
                <include name="**/*.class" />
                <exclude name="**/*Test.class" />
            </fileset>

        </cobertura-instrument>
</target>



<target name="testsuite" depends="instrument">
    <junit fork="yes" dir="${test.dir}" failureProperty="test.failed"  printsummary="withOutAndErr">
            <!--
                Specify the name of the coverage data file to use.
                The value specified below is the default.
            -->
            <sysproperty key="net.sourceforge.cobertura.datafile"
                file="${basedir}/cobertura.ser" />
            <!--
                Note the classpath order: instrumented classes are before the
                original (uninstrumented) classes.  This is important.
            -->
            <classpath location="${instrumented.dir}" />
            <classpath location="${classes.dir}" />

            <!--
                The instrumented classes reference classes used by the
                Cobertura runtime, so Cobertura and its dependencies
                must be on your classpath.
            -->
            <classpath refid="cobertura.classpath" />

            <formatter type="xml" />
            <test name="test.TestSuiteClientMail" todir="${reports.xml.dir}" />

            <!--<batchtest todir="${reports.xml.dir}" unless="testcase">
                <fileset dir="${test.dir}">
                    <include name="**/*Test*.java" />
                </fileset>
            </batchtest>-->
        </junit>
</target>

<target name="cover-report" depends="testsuite">
    <cobertura-report format="xml" destdir="${reports.xml.dir}" srcdir="${test.dir}" />
</target>

有人有想法吗?

Good morning, i've got a question about cobertura report integration in sonar.
I've tried two way: from hudson and from ant task.
if i used hudson to configure a sonar integration, the cobertura report is well integrated to my sonar dashboard but i've got some warning like

Java bytecode scan... 
[WARN]  Class 'javax/mail/Folder' is not accessible through the ClassLoader.
[WARN]  Class 'javax/mail/Folder' is not accessible through the ClassLoader.
[WARN]  Class 'javax/mail/Folder' is not accessible through the ClassLoader.
[WARN]  Class 'javax/mail/Folder' is not accessible through the ClassLoader.
[WARN]  Class 'com/sun/mail/imap/IMAPFolder' is not accessible through the ClassLoader.

But, my cobertura report is well integrated:

 [INFO]  Sensor CoberturaSensor...
 [INFO]  parsing C:\hudson\jobs\Client Mail\workspace\cobertura\reports\coverage.xml
 [INFO]  Sensor CoberturaSensor done: 1218 ms

So, i decide to use ant task so i can manage my librairies, this is my ant task:

 <target name="sonar" depends="cover-report">
<!-- The workDir directory is used by Sonar to store temporary files -->
<sonar:sonar workDir="./" key="fr.simscorps:client.mail" version="0.1-SNAPSHOT" xmlns:sonar="antlib:org.sonar.ant">
<property key="sonar.host.url" value="http://172.30.3.55:1234/sonar/" />
  <!-- source directories (required) -->
  <sources>
    <path location="./src" />
  </sources>

  <!-- list of properties (optional) -->
  <property key="sonar.dynamicAnalysis" value="reuseReports" />
  <property key="sonar.projectName" value="client mail" />
  <property key="sonar.java.source" value="1.5" />
  <property key="sonar.projectVersion" value="0.1-SNAPSHOT" /> 
  <property key="sonar.phase" value="generate-sources"/>
  <property key="sonar.cobertura.reportsPath" value="${reports.xml.dir}/coverage.xml"/>
  <property key="sonar.surefire.reportsPath" value="${reports.xml.dir}/TESTS-test.TestSuiteClientMail.xml" />



  <!-- test source directories (optional) -->
  <tests>
    <path location="./test" />
  </tests>

  <!-- binaries directories, which contain for example the compiled Java bytecode (optional) -->
  <binaries>
    <path location="./bin" />
  </binaries>

  <!-- path to libraries (optional). These libraries are for example used by the Java Findbugs plugin -->
  <libraries>
    <path location="./lib/activation.jar" />
    <path location="./lib/deltasync.jar" />
    <path location="./lib/jaybird_full_2_1_6.jar" />
    <path location="./lib/junit.jar" />
    <path location="./lib/mail.jar" />
    <path location="./lib/libdeltasync/apache-mime4j-0.5.jar"/>
    <path location="./lib/libdeltasync/commons-codec-1.5.jar"/>
    <path location="./lib/libdeltasync/commons-codec-1.5-javadoc.jar"/>
    <path location="./lib/libdeltasync/commons-codec-1.5-sources.jar"/>
    <path location="./lib/libdeltasync/commons-logging-1.1.1.jar"/>
    <path location="./lib/libdeltasync/httpclient-4.1.1.jar"/>
    <path location="./lib/libdeltasync/httpclient-cache-4.1.1.jar"/>
    <path location="./lib/libdeltasync/httpcore-4.1.jar"/>
    <path location="./lib/libdeltasync/httpmime-4.1.1.jar"/>
    <path location="./lib/libdeltasync/logback-classic-0.9.29.jar"/>
    <path location="./lib/libdeltasync/logback-classic-0.9.29-sources.jar"/>
    <path location="./lib/libdeltasync/logback-core-0.9.29.jar"/>
    <path location="./lib/libdeltasync/logback-core-0.9.29-sources.jar"/>
    <path location="./lib/libdeltasync/slf4j-api-1.6.1.jar"/>
    <path location="./lib/libdeltasync/slf4j-api-1.6.1-sources.jar"/>
  </libraries>
</sonar:sonar>
</target>

My report is well generated (about 700ko) and in hudson's log i see the cobertura sensor, but it's like he didn't do anything:

[sonar:sonar] [INFO]  Sensor CoberturaSensor...
[sonar:sonar] [INFO]  Sensor CoberturaSensor done: 0 ms

Here, my other ant task dependency:

 <property name="junit.output.dir" value="junit"/>
<property name="instrumented.dir" value="cobertura/instrumented"/>
<property name="classes.dir" value="bin"/>
<property name="jars.dir" value="lib"/>
<property name="test.dir" value="test"/>
<property name="cobertura.dir" value="${jars.dir}/cobertura"/>
<property name="reports.xml.dir" value="cobertura/reports"/>
<property name="cob.ser.file" value="cobertura.ser" />

 <!-- Define the Sonar task if this hasn't been done in a common script -->
   <taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
   <classpath path="C:\hudson\tools\my_ant\lib" />
   </taskdef>

<path id="cobertura.classpath">
    <fileset dir="${cobertura.dir}">
        <include name="cobertura.jar" />
        <include name="lib/**/*.jar" />
    </fileset>
    <fileset dir="${jars.dir}">
        <include name="**/*.jar"/>
    </fileset>
</path>

<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
<target name="clean" >
    <delete dir="${instrumented.dir}" />
    <delete dir="${reports.xml.dir}" />
    <delete file="${cob.ser.file}" />
</target>

<target name="prepare" depends="clean">
        <mkdir dir="${instrumented.dir}" />
        <mkdir dir="${reports.xml.dir}" />
</target>
<target name="instrument" depends="prepare">
    <cobertura-instrument todir="${instrumented.dir}">
            <ignore regex="org.apache.log4j.*" />
            <fileset dir="${classes.dir}">
                <include name="**/*.class" />
                <exclude name="**/*Test.class" />
            </fileset>

        </cobertura-instrument>
</target>



<target name="testsuite" depends="instrument">
    <junit fork="yes" dir="${test.dir}" failureProperty="test.failed"  printsummary="withOutAndErr">
            <!--
                Specify the name of the coverage data file to use.
                The value specified below is the default.
            -->
            <sysproperty key="net.sourceforge.cobertura.datafile"
                file="${basedir}/cobertura.ser" />
            <!--
                Note the classpath order: instrumented classes are before the
                original (uninstrumented) classes.  This is important.
            -->
            <classpath location="${instrumented.dir}" />
            <classpath location="${classes.dir}" />

            <!--
                The instrumented classes reference classes used by the
                Cobertura runtime, so Cobertura and its dependencies
                must be on your classpath.
            -->
            <classpath refid="cobertura.classpath" />

            <formatter type="xml" />
            <test name="test.TestSuiteClientMail" todir="${reports.xml.dir}" />

            <!--<batchtest todir="${reports.xml.dir}" unless="testcase">
                <fileset dir="${test.dir}">
                    <include name="**/*Test*.java" />
                </fileset>
            </batchtest>-->
        </junit>
</target>

<target name="cover-report" depends="testsuite">
    <cobertura-report format="xml" destdir="${reports.xml.dir}" srcdir="${test.dir}" />
</target>

Does anyone have an idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑忘罢 2024-12-19 00:14:30

[回答]
好吧,我的错,问题出在我使用的语法中:它是


而不是
我们可以看到 这里抱歉

[ANSWER]
Ok, my fault, the problem is in syntax i used: it's

<property key="sonar.cobertura.reportPath" value="${reports.xml.dir}/coverage.xml"/>
and not
<property key="sonar.cobertura.reportsPath" value="${reports.xml.dir}/coverage.xml"/> as we can see here sorry

绿光 2024-12-19 00:14:30

至于您遇到的类加载器错误,我通过确保二进制文件中的路径来摆脱我的错误。库属性是从我的项目的根目录创建的。

<property name="sonar.libraries" value="./Module/resources/web/WEB-INF/lib" />

而不是

<property name="sonar.libraries" value="resources/web/WEB-INF/lib" />

Which 给出了类加载器错误。希望这对某人有帮助。我花了几天时间才弄清楚!

As for the Class Loader errors you are getting, I got rid of mine by making sure the paths in my binaries & libraries property are made from the root of my project.

<property name="sonar.libraries" value="./Module/resources/web/WEB-INF/lib" />

rather than

<property name="sonar.libraries" value="resources/web/WEB-INF/lib" />

Which gives the class loader error. Hope this helps someone. Took my a few days to figure it out!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文