Solved

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

Posted on 2004-08-06
4
2,762 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 250 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

734 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