Skip to content

Instantly share code, notes, and snippets.

@avanwieringen
Created November 23, 2012 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avanwieringen/4135074 to your computer and use it in GitHub Desktop.
Save avanwieringen/4135074 to your computer and use it in GitHub Desktop.
Custom Ant DataType errors
<project name="datatypetest">
<path id="classpath">
<fileset dir="lib">
<include name="**/*.jar" />
</fileset>
<pathelement location="cls" />
</path>
<target name="compile">
<delete dir="cls" />
<mkdir dir="cls" />
<javac srcdir="src" destdir="cls" classpathref="classpath" includeantruntime="false" fork="true" />
</target>
<target name="demotypetest">
<typedef name="demotype" classname="types.DemoType" classpathref="classpath" />
<taskdef name="customtask" classname="tasks.CustomTask" classpathref="classpath" />
<demotype id="demotypeid" data="demotypedata" />
<customtask demotyperef="demotypeid" />
</target>
</project>
Buildfile: /Users/arjan/dev/so-test/build.xml
demotypetest:
[demotype] types.DemoType :: setData :: demotypedata
[customtask] types.DemoType :: setRefid :: demotypeid
BUILD FAILED
C:\Users\300234875\Development\Java\datatypetest\build.xml:21: demotypeid doesn't denote a DemoType
Total time: 462 milliseconds
package tasks;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Reference;
import types.DemoType;
public class CustomTask extends Task {
private DemoType data;
public void setDemotypeRef(Reference ref) {
if(data == null) {
data = new DemoType();
data.setProject(getProject());
}
data.setRefid(ref);
}
public void execute() {
System.out.println(data.getData());
}
}
package types;
import org.apache.tools.ant.types.DataType;
import org.apache.tools.ant.types.Reference;
public class DemoType extends DataType {
private String data;
protected DemoType getRef() {
return (DemoType)getCheckedRef();
}
public void setRefid(Reference ref) {
System.out.println(getClass().getName() + " :: setRefid :: " + ref.getRefId());
super.setRefid(ref);
}
public String getData() {
String ret;
if(isReference()) {
ret = getRef().getData();
} else {
ret = data;
}
System.out.println(getClass().getName() + " :: getData :: " + ret);
return ret;
}
public void setData(String data) {
System.out.println(getClass().getName() + " :: setData :: " + data);
checkAttributesAllowed();
this.data = data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment