C:\workspace\com.magmic\build.xml:99: Class net.sf.antcontrib.logic.IfTask doesn't support the nested "antlib:com.magmic:exists" element.
Shouldn't the Ant introspection stuff kick in and let IfTask use my oen Conditions?
PROJECT DEFINITION:
<project name="Magmic BlackBerry Build Script"
default="help-mini"
xmlns:magmic="antlib:com.magmic"
xmlns:contrib="antlib:net.sf.antcontrib"
xmlns:antenna="http://antenna.sourceforge.net">USAGE:
<target name="load-properties-file">
<contrib:if>
<magmic:exists file="${basedir}/${properties-file}" />
<contrib:then>
<echo level="info">Loading ${properties-file} ...</echo>
<echo level="debug"> ${basedir}/${properties-file}</echo>
<property file="${basedir}/${properties-file}" />
</contrib:then>
</contrib:if>
</target>ANTLIB FILE:
<? xml version="1.0" ?>
<antlib>
<typedef name="exists"
classname="com.magmic.ant.conditions.Exists" /><typedef name="application"
classname="com.magmic.ant.datatypes.Application" />
<typedef name="cod"
classname="com.magmic.ant.datatypes.COD" />
<typedef name="midlet"
classname="com.magmic.ant.datatypes.MIDlet" /><taskdef name="alx" classname="com.magmic.ant.tasks.ALX" /> <taskdef name="filesize" classname="com.magmic.ant.tasks.FileSize" /> <taskdef name="jad" classname="com.magmic.ant.tasks.JAD" /> <taskdef name="jshrink" classname="com.magmic.ant.tasks.JShrink" /> <taskdef name="rapc" classname="com.magmic.ant.tasks.RAPC" /> <taskdef name="version" classname="com.magmic.ant.tasks.Version" /> </antlib>
-- Jeffrey Bacon [EMAIL PROTECTED] Creative Developer http://www.magmic.com
Peter Reilly wrote:
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:[EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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:[EMAIL PROTECTED]">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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
