You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by mattf <ma...@hotmail.com> on 2010/10/22 01:49:10 UTC

How to fail if property expansion failed...

In perl I would say:

map { 
  die "missing library $1" if /\$\{libs\.(.+)\.classpath\}/ 
} @classpath;


and get the feature that if property expansion failed, the build would halt
with a meaningful error message.

In ant:

<filterchain>
  <expandproperties/># doesn't support failonerror attribute
</filterchain>

<fail message="missing library ${missing.library}">
  <condition property="missing.library">  # doesn't support property
attribute
    <matches pattern="libs\.(.+)\.classpath"
string="${libs.list.classpath}"/> # doesn't support property attribute
  </condition>
</fail>

<path path="${classpath}">
   <existing/> # does not fail if unset pathelement
</path>

How can I fail cleanly if the classpath could not be loaded?

Is this item helpful?  yes  no     Previous votes   Yes: 0  No: 0

-- 
View this message in context: http://ant.1045680.n5.nabble.com/How-to-fail-if-property-expansion-failed-tp3231557p3231557.html
Sent from the Ant - Dev mailing list archive at Nabble.com.

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


Re: How to fail if property expansion failed...

Posted by Gilbert Rebhan <gi...@maksimo.de>.
-------- Original Message  --------
Subject: Re: How to fail if property expansion failed...
From: mattf <ma...@hotmail.com>
To: dev@ant.apache.org
Date: 22.10.2010 23:39

> 
> I was hoping to avoid introducing additional requirements, such as antcontrib
> or Ivy.
[..]

> Yes, sort of; a library property is a list of jars, a library-list names
> those properties by name; and is passed to classpath after expansion to the
> actual jars, and relative names expanded.  If the expansion fails, then the
> origin list named an undeclared property, and the name-form (${name}) is
> passed to classpath, indicating failure.  Now, I want ant to fail when
> failure is indicated.<p/>

use fail combined with a nested condition, something like=

<fail message="F a i l u r e => $${yourlibproperty} not set!!">
 <condition>
  <not>
   <isset property="yourlibproperty"/>
  </not>
 </condition>
</fail>


Regards, Gilbert




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


Re: AW: How to fail if property expansion failed...

Posted by mattf <ma...@hotmail.com>.
I was hoping to avoid introducing additional requirements, such as antcontrib
or Ivy.<p/>The list is a merge of two files, one global property list of
libs that have names that dereference to a list of jars (produced and
managed by an external program); and one local -- just part of that name.
These artifacts are introduced in ant as
<loadfile><filterchain><expandproperties/>...<p/>
Then processed by <pathconvert><path><existing/>...<p/>
Thus, the list would have pathsep, not comma; but maybe that doesn't
matter.<p/>

Jan Matèrne-2 wrote:
> 
> - you have defined a list of libraries (@classpath) which you require 
> 
Yes, sort of; a library property is a list of jars, a library-list names
those properties by name; and is passed to classpath after expansion to the
actual jars, and relative names expanded.  If the expansion fails, then the
origin list named an undeclared property, and the name-form (${name}) is
passed to classpath, indicating failure.  Now, I want ant to fail when
failure is indicated.<p/>
Isn't there something in ant core that will help?<p/>
A loop isn't actually required, and for lack of a better solution pattern
matching the whole text is also possible.
<code>
<fail message="missing library ${missing.library}">
      <condition>
        <matches pattern="libs\.(.+)\.classpath"
string="${libs.list.classpath}"/>
      </condition>
    </fail>
</code>

Will give me the full stop I desire, but how can I set the property
${missing.library} to the value of the capture at (.+)?
-- 
View this message in context: http://ant.1045680.n5.nabble.com/How-to-fail-if-property-expansion-failed-tp3231557p3232997.html
Sent from the Ant - Dev mailing list archive at Nabble.com.

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


AW: How to fail if property expansion failed...

Posted by Jan Matèrne <ap...@materne.de>.
Ok, after searching for the perl map function this is what I understand:
- you have defined a list of libraries (@classpath) which you require
- you want to fail if one of these libs is missing

Simply I would define a list (comma separated or one-per-line) and iterate
with antcontrib:for.

<ac:for param="lib" list="${required.libs}">
  <sequential>
    <fail message="@{lib} missing"><not><available .../>

(not checked deeper ;-)


But instead of defining a list of jars you _want_ to have, why not define a
list and let the build system (more precisely the dependency manager) _get_
this list?

With Ivy
- define the "list" in ivy.xml
- use the Ivy Ant tasks (ivy:cachepath, ...) for creating a path with these
defined libs (and downloading them if needed)


Jan

> -----Ursprüngliche Nachricht-----
> Von: mattf [mailto:mattf64@hotmail.com]
> Gesendet: Freitag, 22. Oktober 2010 01:49
> An: dev@ant.apache.org
> Betreff: How to fail if property expansion failed...
> 
> 
> In perl I would say:
> 
> map {
>   die "missing library $1" if /\$\{libs\.(.+)\.classpath\}/
> } @classpath;
> 
> 
> and get the feature that if property expansion failed, the build would
> halt
> with a meaningful error message.
> 
> In ant:
> 
> <filterchain>
>   <expandproperties/># doesn't support failonerror attribute
> </filterchain>
> 
> <fail message="missing library ${missing.library}">
>   <condition property="missing.library">  # doesn't support property
> attribute
>     <matches pattern="libs\.(.+)\.classpath"
> string="${libs.list.classpath}"/> # doesn't support property attribute
>   </condition>
> </fail>
> 
> <path path="${classpath}">
>    <existing/> # does not fail if unset pathelement
> </path>
> 
> How can I fail cleanly if the classpath could not be loaded?
> 
> Is this item helpful?  yes  no     Previous votes   Yes: 0  No: 0
> 
> --
> View this message in context: http://ant.1045680.n5.nabble.com/How-to-
> fail-if-property-expansion-failed-tp3231557p3231557.html
> Sent from the Ant - Dev mailing list archive at Nabble.com.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
> For additional commands, e-mail: dev-help@ant.apache.org



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