ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeffrey Bacon <jba...@magmic.com>
Subject creating a custom Condition
Date Wed, 16 Jun 2004 21:38:17 GMT
I would like to create a custom condition (like the equals condition) 
that I can use in the <if> task from the ant-contrib library.  I looked 
at the source code to the Equals.java file and replicated that however 
Ant doesn't like me to define it as a task since it doesn't have an 
execute() method.  Below is my build.xml snippit, properties file line 
and code for a sample custom condition.  Can anyone help me out as to 
what's wrong?

build.xml:
   <taskdef resource="magmictasks.properties" />

magmictasks.properties:
   exists=com.magmic.anttasks.Exists

usage in build.xml:
     <if>
       <exists file="bin" />
       <then>
         <echo>Not clean</echo>
       </then>
     </if>

build.xml output:

$ ant clean build install
Buildfile: build.xml
No public execute() in class com.magmic.anttasks.Exists

BUILD FAILED
C:\workspace\MagmicAntTasks\build.xml:6: No public execute() in class 
com.magmic.anttasks.Exists

Total time: 0 seconds

============== CODE ==============

package com.magmic.anttasks;

import java.io.File;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.condition.Condition;


/**
  * @author <a href="mailto:jbacon@magmic.com">Jeffrey Bacon</a>
  * @version $Revision: 1 $
  */
public class Exists implements Condition {

   private File file;

   public void setFile(File file) {
       this.file = file;
   }

   /**
    * @see org.apache.tools.ant.taskdefs.condition.Condition#eval()
    */
   public boolean eval() throws BuildException {
     return this.file != null && this.file.exists();
   }
}


-- 
--
Jeffrey Bacon
jbacon@magmic.com
Creative Developer
http://www.magmic.com

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message