Jacoco不使用排除功能从报告中排除该类

时间:2016-05-11 13:47:27

标签: ant jacoco

我正在使用带有Ant的jacoco和下面给出的build.xml。我想从util.3.5 jar中排除eQMIUtil类。但是我在生成报告的同时获得了所有方法。有什么方法可以为此找到解决方案。 ** <arg value= "2*3+4">**实际上做了什么?

<description>
  Example Ant build file that demonstrates how a JaCoCo coverage report
  can be itegrated into an existing build in three simple steps.
</description>

<!-- property name="src.dir" location="./src/main/java" />
<property name="result.dir" location="./target" />
<property name="result.classes.dir" location="${result.dir}/classes" />
<property name="result.report.dir" location="${result.dir}/site/jacoco" />
<property name="result.exec.file" location="${result.dir}/jacoco.exec" /-->

<property name="activity.src.dir" location="./src/MIActivities" />
<property name="modules.src.dir" location="./src/Modules" />
<property name="plugins.src.dir" location="./src/Plugins" />
<property name="classes.src.dir" location="F:/jacoco/test/classes" />

<property name="result.dir" location="./target" />
<property name="result.classes.dir" location="${result.dir}/classes" />
<property name="result.Activities.dir" location="F:/Tomcat/apache-tomcat6/webapps/MI35PCQA01P/Activities" />
<property name="result.report.dir" location="F:/Jacoco/test/target/site" />
<property name="result.exec.file1" location="F:/Jacoco/jacoco.exec" />


<property name="project.parent.build.directory" location="C:/MIWork/Jacoco/Coverage" />

<!-- Step 1: Import JaCoCo Ant tasks -->
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
    <classpath path="F:/Jacoco/jacoco-0.7.5.201505241946/lib/jacocoant.jar" />
</taskdef>

<target name="clean">
    <delete dir="${result.report.dir}" />
</target>

<target name="report" >


    <jacoco:report>

        <executiondata>
                <file file="${result.exec.file1}"/>
        </executiondata>

        <structure name="Example Project">
            <classfiles>

                <fileset file="${classes.src.dir}/util-3.5.jar" >
                 <exclude name="**/*eQMIUtil*.class"/>
                 </fileset>

            </classfiles>
            <sourcefiles encoding="UTF-8">
            </sourcefiles>
        </structure>     
        <html destdir="${result.report.dir}"/>

    </jacoco:report>   
    </target>
<target name="test" depends="report">
    <!-- Step 2: Wrap test execution with the JaCoCo coverage task -->
    <jacoco:coverage destfile="${result.exec.file}">
        <java classname="org.jacoco.examples.parser.Main" fork="true">
            <classpath path="${result.classes.dir}" />
            <arg value="2 * 3 + 4"/>
            <arg value="2 + 3 * 4"/>
            <arg value="(2 + 3) * 4"/>
            <arg value="2 * 2 * 2 * 2"/>
            <arg value="1 + 2 + 3 + 4"/>
            <arg value="2 * 3 + 2 * 5"/>
        </java>
    </jacoco:coverage>
</target>   

<target name="finalreport" depends="test">
    <!-- Step 3: Create coverage report -->
    <jacoco:report>

        <!-- This task needs the collected execution data and ... -->
        <executiondata>
            <file file="${result.exec.file}" />
        </executiondata>

        <!-- the class files and optional source files ... -->
        <structure name="JaCoCo Ant Example">
            <classfiles>
                <fileset dir="${result.classes.dir}" />
            </classfiles>
            <sourcefiles encoding="UTF-8">
                <fileset dir="${src.dir}" />
            </sourcefiles>
        </structure>

        <!-- to produce reports in different formats. -->
        <html destdir="${result.report.dir}" />
        <csv destfile="${result.report.dir}/report.csv" />
        <xml destfile="${result.report.dir}/report.xml" />
    </jacoco:report>
</target>   

<target name="rebuild" depends="clean,report" />

1 个答案:

答案 0 :(得分:0)

您可以嵌套<zipfileset>而不是在<fileset>下嵌套<jacoco:report>

此...

<jacoco:report>
    ...
    <structure name="Example Project">
        <classfiles>
            <fileset file="${classes.src.dir}/util-3.5.jar" >
                 <exclude name="**/*eQMIUtil*.class"/>
             </fileset>
        </classfiles>
        ...
    </structure>     
    ...
</jacoco:report>

......应该成为......

<jacoco:report>
    ...
    <structure name="Example Project">
        <classfiles>
            <zipfileset src="${classes.src.dir}/util-3.5.jar">
                <exclude name="**/*eQMIUtil*.class"/>
            </zipfileset>
        </classfiles>
        ...
    </structure>     
    ...
</jacoco:report>

<zipfileset>有效,因为JAR文件也是ZIP文件。