Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-08-06
4
Medium Priority
?
2,768 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
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

877 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