An easier way is to inject a Map of parsers keyed by the hint and then lookup 
the parser you require based on the configuration of the plugin.

@Component
private Map<String,Parser> parsers;

@Parameter
private String mode;

Parser parser = parsers.get(mode);

We currently have no way to make bindings from plugin configuration for 
injection. Something I'd like to do with the JSR330 work but not possible now.

On Aug 8, 2014, at 6:43 AM, Ben Tatham <[email protected]> wrote:

> Hi,
> I'm trying to do some pretty advanced things with custom plugins with
> @Components.
> 
> Basically, I want to use the same mojo with slight variations, and I want
> to be able to inject those variations via the pom (or via the <packaging>
> perhaps as well).  The plugin already defines a custom lifecycle, so I am
> ok if I have to define that lifecycle twice, I just don't want to have to
> define the 12+ mojos twice for almost the exact same thing.
> 
> Essentially, I have a mojo that define a @Component:
> 
> @Component
> Parser parser;
> 
> 
> I then I have two implementations of that Parser interface:
> 
> @Component(role=Parser.class, hint="simple")
> public class SimpleParser implements Parser
> 
> and
> 
> @Component(role=Parser.class, hint="complex")
> public class ComplexParser implements Parser
> 
> 
> I know that on the mojo itself, could tell the mojo which one to use (by
> setting it like this: @Component(hint = "complex")
> 
> but what I really want is to force the user to define the hint in the pom
> or command line.  But as far as I can tell, there is no way to do this.  Is
> there a way around this other than making two separate mojos, which then
> defeats the purpose of using plexus at all here as far as I can tell,
> because  I may as well just define the implementation explicitly (albeit,
> plexus would still be useful for test code, I suppose).
> 
> Can I use an expression for the hint, and perhaps pass that as a separate
> parameter somehow?
> 
> Any help or suggestions would be appreciated.
> 
> -Ben
> 
> 
> 
> -- 
> Ben Tatham
> Sr. Software Engineer
> Nanometrics Inc.
> +1 613-592-6776 x254
> http://www.nanometrics.ca

Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder,  Apache Maven
http://twitter.com/jvanzyl
http://twitter.com/takari_io
---------------------------------------------------------

In short, man creates for himself a new religion of a rational
and technical order to justify his work and to be justified in it.

  -- Jacques Ellul, The Technological Society









Reply via email to