You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Dimitris Mouchritsas <di...@eurodyn.com> on 2010/02/11 11:07:52 UTC

check property file exists and which properties are missing in Ant 1.8?

Hi all,
I'm giving Ant 1.8.0 a try on a new project. I'd like to ask if there
have been any changes for loading property files (break the build if 
they're not found) and if ant can report on the properties missing.
Are there any related ant-contrib tasks?


Regards
Dimitris

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


Re: AW: check property file exists and which properties are missing in Ant 1.8?

Posted by Dimitris Mouchritsas <di...@eurodyn.com>.
Dimitris Mouchritsas wrote:
> Jan.Materne@rzf.fin-nrw.de wrote:
>>> I'm giving Ant 1.8.0 a try on a new project. I'd like to ask if there
>>> have been any changes for loading property files (break the build if 
>>> they're not found) 
>>
>> should not.
>> But using <property file/> the specified property file doesnt have to
>> exist - since a long time...
>>
>>
>>> and if ant can report on the properties missing.
>>> Are there any related ant-contrib tasks?
>>
>> <fail> with <isset> condition.
>>
>>
>> <macrodef name="requireFile">
>>     <attribute name="file"/>
>>     <sequential>
>>         <fail message="@{file} does not exist.">
>>             <condition>
>>                 <not><available file="@{file}"/></not>
>>             </condition>
>>         </fail>
>>     </sequential>
>> </macrodef>
>>
>> <macrodef name="requireProperty">
>>     <attribute name="property"/>
>>     <sequential>
>>         <fail message="@{property} does not exist.">
>>             <condition>
>>                 <not><isset property="@{property}"/></not>
>>             </condition>
>>         </fail>
>>     </sequential>
>> </macrodef>
>>
>>
>>
>>
>> Jan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
> Seems to work pretty well :) Thanks.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
Ok, I know I didn't ask it on my first mail, but I want ant to display 
all the missing properties, not only the first one. So here's a little 
improvement I did:
Macro:
     <macrodef name="requireProperty">
         <attribute name="property"/>
         <attribute name="example" default="" />
         <sequential>
             <if>
                 <not><isset property="@{property}" /></not>
                 <then>
                     <property name="missing.property" value="true" />
                     <echo>"@{property} is missing. Example: 
@{example}"</echo>
                 </then>
             </if>
         </sequential>
     </macrodef>

Then create a target e.g. check-properties and have init target depend 
on it:

     <target name="check-properties" description="Check required project 
properties">
         <requireFile file="dev_build.properties" />
         <!-- Section: Ivy Properties -->
         <requireProperty property="ivy.nexus.host"
             example="127.0.0.1" />
         <requireProperty property="ivy.maven.repo"
 
example="http://${ivy.nexus.host}:8081/nexus/context/repositories/central" 
/>
         <fail if="missing.property" message="There are missing 
properties. Please see above" />
     </target>

Regards

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


Re: AW: check property file exists and which properties are missing in Ant 1.8?

Posted by Dimitris Mouchritsas <di...@eurodyn.com>.
Jan.Materne@rzf.fin-nrw.de wrote:
>> I'm giving Ant 1.8.0 a try on a new project. I'd like to ask if there
>> have been any changes for loading property files (break the build if 
>> they're not found) 
> 
> should not.
> But using <property file/> the specified property file doesnt have to
> exist - since a long time...
> 
> 
>> and if ant can report on the properties missing.
>> Are there any related ant-contrib tasks?
> 
> <fail> with <isset> condition.
> 
> 
> <macrodef name="requireFile">
>     <attribute name="file"/>
>     <sequential>
>         <fail message="@{file} does not exist.">
>             <condition>
>                 <not><available file="@{file}"/></not>
>             </condition>
>         </fail>
>     </sequential>
> </macrodef>
> 
> <macrodef name="requireProperty">
>     <attribute name="property"/>
>     <sequential>
>         <fail message="@{property} does not exist.">
>             <condition>
>                 <not><isset property="@{property}"/></not>
>             </condition>
>         </fail>
>     </sequential>
> </macrodef>
> 
> 
> 
> 
> Jan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 
Seems to work pretty well :) Thanks.

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


AW: check property file exists and which properties are missing in Ant 1.8?

Posted by Ja...@rzf.fin-nrw.de.
>I'm giving Ant 1.8.0 a try on a new project. I'd like to ask if there
>have been any changes for loading property files (break the build if 
>they're not found) 

should not.
But using <property file/> the specified property file doesnt have to
exist - since a long time...


> and if ant can report on the properties missing.
>Are there any related ant-contrib tasks?

<fail> with <isset> condition.


<macrodef name="requireFile">
    <attribute name="file"/>
    <sequential>
        <fail message="@{file} does not exist.">
            <condition>
                <not><available file="@{file}"/></not>
            </condition>
        </fail>
    </sequential>
</macrodef>

<macrodef name="requireProperty">
    <attribute name="property"/>
    <sequential>
        <fail message="@{property} does not exist.">
            <condition>
                <not><isset property="@{property}"/></not>
            </condition>
        </fail>
    </sequential>
</macrodef>




Jan

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