Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Ant syntax for <and>, also checking existence of property being set

Posted on 2004-08-06
4
Medium Priority
?
2,765 Views
Last Modified: 2012-05-05
The "Current Code" below works.  It simply checks to see what environment (passed on the command line) the build is being run for and then calls the target based on the environment.  I now want to add a little more logic that checks for the existence of a file on the file system, and then if it exist it will do something different.  This is my problem/question...

I need to add an <and> tag, and don't even know if this is supported.  The other issue is that I don't know what the syntax is to see if a property is set (the one that is set if the file exists).  Under the "Current Code" below I put what I want in English, including some comments.  Could you take a look at the "Future Code" below and correct the syntax as needed for the <and> statement and checking for the existence of a property being set?

Thanks!

Lisa

***************** START CURRENT CODE **********************
<target name="FTPFileTask">
      <tstamp><format property="current.time" pattern="hh:mm:ss"/></tstamp>
      <echo>FTP Filles for ${ant.project.name} at ${current.time}</echo>

      <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

      <if>
            <equals arg1="${property.env.name}" arg2="DEV" />
      <then>
            <antcall target="FTPFiles"/>
      </then>

      <else>
            <if>
            <equals arg1="${property.env.name}" arg2="QA" />
            <then>
                  <antcall target="FTPQAFiles"/>
            </then>

      <else>
            <if>
            <equals arg1="${property.env.name}" arg2="PROD" />
            <then>
                  <antcall target="FTPPRODFiles"/>
            </then>
            </if>
      </else>
            </if>
      </else>
      </if>

      <tstamp><format property="current.time" pattern="hh:mm:ss"/></tstamp>
      <echo>Build ALL for ${ant.project.name} at ${current.time}</echo>
</target>
***************** END CURRENT CODE **********************


***************** START FUTURE CODE **********************

<target name="FTPFileTask">
      <tstamp><format property="current.time" pattern="hh:mm:ss"/></tstamp>
      <echo>FTP Filles for ${ant.project.name} at ${current.time}</echo>

<-- ADDED THESE TWO LINES -->
      <available file="${property.app.name}.properties.QA" type="file" property="QAPropertiesFile.exists"/>
      <available file="${property.app.name}.properties.PROD" type="file" property="PRODPropertiesFile.exists"/>

      <taskdef resource="net/sf/antcontrib/antcontrib.properties"/>

      <if>
            <equals arg1="${property.env.name}" arg2="DEV" />
<-- ADDED THSESE THREE LINES. DON'T KNOW SYNTAX TO SEE IF PROPERTY IS SET OR IF AND IS ALLOWED-->
            <and>
                  <the QAPropertiesFile.exist property is set>
            </and>
      <then>
            <antcall target="FTPFiles"/>
      </then>
<-- THIS ELSE STATEMENTS SAYS IF THERE ISN'T A QAPropertiesFile.exists PROPERTY SET THEN FTP TO ALL THREE ENVIRONMENTS -->
      <else>
            <if>
            <equals arg1="${property.env.name}" arg2="DEV" />
            <then>
                  <antcall target="FTPFiles"/>
                  <antcall target="FTPQAFiles"/>
                  <antcall target="FTPPRODFiles"/>
            </then>

      <else>
            <if>
            <equals arg1="${property.env.name}" arg2="QA" />
            <then>
                  <antcall target="FTPQAFiles"/>
            </then>

      <else>
            <if>
            <equals arg1="${property.env.name}" arg2="PROD" />
            <then>
                  <antcall target="FTPPRODFiles"/>
            </then>
            </if>
      </else>
            </if>
      </else>
            </if>
      </else>
      </if>

      <tstamp><format property="current.time" pattern="hh:mm:ss"/></tstamp>
      <echo>Build ALL for ${ant.project.name} at ${current.time}</echo>
</target>
***************** END FUTURE CODE **********************
0
Comment
Question by:lphillips120898
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11739727
You can use a selector in a fileset to check if a file is present:

http://ant.apache.org/manual/CoreTypes/selectors.html#presentselect
0
 
LVL 92

Expert Comment

by:objects
ID: 11740480
try the condition tag.

or write your own task, its pretty simple.
0
 
LVL 1

Accepted Solution

by:
wolfc earned 1000 total points
ID: 11742556
According to the docs:
     <if>
          <and>
               <equals arg1="${property.env.name}" arg2="DEV" />
               <isset property="QAPropertiesFile.exist"/>
          </and>
          <then>
                ...
          </then>
      </if>

Haven't tried it though. :-)
0
 

Author Comment

by:lphillips120898
ID: 11754625
Worked great!  Thanks!
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn different types of Android Layout and some basics of an Android App.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This video teaches viewers about errors in exception handling.
Suggested Courses

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question