ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: creating a custom Condition
Date Thu, 17 Jun 2004 15:42:27 GMT
Chuck Daniels wrote:

>This is new for 1.6.  See http://ant.apache.org/manual/index.html.  Click on
>the "Concepts and Types" link on the left.
>  
>
Also,  it is only in ant 1.6+ that one can have custom conditions.


>  
>
>>-----Original Message-----
>>From: Jeffrey Bacon [mailto:jbacon@magmic.com]
>>Sent: Thursday, June 17, 2004 3:37 PM
>>To: Ant Users List
>>Subject: Re: creating a custom Condition
>>
>>
>>thanks.  Is there documentation for this anywhere?  I read "Java
>>Development with Ant" by Erik Hatcher & Steve Loughran which coevers Ant
>>1.5 and it didn't mention this. 
>>
Hopefully there will be a new edition of this excellent book........

Peter

>> Searching on the web for extending Ant
>>all talked about properties file firmat not XML format.  Is this
>>new in 1.6?
>>
>>--
>>Jeffrey Bacon
>>jbacon@magmic.com
>>Creative Developer
>>http://www.magmic.com
>>
>>
>>Peter Reilly wrote:
>>    
>>
>>>You need to use <typedef> and not <taskdef>
>>>
>>>One can mix typedefs and taskdefs  in an xml resource
>>>file:
>>>
>>>magmic.xml
>>><antlib>
>>>   <typedef name="exists" classname="com.magmic.anttasks.Exists"/>
>>>   <taskdef name="mytask" classname="com.magmic.anttasks.MyTask"/>
>>></antlib>
>>>
>>>build.xml
>>><typedef resource="magmic.xml"/>
>>>
>>>If you place the definitions a resource called com/magmic/antlib.xml,
>>>you can
>>>use the preferred xml namespace short-cut for third-party ant type/task
>>>plugins:
>>>
>>><project xmlns:mg="antlib:com.magmic"
>>>        xmlns:ac="antlib:net.sf.antcontrib">
>>>  <ac:if>
>>>     <mg:exists file="bin"/>
>>>     <ac:then>
>>>        <echo>The file 'bin', it does exist!</echo>
>>>     </ac:then>
>>>  </ac:if>
>>></project>
>>>
>>>The reason it is preferred to use xml namespaces for third-partry tasks
>>>is that it is possible for a type/task of the name "exists" to
>>>      
>>>
>>be present
>>    
>>
>>>in ant-contrib or ant core at some time in the future.
>>>
>>>Peter
>>>
>>>Jeffrey Bacon wrote:
>>>
>>>      
>>>
>>>>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();
>>>>  }
>>>>}
>>>>
>>>>
>>>>        
>>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>>For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>For additional commands, e-mail: user-help@ant.apache.org
>>
>>    
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>
>
>  
>


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


Mime
View raw message