Solved

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

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
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…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

756 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