You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by 張旭 <zh...@gmail.com> on 2007/06/06 04:02:39 UTC

calling plugin in another plugin?

Does maven2 has api to add and call a plugin in another plugin ?

Or should I spell out dependency on the plugin being called and invoke
Mojo.execute() directly?

Anybody can help? Thanks in advance.

Re: calling plugin in another plugin?

Posted by Kenney Westerhof <ke...@apache.org>.

張旭 wrote:
> Thanks to everyone.
> 
> Now I know there is no way through maven2 api to call another plugin. Am I
> right?

No, but for your sake, let's say yes. ;)

> According to Jason, it's a bad idea to call one plugin directly in another.

Also according to any other maven developer. It's totally against the principals of maven.

> But I still think it's maybe very convenience to do things like that so I
> can use functions of other plugin directly and have parameters passed to
> other plugin totally under my control.

If you do this kind of things in a plugin, the POM is no longer descriptive of the process.
Your plugin would have an influence on the build, which could change the build. For instance,
your plugin could add a dependency depending on the current time (bad example but it illustrates the problem).
In this case, the build is no longer repeatable, which is bad.

As to using functions of plugins directly: that's not recommended.
Plugins/Mojos should be thin wrappers around a library. You'd want to use the library directly.
The mojo's not only make those libraries available to your build, but also hook them in in a precise way.

And you don't want to control parameters of other plugins - the POM author should control those.

In maven 2.1 there is a shared-context component that can be used by plugins to communicate data
to eachother, but it will not allow you to call plugins.

The only API you are allowed to use if you should depend on another plugin would be the Mojo api: execute().
You can never count on any 3rd party library (the plugin's dependency) being there, as the Mojo is
a facade or front-end for those libraries. And you should not depend on another plugin and call it,
because you cannot configure it properly - this is dealt with in maven core.

Consider this the same limitation as Ant poses. You don't want the 'mkdir' task to have any 
influence on the 'javac' task. The only communication between these two is through the configuration
of those tasks. In ant, there are no 2 tasks that call eachother. Maven mojo's are comparable with ant tasks,
though more goal oriented, and no maven mojo will call another mojo directly.

Whatever you're trying to accomplish, there's a better, Maven-way, to do it.

-- Kenney

> 
> 
> On 6/7/07, David Jackman <Da...@fastsearch.com> wrote:
>>
>> Here's another situation where I want to have a plugin call another
>> plugin.  Can you tell me the "right" way to accomplish this?
>>
>> In our group we have a release procedure that involves a few more steps
>> beyond running the release:prepare mojo.  In fact, some of the parameters
>> into the release:prepare mojo are based on internal standards, so they 
>> could
>> be computed automatically.  I want to create a single plugin that 
>> embodies
>> this entire release process that also calls the release:prepare mojo with
>> the correct parameters as part of that process.
>>
>> This would be another situation where one plugin invokes another
>> plugin.  Obviously there is coupling there.  What is a better way to 
>> achieve
>> this without that coupling (is it even possible)?  Would I create a
>> lifecycle within my mojo that puts the necessary data on the bus and 
>> invokes
>> the release:prepare mojo as part of that lifecycle (thinking in Maven 
>> 2.1terms)?
>>
>> ..David..
>>
>>
>> -----Original Message-----
>> From: Kenney Westerhof [mailto:kenney@apache.org]
>> Sent: Wednesday, June 06, 2007 5:48 PM
>> To: Maven Users List
>> Subject: Re: calling plugin in another plugin?
>>
>>
>>
>> Nunn, Gerald wrote:
>> > Jason,
>> >
>> >> It's a bad practice, and leads to coupling between plugins which is
>> >> bad. We've seen the aftermath of this happening in Maven 1.x.
>> >
>> > Since I'm doing this already I'm curious how this could be done better
>> and accomplish my goal, I'm a relative newbie to Mojos so I'm 
>> wondering if I
>> am missing a better approach.
>> >
>> > In my case, I needed a plugin that can handle a WebLogic shared 
>> library.
>> A shared library is a WAR or EAR that contains many different assets
>> including JARs and in order to be able to use these in Maven I've 
>> created a
>> plugin that temporarily unpacks the shared library and installs each JAR
>> individually under a library group name. It also creates a parent POM for
>> the library that can be used to drag in all the dependencies defined 
>> by the
>> library.
>> >
>> > In order to do this, my plugin needs to install each file individually.
>> Rather then rewrite the install plugin, I simply use my invoker class to
>> invoke the install plugin for each file I have unpacked passing in the
>> necessary parameters to make this work.
>> >
>> > How could I accomplish the same goal using the approach you outlined?
>>
>> This is a one-time setup, and really not part of the build.
>> You should have had those jars in the ears/wars in a repository already.
>>
>> Either create a shellscript for it, or a pom, declaring a dependency on
>> the war/ear (i assume that one _is_
>> in a repository? if not - it shouldn't be part of the maven build
>> lifecycle).
>>
>> You use the maven-dependency-plugin to unpack the war/ear (for 
>> instance in
>> generate-resources), say to
>> ${project.build.directory}/foo/
>> and specify a series of executions of the install plugin (for instance in
>> process-resources), each one configured
>> with the location a jar in ${project.build.directory}/foo/.
>>
>> Anyway, this is not recommended practice, but I can see why your 
>> plugin is
>> useful.
>> The eclipse plugin has a similar mojo, that scans an eclipse installation
>> directory for plugins
>> and installs each plugin as a maven2 artifact in the local directory. It
>> doesn't use
>> the install mojo, afaik, but the maven api's.
>> I'm assuming your plugin is similar, in that it can unpack/install
>> wars/ears found in a bea weblogic installation
>> directory?
>>
>> -- Kenney
>>
>> >
>> > Thanks,
>> >
>> > Gerald
>>
>> ---------------------------------------------------------------------
>> 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: calling plugin in another plugin?

Posted by 張旭 <zh...@gmail.com>.
Thanks to everyone.

Now I know there is no way through maven2 api to call another plugin. Am I
right?

According to Jason, it's a bad idea to call one plugin directly in another.

But I still think it's maybe very convenience to do things like that so I
can use functions of other plugin directly and have parameters passed to
other plugin totally under my control.


On 6/7/07, David Jackman <Da...@fastsearch.com> wrote:
>
> Here's another situation where I want to have a plugin call another
> plugin.  Can you tell me the "right" way to accomplish this?
>
> In our group we have a release procedure that involves a few more steps
> beyond running the release:prepare mojo.  In fact, some of the parameters
> into the release:prepare mojo are based on internal standards, so they could
> be computed automatically.  I want to create a single plugin that embodies
> this entire release process that also calls the release:prepare mojo with
> the correct parameters as part of that process.
>
> This would be another situation where one plugin invokes another
> plugin.  Obviously there is coupling there.  What is a better way to achieve
> this without that coupling (is it even possible)?  Would I create a
> lifecycle within my mojo that puts the necessary data on the bus and invokes
> the release:prepare mojo as part of that lifecycle (thinking in Maven 2.1terms)?
>
> ..David..
>
>
> -----Original Message-----
> From: Kenney Westerhof [mailto:kenney@apache.org]
> Sent: Wednesday, June 06, 2007 5:48 PM
> To: Maven Users List
> Subject: Re: calling plugin in another plugin?
>
>
>
> Nunn, Gerald wrote:
> > Jason,
> >
> >> It's a bad practice, and leads to coupling between plugins which is
> >> bad. We've seen the aftermath of this happening in Maven 1.x.
> >
> > Since I'm doing this already I'm curious how this could be done better
> and accomplish my goal, I'm a relative newbie to Mojos so I'm wondering if I
> am missing a better approach.
> >
> > In my case, I needed a plugin that can handle a WebLogic shared library.
> A shared library is a WAR or EAR that contains many different assets
> including JARs and in order to be able to use these in Maven I've created a
> plugin that temporarily unpacks the shared library and installs each JAR
> individually under a library group name. It also creates a parent POM for
> the library that can be used to drag in all the dependencies defined by the
> library.
> >
> > In order to do this, my plugin needs to install each file individually.
> Rather then rewrite the install plugin, I simply use my invoker class to
> invoke the install plugin for each file I have unpacked passing in the
> necessary parameters to make this work.
> >
> > How could I accomplish the same goal using the approach you outlined?
>
> This is a one-time setup, and really not part of the build.
> You should have had those jars in the ears/wars in a repository already.
>
> Either create a shellscript for it, or a pom, declaring a dependency on
> the war/ear (i assume that one _is_
> in a repository? if not - it shouldn't be part of the maven build
> lifecycle).
>
> You use the maven-dependency-plugin to unpack the war/ear (for instance in
> generate-resources), say to
> ${project.build.directory}/foo/
> and specify a series of executions of the install plugin (for instance in
> process-resources), each one configured
> with the location a jar in ${project.build.directory}/foo/.
>
> Anyway, this is not recommended practice, but I can see why your plugin is
> useful.
> The eclipse plugin has a similar mojo, that scans an eclipse installation
> directory for plugins
> and installs each plugin as a maven2 artifact in the local directory. It
> doesn't use
> the install mojo, afaik, but the maven api's.
> I'm assuming your plugin is similar, in that it can unpack/install
> wars/ears found in a bea weblogic installation
> directory?
>
> -- Kenney
>
> >
> > Thanks,
> >
> > Gerald
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: calling plugin in another plugin?

Posted by Kenney Westerhof <ke...@apache.org>.

David Jackman wrote:
> Here's another situation where I want to have a plugin call another plugin.  
> Can you tell me the "right" way to accomplish this?
> 
> In our group we have a release procedure that involves a few more steps 
> beyond running the release:prepare mojo.  In fact, some of the parameters 
> into the release:prepare mojo are based on internal standards, so they could
> be computed automatically.
> I want to create a single plugin that embodies this entire release process that 
> also calls the release:prepare mojo with the correct parameters as part of that process.
> 
> This would be another situation where one plugin invokes another plugin.  
> Obviously there is coupling there.  What is a better way to achieve this without that
> coupling (is it even possible)?  Would I create a lifecycle within my mojo that puts
> the necessary data on the bus and invokes the release:prepare mojo as part of that lifecycle (thinking in Maven 2.1 terms)?

This is the wrong approach - you don't want to wrap the release plugin, but extend it.
You could take a look at the release project ( https://svn.apache.org/repos/asf/maven/release/trunk ).
The release-manager works with an internal 'lifecycle' of it's own, with phases etc.
I'm sure there's a place there where you can attach a component of your own that does the preparation you need.

When you found the spot to hook in your functionality, you create a new project in your corp SCM,
that has a dependency on release-manager. It declares a components.xml with your component(s) listed,
in such a way that the release-manager picks them up and attaches them to the proper phase.

Take a look at release/maven-release-manager/src/main/resources/META-INF/plexus/components.xml). The first component
declares the phases, the other components implement these phases.
Your component declaration in your components.xml would look something like this:

    <component>
      <role>org.apache.maven.shared.release.phase.PreparePhase</role>
      <role-hint>input-variables</role-hint>
      <implementation>com.yourcompany.maven.release.phase.CustomPreparePhase</implementation>
    </component>

and your CustomPreparePhase class would implement PreparePhase.

then you package this project up, and in your company root pom you declare a pluginManagement section
for the release plugin, listing a dependency on your project containing the above, like so:
<pluginManagement>
  <plugins>
    <plugin>
      <artifactId>maven-release-plugin</...
      <dependencies>
        <dependency>
          <groupId>com.yourcompany.maven
          <artifactId>your-extension</artifactId>
          <version.....

then whenever you do a release:prepare, your component will be injected into the release manager
and be executed.

That's imho the proper approach.

-- Kenney


> 
> ..David..
> 
> 
> -----Original Message-----
> From: Kenney Westerhof [mailto:kenney@apache.org] 
> Sent: Wednesday, June 06, 2007 5:48 PM
> To: Maven Users List
> Subject: Re: calling plugin in another plugin?
> 
> 
> 
> Nunn, Gerald wrote:
>> Jason,
>>
>>> It's a bad practice, and leads to coupling between plugins which is  
>>> bad. We've seen the aftermath of this happening in Maven 1.x.
>> Since I'm doing this already I'm curious how this could be done better and accomplish my goal, I'm a relative newbie to Mojos so I'm wondering if I am missing a better approach. 
>>
>> In my case, I needed a plugin that can handle a WebLogic shared library. A shared library is a WAR or EAR that contains many different assets including JARs and in order to be able to use these in Maven I've created a plugin that temporarily unpacks the shared library and installs each JAR individually under a library group name. It also creates a parent POM for the library that can be used to drag in all the dependencies defined by the library.
>>
>> In order to do this, my plugin needs to install each file individually. Rather then rewrite the install plugin, I simply use my invoker class to invoke the install plugin for each file I have unpacked passing in the necessary parameters to make this work.
>>
>> How could I accomplish the same goal using the approach you outlined?
> 
> This is a one-time setup, and really not part of the build.
> You should have had those jars in the ears/wars in a repository already.
> 
> Either create a shellscript for it, or a pom, declaring a dependency on the war/ear (i assume that one _is_
> in a repository? if not - it shouldn't be part of the maven build lifecycle).
> 
> You use the maven-dependency-plugin to unpack the war/ear (for instance in generate-resources), say to
> ${project.build.directory}/foo/
> and specify a series of executions of the install plugin (for instance in process-resources), each one configured
> with the location a jar in ${project.build.directory}/foo/.
> 
> Anyway, this is not recommended practice, but I can see why your plugin is useful.
> The eclipse plugin has a similar mojo, that scans an eclipse installation directory for plugins
> and installs each plugin as a maven2 artifact in the local directory. It doesn't use
> the install mojo, afaik, but the maven api's.
> I'm assuming your plugin is similar, in that it can unpack/install wars/ears found in a bea weblogic installation
> directory?
> 
> -- Kenney
> 
>> Thanks,
>>
>> Gerald
> 
> ---------------------------------------------------------------------
> 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: calling plugin in another plugin?

Posted by David Jackman <Da...@fastsearch.com>.
Here's another situation where I want to have a plugin call another plugin.  Can you tell me the "right" way to accomplish this?

In our group we have a release procedure that involves a few more steps beyond running the release:prepare mojo.  In fact, some of the parameters into the release:prepare mojo are based on internal standards, so they could be computed automatically.  I want to create a single plugin that embodies this entire release process that also calls the release:prepare mojo with the correct parameters as part of that process.

This would be another situation where one plugin invokes another plugin.  Obviously there is coupling there.  What is a better way to achieve this without that coupling (is it even possible)?  Would I create a lifecycle within my mojo that puts the necessary data on the bus and invokes the release:prepare mojo as part of that lifecycle (thinking in Maven 2.1 terms)?

..David..


-----Original Message-----
From: Kenney Westerhof [mailto:kenney@apache.org] 
Sent: Wednesday, June 06, 2007 5:48 PM
To: Maven Users List
Subject: Re: calling plugin in another plugin?



Nunn, Gerald wrote:
> Jason,
> 
>> It's a bad practice, and leads to coupling between plugins which is  
>> bad. We've seen the aftermath of this happening in Maven 1.x.
> 
> Since I'm doing this already I'm curious how this could be done better and accomplish my goal, I'm a relative newbie to Mojos so I'm wondering if I am missing a better approach. 
> 
> In my case, I needed a plugin that can handle a WebLogic shared library. A shared library is a WAR or EAR that contains many different assets including JARs and in order to be able to use these in Maven I've created a plugin that temporarily unpacks the shared library and installs each JAR individually under a library group name. It also creates a parent POM for the library that can be used to drag in all the dependencies defined by the library.
> 
> In order to do this, my plugin needs to install each file individually. Rather then rewrite the install plugin, I simply use my invoker class to invoke the install plugin for each file I have unpacked passing in the necessary parameters to make this work.
> 
> How could I accomplish the same goal using the approach you outlined?

This is a one-time setup, and really not part of the build.
You should have had those jars in the ears/wars in a repository already.

Either create a shellscript for it, or a pom, declaring a dependency on the war/ear (i assume that one _is_
in a repository? if not - it shouldn't be part of the maven build lifecycle).

You use the maven-dependency-plugin to unpack the war/ear (for instance in generate-resources), say to
${project.build.directory}/foo/
and specify a series of executions of the install plugin (for instance in process-resources), each one configured
with the location a jar in ${project.build.directory}/foo/.

Anyway, this is not recommended practice, but I can see why your plugin is useful.
The eclipse plugin has a similar mojo, that scans an eclipse installation directory for plugins
and installs each plugin as a maven2 artifact in the local directory. It doesn't use
the install mojo, afaik, but the maven api's.
I'm assuming your plugin is similar, in that it can unpack/install wars/ears found in a bea weblogic installation
directory?

-- Kenney

> 
> Thanks,
> 
> Gerald

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


Re: calling plugin in another plugin?

Posted by Kenney Westerhof <ke...@apache.org>.

Nunn, Gerald wrote:
> Jason,
> 
>> It's a bad practice, and leads to coupling between plugins which is  
>> bad. We've seen the aftermath of this happening in Maven 1.x.
> 
> Since I'm doing this already I'm curious how this could be done better and accomplish my goal, I'm a relative newbie to Mojos so I'm wondering if I am missing a better approach. 
> 
> In my case, I needed a plugin that can handle a WebLogic shared library. A shared library is a WAR or EAR that contains many different assets including JARs and in order to be able to use these in Maven I've created a plugin that temporarily unpacks the shared library and installs each JAR individually under a library group name. It also creates a parent POM for the library that can be used to drag in all the dependencies defined by the library.
> 
> In order to do this, my plugin needs to install each file individually. Rather then rewrite the install plugin, I simply use my invoker class to invoke the install plugin for each file I have unpacked passing in the necessary parameters to make this work.
> 
> How could I accomplish the same goal using the approach you outlined?

This is a one-time setup, and really not part of the build.
You should have had those jars in the ears/wars in a repository already.

Either create a shellscript for it, or a pom, declaring a dependency on the war/ear (i assume that one _is_
in a repository? if not - it shouldn't be part of the maven build lifecycle).

You use the maven-dependency-plugin to unpack the war/ear (for instance in generate-resources), say to
${project.build.directory}/foo/
and specify a series of executions of the install plugin (for instance in process-resources), each one configured
with the location a jar in ${project.build.directory}/foo/.

Anyway, this is not recommended practice, but I can see why your plugin is useful.
The eclipse plugin has a similar mojo, that scans an eclipse installation directory for plugins
and installs each plugin as a maven2 artifact in the local directory. It doesn't use
the install mojo, afaik, but the maven api's.
I'm assuming your plugin is similar, in that it can unpack/install wars/ears found in a bea weblogic installation
directory?

-- Kenney

> 
> Thanks,
> 
> Gerald

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


RE: calling plugin in another plugin?

Posted by "Nunn, Gerald" <Ge...@CIBC.com>.
Jason,

>It's a bad practice, and leads to coupling between plugins which is  
>bad. We've seen the aftermath of this happening in Maven 1.x.

Since I'm doing this already I'm curious how this could be done better and accomplish my goal, I'm a relative newbie to Mojos so I'm wondering if I am missing a better approach. 

In my case, I needed a plugin that can handle a WebLogic shared library. A shared library is a WAR or EAR that contains many different assets including JARs and in order to be able to use these in Maven I've created a plugin that temporarily unpacks the shared library and installs each JAR individually under a library group name. It also creates a parent POM for the library that can be used to drag in all the dependencies defined by the library.

In order to do this, my plugin needs to install each file individually. Rather then rewrite the install plugin, I simply use my invoker class to invoke the install plugin for each file I have unpacked passing in the necessary parameters to make this work.

How could I accomplish the same goal using the approach you outlined?

Thanks,

Gerald

Re: calling plugin in another plugin?

Posted by Jason van Zyl <ja...@maven.org>.
On 6 Jun 07, at 6:52 AM 6 Jun 07, Jo Vandermeeren wrote:

> Hi Zhangxu,
>
> On 6/6/07, 張旭 <zh...@gmail.com> wrote:
>>
>> Does maven2 has api to add and call a plugin in another plugin ?
>
>
>
> This question has been asked a couple of times in the past, but  
> nobody seems
> to have an answer.

It's a bad practice, and leads to coupling between plugins which is  
bad. We've seen the aftermath of this happening in Maven 1.x.

What we promote is augmenting the lifecycle, or the creation of new  
lifecycles to slot in the functionality required.

In 2.0.x it is possible for Mojos in the same plugin to communicate  
with one another and in 2.1.x we have a data bus of sorts where  
information can be placed on the bus and examined by other plugins  
where this information can be keyed off of to do work generally.

If you have a set of plugins that work together then make a lifecycle  
given you can control the execution and ordering of the lifecycle  
instead of directly invoking Mojos from one another which is  
categorically a bad practice. It will lead to coupling and make your  
Mojo un-reusable for other use cases i.e. slotting them into other  
lifecycles.

> So, I think it's fair to conclude that there is no API available  
> for this.
>
> Or should I spell out dependency on the plugin being called and invoke
>> Mojo.execute() directly?
>
>
>
> You could indeed add the resp. plugin as a dependency and call it  
> directly,
> but how about configuring the plugin's input parameters?
> That's a real pain.
>
> An API would be very nice, including some form of Configuration  
> object to
> pass to the plugin.
>
> Cheers
> Jo

Thanks,

Jason

----------------------------------------------------------
Jason van Zyl
Founder and PMC Chair, Apache Maven
jason at sonatype dot com
----------------------------------------------------------




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


RE: calling plugin in another plugin?

Posted by "Nunn, Gerald" <Ge...@CIBC.com>.
package com.bea.ps.maven.util;

import java.lang.reflect.Field;
import java.util.Map;

import org.apache.maven.plugin.ContextEnabled;
import org.apache.maven.plugin.Mojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.logging.Log;

public class MojoInvoker {

	private Log log;
	private Map pluginContext;
	
	public MojoInvoker(Log log, Map pluginContext) {
		this.log = log;
		this.pluginContext = pluginContext;
	}

	public void invoke(String mojoClass, Map<String,Object> parameters) throws MojoExecutionException, MojoFailureException {
		try {
			Class clazz = Class.forName(mojoClass);
			invoke(clazz,parameters);
		} catch (ClassNotFoundException e) {
			throw new MojoExecutionException("No class was found for "+mojoClass,e);
		}
	}

	
	public void invoke(Class mojoClass, Map<String,Object> parameters) throws MojoExecutionException, MojoFailureException {
		Object object = null;
		try {
			object = mojoClass.newInstance();
		} catch (InstantiationException e) {
			throw new MojoExecutionException(mojoClass.getName()+" could not be instantiated",e);
		} catch (IllegalAccessException e) {
			throw new MojoExecutionException(mojoClass.getName()+" could not be instantiated",e);
		}
		if (!(object instanceof Mojo)) throw new MojoExecutionException(mojoClass.getName()+" does not implement the Mojo interface, execution aborted");
		Mojo mojo = (Mojo)object;
		mojo.setLog(log);
		if (mojo instanceof ContextEnabled) ((ContextEnabled)mojo).setPluginContext(pluginContext);
		setParameters(mojo,parameters);
		mojo.execute();
	}
	
	public Log getLog() {
		return log;
	}
	
	public Map getPluginContext() {
		return pluginContext;
	}
	
	private void setParameters(Mojo mojo, Map<String,Object> parameters)  throws MojoExecutionException, MojoFailureException  {
		log.debug("    Assigning values to mojo '"+mojo.getClass().getName()+"'");
		
		Class current = mojo.getClass();
		while (current!=null) {
			log.debug("Applying parameters to "+current.getName());

			Field[] fields = current.getDeclaredFields();
			for (int i=0; i<fields.length; i++) {
				log.debug("    Getting value for field '"+fields[i].getName()+"'");
				Object value = parameters.get(fields[i].getName());
				log.debug("    Value for field '"+fields[i].getName()+"' equals '"+value+"'");
	
				if (value!=null) {
					fields[i].setAccessible(true);
					try {
						log.debug("    Assigning value '"+value+"' to field '"+fields[i].getName()+"'");
						fields[i].set(mojo,value);
					} catch (IllegalAccessException e) {
						throw new MojoExecutionException("Could not access field '"+fields[i].getName()+"' for class '"+mojo.getClass().getName()+"'",e);
					}
				}
			}
			current = current.getSuperclass();
		}
	}
}

-----Original Message-----
From: Wayne Fay [mailto:waynefay@gmail.com]
Sent: Wednesday, June 06, 2007 10:43 AM
To: Maven Users List
Subject: Re: calling plugin in another plugin?


If you attached something to your email, it was removed before being
sent on to the rest of the list, unfortunately.

Please resend (in the message body) or provide a download link -- it
sounds useful.

Wayne

On 6/6/07, Nunn, Gerald <Ge...@cibc.com> wrote:
> Here is a MojoInvoker class I wrote that invokes one Mojo from another using reflection, I use it to invoke the install plugin from a plugin that handles breaking up and installing weblogic shared libraries into the repository. The philosphy is that the plugin doing the invoking is familiar with the invoked plugin and is responsible for passing parameters accordingly through a map. Reflection is used to assign the parameters to the mojo's attributes.
>
> While it's only been tested with the install plugin it might be useful for what you want to do and could be broadened out into a general API.
>
> Gerald
>
>
> ---------------------------------------------------------------------
> 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: calling plugin in another plugin?

Posted by Wayne Fay <wa...@gmail.com>.
If you attached something to your email, it was removed before being
sent on to the rest of the list, unfortunately.

Please resend (in the message body) or provide a download link -- it
sounds useful.

Wayne

On 6/6/07, Nunn, Gerald <Ge...@cibc.com> wrote:
> Here is a MojoInvoker class I wrote that invokes one Mojo from another using reflection, I use it to invoke the install plugin from a plugin that handles breaking up and installing weblogic shared libraries into the repository. The philosphy is that the plugin doing the invoking is familiar with the invoked plugin and is responsible for passing parameters accordingly through a map. Reflection is used to assign the parameters to the mojo's attributes.
>
> While it's only been tested with the install plugin it might be useful for what you want to do and could be broadened out into a general API.
>
> Gerald
>
>
> ---------------------------------------------------------------------
> 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: calling plugin in another plugin?

Posted by "Nunn, Gerald" <Ge...@CIBC.com>.
Here is a MojoInvoker class I wrote that invokes one Mojo from another using reflection, I use it to invoke the install plugin from a plugin that handles breaking up and installing weblogic shared libraries into the repository. The philosphy is that the plugin doing the invoking is familiar with the invoked plugin and is responsible for passing parameters accordingly through a map. Reflection is used to assign the parameters to the mojo's attributes.

While it's only been tested with the install plugin it might be useful for what you want to do and could be broadened out into a general API.

Gerald


Re: calling plugin in another plugin?

Posted by Jo Vandermeeren <jo...@gmail.com>.
Hi Zhangxu,

On 6/6/07, 張旭 <zh...@gmail.com> wrote:
>
> Does maven2 has api to add and call a plugin in another plugin ?



This question has been asked a couple of times in the past, but nobody seems
to have an answer.
So, I think it's fair to conclude that there is no API available for this.

Or should I spell out dependency on the plugin being called and invoke
> Mojo.execute() directly?



You could indeed add the resp. plugin as a dependency and call it directly,
but how about configuring the plugin's input parameters?
That's a real pain.

An API would be very nice, including some form of Configuration object to
pass to the plugin.

Cheers
Jo