Peter,

Many thanks for your help, here are my findings:

In your first example you suggested:

        <script language="jython">
import org.apache.tools.ant.taskdefs.Mkdir as Mkdir
import java.io.File as File
testDir=File('./build/weblogic92/test')
mkdir = Mkdir()
mkdir.setDir(testDir)   <-- Upto here it works
mkdir.execute()         
        </script>

A call to execute leads to a NullPointerException

Your second suggestion works!

       <script language="jython">
import org.apache.tools.ant.taskdefs.Mkdir as Mkdir
import java.io.File as File
mkdir = project.createTask("mkdir")
mkdir.dir = File("createme")
mkdir.execute()
        </script>

This code can also be run using my preferred form of calling an external
.py script:

 <script language="jython" src="tools/jython/antCallTest2.py"/>

antCallTest2.py

import org.apache.tools.ant.taskdefs.Mkdir as Mkdir
import java.io.File as File
mkdir = project.createTask("mkdir")
mkdir.dir = File("createme")
mkdir.execute()


Thanks again, you have streamlined my weblogic build process greatly :)

Cheers,
Hoos

-----Original Message-----
From: Peter Reilly [mailto:[EMAIL PROTECTED] 
Sent: 10 August 2006 16:51
To: Ant Users List
Subject: Re: Calling ant tasks from jython

I normally use project.createTask() even though it does not support
presets.

example:
<project name="j">
    <macrodef name="x">
        <attribute name="y"/>
        <sequential>
            <echo>y is @{y}</echo>
        </sequential>
    </macrodef>

    <script language="jython">
import java.io.File as File

d = project.createTask("delete")
d.dir = File("createme")
d.quiet = 1
d.execute()

mkdir = project.createTask("mkdir")
mkdir.dir = File("createme")
mkdir.execute()
    </script>

    <script language="jython">
x = project.createTask("x")
x.setDynamicAttribute("y", "abc")
x.execute()
    </script>
</project>

outputs:
Buildfile: jython.xml
   [delete] Deleting directory C:\work\a\createme
    [mkdir] Created dir: C:\work\a\createme
     [echo] y is abc

BUILD SUCCESSFUL
Total time: 1 second

Peter

On 8/10/06, Hussein Badakhchani <[EMAIL PROTECTED]> wrote:
>
> I can call the depreciated Copyfile task without a problem. I guess
ant
> tasks need some boot strapping if they are to be used out side of ant.
> Does anyone have an example of using an ant task in some custom Java
> code, this might shed some light on what I need to do.
>
> -----Original Message-----
> From: Hussein Badakhchani [mailto:[EMAIL PROTECTED]
> Sent: 10 August 2006 14:38
> To: Ant Users List
> Subject: RE: Calling ant tasks from jython
>
> Thanks, your right that was a typo in my message. I still have the
> error.
>
> -----Original Message-----
> From: Peter Reilly [mailto:[EMAIL PROTECTED]
> Sent: 10 August 2006 14:32
> To: Ant Users List
> Subject: Re: Calling ant tasks from jython
>
> just a quick look:
>
>     Mkdir.setDir(testDir)
>
> should be mkdir.setDir(testDir)
>
> Peter
>
>
> On 8/10/06, Hussein Badakhchani <[EMAIL PROTECTED]> wrote:
> >
> > Hello,
> >
> >
> >
> > I am calling a jython script from my build.xml file using the script
> > task e.g:
> >
> >
> >
> > <script language="jython" src="tools/jython/antCallTest.py"/>
> >
> >
> >
> > I want to use ant tasks from antCallTest.py. While I don't seem to
> have
> > any problems retrieving my projects properties it seems that any
call
> I
> > make to an ant task method requires an extra argument.
> >
> > For example:
> >
> >
> >
> > Script called from my build.xml file
> >
> >
> >
> > import org.apache.tools.ant.taskdefs.Mkdir as Mkdir
> >
> > import java.io.File as File
> >
> >
> >
> > # These calls all work file
> >
> > print "Ant Call Test"
> >
> > print project.getProperty('build.dir')
> >
> > print project.getName()
> >
> >
> >
> > testDir=File('./test')
> >
> > mkdir = Mkdir()
> >
> >
> >
> > # At this point I get the error
> >
> > Mkdir.setDir(testDir)
> >
> >
> >
> >
> >
> > Traceback (innermost last):
> >
> > File "<string>", line 10, in ?
> >
> > TypeError: setDir(): expected 2 args; got 1
> >
> >
> >
> >
> >
> > The setDir method only accepts 1 argument as per the api.
> >
> > I have tried passing in an instance of self but I get the following
> > error:
> >
> >
> >
> > Mkdir.setDir(self, testDir)
> >
> >
> >
> > Traceback (innermost last):
> >
> >   File "<string>", line 10, in ?
> >
> > TypeError: setDir(): self arg can't be coerced to
> >
> >
> >
> > Jython does not tell me what object self cannot be coerced to!
> >
> >
> >
> > What am I missing here?
> >
> >
> >
> > Hussein Badakhchani
> >
> > Middleware Analyst
> >
> > Infrastructure Support
> >
> >
> >
> > Blog: http://dev2dev.bea.com/blog/hoos/
> >
> >
> >
> >
> >
> >
> >
> > *****************************************************
> >
> >     You can find us at www.voca.com
> >
> > *****************************************************
> > This communication is confidential and intended for
> > the exclusive use of the addressee only. You should
> > not disclose its contents to any other person.
> > If you are not the intended recipient please notify
> > the sender named above immediately.
> >
> > Registered in England, No 1023742,
> > Registered Office: Voca Limited
> > Drake House, Three Rivers Court,
> > Homestead Road, Rickmansworth,
> > Hertfordshire, WD3 1FX
> >
> >
> > This message has been checked for all email viruses by MessageLabs.
> >
>
>
> This message has been checked for all email viruses by MessageLabs.
>
>
> This message has been checked for all email viruses by MessageLabs.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
> This message has been checked for all email viruses by MessageLabs.
>
>
>
> This message has been checked for all email viruses by MessageLabs.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


This message has been checked for all email viruses by MessageLabs.


This message has been checked for all email viruses by MessageLabs.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to