ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Weintraub" <qazw...@gmail.com>
Subject Re: Simple if/else Condition
Date Wed, 18 Jul 2007 15:36:43 GMT
That's what I get for answering mail past midnight after my brain goes
to sleep. I mean "target" and not "task".

Hmmm. How to tell whether a directory is empty...

You could do this:

<delete dir="mydirectory"/>
<mkdir dir="mydirectory"/>

Then, the answer will be yes. No good.

I haven't tried this, but it might work:

1). Create a Path that contains the files in the directory you want to test.

<path id="testpath">
<fileset dir="mydirectory"/>
</path>

2). Convert the path to a property:

<property name="myproperty" refid="testpath"/>

3). Now compare that property to an empty string

<condition property="is_directory_empty">
     <isequal arg1="${myproperty}" arg2="" trim="true"/>
</condition>

The theory is that if there are no files in the directory, then the
PATH will be empty.

On 7/18/07, Evan J <maps.this.address@gmail.com> wrote:
> Thank you Qazwart, except that we don't have `task' task but rather
> `target' for antcall. Either way, it should get the job done.
>
> Now I have to figure out to see how I can check whether a directory
> (and its subdirectories) are empty -- Length doesn't help.
>
> On 7/18/07, Qazwart <qazwart@gmail.com> wrote:
> >
> > On Jul 17, 2007, at 11:18 PM, Evan J wrote:
> > > if (condition)
> > >  perform some task, i.e. echo message="condition met"
> > > else
> > >  perform another task
> >
> > Check out the AntContrib tasks at <http://ant-contrib.sourceforge.net/
> > tasks/tasks/index.html>.
> > There is actually an <if> ant task at <http://ant-
> > contrib.sourceforge.net/tasks/tasks/if.html>. I've used it quite
> > successfully with Ant 1.7.
> >
> > If you don't want to use optional tasks, you can use the <condition>
> > task like this to emulate an <if><else> task:
> >
> > <condition
> >      property="os_is_windows"
> >      value="true">
> >      <os family="windows"/>
> > </condition>
> > <antcall task="windows_task"/>
> > <antcall task="unix_task"/>
> >
> > <task name="windows_task if="os_is_windows">
> >      <blah>
> >      </blah>
> > </task>
> >
> > <task name="unix_task" unless="os_is_windows">
> >      <blah>
> >      </blah>
> > </task>
> >
> > David Weintraub
> > david@weintraub.name
> > qazwart@gmail.com
> >
> >
> >
> > ---------------------------------------------------------------------
> > 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
>
>


-- 
--
David Weintraub
qazwart@gmail.com

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


Mime
View raw message