You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by peter reilly <pe...@corvil.com> on 2003/04/01 13:54:05 UTC

Re: How do I get at the project base dir inside a subclass of BaseExtendSelector?

My bad...
Yes you are right, for (current) custom selectors the unknown element
stuff is not invoked.

The best way to get your fix into ant is
to make a bugzilla bug/enhancement request.
(from the main ant page, you will need to
register)

Get the lastest ant cvs  and make the
patch against that.

Sometimes the ant commiters apply the patch
on the same day, sometimes not..


On Tuesday 01 April 2003 13:12, Tim Gordon wrote:
> Hmmm
>
> Tried your fix by doing a diff between the cvs tip and the revision tagged
> for 1.5.2 (which is what I'm using) - certainly in 1.5.2
> UnknownElement.handleChildren wasn't getting called when I ran my build...
> maybe a 1.5.2 thing
>
> I actually fixed it in ExtendSelector:
>
> RCS file:
> /home/cvspublic/ant/src/main/org/apache/tools/ant/types/selectors/ExtendSel
>e ctor.java,v
> retrieving revision 1.6
> diff -c -r1.6 ExtendSelector.java
> *** ExtendSelector.java 10 Feb 2003 14:14:35 -0000      1.6
> --- ExtendSelector.java 1 Apr 2003 12:06:55 -0000
> ***************
> *** 106,111 ****
> --- 106,114 ----
>                       AntClassLoader.initializeClass(c);
>                   }
>                   dynselector = (FileSelector) c.newInstance();
> +                 if (dynselector instanceof ProjectComponent) {
> +
> ((ProjectComponent)dynselector).setProject(getProject());
> +                 }
>               }
>               catch (ClassNotFoundException cnfexcept) {
>                   setError("Selector " + classname +
>
> although I could have used a technique similar to your reflexion in
> setProjectOnObject, but Extend selector already inherits a dependency on
> ProjectComponent How do I go about reporting this sort of thing? I've not
> made contributions to Apache before...
>
> Tim
>
> -----Original Message-----
> From: peter reilly [mailto:peter.reilly@corvil.com]
> Sent: 31 March 2003 17:48
> To: Ant Users List
> Subject: Re: How do I get at the project base dir inside a subclass of
> BaseExtendSelector?
>
>
> It is (I think) a bug of ant.
>
> I made a patch to get UnknownElement.java to set
> the project on created children. I use this for
> custom filters (and custom conditions and selectors).
>
> The patch is part of bugzilla: 18312.
>
> The relevant part follows:
>
> Peter
>
> Index: src/main/org/apache/tools/ant/UnknownElement.java
> ===================================================================
> RCS file:
> /home/cvspublic/ant/src/main/org/apache/tools/ant/UnknownElement.java,v
> retrieving revision 1.41
> diff -c -r1.41 UnknownElement.java
> *** src/main/org/apache/tools/ant/UnknownElement.java	7 Mar 2003 11:22:59
> -0000	1.41
> --- src/main/org/apache/tools/ant/UnknownElement.java	27 Mar 2003 17:52:32
> -0000
> ***************
> *** 56,61 ****
> --- 56,62 ----
>
>   import java.util.Vector;
>   import java.io.IOException;
> + import java.lang.reflect.Method;
>
>   /**
>    * Wrapper class that holds all the information necessary to create a
> task ***************
> *** 259,264 ****
> --- 260,266 ----
>           throws BuildException {
>           if (parent instanceof TaskAdapter) {
>               parent = ((TaskAdapter) parent).getProxy();
> +             setProjectOnObject(parent);
>           }
>
>           Class parentClass = parent.getClass();
> ***************
> *** 277,282 ****
> --- 279,285 ----
>                       throw getNotFoundException("task", child.getTag());
>                   }
>
> +                 setProjectOnObject(realChild);
>                   // XXX DataTypes will be wrapped or treated like normal
> components
>                   if (realChild instanceof Task) {
>                       Task task = (Task) realChild;
> ***************
> *** 291,298 ****
> --- 294,304 ----
>               } else {
>                   realChild
>                       = ih.createElement(getProject(), parent,
> child.getTag());
> +                 if (realChild != null)
> +                     setProjectOnObject(realChild);
>               }
>
> +
>               childWrapper.setProxy(realChild);
>               if (parent instanceof TaskContainer
>                   && realChild instanceof Task) {
> ***************
> *** 433,437 ****
> --- 439,464 ----
>           }
>           return null;
>       }
> +
> +     /**
> +      * set the project on a created object
> +      * Need to set the project before other set/add elements
> +      * are called
> +      */
> +     private void setProjectOnObject(Object obj) {
> +         try {
> +             Method method =
> +                 obj.getClass().getMethod(
> +                     "setProject", new Class[] {Project.class});
> +             if (method != null) {
> +                 method.invoke(obj, new Object[] {getProject()});
> +             }
> +         } catch (Throwable e) {
> +             // ignore this if the object does not have
> +             // a set project method or the method
> +             // is private/protected.
> +         }
> +     }
> +
>
>   }// UnknownElement
>
> On Monday 31 March 2003 18:40, Tim Gordon wrote:
> > Hi
> >
> > I'm passing <param name="somedir" value="${some.relative.directory}">
> > parameter into a custom selector, which is a subclass of
> > BaseExtendSelector. ${some.relative.directory} is defined relative to the
> > project ${basedir}, so inside my code I'll get a string value for the
> > "somedir" parameter which is basically useless to me unless I can do
> >
> > new File(project.getBasedir(), somedir);
> >
> > However, setProject() never seems to get called on my custom selector,
>
> even
>
> > though it's a ProjectComponent. Is this a bug in ANT BaseExtendSelector
> > or AbstractFileSet, not setting the project on the component?
> >
> > I can acheive the effect I'm after by passing in <param name="somedir"
> > value="${basedir}/${some.relative.directory}"> - do I have to live with
> > that? I'd rather pass in paths defined relative to the project basedir,
> > which is consistent with passing around directories in the rest of ANT.
> >
> > Tim Gordon
> >
> > Allustra Limited
> > 1 Royal Exchange Avenue
> > London
> > EC3V 3LT
> > Tel 020 7464 4190
> > Tel 020 7464 4194
> > http://www.allustra.com/
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> > For additional commands, e-mail: user-help@ant.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org