You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Nicholas Christopher <nw...@flashcom.net> on 2000/11/01 00:11:30 UTC
Re: Hostname and loops
Stefan Bodewig wrote:
>
> >>>>> "NC" == Nicholas Christopher <nw...@flashcom.net> writes:
>
> NC> I realize I can -DHOSTNAME=xxxx on ant's command line but is
> NC> there a way for to stuff InetAddress.getLocalHost().getHostName()
> NC> into a property?
>
> No, but writing a task to do so would be trivial.
>
Not trivial enough :-) Tasks seem easy but I couldn't immediately see how a task
could set a property.
> NC> - loops
>
> Aargh! Sorry, forget that 8-).
>
> NC> We had operations that looped over lists of items, like copy all
> NC> the files in the selected sub directories bin,etc,lib
> NC> etc. (i.e. not all the sub directories just some) Can I build a
> NC> fileset that I could feed to the copy task that would do that?
>
> I think you could, something like
>
> <fileset dir=".">
> <include name="bin/**" />
> <include name="etc/**" />
> <include name="lib/**" />
> </fileset>
>
> NC> It seemed I wanted a fileset made up of several filesets
>
> You can specify more than one fileset for <copy> as well.
Thanks. This seems to me a little cloudiness with ant. Javac uses multiple <src>
tags, javadoc <sourcepath>, etc. It be nice is there was a single consistant
file list mechanism.
Re: Hostname and loops
Posted by Nicholas Christopher <nw...@flashcom.net>.
I'll give it a try - many thanks.
Conor MacNeill wrote:
>
> Nicholas,
>
> > From: nwc@tanya-hide.medimom.com [mailto:nwc@tanya-hide.medimom.com]On
> > Behalf Of Nicholas Christopher
> > Sent: Wednesday, 1 November 2000 10:12
> > To: ant-user@jakarta.apache.org
> > Subject: Re: Hostname and loops
> >
> >
> > Stefan Bodewig wrote:
> > >
> > > >>>>> "NC" == Nicholas Christopher <nw...@flashcom.net> writes:
> > >
> > > NC> I realize I can -DHOSTNAME=xxxx on ant's command line but is
> > > NC> there a way for to stuff InetAddress.getLocalHost().getHostName()
> > > NC> into a property?
> > >
> > > No, but writing a task to do so would be trivial.
> > >
> >
> > Not trivial enough :-) Tasks seem easy but I couldn't immediately
> > see how a task
> > could set a property.
> >
>
> Try
>
> public class Hostname extends Task {
>
> protected String propertyName;
>
> public void setPropertyName(String propertyName) {
> this.propertyName = propertyName;
> }
>
> public void execute() throws BuildException {
> try {
> project.setProperty(propertyName,
> InetAddress.getLocalHost().getHostName());
> } catch (Exception e) {
> throw new BuildException(e, location);
> }
> }
> }
>
> Use it like this
>
> <target name="tryme">
> <taskdef name="hostname"
> classname="org.apache.tools.ant.taskdefs.Hostname"/>
> <hostname propertyName="goofy"/>
> <echo message="Hostname is ${goofy}"/>
> </target>
>
> You'll may need to add more error checking (is propertyName set, for
> example). I'll leave the details to you.
> Conor
RE: Hostname and loops
Posted by Conor MacNeill <co...@ebinteractive.com.au>.
Nicholas,
> From: nwc@tanya-hide.medimom.com [mailto:nwc@tanya-hide.medimom.com]On
> Behalf Of Nicholas Christopher
> Sent: Wednesday, 1 November 2000 10:12
> To: ant-user@jakarta.apache.org
> Subject: Re: Hostname and loops
>
>
> Stefan Bodewig wrote:
> >
> > >>>>> "NC" == Nicholas Christopher <nw...@flashcom.net> writes:
> >
> > NC> I realize I can -DHOSTNAME=xxxx on ant's command line but is
> > NC> there a way for to stuff InetAddress.getLocalHost().getHostName()
> > NC> into a property?
> >
> > No, but writing a task to do so would be trivial.
> >
>
> Not trivial enough :-) Tasks seem easy but I couldn't immediately
> see how a task
> could set a property.
>
Try
public class Hostname extends Task {
protected String propertyName;
public void setPropertyName(String propertyName) {
this.propertyName = propertyName;
}
public void execute() throws BuildException {
try {
project.setProperty(propertyName,
InetAddress.getLocalHost().getHostName());
} catch (Exception e) {
throw new BuildException(e, location);
}
}
}
Use it like this
<target name="tryme">
<taskdef name="hostname"
classname="org.apache.tools.ant.taskdefs.Hostname"/>
<hostname propertyName="goofy"/>
<echo message="Hostname is ${goofy}"/>
</target>
You'll may need to add more error checking (is propertyName set, for
example). I'll leave the details to you.
Conor