带有JDK 1.6.0_35的Cobertura 2.0.3无法进行仪器类

时间:2013-12-06 05:30:42

标签: ant cobertura

我试图通过ant运行cobertura,使用jdk1.6.0.35,但在检测时获得异常。怎么解决? 异常消息如下:

[cobertura-instrument] [12/06 13:19:26] [WARN] CoberturaInstrumenter: Unable to instrument file D:\workcontext\niyong_crm_v1_0\crm\code\ulcif\web\WEB-INF\classes\com\ulic\ulcif\ws\service\impl\CustomerCIImpl.class
[cobertura-instrument] java.lang.IncompatibleClassChangeError: net/sourceforge/cobertura/instrument/pass1/DetectIgnoredCodeClassVisitor
[cobertura-instrument]  at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:149)
[cobertura-instrument]  at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.instrumentClass(CoberturaInstrumenter.java:121)
[cobertura-instrument]  at net.sourceforge.cobertura.instrument.CoberturaInstrumenter.addInstrumentationToSingleClass(CoberturaInstrumenter.java:234)
[cobertura-instrument]  at net.sourceforge.cobertura.instrument.Main.addInstrumentationToSingleClass(Main.java:298)
[cobertura-instrument]  at net.sourceforge.cobertura.instrument.Main.addInstrumentation(Main.java:307)
[cobertura-instrument]  at net.sourceforge.cobertura.instrument.Main.parseArguments(Main.java:399)
[cobertura-instrument]  at net.sourceforge.cobertura.instrument.Main.main(Main.java:421)

3 个答案:

答案 0 :(得分:0)

你有没有将Cobertura添加到你的蚂蚁任务中?

请参阅: https://github.com/cobertura/cobertura/wiki/Ant-Task-Reference

我的样子如下:

    <target name="process-classes" depends="compile" description="post-process the generated files from compilation, for example to do bytecode enhancement on Java classes.">
        <path id="cobertura.auxpath">
              <pathelement path="${target.dir}/classes"/>
              <pathelement location="classes"/>
        </path>

        <mkdir dir="${target.dir}/cobertura-ser" />
        <mkdir dir="${target.dir}/cobertura-classes" />

        <!-- Copy all the files into the file that eventually get's built into the instrumented JAR -->
        <copy todir="${target.dir}/cobertura-classes">
            <fileset dir="${target.dir}/classes" /> 
        </copy>

        <!-- Instrument all the classes in place -->
        <cobertura-instrument todir="${target.dir}/cobertura-classes" 
            datafile="${target.dir}/cobertura-ser/cobertura.ser" 
            classpathref="cobertura.path">
            <fileset dir="${target.dir}/classes" >
                 <include name="**/*.class" />
                 <exclude name="**/*Test.class" />
            </fileset>
            <auxClasspath>
              <path refid="cobertura.auxpath" />
            </auxClasspath>
        </cobertura-instrument> 
    </target>

答案 1 :(得分:0)

我已经通过将asm-3.3.1更改为asm-all-5.0.4解决了这个问题。

答案 2 :(得分:0)

来自https://github.com/cobertura/cobertura/wiki/FAQ#classnotfoundexception-during-instrumentation

&#34;这是因为在cobertura 2.0中的检测期间,我们使用ASM来重建.class文件。我们重建了stackmap,这是与java 7以及之后的任何东西兼容的要求。这并不意味着我们重新编译代码,但ASM要求我们提供其他类的二进制文件,以防它需要查找任何超级方法。为了解决这个问题,我们使用了一个名为auxClasspath的参数。&#34;

你需要有asm,asm-analysis,asm-commons,asm-tree和asm-util jar。

此外,添加ant文件(build.xml)的辅助路径应该可以解决问题。 尝试添加以下代码:

<path id="cobertura.auxpath">
<pathelement location="${bin}"/>
    </path>

    <target name="instrument_coverage" depends="init_coverage"
        description="Instruments source code for coverage measurement">
        <cobertura-instrument datafile="${coverage.datafile}">
            <fileset refid="coverage-files"/>
        <auxClasspath>
              <path refid="cobertura.auxpath" />
            </auxClasspath>
        </cobertura-instrument>
    </target>

这对我有用。