You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Steve Loughran <st...@apache.org> on 2006/03/15 14:38:25 UTC
TaskAdapting something that extends WaitFor
I spent yesterday refactoring my (work) code that delegated to WaitFor
to extend it, and to use the TaskAdaptor to adapt it.
Only now, the extended task doesnt run. It gets created, it gets
configured, but its execute() method never gets called, and neither does
that of WaitFor(). I can be 100% sure of this, because it throws an
exception when run: that exception is never raised.
public void execute() throws BuildException {
if(true) {
throw new BuildException("in setproject");
}
ProjectHelper helper = new ProjectHelper(getProject());
if(timeoutProperty==null) {
String property;
property = helper.createUniquePropertyName();
setTimeoutProperty(property);
}
log("About to wait for "+timeoutProperty+"; setting property
"+timeoutProperty);
super.execute();
if(getProject().getProperty(timeoutProperty)!=null) {
throw new BuildException(message);
}
}
this exception is never thrown. Nor is the parent class called; I've
added some debug statements to WaitFor to be sure of that.
I can hypothesise two causes
-its a consequence of subclassing something that already has an
execute() method.
-Somehow ant thinks it is a datatype, not a task.
when I throw a fault in setProject, this is the stack trace.
at
org.smartfrog.tools.ant.FaultingWaitForTask.setProject(FaultingWaitForTask.java:83)
at org.apache.tools.ant.Project.setProjectReference(Project.java:2179)
at
org.apache.tools.ant.AntTypeDefinition.innerCreateAndSet(AntTypeDefinition.java:313)
at
org.apache.tools.ant.AntTypeDefinition.createAndSet(AntTypeDefinition.java:255)
at
org.apache.tools.ant.AntTypeDefinition.icreate(AntTypeDefinition.java:200)
at
org.apache.tools.ant.AntTypeDefinition.create(AntTypeDefinition.java:187)
at
org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:239)
at
org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:216)
at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:400)
at
org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:158)
at org.apache.tools.ant.Task.perform(Task.java:368)
What is going on?
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: TaskAdapting something that extends WaitFor
Posted by Steve Loughran <st...@apache.org>.
Matt Benson wrote:
> --- Steve Loughran <st...@apache.org> wrote:
>
>> Matt Benson wrote:
>>> How are you invoking it?
>> as a task:
>>
>> <sf-faultingwaitfor maxwait="2"
>> message="equality failed">
>> <equals arg1="a" arg2="b"/>
>> </sf-faultingwaitfor>
>>
>> Its declared as a task too; in a properties file I
>> load with taskdef.
>> When it delegated to waitfor it worked, but now that
>> it subclasses it
>> doesnt exec.
>
> Hmm... this works:
>
> <project default="bar">
> <property name="src" value="Foo.java" />
> <available property="gotsrc" file="${src}" />
>
> <target name="write" unless="gotsrc">
> <echo file="${src}">public class Foo extends
> org.apache.tools.ant.taskdefs.WaitFor {}
> </echo>
> </target>
>
> <target name="compile" depends="write">
> <javac srcdir="${basedir}" includes="${src}" />
> </target>
>
> <target name="foo" depends="compile">
> <taskdef name="foo" classname="Foo"
> classpath="${basedir}" />
> <foo maxwait="5" maxwaitunit="second"
> timeoutproperty="foo">
> <or />
> </foo>
> </target>
>
> <target name="bar" depends="foo" if="foo">
> <echo>$${foo}=${foo}</echo>
> </target>
>
> <target name="clean">
> <delete>
> <fileset dir="${basedir}"
> includes="${src},*.class" />
> </delete>
> </target>
>
> </project>
>
> So... I dunno... :|
The tests work for me too. Wierd. Whatever, I can't extend WaitFor
because it doesnt work with the stuff in the other JAR. Which I can't
replicate in the simpler test case situation.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: TaskAdapting something that extends WaitFor
Posted by Matt Benson <gu...@yahoo.com>.
--- Steve Loughran <st...@apache.org> wrote:
> Matt Benson wrote:
> > How are you invoking it?
>
> as a task:
>
> <sf-faultingwaitfor maxwait="2"
> message="equality failed">
> <equals arg1="a" arg2="b"/>
> </sf-faultingwaitfor>
>
> Its declared as a task too; in a properties file I
> load with taskdef.
> When it delegated to waitfor it worked, but now that
> it subclasses it
> doesnt exec.
Hmm... this works:
<project default="bar">
<property name="src" value="Foo.java" />
<available property="gotsrc" file="${src}" />
<target name="write" unless="gotsrc">
<echo file="${src}">public class Foo extends
org.apache.tools.ant.taskdefs.WaitFor {}
</echo>
</target>
<target name="compile" depends="write">
<javac srcdir="${basedir}" includes="${src}" />
</target>
<target name="foo" depends="compile">
<taskdef name="foo" classname="Foo"
classpath="${basedir}" />
<foo maxwait="5" maxwaitunit="second"
timeoutproperty="foo">
<or />
</foo>
</target>
<target name="bar" depends="foo" if="foo">
<echo>$${foo}=${foo}</echo>
</target>
<target name="clean">
<delete>
<fileset dir="${basedir}"
includes="${src},*.class" />
</delete>
</target>
</project>
So... I dunno... :|
-Matt
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: TaskAdapting something that extends WaitFor
Posted by Steve Loughran <st...@apache.org>.
Matt Benson wrote:
> How are you invoking it?
as a task:
<sf-faultingwaitfor maxwait="2" message="equality failed">
<equals arg1="a" arg2="b"/>
</sf-faultingwaitfor>
Its declared as a task too; in a properties file I load with taskdef.
When it delegated to waitfor it worked, but now that it subclasses it
doesnt exec.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org
Re: TaskAdapting something that extends WaitFor
Posted by Matt Benson <gu...@yahoo.com>.
How are you invoking it?
--- Steve Loughran <st...@apache.org> wrote:
>
>
> I spent yesterday refactoring my (work) code that
> delegated to WaitFor
> to extend it, and to use the TaskAdaptor to adapt
> it.
>
> Only now, the extended task doesnt run. It gets
> created, it gets
> configured, but its execute() method never gets
> called, and neither does
> that of WaitFor(). I can be 100% sure of this,
> because it throws an
> exception when run: that exception is never raised.
>
>
> public void execute() throws BuildException {
> if(true) {
> throw new BuildException("in
> setproject");
> }
> ProjectHelper helper = new
> ProjectHelper(getProject());
>
> if(timeoutProperty==null) {
> String property;
> property =
> helper.createUniquePropertyName();
> setTimeoutProperty(property);
> }
> log("About to wait for "+timeoutProperty+";
> setting property
> "+timeoutProperty);
> super.execute();
>
> if(getProject().getProperty(timeoutProperty)!=null)
> {
> throw new BuildException(message);
> }
> }
>
> this exception is never thrown. Nor is the parent
> class called; I've
> added some debug statements to WaitFor to be sure of
> that.
>
> I can hypothesise two causes
> -its a consequence of subclassing something that
> already has an
> execute() method.
> -Somehow ant thinks it is a datatype, not a task.
>
> when I throw a fault in setProject, this is the
> stack trace.
>
> at
>
org.smartfrog.tools.ant.FaultingWaitForTask.setProject(FaultingWaitForTask.java:83)
> at
>
org.apache.tools.ant.Project.setProjectReference(Project.java:2179)
> at
>
org.apache.tools.ant.AntTypeDefinition.innerCreateAndSet(AntTypeDefinition.java:313)
> at
>
org.apache.tools.ant.AntTypeDefinition.createAndSet(AntTypeDefinition.java:255)
> at
>
org.apache.tools.ant.AntTypeDefinition.icreate(AntTypeDefinition.java:200)
> at
>
org.apache.tools.ant.AntTypeDefinition.create(AntTypeDefinition.java:187)
> at
>
org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:239)
> at
>
org.apache.tools.ant.ComponentHelper.createComponent(ComponentHelper.java:216)
> at
>
org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:400)
> at
>
org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:158)
> at org.apache.tools.ant.Task.perform(Task.java:368)
>
> What is going on?
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> dev-unsubscribe@ant.apache.org
> For additional commands, e-mail:
> dev-help@ant.apache.org
>
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org