ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Juergen Hermann" ...@web.de>
Subject Re: NullPointerException when adding listener
Date Thu, 21 Jul 2005 20:57:05 GMT
On Thu, 21 Jul 2005 11:42:15 -0700 (PDT), Matt Benson wrote:

>Looks like your XmlLogger object needs -some-
>configuration between instantiation and addition as a
>listener.

Well, in some twisted way, yes. The XmlLogger does two things: recording 
seen tasks in "tasks", and recording timing info. When created inside the 
build script, some info is missing ('cause of missed events), leading to the 
RuntimeError and a NullPointerExeption. Which is why this thing works:

<?xml version="1.0" encoding="ISO-8859-1"?>
<project name="logger.test" default="test" basedir=".">
    <description>
        Test Adding Logger via Scripting
    </description>

    <property name="XmlLogger.file" location="ant.log.xml"/>
    <script language="jython"><![CDATA[if 1:
        from org.apache.tools.ant import BuildEvent, XmlLogger

        class TardyXmlLogger(XmlLogger):
            """ Deals with errors due to missed events when we're created
                inside the build script.
            """
            def __init__(self):
                # ignore one event, namely our own finishing
                self.ignore = True
    
                # add timing info for build start event
                self.buildStarted(BuildEvent(project))
    
            def taskFinished(self, event):
                if not self.ignore:
                    XmlLogger.taskFinished(self, event)
                self.ignore = False

        listener = TardyXmlLogger()
        project.addBuildListener(listener)
        ]]>
    </script>

    <target name="empty">
    </target>

    <target name="test">
        <echo message="Hello world!"/>
        <antcall target="empty"/>
    </target>
</project>




Ciao, J├╝rgen



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message