Ant 脚本中的 Groovy 任务可自定义 Cobertura?
我正在尝试自定义 Cobertura 的行为以实现代码覆盖率。默认情况下,Cobertura 检测构建中的所有类,但我想读取一个特定的 xml,通常如下所示:
<include>
....
<targetclass name = "com.example.ExMain">
<method name = "helloWorld" returnType="String">
</target>
....
</include>
我想读取这样一个由外部提供的 xml源代码并自定义 Cobertura 以仅检测上面 xml 中指定的类。为此,我编写了一个 groovy 脚本,现在我需要将 groovy 脚本挂接到 Cobertura 的 ant 构建脚本中。
这是这部分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 中提到的自定义类之外,没有其他选择。这怎么可能 完毕?
I am trying to customize the behavior of Cobertura for code coverage.. By default Cobertura instruments all the classes in the build but I want to read a particular xml which typically looks like :
<include>
....
<targetclass name = "com.example.ExMain">
<method name = "helloWorld" returnType="String">
</target>
....
</include>
I want to read such an xml that is supplied from an external source and customize Cobertura to instrument only the classes specified in the above xml.. For this I've written a groovy script and now I need to hook in the groovy script into the ant build script for Cobertura..
This is the portion of the ant section where the Cobertura actually instruments the classes.
...
<cobertura-instrument todir="${instrumented.dir}">
<ignore regex="org.apache.log4j.*" />
<fileset dir="${classes.dir}">
<exclude name="**/*.class" />//Custom change
</fileset>
</cobertura-instrument>
...
Note that in the above section, I've explicitly excluded instrumentation of Cobertura to be able to hook in my script..
Apparently fileset doesn't allow me to include a groovy task inside it to invoke my custom script to read the xml.. If I place the groovy task outside, somehow the reports don't get generated.. So I guess there is no other option except for to invoke the groovy script within the fileset to include custom classes mentioned in the xml.. How can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够在单独的 Groovy 块中设置一个或多个属性,并在您的 cobertura 配置中引用它们。这个简化的示例展示了如何从 Groovy 代码片段设置 Ant 属性。
You should be able to set one or more properties in a separate Groovy block and reference them in your cobertura configuration. This simplified example shows how you can set an Ant property from your Groovy code snippet.