ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rainer Noack" <rai...@noacks.net>
Subject RE: Question regarding Ant custom task
Date Sun, 10 Apr 2005 10:20:48 GMT
Hi,

Example for 2:

public class CustomAntTask extends oata.Task {
    public void execute() {
        ....
        int j=customObject.j;
        if(j>5) {
            oata.taskdefs.email.EmailTask
mailTask=(oata.taskdefs.email.EmailTask)getProject().createTask("mail");
            mailTask.setFrom(new
oata.taskdefs.email.EmailAddress("me@my.org"));
            mailTask.setTo(new
oata.taskdefs.email.EmailAddress("foo@bar.com"));
            mailTask.setMessage(new oata.taskdefs.email.Message("the value
of j is "+j));
            mailTask.execute();
        }
        ...
    }
}

Example for 3:
public class CustomAntTask extends oata.Task {
    public void execute() {
        ....
        int j=customObject.j;
        getProject().setProperty("my.j",String.valueOf(j));
        if(j>5)
            getProject().setProperty("send.email","true");
        ...
    }
}    
Build.xml snippet
...
<target name="customTaskTarget">
    <customTask ..../>
</target>
<target name="sendEmail" if="send.email" depends="customTaskTarget">
    <mail from="me@my.org" tolist="foo@bar.com" message="the value of j is
${my.j}"/>
</target>
...

(Not tested, oata means org.apache.tools.ant)

Cheers

Rainer


> -----Original Message-----
> From: Srikrishna_Parthasarathy@timeinc.com 
> [mailto:Srikrishna_Parthasarathy@timeinc.com] 
> Sent: Friday, April 08, 2005 5:09 PM
> To: user@ant.apache.org; rainer@noacks.net
> Subject: RE: Question regarding Ant custom task
> 
> 
> Hello
> 
> Thanks for responding. 
> 
> Since I have i,j variable is defined outside of all methods 
> in my method, their values are available anywhere in any method.
> 
> Can you provide pseudo code or any example snippet for 2 and 3 ? 
> 
> I am new to ant world ?
> 
> Eagerly awaiting your response to implement your suggestions.
> 
> Thanks
> srikrishna
> 
> 
> 
> -----Original Message-----
> From: Rainer Noack [mailto:rainer@noacks.net] 
> Sent: Thursday, April 07, 2005 4:56 PM
> To: 'Ant Users List'
> Subject: RE: Question regarding Ant custom task
> 
> Hi srikrishna,
> 
> 1. What do you mean with a "global variable" in Java?
> 2. You can use Project.createTask("mail") to create a 
> mailtask. 3. Another way (easier): set a ant-property with 
> the value of j from inside your javacode
>    and call the mailtask from your build script depending on 
> the existence or value of this property.
> 
> Cheers
> 
> Rainer
> 
> 
> > -----Original Message-----
> > From: Srikrishna_Parthasarathy@timeinc.com
> > [mailto:Srikrishna_Parthasarathy@timeinc.com] 
> > Sent: Thursday, April 07, 2005 10:04 PM
> > To: user@ant.apache.org
> > Subject: Question regarding Ant custom task
> > 
> > 
> > 
> > I have a Java class with couple of public methods. When this
> > method is called in a target task .
> > 
> > 
> > public String statcollection(){
> > 
> > 
> > 
> > 
> >     if (j>0){
> > 
> > 		 System.out.println("Problem with the messages");
> > 
> > 		 System.out.println("The number of messages in
> > the queue since  "+ minutesinput +"minutes " + j );
> > 
> > 
> > 		 System.out.println("Actual Directory for messages is "
> > + ActualDir);
> > 
> > 	 }else
> > 	 {
> > 		  System.out.println("The number of messages in the
> > queue since  "+ minutesinput +"minutes " + j );
> > 
> > 		  System.out.println("The total number of messages in
> > the queue " +  i);
> > 
> >  }
> > 
> > 
> > 	return ActualDir;
> > }
> > 
> > 
> > The variable j is global. Is it possible inside the task to
> > check for the value of j and use a subtask to send out an email.
> > 
> > 
> > Your input is highly appreciated.
> > 
> > Thanks
> > srikrishna
> > 
> > 
> > 
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 


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


Mime
View raw message