You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Mansour <ma...@yahoo.com> on 2008/12/18 10:32:26 UTC

how to extend maven plugin

Hello all,
I need to extend (use) an existing maven plugin from my plugin. How do I 
proceed, or where do I start ? is there any links ? To be more specific, 
I need to extend the docbkx maven plugin to generate docbook output. In 
my own, I need to customize the style sheet, header,....etc and wrap it 
all in a package for consistency between generated documents. Any advice ?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: how to extend maven plugin

Posted by Stephen Connolly <st...@gmail.com>.
2008/12/18 Mansour <ma...@yahoo.com>

> > Put the worker classes in a separate jar, leave the classes extending
> > AbstractMojo in the plugin, and have the plugin depend on the worker
> classes
> > jar.
> >
> Where does my new mojo fits ? If I separate the logic in a jar artifact
> (which by the way the author of the docbkx did a great job on that) and
> leave the old  mojo, then where does the modification goes?  In a  new
> mojo, in  the original one ?  in the pom  (set the default values) ?


In a new mojo, or in a new jar that depends on the old mojo's worker jar,
and then you write a mojo that uses your new jar


>
> > Examples of this pattern would be in some of the plugins (I suspect the
> > enforcer and resources plugins would be good examples)
> >
> I am looking into this now
> http://maven.apache.org/plugins/maven-enforcer-plugin/usage.html , and
> will check out the source soon.
> > -Stephen
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: how to extend maven plugin

Posted by Mansour <ma...@yahoo.com>.
Stephen Connolly wrote:
> 2008/12/18 Luke Patterson <lu...@gmail.com>
>
>   
>> For most situations, you could consider the plugin artifact to be
>> prez-layer.  You are using the mojo injection mechanism and maven api
>> to gather input for the utility-artifact/wrapped-tool to process.
>>
>> Is that consistent with what you were saying Stephen?
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>>     
> Sort of.
>
> The key point is that the plugin has the Mojo... the annotations will be
> injected into the Mojo... the Mojo's execute method then passes the
> parameters to the worker class... the worker classes *do not* extend
> AbstractMojo or any kind of Mojo.... if fact it's as if they don't know
> about Mojo at all... otherwise were back to the same problem again.
>   
If we talk web development, you mean business logic by worker class, and
Mojo is just the class that extract the data from the plugin config
(pom) then passes these data to the business logic. Ok, I see now the
big picture. But then,
> Put the worker classes in a separate jar, leave the classes extending
> AbstractMojo in the plugin, and have the plugin depend on the worker classes
> jar.
>   
Where does my new mojo fits ? If I separate the logic in a jar artifact
(which by the way the author of the docbkx did a great job on that) and 
leave the old  mojo, then where does the modification goes?  In a  new
mojo, in  the original one ?  in the pom  (set the default values) ?
> Examples of this pattern would be in some of the plugins (I suspect the
> enforcer and resources plugins would be good examples)
>   
I am looking into this now
http://maven.apache.org/plugins/maven-enforcer-plugin/usage.html , and
will check out the source soon.
> -Stephen
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: how to extend maven plugin

Posted by Stephen Connolly <st...@gmail.com>.
2008/12/18 Luke Patterson <lu...@gmail.com>

> For most situations, you could consider the plugin artifact to be
> prez-layer.  You are using the mojo injection mechanism and maven api
> to gather input for the utility-artifact/wrapped-tool to process.
>
> Is that consistent with what you were saying Stephen?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
Sort of.

The key point is that the plugin has the Mojo... the annotations will be
injected into the Mojo... the Mojo's execute method then passes the
parameters to the worker class... the worker classes *do not* extend
AbstractMojo or any kind of Mojo.... if fact it's as if they don't know
about Mojo at all... otherwise were back to the same problem again.

Put the worker classes in a separate jar, leave the classes extending
AbstractMojo in the plugin, and have the plugin depend on the worker classes
jar.

Examples of this pattern would be in some of the plugins (I suspect the
enforcer and resources plugins would be good examples)

-Stephen

Re: how to extend maven plugin

Posted by Luke Patterson <lu...@gmail.com>.
For most situations, you could consider the plugin artifact to be
prez-layer.  You are using the mojo injection mechanism and maven api
to gather input for the utility-artifact/wrapped-tool to process.

Is that consistent with what you were saying Stephen?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: how to extend maven plugin

Posted by Mansour <ma...@yahoo.com>.
Thank you Stephen,

hum, Let's make sure I got the idea. Every plugin consist of mojo
classes. So in this case, I start my plugin and set the modified docbokx
plugin as a depency (jar depency), then I extend the mojos I want to
modify and over ride them by setting the default values I need. In order
to do this, I need to move the mojos from the docbokx into a separate
jar file. Is this right ?

Or, download the source for the docbokx plugin, and modify it. Will this
be easier?

Which approach you will  go for?

Stephen Connolly wrote:
>
> The idea is to develop plugins so that most (if not all) the work is
> performed in a regular jar artifact... that way, to extend the plugin you
> just depend on the jar file not the plugin.
>
> What you therefore want to do is ensure that the plugin you need to extend
> is refactored so that 99.9% of the code in the mojo is moved into a separate
> module, then you just depend on that module.
>
>   
>> Thank you.
>>     
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
>>>
>>>       
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
>>     
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: how to extend maven plugin

Posted by Stephen Connolly <st...@gmail.com>.
2008/12/18 Mansour <ma...@yahoo.com>

> Jörg Schaible wrote:
> > Mansour wrote at Donnerstag, 18. Dezember 2008 10:32:
> >
> >
> >> Hello all,
> >> I need to extend (use) an existing maven plugin from my plugin. How do I
> >> proceed, or where do I start ? is there any links ? To be more specific,
> >> I need to extend the docbkx maven plugin to generate docbook output. In
> >> my own, I need to customize the style sheet, header,....etc and wrap it
> >> all in a package for consistency between generated documents. Any advice
> ?
> >>
> >
> > In short: Don't do it.
> >
> > Maven loads every plugin only once. If you depend on a different plugin,
> you
> > also specify its version in the dependencies. This has the unfortunate
> > result, that either the user-specified version for that plugin is ignored
> > or the the version you defined in your dependency.
> I though I can ignore the version in the POM so that m plugin will use

the latest.
>

> > The used version is
> > simply defined by the sequence Maven loads the plugin (either because the
> > user uses it directly or your plugin is used and it will load in
> > consequence the other one). If the version does not match, the user might
> > get some strange effects especially if the versions are not compatible.
> >
> > - Jörg
> >
>
> OK, What alternatives do I have, then. I thought maven2 plugins are
> reusable and they can be used from another plugins. What do other plugin
> authors do in this case ?


The idea is to develop plugins so that most (if not all) the work is
performed in a regular jar artifact... that way, to extend the plugin you
just depend on the jar file not the plugin.

What you therefore want to do is ensure that the plugin you need to extend
is refactored so that 99.9% of the code in the mojo is moved into a separate
module, then you just depend on that module.

>
>
> Thank you.
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: how to extend maven plugin

Posted by Mansour <ma...@yahoo.com>.
Jörg Schaible wrote:
> Mansour wrote at Donnerstag, 18. Dezember 2008 10:32:
>
>   
>> Hello all,
>> I need to extend (use) an existing maven plugin from my plugin. How do I
>> proceed, or where do I start ? is there any links ? To be more specific,
>> I need to extend the docbkx maven plugin to generate docbook output. In
>> my own, I need to customize the style sheet, header,....etc and wrap it
>> all in a package for consistency between generated documents. Any advice ?
>>     
>
> In short: Don't do it.
>
> Maven loads every plugin only once. If you depend on a different plugin, you
> also specify its version in the dependencies. This has the unfortunate
> result, that either the user-specified version for that plugin is ignored
> or the the version you defined in your dependency. 
I though I can ignore the version in the POM so that m plugin will use
the latest.
> The used version is
> simply defined by the sequence Maven loads the plugin (either because the
> user uses it directly or your plugin is used and it will load in
> consequence the other one). If the version does not match, the user might
> get some strange effects especially if the versions are not compatible.
>
> - Jörg
>   

OK, What alternatives do I have, then. I thought maven2 plugins are
reusable and they can be used from another plugins. What do other plugin
authors do in this case ?

Thank you.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: how to extend maven plugin

Posted by Jörg Schaible <jo...@gmx.de>.
Mansour wrote at Donnerstag, 18. Dezember 2008 10:32:

> Hello all,
> I need to extend (use) an existing maven plugin from my plugin. How do I
> proceed, or where do I start ? is there any links ? To be more specific,
> I need to extend the docbkx maven plugin to generate docbook output. In
> my own, I need to customize the style sheet, header,....etc and wrap it
> all in a package for consistency between generated documents. Any advice ?

In short: Don't do it.

Maven loads every plugin only once. If you depend on a different plugin, you
also specify its version in the dependencies. This has the unfortunate
result, that either the user-specified version for that plugin is ignored
or the the version you defined in your dependency. The used version is
simply defined by the sequence Maven loads the plugin (either because the
user uses it directly or your plugin is used and it will load in
consequence the other one). If the version does not match, the user might
get some strange effects especially if the versions are not compatible.

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org