我正试图在一个将使用Cobertura 2.0.3的Ant项目上升级到Java 7。
build.xml中的Cobertura目标:
<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}/cobertura-classes" >
<include name="**/*.class" />
</fileset>
<auxClasspath>
<path refid="cobertura.auxpath" />
</auxClasspath>
</cobertura-instrument>
</target>
在构建的检测阶段,我看到ClassNotFoundException和ExceptionInInitializerError
[cobertura-instrument] Cobertura 2.0.3 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-instrument] Sep 16, 2014 1:53:50 PM net.sourceforge.cobertura.coveragedata.TouchCollector registerClass
[cobertura-instrument] SEVERE: Exception when registering class: {path}/dao/DefaultDAO
[cobertura-instrument] java.lang.ClassNotFoundException: {path}.dao.DefaultDAO
[cobertura-instrument] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[cobertura-instrument] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[cobertura-instrument] at java.security.AccessController.doPrivileged(Native Method)
[cobertura-instrument] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[cobertura-instrument] at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
[cobertura-instrument] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[cobertura-instrument] at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
[cobertura-instrument] at java.lang.Class.forName0(Native Method)
[cobertura-instrument] at java.lang.Class.forName(Class.java:266)
[cobertura-instrument] at net.sourceforge.cobertura.coveragedata.TouchCollector.registerClass(TouchCollector.java:80)
[cobertura-instrument] at {path}.dao.DefaultDAO.__cobertura_init(DefaultDAO.java)
[cobertura-instrument] at {path}.dao.DefaultDAO.<clinit>(DefaultDAO.java)
[cobertura-instrument] WARN instrumentClass, Unable to instrument file C:codepolicymainpolicy-basetargetcobertura-classes{path}persistencecascadebuilderBuildingCascadeBuilder.class
[cobertura-instrument] java.lang.ExceptionInInitializerError
[cobertura-instrument] at java.lang.Class.forName0(Native Method)
[cobertura-instrument] at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:266)
[cobertura-instrument] at java.lang.Class.forName(Class.java:266)
[cobertura-instrument] at net.sourceforge.cobertura.instrument.CoberturaClassWriter.getCommonSuperClass(CoberturaClassWriter.java:32)
[cobertura-instrument] at org.objectweb.asm.ClassWriter.a(Unknown Source)
[cobertura-instrument] at org.objectweb.asm.Frame.a(Unknown Source)
[cobertura-instrument] at org.objectweb.asm.Frame.a(Unknown Source)
[cobertura-instrument] at org.objectweb.asm.MethodWriter.visitMaxs(Unknown Source)
[cobertura-instrument] at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
[cobertura-instrument] at org.objectweb.asm.util.CheckMethodAdapter.visitMaxs(Unknown Source)
[cobertura-instrument] at org.objectweb.asm.MethodVisitor.visitMaxs(Unknown Source)
[cobertura-instrument] at org.objectweb.asm.commons.LocalVariablesSorter.visitMaxs(Unknown Source)
[cobertura-instrument] at org.objectweb.asm.tree.MethodNode.accept(Unknown Source)
[cobertura-instrument] at org.objectweb.asm.util.CheckMethodAdapter$1.visitEnd(Unknown Source)
[cobertura-instrument] at org.objectweb.asm.MethodVisitor.visitEnd(Unknown Source)
我做错了什么?
如果我评论这个块,错误就会得到解决:
<fileset dir="${target.dir}/cobertura-classes" >
<include name="**/*.class" />
</fileset>
我不知道为什么。如果你知道,请贴出答案。
我得到这个:
process-classes:
[mkdir] Created dir: C:codepolicymainpolicy-basetargetcobertura-ser
[mkdir] Created dir: C:codepolicymainpolicy-basetargetcobertura-classes
[copy] Copying 465 files to C:codepolicymainpolicy-basetargetcobertura-classes
[cobertura-instrument] Cobertura 2.0.3 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-instrument] Sep 16, 2014 4:08:10 PM net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler saveCoverageData
[cobertura-instrument] INFO: Cobertura: Saved information on 0 classes.
这是否意味着没有类被插入指令?
[编辑]我改成了这个,类正在被检测。但是,由于超时问题,我的构建失败了。
<fileset dir="${target.dir}/classes" >
<include name="**/*.class" />
<exclude name="**/*Test.class" />
</fileset>