Bug 46331 - Get the related Task object from the Condition implementation object
Summary: Get the related Task object from the Condition implementation object
Status: NEW
Alias: None
Product: Ant
Classification: Unclassified
Component: Core tasks (show other bugs)
Version: 1.7.1
Hardware: All All
: P2 enhancement with 1 vote (vote)
Target Milestone: 1.7.1
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-03 03:36 UTC by Guillaume Delalondre
Modified: 2008-12-03 03:36 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Guillaume Delalondre 2008-12-03 03:36:22 UTC
When a custom condition is implemented (Condition interface), there is no direct way to get the related Ant Task.
This is useful - for logging purpose - to link a logged message to the related task.

In the example below, I want to associated the message logged in the Groovy script to the waitfor task, because I use XmlLogger to generate my report and the message must be associated to the task XML element to be properly displayed in the HTML report.
The workaround consists in setting an id to the waitfor task to be able to get them through project references.
But, I've read in Ant manual that setting an id for task won't be supported in Ant future versions:
http://ant.apache.org/manual/using.html#tasks

Example (and workaround):
        <waitfor maxwait="${maxwait}" maxwaitunit="${maxwait.unit}"
                 checkevery="${checkevery}" checkeveryunit="${checkevery.unit}"
                 timeoutproperty="DataInsWaitDvAvailable.timeout"
                 id="DataInsWaitDvAvailable_waitfor">
            <scriptcondition language="groovy" value="false">
                import groovy.sql.Sql

                def sql = Sql.newInstance(
                    "jdbc:oracle:thin:${dbUrl}",
                    "${dbUserViewer}", "${dbUserViewerPassword}",
                    "oracle.jdbc.driver.OracleDriver")

                def fields = []
                def row = sql.firstRow("${sqlQuery}", fields)
                def task = project.references.DataInsWaitDvAvailable_waitfor

                project.log(task, "Count=${row[0]} (expected=${expectedCount})", project.MSG_INFO)

                if (row[0] == (expectedCount as Integer)) {
                    self.setValue(true);
                } else {
                    self.setValue(false);
                }
            </scriptcondition>
        </waitfor>