You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by "Perrier, Nathan" <np...@ptc.com> on 2010/09/15 19:12:33 UTC

Conditional import?

Hi All,

 

Is there a way to do a conditionally import in ant?  

 

For example:

 

<import file="file1.xml" if="some_property_is_set" />

 

Or if not using <import>, can this be done with XML Entities?

 

 

Thanks much,

-Nathan


Re: Conditional import?

Posted by Cyril Sagan <cy...@gmail.com>.
The only way we've found to accomplish this is with <if/> from ant-contrib.
 Using your example:

<ac:if>
    <isset property="some_property_is_set" />
    <then>
        <import file="file1.xml" />
    </then>
</ac:if>

Hope this helps.

--Cyril

On Thu, Sep 16, 2010 at 12:03 AM, Stefan Bodewig <bo...@apache.org> wrote:

> On 2010-09-15, John W. Lewis wrote:
>
> > Can imports go in targets?
>
> No.
>
> Ant needs to know all targets in order to build the dependency graph
> before it can start executing the first target.  This means all <import>
> must have been done before any target is run.
>
> > The way I have done it in the past is to conditionally set a property
> > and import the property.  When I don't want to import something, I set
> > the property to a filename that does not exist.  Make sure you
> > <import optional="true" />.
>
> Good idea.
>
> Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

Re: Conditional import?

Posted by Stefan Bodewig <bo...@apache.org>.
On 2010-09-15, John W. Lewis wrote:

> Can imports go in targets?

No.

Ant needs to know all targets in order to build the dependency graph
before it can start executing the first target.  This means all <import>
must have been done before any target is run.

> The way I have done it in the past is to conditionally set a property
> and import the property.  When I don't want to import something, I set
> the property to a filename that does not exist.  Make sure you
> <import optional="true" />.

Good idea.

Stefan

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


RE: Conditional import?

Posted by "John W. Lewis" <Jo...@sas.com>.
Can imports go in targets?

The way I have done it in the past is to conditionally set a property and import the property.  When I don't want to import something, I set the property to a filename that does not exist.   Make sure you <import optional="true" />.

John


-----Original Message-----
From: Murray, Mike [mailto:mbm@ptc.com] 
Sent: Wednesday, September 15, 2010 1:16 PM
To: Ant Users List
Subject: RE: Conditional import?

Put it inside a target.

-----Original Message-----
From: Perrier, Nathan [mailto:nperrier@ptc.com]
Sent: Wednesday, September 15, 2010 12:13 PM
To: user@ant.apache.org
Subject: Conditional import?

Hi All,

 

Is there a way to do a conditionally import in ant?  

 

For example:

 

<import file="file1.xml" if="some_property_is_set" />

 

Or if not using <import>, can this be done with XML Entities?

 

 

Thanks much,

-Nathan


---------------------------------------------------------------------
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


RE: Conditional import?

Posted by "Murray, Mike" <mb...@ptc.com>.
Put it inside a target.

-----Original Message-----
From: Perrier, Nathan [mailto:nperrier@ptc.com] 
Sent: Wednesday, September 15, 2010 12:13 PM
To: user@ant.apache.org
Subject: Conditional import?

Hi All,

 

Is there a way to do a conditionally import in ant?  

 

For example:

 

<import file="file1.xml" if="some_property_is_set" />

 

Or if not using <import>, can this be done with XML Entities?

 

 

Thanks much,

-Nathan


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