2011-12-23 95 views
2

我想定制的Cobertura的行为代码覆盖..默认的Cobertura仪器在构建所有的类,但我想读一个特定的XML通常是这样的:蚂蚁脚本中的Groovy任务来自定义Cobertura?

<include> 
    .... 
    <targetclass name = "com.example.ExMain"> 
     <method name = "helloWorld" returnType="String"> 
    </target> 
    .... 
</include> 

我想读这样的xml是从外部源提供的,并且自定义Cobertura以便仅处理上述xml中指定的类。为此,我编写了一个groovy脚本,现在我需要将groovy脚本挂接到ant构建脚本中Cobertura ..

这是Cobertura实际处理类的蚂蚁部分。

... 
<cobertura-instrument todir="${instrumented.dir}"> 
    <ignore regex="org.apache.log4j.*" /> 
    <fileset dir="${classes.dir}"> 
    <exclude name="**/*.class" />//Custom change         
    </fileset>    
</cobertura-instrument> 
... 

注意,在上面的部分,我已经明确排除的Cobertura的仪器能在我的脚本挂钩..

显然文件集不允许我到包括内部具有常规任务调用我的自定义脚本来读取XML ..如果我把groovy任务外,不知何故报告不会得到生成..所以我想没有其他选择,除了调用文件集中的groovy脚本,以包括自定义在xml中提到的类..这怎么做到的?

回答

0

您应该可以在单独的Groovy块中设置一个或多个属性,并在cobertura配置中引用它们。这个简化的例子展示了如何从Groovy代码片段中设置一个Ant属性。

<project name="MyProject" default="dist" basedir="."> 
<description> 
    simple example build file 
</description> 

<path id="groovyPath"> 
    <pathelement location="lib/groovy-all-1.8.6.jar"/> 
</path> 

<taskdef name="groovy" 
     classname="org.codehaus.groovy.ant.Groovy" 
     classpathref="groovyPath"/> 
<target name="loadXml"> 
    <groovy> 
     properties.parsedXml = 'some pattern that can be used to configure a task' 
    </groovy> 
</target> 

<target name="configureTask" depends="loadXml"> 
    <echo message="${parsedXml}"/> 
</target>