You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by Jochen Kuhnle <jo...@kuhnle.net> on 2007/07/03 11:32:18 UTC

Proposoal: MNG-2521 Multi Mojo Configuration

Hi,

Eric Redmond told me to write up the stuff I posted about MNG-2521 as a 
proposal, so here's the first one:

Many Mojos (e.g. the compiler) execute in different phases of the build 
lifecycle using different "configurations". With the current JavaDoc 
and MNG-2521 annotations, a Mojo cannot be annotated with more than one 
goal. Multiple "configurations" are done by subclassing a Mojo for each 
"configuration", e.g. CompilerMojo and TestCompilerMojo, which are 
virtually identical except parameter annotations and attribute names. 
With MNG-2521, the proposal is to extend the annotations to allow a 
Mojo to be annotated with multiple goals.

For this, list annotations should be introduced for each annotation 
(Goal, Parameter and Component). Each member of the list should have an 
optional attribute specifying for which goal the annotation is. If this 
attribute is missing, the annotation should be valid for all goals.

Example for a CompilerMojo

@Goals(
	@Goal(goal = "compile", phase = "compile", 
requiresDependencyResolution = "compile"),
	@Goal(goal = "testCompile", phase = "test-compile", 
requiresDependencyResolution = "test"))
public class CompilerMojo extends AbstractMojo {

	@Parameter(expression = "${basedir}", required = true, readonly = 
true) // Valid for all goals
	private File basedir;

	@Parameters(
		@Parameter(goal = "compile", expression = 
"${project.compileSourceRoots}"), // Valid only for goal "compile"
		@Parameter(goal = "testCompile", expression = 
"${project.testCompileSourceRoots}")) // Valid only for goal 
"testCompile"
	private List compileSourceRoots;
}

Saves two classes and some typing.

When a parameter needs to have different names for different goals 
(e.g. "includes" and "testIncludes"), you can use setters:

private List includes;

@Parameter(goal = "compile), // Valid only for goal "compile"
public void setIncludes(List includes) {
	this.includes = includes;
}

@Parameter(goal = "testCompile")) // Valid only for goal "testCompile"
public void setTestIncludes(List includes) {
	this.includes = includes;
}

On the long run, it would be nice to decouple a parameter name from the 
underlying attribute or method name, and allow the parameter name to be 
specified in the annotation.

Regards,
Jochen



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


Re: Proposoal: MNG-2521 Multi Mojo Configuration

Posted by Mark Hobson <ma...@gmail.com>.
On 03/07/07, Jochen Kuhnle <jo...@kuhnle.net> wrote:
> I don't think multiple annotations of the same type are possible, i.e.
>
> @Goal(...)
> @Goal(...)
> class MyMojo {
> }
>
> does not work. At least with Eclipse ;-)

Well I never, good point :)  From JLS 9.7:

"It is a compile-time error if a declaration is annotated with more
than one annotation for a given annotation type."

A meta-annotation could have been useful to control this.  Ignore my
ramblings then.. ;)

Cheers,

Mark

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


Re: Proposoal: MNG-2521 Multi Mojo Configuration

Posted by Jochen Kuhnle <jo...@kuhnle.net>.
On 2007-07-03 11:40:06 +0200, "Mark Hobson" <ma...@gmail.com> said:

> On 03/07/07, Jochen Kuhnle <jo...@kuhnle.net> wrote:
>> Hi,


>> 
>> 
>> Example for a CompilerMojo
>> 
>> @Goals(
>>         @Goal(goal = "compile", phase = "compile",
>> requiresDependencyResolution = "compile"),
>>         @Goal(goal = "testCompile", phase = "test-compile",
>> requiresDependencyResolution = "test"))
>> public class CompilerMojo extends AbstractMojo {
> 
> Why introduce the @Goals annotation when you could just specify
> multiple @Goal annotations on the class?

I don't think multiple annotations of the same type are possible, i.e.

@Goal(...)
@Goal(...)
class MyMojo {
}

does not work. At least with Eclipse ;-)

Regards,
Jochen



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


Re: Proposoal: MNG-2521 Multi Mojo Configuration

Posted by Mark Hobson <ma...@gmail.com>.
On 03/07/07, Jochen Kuhnle <jo...@kuhnle.net> wrote:
> Hi,
>
> Eric Redmond told me to write up the stuff I posted about MNG-2521 as a
> proposal, so here's the first one:
>
> Many Mojos (e.g. the compiler) execute in different phases of the build
> lifecycle using different "configurations". With the current JavaDoc
> and MNG-2521 annotations, a Mojo cannot be annotated with more than one
> goal. Multiple "configurations" are done by subclassing a Mojo for each
> "configuration", e.g. CompilerMojo and TestCompilerMojo, which are
> virtually identical except parameter annotations and attribute names.
> With MNG-2521, the proposal is to extend the annotations to allow a
> Mojo to be annotated with multiple goals.
>
> For this, list annotations should be introduced for each annotation
> (Goal, Parameter and Component). Each member of the list should have an
> optional attribute specifying for which goal the annotation is. If this
> attribute is missing, the annotation should be valid for all goals.
>
> Example for a CompilerMojo
>
> @Goals(
>         @Goal(goal = "compile", phase = "compile",
> requiresDependencyResolution = "compile"),
>         @Goal(goal = "testCompile", phase = "test-compile",
> requiresDependencyResolution = "test"))
> public class CompilerMojo extends AbstractMojo {

Why introduce the @Goals annotation when you could just specify
multiple @Goal annotations on the class?

>         @Parameter(expression = "${basedir}", required = true, readonly =
> true) // Valid for all goals
>         private File basedir;
>
>         @Parameters(
>                 @Parameter(goal = "compile", expression =
> "${project.compileSourceRoots}"), // Valid only for goal "compile"
>                 @Parameter(goal = "testCompile", expression =
> "${project.testCompileSourceRoots}")) // Valid only for goal
> "testCompile"
>         private List compileSourceRoots;
> }

Same as above with @Parameters.

> Saves two classes and some typing.
>
> When a parameter needs to have different names for different goals
> (e.g. "includes" and "testIncludes"), you can use setters:
>
> private List includes;
>
> @Parameter(goal = "compile), // Valid only for goal "compile"
> public void setIncludes(List includes) {
>         this.includes = includes;
> }
>
> @Parameter(goal = "testCompile")) // Valid only for goal "testCompile"
> public void setTestIncludes(List includes) {
>         this.includes = includes;
> }
>
> On the long run, it would be nice to decouple a parameter name from the
> underlying attribute or method name, and allow the parameter name to be
> specified in the annotation.

Cheers,

Mark

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