Solved

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

Posted on 2004-08-06
4
2,757 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
Comment Utility
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
Comment Utility
try the condition tag.

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

Accepted Solution

by:
wolfc earned 250 total points
Comment Utility
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
Comment Utility
Worked great!  Thanks!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now