You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bu...@apache.org on 2002/06/03 23:18:02 UTC
DO NOT REPLY [Bug 9589] New: -
Custom task cannot use custom types due to different classloaders
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9589>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND
INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=9589
Custom task cannot use custom types due to different classloaders
Summary: Custom task cannot use custom types due to different
classloaders
Product: Ant
Version: 1.5Beta2
Platform: PC
OS/Version: Windows NT/2K
Status: NEW
Severity: Major
Priority: Other
Component: Core
AssignedTo: ant-dev@jakarta.apache.org
ReportedBy: wr0ngway@yahoo.com
First I create a custom type and a custom task, and place them in the same jar.
Then, in my build script, for each of those I specify a custom classpath
pointing to the same jar in their respective taskdef/typedef. If in my task I
then try to use the type by casting a reference to the types Type, I get a
ClassCastException because the task and type are defined in different
classloaders, and thus the Task's use of the type's Type is going to be an
entirely different class. e.g:
//FooType.java
//-------------
package com.foo;
import org.apache.tools.ant.types.DataType;
public class FooType extends DataType
{
private String foo;
public FooType()
{
super();
System.out.println("FooType ctor");
}
public void setFoo(String foo)
{
this.foo = foo;
project.log("FooType setFoo", project.MSG_WARN);
}
public String toString()
{
return foo;
}
}
//BlahTask.java
//-------------
package com.foo;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Reference;
public class BlahTask extends Task
{
private FooType foo;
public BlahTask()
{
super();
System.out.println("BlahTask ctor");
}
public void setFooref(Reference fooref)
{
if (fooref != null)
{
Object thefoo = fooref.getReferencedObject(project);
if (thefoo != null)
this.foo = (FooType) thefoo; //ClassCastEx here
}
}
public void execute() throws BuildException
{
project.log("Blah", project.MSG_INFO);
}
}
build.xml
---------
<project name="antbug" default="all">
<taskdef name="blah" classname="com.foo.BlahTask" classpath="classes"/>
<typedef name="footype" classname="com.foo.FooType" classpath="classes"/>
<footype id="somefoo" foo="foobar"/>
<target name="all">
<echo message="Howdy"/>
<blah fooref="somefoo"/>
</target>
</project>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>