开发者

Gant build scripting, how to retrieve a task that I want to execute

This is in grails, but I don't think anything specific to grails applies.

I have a Gant script that looks something like this:

includeTargets << grailsScript( "Init" )
includeTargets << grailsScript( "TestApp" )

target(main: "run tests with jacoco code coverage...") {  
     taskdef ( name:'coverage', classname:'org.jacoco.ant.CoverageTask', classpathref:'core.classpath' )
     coverage(*** NEED TO PUT RUN-TESTS TASK HERE ***)
}

setDefaultTarget(main)

The idea is I'm trying to run some unit tests with jacoco code coverage. The target to run the tests is defined in TestApp.groovy ( allTests() ) and can be imported and run just fine, but the coverage task from jacoco wants the allTests() task added to it as a child task. It needs to "wrap" the task to run the tests. The Ant xml equivalent for what I'm trying to do is this:

<jacoco:coverage>
    <taskToRunTheTests ... >
        < ... setup ... >
    </taskToRunTheTests>
</jacoco:coverage>

So I guess what I'm looking for is a way, in Gant, to get a Task from a target definition, and pass it along to the coverage task (I can do coverageTask.addChild(theRunTestsTask) ... coverageTask.execute() if necessary).

This is an开发者_StackOverflow obscure one, hope somebody can help we with it.


I managed to get it working, this doesn't exactly answer your specific question but the original idea; to have jacoco-produced coverage for junit tests within a gant build. I couldn't get the jacoco:coverage working so I did it with the jacoco agent; something like this:

Setting up the agent:

import static groovy.xml.NamespaceBuilder.newInstance as namespace
def jacoco = namespace(ant, 'antlib:org.jacoco.ant')

...

jacoco.agent(property: 'agentvmparam', destfile: "$dirs.projDir\\target\\jacoco.exec", includes: '*', output: 'file', dumponexit: 'true')

...

and at this point we need to pass the agentvmparam to the JVM running junit;

jvmarg(value:"${agentvmparam}")

And it's working like a charm.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜