You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Erik Hatcher <ja...@ehatchersolutions.com> on 2002/05/18 01:35:52 UTC

custom selector problem

 [ sorry for the duplication - my first attempt was from an unsubscribed
address, so sending again just in case ]

Bruce or others,

I'm writing a custom selector and have come across a couple of issues:

1) It won't work unless the custom selector is in the system classpath.  I'm
getting this error and I'm using the <custom classname="..."
classpath="..."/> construct with the right classpath.

    "Selector org.example.MySelector not initialized, no such class"

    In ExtendSelector I see this:

    public void selectorCreate() {
        if (classname != null && classname.length() > 0) {
            try {
                dynselector = (ExtendFileSelector)
                        Class.forName(classname).newInstance();
            }

    So its not even using the 'classpath' variable in ExtendSelector.
 Bruce - could you fix this up using the AntClassLoader tricks that is used
in other places?  Most appreciated!  I'll do it (eventually) if you don't.
But this really needs to get into Ant 1.5 to make custom selectors useful.

2) Shouldn't I be allowed to create a selector that simply implements
FileSelector?  I can't according to the code above - I must extend
ExtendFileSelector... but what if I don't need parameters?  No big deal
here, just thought I'd toss it out there

3) My selector works great when not nested, but I tried inverting my
selection by using:

    <not>
        <custom.../>
    </not>

    and I got this error:
        "Internal Error: The dynamic selector is not set"

    I looked around a little but have not found the cause of this yet -
perhaps its due to lazy initialization somewhere?  (maybe need addConfigured
instead of create?)

Thanks for having a look at these - I'll add this to my ever-growing to-do
list that I hope to start whittling away in the next couple of weeks.

    Erik




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: custom selector problem

Posted by Bruce Atherton <br...@callenish.com>.
At 03:55 PM 5/21/2002 -0400, Erik Hatcher wrote:
>I think you are right on with the addConfigured stuff.

Thanks for the feedback, it helps clear things up for me.

>Have you duplicated the issue?  If not, do you
>want me to send you the code to duplicate?

I haven't duplicated it, but then I haven't tried yet. I only got your 
email late last night (it was a long weekend where I live). I will set up 
some tests tonight. You can either send me your code anyway, or wait until 
I try replicating the problem. I suspect that the problem will be easy to 
reproduce, though. :-)



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: custom selector problem

Posted by Erik Hatcher <ja...@ehatchersolutions.com>.
Bruce,

I think you are right on with the addConfigured stuff.  If you are deferring
all references to child elements until execute() then createXXX is
preferable as you have implemented it.  Although obviously something is
wrong somewhere, somehow.  Have you duplicated the issue?  If not, do you
want me to send you the code to duplicate?

    Erik

----- Original Message -----
From: "Bruce Atherton" <br...@callenish.com>
To: "Ant Developers List" <an...@jakarta.apache.org>
Sent: Tuesday, May 21, 2002 3:45 PM
Subject: Re: custom selector problem


> At 11:51 AM 5/21/2002 +0200, Stefan Bodewig wrote:
> >Take a look at the recent version of develop.html (the "Supporting
> >nested elements" section) and see whether this helps.
>
> Thanks. I think I understand from the code what the basic difference is. I
> even understand conceptually - you are initializing depth first versus
> breadth first. What I don't understand is what the impact is on the rest
of
> the code during a build, particularly with regard to instantiations that
> seem to go "missing" like in my reference problem or Erik's example.
>
> In thinking about it now, the only reason that I can see to use
> addConfigured() is if the add* method wants to do something
> programmatically with the element object passed in rather than deferring
> that until execute() time. Are there any other reasons to use
addConfigured()?
>
> I'll go over the code again and make sure I don't break the rule to leave
> all execution to the execute() part of the life cycle. If I follow that
> religiously, I hope that I would never need addConfigured(). Somebody
> please contradict me if I am wrong.
>
>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: custom selector problem

Posted by Bruce Atherton <br...@callenish.com>.
At 11:51 AM 5/21/2002 +0200, Stefan Bodewig wrote:
>Take a look at the recent version of develop.html (the "Supporting
>nested elements" section) and see whether this helps.

Thanks. I think I understand from the code what the basic difference is. I 
even understand conceptually - you are initializing depth first versus 
breadth first. What I don't understand is what the impact is on the rest of 
the code during a build, particularly with regard to instantiations that 
seem to go "missing" like in my reference problem or Erik's example.

In thinking about it now, the only reason that I can see to use 
addConfigured() is if the add* method wants to do something 
programmatically with the element object passed in rather than deferring 
that until execute() time. Are there any other reasons to use addConfigured()?

I'll go over the code again and make sure I don't break the rule to leave 
all execution to the execute() part of the life cycle. If I follow that 
religiously, I hope that I would never need addConfigured(). Somebody 
please contradict me if I am wrong.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: custom selector problem

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 20 May 2002, Bruce Atherton <br...@callenish.com> wrote:

> I have to admit I'm fuzzy on the whole add/addConfigured dichotomy,
> and judging by Jon's comment in IntrospectionHelper I'm not
> alone.

Take a look at the recent version of develop.html (the "Supporting
nested elements" section) and see whether this helps.

Stefan

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: custom selector problem

Posted by Bruce Atherton <br...@callenish.com>.
At 07:35 PM 5/17/02 -0400, Erik Hatcher wrote:
>I'm writing a custom selector and have come across a couple of issues:

Thanks for the reports. I'll look into fixing them.


>1) It won't work unless the custom selector is in the system classpath.  I'm
>getting this error and I'm using the <custom classname="..."
>classpath="..."/> construct with the right classpath.
>
>     "Selector org.example.MySelector not initialized, no such class"
>
>     In ExtendSelector I see this:
>
>     public void selectorCreate() {
>         if (classname != null && classname.length() > 0) {
>             try {
>                 dynselector = (ExtendFileSelector)
>                         Class.forName(classname).newInstance();
>             }

This looks like an older version of the code, before I added the actual 
implementation of the custom classpath stuff. I may have goofed up in 
copying files between machines. Hopefully the fix will be as easy as 
finding the right file.

>But this really needs to get into Ant 1.5 to make custom selectors useful.

Absolutely.


>2) Shouldn't I be allowed to create a selector that simply implements
>FileSelector?  I can't according to the code above - I must extend
>ExtendFileSelector... but what if I don't need parameters?  No big deal
>here, just thought I'd toss it out there

Ok. So the call to addParam() could throw a build exception if the selector 
wasn't an ExtendSelector, and in isSelected() it would only call 
setParameters() for the same reason. Should be easy enough to do.


>3) My selector works great when not nested, but I tried inverting my
>selection by using:
>
>     <not>
>         <custom.../>
>     </not>
>
>     and I got this error:
>         "Internal Error: The dynamic selector is not set"
>
>     I looked around a little but have not found the cause of this yet -
>perhaps its due to lazy initialization somewhere?  (maybe need addConfigured
>instead of create?)

This looks similar to the error I got when trying to use selectors that 
were referenced from inside another target. Could the problem be that I 
needed to use addConfigured() instead all along? I have to admit I'm fuzzy 
on the whole add/addConfigured dichotomy, and judging by Jon's comment in 
IntrospectionHelper I'm not alone. Can anybody clarify, particularly 
regarding how it affects this?


>Thanks for having a look at these - I'll add this to my ever-growing to-do
>list that I hope to start whittling away in the next couple of weeks.

I hope to get fixes in long before then!



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>