ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: Custom Selectors missing Project and logging?
Date Tue, 12 Aug 2003 21:29:43 GMT
I used the protected parameters myself. Here's an example. You probably need
to override verifySettings() and call explicitly validate() in your
isSelected() method, as demonstrated below. --DD

PS: Note that Ant CVS HEAD configures selectors using the same introspection
rules as for types and tasks, and thus supercedes the Parameter-based stuff.

public class TestTypeAndConfigSelector
             extends BaseExtendSelector {

  /**
   * Converters the recorded parameters into setter calls.
   * <p>
   * This selector can be configured either explicitly in code using the
   * non-default constructor, and by calling explicitly {@link #setType}
   * or {@link #setConfig}, or by the Ant selector mechanism using
   * parameters, and thus requires to keep track whether is was configured
   * or not.
   */
  public void verifySettings() {
    if (_configured) {
      return;
    }
    if (parameters == null) {
        setError("Nested 'type' and/or 'config' params required!");
        return;
    }
    for (int i = 0; i < parameters.length; ++i) {
      Parameter param = parameters[i];
      String name = param.getName().toLowerCase().intern();
      String value = param.getValue();
      if (name == "type") {
        setType(value);
      }
      else if (name == "config") {
        setConfig(value);
      }
      else if (name == "typefield") {
        setTypeField(value);
      }
      else if (name == "configfield") {
        setConfigField(value);
      }
      else {
        setError("Invalid param name: " + name);
        return;
      }
    }
    _configured = true;
  }

  // Implements FileSelector#isSelected
  //       thru BaseExtendSelector#isSelected
  public boolean isSelected(File basedir, String filename, File file)
                 throws BuildException {
    validate(); // calls verifySettings...
    ...
    return true;
  }

} // END class TestTypeAndConfigSelector


> -----Original Message-----
> From: Robert Rice [mailto:robert@windermere.com]
> Sent: Tuesday, August 12, 2003 4:29 PM
> To: Ant Users List
> Subject: RE: Custom Selectors missing Project and logging?
> 
> Any chance this also goes for the list of parameters?  getParameters( )
> seems to return null, though I am setting two parameters on the custom
> selector using the <param> nested element.
> 
> Robert Rice
> 
> On Tue, 12 Aug 2003, Dominique Devienne wrote:
> 
> > I think I spoke too soon...
> >
> > You can get back the current Task, thru Project#getThreadTask, but you
> need
> > a Project instance to do that. I'm not sure the current project is ever
> > registered... Sorry, --DD
> >
> > > -----Original Message-----
> > > From: Robert Rice [mailto:robert@windermere.com]
> > > Sent: Tuesday, August 12, 2003 2:54 PM
> > > To: Dominique Devienne
> > > Subject: RE: Custom Selectors missing Project and logging?
> > >
> > > Thanks for the help.  I was guessing that it might be a bug.  Just
> seemed
> > > too strange since Project is usually readily available.
> > >
> > > If you find the reference to getting the current project, I would sure
> be
> > > interested.  I had previously poked around thinking I might be able to
> > > find it but no luck.  I will follow your suggestions and see what I
> can
> > > find.
> > >
> > > Thanks again,
> > > Robert Rice
> >
> > > -----Original Message-----
> > > From: Dominique Devienne [mailto:DDevienne@lgc.com]
> > > Sent: Tuesday, August 12, 2003 2:19 PM
> > > To: 'Ant Users List'
> > > Subject: RE: Custom Selectors missing Project and logging?
> > >
> > > I think there was a bug (now fixed in CVS) where setProject() was not
> > > called for custom selectors in 1.5.x.
> > >
> > > As a turn around, somebody posted a few months back a trick getting
> back
> > > the
> > > current project for the current thread either thru the context loaded,
> or
> > > a
> > > thread local (I think it was the former). I cannot find the reference
> > > though... --DD
> > >
> > > > -----Original Message-----
> > > > From: Robert Rice [mailto:robert@windermere.com]
> > > > Sent: Tuesday, August 12, 2003 2:32 PM
> > > > To: user@ant.apache.org
> > > > Subject: Custom Selectors missing Project and logging?
> > > >
> > > > I'm writing a simple custom selector that extends
> > > > BaseExtendSelector.  Thus far, I have only implemented the one
> required
> > > > method: public boolean isSelected( File basedir, String filename,
> File
> > > > file );
> > > > My custom selector is declared using the <custom ...> tag nested
> within
> > > a
> > > > <fileset>.
> > > >
> > > > I am trying to log messages from this custom selector.  It does not
> log.
> > > > As I look closer, I find that the project reference ( getProject( )
> ) is
> > > > null, which may explain why no logging takes place.
> > > >
> > > > Is there something I need to do within my selector implementation,
> or in
> > > > the way that I reference it in my build file, to cause the project
> to
> > > get
> > > > set on the selector?
> > > >
> > > > Robert Rice
> > >
> > > ---------------------------------------------------------------------
> > > 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
> >
> 
> 
> ---------------------------------------------------------------------
> 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


Mime
View raw message