ant-ivy-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nicolas Lalevée <nicolas.lale...@hibnet.org>
Subject Re: Ivy Settings Conditionally Use an Environment Variable?
Date Thu, 02 Aug 2012 08:19:32 GMT
I think https://issues.apache.org/jira/browse/IVY-1367 is the answer :)

Nicolas

Le 2 août 2012 à 10:13, Eyad Ebrahim a écrit :

> I agree with Mitch. Such logic is better to be done in IVY.
> But if you are using IvyDE as well, things will get rough, since you won't
> be passing through the ant files.
> 
> Yesterday someone had something similar, and I had also some ideas in this
> regard:
> http://mail-archives.apache.org/mod_mbox/ant-ivy-user/201208.mbox/browser
> 
> 
> On Thu, Aug 2, 2012 at 6:00 AM, Mitch Gitman <mgitman@gmail.com> wrote:
> 
>> For this life of me, I can't find this in the Ivy documentation,
>> but--assuming you're using Ant and the ivy:settings Ant task--Ivy will
>> consume all the containing Ant Project's properties as Ivy variables, as
>> needed.
>> 
>> So what you could do is define just the following in your ivysettings.xml:
>> <property name="ivy.repos.server" value="http://ivy:8081" override="false"
>> />
>> 
>> Then you place your condition in the Ant script:
>> <condition property="ivy.repos.server" value="${env.IVY_SERVER}">
>>    <isset property="env.IVY_SERVER"/>
>>  </condition>
>> 
>> Better yet, put everything in the Ant script.
>> 
>> Beyond that, you could take advantage of the immutability of Ant properties
>> and just define the following in Ant:
>> <property name="env.IVY_SERVER" value="http://ivy:8081" />
>> 
>> This line will be your fallback if the environment variable IVY_SERVER is
>> not defined. Then consume env.IVY_SERVER in your ivysettings.xml. There's
>> something funky though about consuming an environment variable directly
>> like this. There are more elegant mechanisms than environment variables for
>> non-bootstrappy user-varying content.
>> 
>> Another, not necessarily elegant technique I've seen is to use special
>> marker variables to import different nested Ivy settings into your main Ivy
>> setting using the include element. So you might do:
>> <include file="ivysettings-${environment}.xml"
>> 
>> Then you can define different Ivy resolvers/repositories with the same name
>> but which potentially use vastly different configurations.
>> 
>> On Tue, Jul 31, 2012 at 1:04 PM, J.C. Hamlin <JHamlin@successfactors.com
>>> wrote:
>> 
>>>  I am looking for help with using Ivy and environment variables. Is
>>> there any way to conditionally use an environment variable in
>>> ivysettings.xml, and if it is not set, then fall back on a default?
>>> Basically, what we want is something like that if the IVY_SERVER
>>> environment variable is set, use it, otherwise default to
>> http://ivy:8081/.
>>> Kind of like how shell would do it with a definition like ${IVY_SERVER:-
>>> http://ivy:8081}. I can’t find a way to achieve this same behavior in
>>> Ivy. ****
>>> 
>>> ** **
>>> 
>>> We tried this in ivysettings.xml:****
>>> 
>>> ** **
>>> 
>>>  <properties environment="env"/>****
>>> 
>>>  <property name="ivy.repos.server" value="${env.IVY_SERVER}"
>>> override="false"/>****
>>> 
>>>  <property name="ivy.repos.server" value="http://ivy:8081"
>>> override="false"/>****
>>> 
>>> ** **
>>> 
>>> And it doesn't work. ivy.repos.server either ends up with the value of
>> the
>>> environment variable IVY_SERVER (which is desirable) or the value
>>> ${env.IVY_SERVER} if no environment variable is defined (which is
>>> undesirable). So, in our attempt, the second property setting never
>> happens.
>>> ****
>>> 
>>> ** **
>>> 
>>> Now I understand this is the way it works in ant, so this make Ivy
>>> consistent with how ant works. However, ant has “condition”, which can
>>> achieve the actual effect that we want like this:****
>>> 
>>> ** **
>>> 
>>>  <condition property="ivy.repos.server" value="${env.IVY_SERVER}">****
>>> 
>>>    <isset property="env.IVY_SERVER"/>****
>>> 
>>>  </condition>****
>>> 
>>>  <property name="ivy.repos.server" value="http://ivy:8081"/>****
>>> 
>>> ** **
>>> 
>>> Is there a way to do this with Ivy? If not, that makes it pretty
>>> impossible to allow users to use environment variables to override the
>>> default behavior of the system.****
>>> 
>>> ** **
>>> 
>>> Any help would be appreciated. Thanks in advance.****
>>> 
>>> ** **
>>> 
>>> -J.C.****
>>> 
>>> <http://www.successfactors.com>
>>> 
>>> 
>> 


Mime
View raw message