Created
November 23, 2012 10:45
-
-
Save avanwieringen/4135074 to your computer and use it in GitHub Desktop.
Custom Ant DataType errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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