You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by plim <pe...@correlationtech.com> on 2003/05/23 21:42:52 UTC

How to return a value from

Hi all,
I have a target called "get.branch.tag" that prompts the user to enter a
cvs branch tag. 
How can I return the user's input back to the calling target?
 
This tag will be used to update my sources from cvs via a <cvs
command="${branch.tag}" ..../>.
 
pengster
 

RE: How to return a value from

Posted by Jacob Kjome <ho...@visi.com>.
These tasks would be really handy!  Have you thought about contributing 
them to something like the ant-contrib project?  That way, there would be a 
standard distribution where someone could access these useful tasks.

Jake

At 12:56 PM 5/23/2003 -0700, you wrote:
>I've asked the same question before with no answers... so i wrote a couple
>of tasks... (See below)
>Hope this helps.
>Here's how it's used:
>
><!-- declare them -->
><taskdef name="setreturn" classname="com.arranger.jarl.ant.SetReturnValue">
>  <classpath refid="class.path"/>
></taskdef>
><taskdef name="getreturn" classname="com.arranger.jarl.ant.GetReturnValue">
>  <classpath refid="class.path"/>
></taskdef>
>
><target name="testPrompt">
>         <antcall target="promptUser" />
>         <getreturn name="valueSelected"/>
>         <echo message="${valueSelected}"/>
></target>
>
><target name="promptUser">
>         <!-- prompt user -->
>         <input message="Enter Vluae" addproperty="value.selected"/>
>         <setreturn name="valueSelected" value="${value.selected}"/>
></target>
>
>
>
>
>******************GetReturnValue*********************
>public class GetReturnValue extends Task {
>
>     protected String m_name;
>
>     public String getName() {
>         return m_name;
>     }
>
>     public void setName(String name) {
>         m_name = name;
>     }
>
>     /**
>      * Uses system.properties to get return values
>      * @throws BuildException
>      */
>     public void execute() throws BuildException {
>         //set project property
>         String value = System.getProperty(m_name);
>         if (value != null) {
>             project.setUserProperty(m_name, value);
>         }
>     }
>}
>
>******************SetReturnValue*********************
>public class SetReturnValue extends Task {
>
>     protected String m_name;
>     protected String m_value;
>
>     public String getName() {
>         return m_name;
>     }
>
>     public void setName(String name) {
>         m_name = name;
>     }
>
>     public String getValue() {
>         return m_value;
>     }
>
>     public void setValue(String value) {
>         m_value = value;
>     }
>
>     /**
>      * Uses system.properties to pass return values
>      * @throws BuildException
>      */
>     public void execute() throws BuildException {
>         //set system property
>         System.setProperty(m_name, m_value);
>     }
>}
>
>
>-----Original Message-----
>From: plim [mailto:pengster@correlationtech.com]
>Sent: Friday, May 23, 2003 12:43 PM
>To: Ant-User@Jakarta. Apache. Org
>Subject: How to return a value from <antcall>
>
>
>Hi all,
>I have a target called "get.branch.tag" that prompts the user to enter a
>cvs branch tag.
>How can I return the user's input back to the calling target?
>
>This tag will be used to update my sources from cvs via a <cvs
>command="${branch.tag}" ..../>.
>
>pengster
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org

Re: How to return a value from

Posted by Antoine Levy-Lambert <le...@tiscali-dsl.de>.
I am not aware of possibilities of having antcall set information which is
visible to the calling task.
Antoine
----- Original Message -----
From: "plim" <pe...@correlationtech.com>
To: "Ant-User@Jakarta. Apache. Org" <an...@jakarta.apache.org>
Sent: Friday, May 23, 2003 9:42 PM
Subject: How to return a value from <antcall>


> Hi all,
> I have a target called "get.branch.tag" that prompts the user to enter a
> cvs branch tag.
> How can I return the user's input back to the calling target?
>
> This tag will be used to update my sources from cvs via a <cvs
> command="${branch.tag}" ..../>.
>
> pengster
>
>



RE: How to return a value from

Posted by Mark Imel <an...@imelshire.com>.
I've asked the same question before with no answers... so i wrote a couple
of tasks... (See below)
Hope this helps.
Here's how it's used:

<!-- declare them -->
<taskdef name="setreturn" classname="com.arranger.jarl.ant.SetReturnValue">
 <classpath refid="class.path"/>
</taskdef>
<taskdef name="getreturn" classname="com.arranger.jarl.ant.GetReturnValue">
 <classpath refid="class.path"/>
</taskdef>

<target name="testPrompt">
	<antcall target="promptUser" />
	<getreturn name="valueSelected"/>
	<echo message="${valueSelected}"/>
</target>

<target name="promptUser">
	<!-- prompt user -->
	<input message="Enter Vluae" addproperty="value.selected"/>
	<setreturn name="valueSelected" value="${value.selected}"/>
</target>




******************GetReturnValue*********************
public class GetReturnValue extends Task {

    protected String m_name;

    public String getName() {
        return m_name;
    }

    public void setName(String name) {
        m_name = name;
    }

    /**
     * Uses system.properties to get return values
     * @throws BuildException
     */
    public void execute() throws BuildException {
        //set project property
        String value = System.getProperty(m_name);
        if (value != null) {
            project.setUserProperty(m_name, value);
        }
    }
}

******************SetReturnValue*********************
public class SetReturnValue extends Task {

    protected String m_name;
    protected String m_value;

    public String getName() {
        return m_name;
    }

    public void setName(String name) {
        m_name = name;
    }

    public String getValue() {
        return m_value;
    }

    public void setValue(String value) {
        m_value = value;
    }

    /**
     * Uses system.properties to pass return values
     * @throws BuildException
     */
    public void execute() throws BuildException {
        //set system property
        System.setProperty(m_name, m_value);
    }
}


-----Original Message-----
From: plim [mailto:pengster@correlationtech.com]
Sent: Friday, May 23, 2003 12:43 PM
To: Ant-User@Jakarta. Apache. Org
Subject: How to return a value from <antcall>


Hi all,
I have a target called "get.branch.tag" that prompts the user to enter a
cvs branch tag.
How can I return the user's input back to the calling target?

This tag will be used to update my sources from cvs via a <cvs
command="${branch.tag}" ..../>.

pengster