[MPLUGIN-204] added support for some Maven objects injected as components: session, project, mojo, plugin and settings
git-svn-id: https://svn.apache.org/repos/asf/maven/plugin-tools/trunk@1343086 13f79535-47bb-0310-9956-ffa450edef68master
parent
4229553d33
commit
1e7bbd5bc6
|
|
@ -29,7 +29,9 @@ import java.lang.annotation.Target;
|
||||||
/**
|
/**
|
||||||
* Used to configure injection of Plexus components by
|
* Used to configure injection of Plexus components by
|
||||||
* <a href="/ref/current/maven-core/apidocs/org/apache/maven/plugin/MavenPluginManager.html">
|
* <a href="/ref/current/maven-core/apidocs/org/apache/maven/plugin/MavenPluginManager.html">
|
||||||
* <code>MavenPluginManager.getConfiguredMojo(...)</code></a>.
|
* <code>MavenPluginManager.getConfiguredMojo(...)</code></a> and special Maven
|
||||||
|
* objects as well: <code>session</code>, <code>project</code>, <code>mojo</code>, <code>plugin</code>,
|
||||||
|
* <code>settings</code>.
|
||||||
*
|
*
|
||||||
* @author Olivier Lamy
|
* @author Olivier Lamy
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
|
|
|
||||||
|
|
@ -42,12 +42,12 @@ under the License.
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-plugin-api</artifactId>
|
<artifactId>maven-plugin-api</artifactId>
|
||||||
<version>2.0</version>
|
<version>2.2.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-project</artifactId>
|
<artifactId>maven-core</artifactId>
|
||||||
<version>2.0</version>
|
<version>2.2.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.codehaus.plexus</groupId>
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
|
|
||||||
|
|
@ -19,15 +19,20 @@ package org.apache.maven.plugin.coreit;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
|
import org.apache.maven.plugin.MojoExecution;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
import org.apache.maven.plugins.annotations.Component;
|
import org.apache.maven.plugins.annotations.Component;
|
||||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||||
import org.apache.maven.plugins.annotations.Execute;
|
import org.apache.maven.plugins.annotations.Execute;
|
||||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.project.MavenProjectHelper;
|
import org.apache.maven.project.MavenProjectHelper;
|
||||||
|
import org.apache.maven.settings.Settings;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
|
@ -63,6 +68,21 @@ public class FirstMojo
|
||||||
@Component( role = MavenProjectHelper.class, hint = "test" )
|
@Component( role = MavenProjectHelper.class, hint = "test" )
|
||||||
private Object projectHelper;
|
private Object projectHelper;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
private MavenSession session;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
private MavenProject project;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
private MojoExecution mojo;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
private PluginDescriptor plugin;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
private Settings settings;
|
||||||
|
|
||||||
public void execute()
|
public void execute()
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -32,16 +32,35 @@ assert mojo.configuration.touchFile[0].text() == '${first.touchFile}'
|
||||||
assert mojo.configuration.touchFile[0].'@implementation' == 'java.io.File'
|
assert mojo.configuration.touchFile[0].'@implementation' == 'java.io.File'
|
||||||
assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.directory}/touch.txt'
|
assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.directory}/touch.txt'
|
||||||
|
|
||||||
|
assert mojo.configuration.session[0].text() == ''
|
||||||
|
assert mojo.configuration.session[0].'@implementation' == 'org.apache.maven.execution.MavenSession'
|
||||||
|
assert mojo.configuration.session[0].'@default-value' == '${session}'
|
||||||
|
|
||||||
|
assert mojo.configuration.project[0].text() == ''
|
||||||
|
assert mojo.configuration.project[0].'@implementation' == 'org.apache.maven.project.MavenProject'
|
||||||
|
assert mojo.configuration.project[0].'@default-value' == '${project}'
|
||||||
|
|
||||||
|
assert mojo.configuration.mojo[0].text() == ''
|
||||||
|
assert mojo.configuration.mojo[0].'@implementation' == 'org.apache.maven.plugin.MojoExecution'
|
||||||
|
assert mojo.configuration.mojo[0].'@default-value' == '${mojo}'
|
||||||
|
|
||||||
|
assert mojo.configuration.plugin[0].text() == ''
|
||||||
|
assert mojo.configuration.plugin[0].'@implementation' == 'org.apache.maven.plugin.descriptor.PluginDescriptor'
|
||||||
|
assert mojo.configuration.plugin[0].'@default-value' == '${plugin}'
|
||||||
|
|
||||||
|
assert mojo.configuration.settings[0].text() == ''
|
||||||
|
assert mojo.configuration.settings[0].'@implementation' == 'org.apache.maven.settings.Settings'
|
||||||
|
assert mojo.configuration.settings[0].'@default-value' == '${settings}'
|
||||||
|
|
||||||
assert mojo.requirements.requirement.size() == 1
|
assert mojo.requirements.requirement.size() == 1
|
||||||
|
|
||||||
assert mojo.requirements.requirement[0].role.text() == 'org.apache.maven.project.MavenProjectHelper'
|
assert mojo.requirements.requirement[0].role.text() == 'org.apache.maven.project.MavenProjectHelper'
|
||||||
assert mojo.requirements.requirement[0].'role-hint'.text() == 'test'
|
assert mojo.requirements.requirement[0].'role-hint'.text() == 'test'
|
||||||
assert mojo.requirements.requirement[0].'field-name'.text() == 'projectHelper'
|
assert mojo.requirements.requirement[0].'field-name'.text() == 'projectHelper'
|
||||||
|
|
||||||
assert mojo.parameters.parameter.size() == 3
|
assert mojo.parameters.parameter.size() == 8
|
||||||
|
|
||||||
def parameter = mojo.parameters.parameter.findAll{ it.name.text() == "aliasedParam" }[0]
|
|
||||||
|
|
||||||
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "aliasedParam" }[0]
|
||||||
assert parameter.name.text() == 'aliasedParam'
|
assert parameter.name.text() == 'aliasedParam'
|
||||||
assert parameter.alias.text() == 'alias'
|
assert parameter.alias.text() == 'alias'
|
||||||
assert parameter.type.text() == 'java.lang.String'
|
assert parameter.type.text() == 'java.lang.String'
|
||||||
|
|
@ -50,18 +69,7 @@ assert parameter.required.text() == 'false'
|
||||||
assert parameter.editable.text() == 'true'
|
assert parameter.editable.text() == 'true'
|
||||||
assert parameter.description.text() == ''
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "touchFile" }[0]
|
|
||||||
|
|
||||||
assert parameter.name.text() == 'touchFile'
|
|
||||||
assert parameter.alias.isEmpty()
|
|
||||||
assert parameter.type.text() == 'java.io.File'
|
|
||||||
assert parameter.deprecated.isEmpty()
|
|
||||||
assert parameter.required.text() == 'true'
|
|
||||||
assert parameter.editable.text() == 'true'
|
|
||||||
assert parameter.description.text() == ''
|
|
||||||
|
|
||||||
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "basedir" }[0]
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "basedir" }[0]
|
||||||
|
|
||||||
assert parameter.name.text() == 'basedir'
|
assert parameter.name.text() == 'basedir'
|
||||||
assert parameter.alias.isEmpty()
|
assert parameter.alias.isEmpty()
|
||||||
assert parameter.type.text() == 'java.io.File'
|
assert parameter.type.text() == 'java.io.File'
|
||||||
|
|
@ -70,6 +78,60 @@ assert parameter.required.text() == 'false'
|
||||||
assert parameter.editable.text() == 'false'
|
assert parameter.editable.text() == 'false'
|
||||||
assert parameter.description.text() == 'Project directory.'
|
assert parameter.description.text() == 'Project directory.'
|
||||||
|
|
||||||
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "mojo" }[0]
|
||||||
|
assert parameter.name.text() == 'mojo'
|
||||||
|
assert parameter.alias.isEmpty()
|
||||||
|
assert parameter.type.text() == 'org.apache.maven.plugin.MojoExecution'
|
||||||
|
assert parameter.deprecated.isEmpty()
|
||||||
|
assert parameter.required.text() == 'false'
|
||||||
|
assert parameter.editable.text() == 'false'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "plugin" }[0]
|
||||||
|
assert parameter.name.text() == 'plugin'
|
||||||
|
assert parameter.alias.isEmpty()
|
||||||
|
assert parameter.type.text() == 'org.apache.maven.plugin.descriptor.PluginDescriptor'
|
||||||
|
assert parameter.deprecated.isEmpty()
|
||||||
|
assert parameter.required.text() == 'false'
|
||||||
|
assert parameter.editable.text() == 'false'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "project" }[0]
|
||||||
|
assert parameter.name.text() == 'project'
|
||||||
|
assert parameter.alias.isEmpty()
|
||||||
|
assert parameter.type.text() == 'org.apache.maven.project.MavenProject'
|
||||||
|
assert parameter.deprecated.isEmpty()
|
||||||
|
assert parameter.required.text() == 'false'
|
||||||
|
assert parameter.editable.text() == 'false'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "session" }[0]
|
||||||
|
assert parameter.name.text() == 'session'
|
||||||
|
assert parameter.alias.isEmpty()
|
||||||
|
assert parameter.type.text() == 'org.apache.maven.execution.MavenSession'
|
||||||
|
assert parameter.deprecated.isEmpty()
|
||||||
|
assert parameter.required.text() == 'false'
|
||||||
|
assert parameter.editable.text() == 'false'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "settings" }[0]
|
||||||
|
assert parameter.name.text() == 'settings'
|
||||||
|
assert parameter.alias.isEmpty()
|
||||||
|
assert parameter.type.text() == 'org.apache.maven.settings.Settings'
|
||||||
|
assert parameter.deprecated.isEmpty()
|
||||||
|
assert parameter.required.text() == 'false'
|
||||||
|
assert parameter.editable.text() == 'false'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "touchFile" }[0]
|
||||||
|
assert parameter.name.text() == 'touchFile'
|
||||||
|
assert parameter.alias.isEmpty()
|
||||||
|
assert parameter.type.text() == 'java.io.File'
|
||||||
|
assert parameter.deprecated.isEmpty()
|
||||||
|
assert parameter.required.text() == 'true'
|
||||||
|
assert parameter.editable.text() == 'true'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "second" }[0]
|
mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "second" }[0]
|
||||||
|
|
||||||
assert mojo.requiresDependencyCollection.text() == 'compile'
|
assert mojo.requiresDependencyCollection.text() == 'compile'
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,12 @@ under the License.
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.maven</groupId>
|
<groupId>org.apache.maven</groupId>
|
||||||
<artifactId>maven-plugin-api</artifactId>
|
<artifactId>maven-plugin-api</artifactId>
|
||||||
<version>2.0</version>
|
<version>2.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven</groupId>
|
||||||
|
<artifactId>maven-core</artifactId>
|
||||||
|
<version>2.2.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,13 @@ package org.apache.maven.plugin.coreit;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
|
import org.apache.maven.plugin.MojoExecution;
|
||||||
import org.apache.maven.plugin.MojoExecutionException;
|
import org.apache.maven.plugin.MojoExecutionException;
|
||||||
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.apache.maven.settings.Settings;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
@ -64,6 +69,31 @@ public class FirstMojo
|
||||||
*/
|
*/
|
||||||
private Object projectHelper;
|
private Object projectHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @component
|
||||||
|
*/
|
||||||
|
private MavenSession session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @component
|
||||||
|
*/
|
||||||
|
private MavenProject project;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @component
|
||||||
|
*/
|
||||||
|
private MojoExecution mojo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @component
|
||||||
|
*/
|
||||||
|
private PluginDescriptor plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @component
|
||||||
|
*/
|
||||||
|
private Settings settings;
|
||||||
|
|
||||||
public void execute()
|
public void execute()
|
||||||
throws MojoExecutionException
|
throws MojoExecutionException
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -32,37 +32,105 @@ assert mojo.configuration.touchFile[0].text() == '${first.touchFile}'
|
||||||
assert mojo.configuration.touchFile[0].'@implementation' == 'java.io.File'
|
assert mojo.configuration.touchFile[0].'@implementation' == 'java.io.File'
|
||||||
assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.directory}/touch.txt'
|
assert mojo.configuration.touchFile[0].'@default-value' == '${project.build.directory}/touch.txt'
|
||||||
|
|
||||||
|
assert mojo.configuration.session[0].text() == ''
|
||||||
|
assert mojo.configuration.session[0].'@implementation' == 'org.apache.maven.execution.MavenSession'
|
||||||
|
assert mojo.configuration.session[0].'@default-value' == '${session}'
|
||||||
|
|
||||||
|
assert mojo.configuration.project[0].text() == ''
|
||||||
|
assert mojo.configuration.project[0].'@implementation' == 'org.apache.maven.project.MavenProject'
|
||||||
|
assert mojo.configuration.project[0].'@default-value' == '${project}'
|
||||||
|
|
||||||
|
assert mojo.configuration.mojo[0].text() == ''
|
||||||
|
assert mojo.configuration.mojo[0].'@implementation' == 'org.apache.maven.plugin.MojoExecution'
|
||||||
|
assert mojo.configuration.mojo[0].'@default-value' == '${mojo}'
|
||||||
|
|
||||||
|
assert mojo.configuration.plugin[0].text() == ''
|
||||||
|
assert mojo.configuration.plugin[0].'@implementation' == 'org.apache.maven.plugin.descriptor.PluginDescriptor'
|
||||||
|
assert mojo.configuration.plugin[0].'@default-value' == '${plugin}'
|
||||||
|
|
||||||
|
assert mojo.configuration.settings[0].text() == ''
|
||||||
|
assert mojo.configuration.settings[0].'@implementation' == 'org.apache.maven.settings.Settings'
|
||||||
|
assert mojo.configuration.settings[0].'@default-value' == '${settings}'
|
||||||
|
|
||||||
assert mojo.requirements.requirement.size() == 1
|
assert mojo.requirements.requirement.size() == 1
|
||||||
|
|
||||||
assert mojo.requirements.requirement[0].role.text() == 'org.apache.maven.project.MavenProjectHelper'
|
assert mojo.requirements.requirement[0].role.text() == 'org.apache.maven.project.MavenProjectHelper'
|
||||||
assert mojo.requirements.requirement[0].'role-hint'.text() == 'test'
|
assert mojo.requirements.requirement[0].'role-hint'.text() == 'test'
|
||||||
assert mojo.requirements.requirement[0].'field-name'.text() == 'projectHelper'
|
assert mojo.requirements.requirement[0].'field-name'.text() == 'projectHelper'
|
||||||
|
|
||||||
assert mojo.parameters.parameter.size() == 3
|
assert mojo.parameters.parameter.size() == 8
|
||||||
|
|
||||||
assert mojo.parameters.parameter[0].name.text() == 'aliasedParam'
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "aliasedParam" }[0]
|
||||||
assert mojo.parameters.parameter[0].alias.text() == 'alias'
|
assert parameter.name.text() == 'aliasedParam'
|
||||||
assert mojo.parameters.parameter[0].type.text() == 'java.lang.String'
|
assert parameter.alias.text() == 'alias'
|
||||||
assert mojo.parameters.parameter[0].deprecated.text() == 'As of 0.2'
|
assert parameter.type.text() == 'java.lang.String'
|
||||||
assert mojo.parameters.parameter[0].required.text() == 'false'
|
assert parameter.deprecated.text() == 'As of 0.2'
|
||||||
assert mojo.parameters.parameter[0].editable.text() == 'true'
|
assert parameter.required.text() == 'false'
|
||||||
assert mojo.parameters.parameter[0].description.text() == ''
|
assert parameter.editable.text() == 'true'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
assert mojo.parameters.parameter[1].name.text() == 'basedir'
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "basedir" }[0]
|
||||||
assert mojo.parameters.parameter[1].alias.isEmpty()
|
assert parameter.name.text() == 'basedir'
|
||||||
assert mojo.parameters.parameter[1].type.text() == 'java.io.File'
|
assert parameter.alias.isEmpty()
|
||||||
assert mojo.parameters.parameter[1].deprecated.isEmpty()
|
assert parameter.type.text() == 'java.io.File'
|
||||||
assert mojo.parameters.parameter[1].required.text() == 'false'
|
assert parameter.deprecated.isEmpty()
|
||||||
assert mojo.parameters.parameter[1].editable.text() == 'false'
|
assert parameter.required.text() == 'false'
|
||||||
assert mojo.parameters.parameter[1].description.text() == 'Project directory.'
|
assert parameter.editable.text() == 'false'
|
||||||
|
assert parameter.description.text() == 'Project directory.'
|
||||||
|
|
||||||
assert mojo.parameters.parameter[2].name.text() == 'touchFile'
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "mojo" }[0]
|
||||||
assert mojo.parameters.parameter[2].alias.isEmpty()
|
assert parameter.name.text() == 'mojo'
|
||||||
assert mojo.parameters.parameter[2].type.text() == 'java.io.File'
|
assert parameter.alias.isEmpty()
|
||||||
assert mojo.parameters.parameter[2].deprecated.isEmpty()
|
assert parameter.type.text() == 'org.apache.maven.plugin.MojoExecution'
|
||||||
assert mojo.parameters.parameter[2].required.text() == 'true'
|
assert parameter.deprecated.isEmpty()
|
||||||
assert mojo.parameters.parameter[2].editable.text() == 'true'
|
assert parameter.required.text() == 'false'
|
||||||
assert mojo.parameters.parameter[2].description.text() == ''
|
assert parameter.editable.text() == 'false'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "plugin" }[0]
|
||||||
|
assert parameter.name.text() == 'plugin'
|
||||||
|
assert parameter.alias.isEmpty()
|
||||||
|
assert parameter.type.text() == 'org.apache.maven.plugin.descriptor.PluginDescriptor'
|
||||||
|
assert parameter.deprecated.isEmpty()
|
||||||
|
assert parameter.required.text() == 'false'
|
||||||
|
assert parameter.editable.text() == 'false'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "project" }[0]
|
||||||
|
assert parameter.name.text() == 'project'
|
||||||
|
assert parameter.alias.isEmpty()
|
||||||
|
assert parameter.type.text() == 'org.apache.maven.project.MavenProject'
|
||||||
|
assert parameter.deprecated.isEmpty()
|
||||||
|
assert parameter.required.text() == 'false'
|
||||||
|
assert parameter.editable.text() == 'false'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "session" }[0]
|
||||||
|
assert parameter.name.text() == 'session'
|
||||||
|
assert parameter.alias.isEmpty()
|
||||||
|
assert parameter.type.text() == 'org.apache.maven.execution.MavenSession'
|
||||||
|
assert parameter.deprecated.isEmpty()
|
||||||
|
assert parameter.required.text() == 'false'
|
||||||
|
assert parameter.editable.text() == 'false'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "settings" }[0]
|
||||||
|
assert parameter.name.text() == 'settings'
|
||||||
|
assert parameter.alias.isEmpty()
|
||||||
|
assert parameter.type.text() == 'org.apache.maven.settings.Settings'
|
||||||
|
assert parameter.deprecated.isEmpty()
|
||||||
|
assert parameter.required.text() == 'false'
|
||||||
|
assert parameter.editable.text() == 'false'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
|
parameter = mojo.parameters.parameter.findAll{ it.name.text() == "touchFile" }[0]
|
||||||
|
assert parameter.name.text() == 'touchFile'
|
||||||
|
assert parameter.alias.isEmpty()
|
||||||
|
assert parameter.type.text() == 'java.io.File'
|
||||||
|
assert parameter.deprecated.isEmpty()
|
||||||
|
assert parameter.required.text() == 'true'
|
||||||
|
assert parameter.editable.text() == 'true'
|
||||||
|
assert parameter.description.text() == ''
|
||||||
|
|
||||||
mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "second"}[0]
|
mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "second"}[0]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,7 @@ import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScanner;
|
||||||
import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScannerRequest;
|
import org.apache.maven.tools.plugin.annotations.scanner.MojoAnnotationsScannerRequest;
|
||||||
import org.apache.maven.tools.plugin.extractor.ExtractionException;
|
import org.apache.maven.tools.plugin.extractor.ExtractionException;
|
||||||
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
|
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
|
||||||
|
import org.apache.maven.tools.plugin.util.PluginUtils;
|
||||||
import org.codehaus.plexus.archiver.UnArchiver;
|
import org.codehaus.plexus.archiver.UnArchiver;
|
||||||
import org.codehaus.plexus.archiver.manager.ArchiverManager;
|
import org.codehaus.plexus.archiver.manager.ArchiverManager;
|
||||||
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
|
import org.codehaus.plexus.archiver.manager.NoSuchArchiverException;
|
||||||
|
|
@ -545,8 +546,19 @@ public class JavaAnnotationsMojoDescriptorExtractor
|
||||||
org.apache.maven.plugin.descriptor.Parameter parameter =
|
org.apache.maven.plugin.descriptor.Parameter parameter =
|
||||||
new org.apache.maven.plugin.descriptor.Parameter();
|
new org.apache.maven.plugin.descriptor.Parameter();
|
||||||
parameter.setName( componentAnnotationContent.getFieldName() );
|
parameter.setName( componentAnnotationContent.getFieldName() );
|
||||||
|
|
||||||
|
String expression = PluginUtils.MAVEN_COMPONENTS.get( componentAnnotationContent.getRoleClassName() );
|
||||||
|
if ( expression == null )
|
||||||
|
{
|
||||||
parameter.setRequirement( new Requirement( componentAnnotationContent.getRoleClassName(),
|
parameter.setRequirement( new Requirement( componentAnnotationContent.getRoleClassName(),
|
||||||
componentAnnotationContent.hint() ) );
|
componentAnnotationContent.hint() ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
parameter.setDefaultValue( expression );
|
||||||
|
parameter.setImplementation( componentAnnotationContent.getRoleClassName() );
|
||||||
|
parameter.setType( componentAnnotationContent.getRoleClassName() );
|
||||||
|
}
|
||||||
parameter.setDeprecated( componentAnnotationContent.getDeprecated() );
|
parameter.setDeprecated( componentAnnotationContent.getDeprecated() );
|
||||||
parameter.setSince( componentAnnotationContent.getSince() );
|
parameter.setSince( componentAnnotationContent.getSince() );
|
||||||
|
|
||||||
|
|
@ -563,7 +575,6 @@ public class JavaAnnotationsMojoDescriptorExtractor
|
||||||
return mojoDescriptors;
|
return mojoDescriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected ExecuteAnnotationContent findExecuteInParentHierarchy( MojoAnnotatedClass mojoAnnotatedClass,
|
protected ExecuteAnnotationContent findExecuteInParentHierarchy( MojoAnnotatedClass mojoAnnotatedClass,
|
||||||
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
|
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,10 @@ Maven Plugin Tool for Annotations
|
||||||
* Supported Annotations
|
* Supported Annotations
|
||||||
|
|
||||||
+---------+
|
+---------+
|
||||||
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
|
import org.apache.maven.plugin.MojoExecution;
|
||||||
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
import org.apache.maven.plugins.annotations.ResolutionScope;
|
import org.apache.maven.plugins.annotations.ResolutionScope;
|
||||||
import org.apache.maven.plugins.annotations.Component;
|
import org.apache.maven.plugins.annotations.Component;
|
||||||
import org.apache.maven.plugins.annotations.Execute;
|
import org.apache.maven.plugins.annotations.Execute;
|
||||||
|
|
@ -43,6 +46,8 @@ import org.apache.maven.plugins.annotations.InstanciationStrategy;
|
||||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||||
import org.apache.maven.plugins.annotations.Mojo;
|
import org.apache.maven.plugins.annotations.Mojo;
|
||||||
import org.apache.maven.plugins.annotations.Parameter;
|
import org.apache.maven.plugins.annotations.Parameter;
|
||||||
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.apache.maven.settings.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mojo Description. @Mojo( name = "<goal-name>" ) is the minimal required annotation.
|
* Mojo Description. @Mojo( name = "<goal-name>" ) is the minimal required annotation.
|
||||||
|
|
@ -88,6 +93,21 @@ public class MyMojo
|
||||||
hint = "..." )
|
hint = "..." )
|
||||||
private MyComponent component;
|
private MyComponent component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
private MavenSession session;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
private MavenProject project;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
private MojoExecution mojo;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
private PluginDescriptor plugin;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
private Settings settings;
|
||||||
|
|
||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
...
|
...
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,9 @@ package org.apache.maven.tools.plugin.util;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
import org.apache.maven.plugin.descriptor.MojoDescriptor;
|
||||||
import org.apache.maven.plugin.descriptor.Parameter;
|
import org.apache.maven.plugin.descriptor.Parameter;
|
||||||
|
|
@ -42,6 +44,23 @@ public final class PluginUtils
|
||||||
// nop
|
// nop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expression associated with class types to recognize Maven objects as components.
|
||||||
|
*/
|
||||||
|
public static final Map<String, String> MAVEN_COMPONENTS;
|
||||||
|
static
|
||||||
|
{
|
||||||
|
Map<String, String> mavenComponents = new HashMap<String, String>();
|
||||||
|
|
||||||
|
mavenComponents.put( "org.apache.maven.execution.MavenSession", "${session}" );
|
||||||
|
mavenComponents.put( "org.apache.maven.project.MavenProject", "${project}" );
|
||||||
|
mavenComponents.put( "org.apache.maven.plugin.MojoExecution", "${mojo}" );
|
||||||
|
mavenComponents.put( "org.apache.maven.plugin.descriptor.PluginDescriptor", "${plugin}" );
|
||||||
|
mavenComponents.put( "org.apache.maven.settings.Settings", "${settings}" );
|
||||||
|
|
||||||
|
MAVEN_COMPONENTS = Collections.unmodifiableMap( mavenComponents );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param basedir not null
|
* @param basedir not null
|
||||||
* @param include not null
|
* @param include not null
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
|
||||||
import org.apache.maven.tools.plugin.PluginToolsRequest;
|
import org.apache.maven.tools.plugin.PluginToolsRequest;
|
||||||
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
|
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
|
||||||
import org.apache.maven.tools.plugin.extractor.ExtractionException;
|
import org.apache.maven.tools.plugin.extractor.ExtractionException;
|
||||||
|
import org.apache.maven.tools.plugin.util.PluginUtils;
|
||||||
|
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
import org.codehaus.plexus.logging.AbstractLogEnabled;
|
||||||
|
|
@ -513,7 +514,18 @@ public class JavaMojoDescriptorExtractor
|
||||||
roleHint = componentTag.getNamedParameter( "role-hint" );
|
roleHint = componentTag.getNamedParameter( "role-hint" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String expression = PluginUtils.MAVEN_COMPONENTS.get( role );
|
||||||
|
|
||||||
|
if ( expression == null )
|
||||||
|
{
|
||||||
pd.setRequirement( new Requirement( role, roleHint ) );
|
pd.setRequirement( new Requirement( role, roleHint ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pd.setDefaultValue( expression );
|
||||||
|
pd.setImplementation( role );
|
||||||
|
pd.setType( role );
|
||||||
|
}
|
||||||
|
|
||||||
pd.setEditable( false );
|
pd.setEditable( false );
|
||||||
/* TODO: or better like this? Need @component fields be editable for the user?
|
/* TODO: or better like this? Need @component fields be editable for the user?
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,12 @@ Maven Plugin Tool for Java Annotated with Mojo Javadoc Tags
|
||||||
* Supported Mojo Javadoc Tags
|
* Supported Mojo Javadoc Tags
|
||||||
|
|
||||||
+---------+
|
+---------+
|
||||||
|
import org.apache.maven.execution.MavenSession;
|
||||||
import org.apache.maven.plugin.AbstractMojo;
|
import org.apache.maven.plugin.AbstractMojo;
|
||||||
|
import org.apache.maven.plugin.MojoExecution;
|
||||||
|
import org.apache.maven.plugin.descriptor.PluginDescriptor;
|
||||||
|
import org.apache.maven.project.MavenProject;
|
||||||
|
import org.apache.maven.settings.Settings;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mojo Description: goal is the only required annotation.
|
* Mojo Description: goal is the only required annotation.
|
||||||
|
|
@ -77,6 +82,31 @@ public class MyMojo
|
||||||
*/
|
*/
|
||||||
private Component component;
|
private Component component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @component
|
||||||
|
*/
|
||||||
|
private MavenSession session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @component
|
||||||
|
*/
|
||||||
|
private MavenProject project;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @component
|
||||||
|
*/
|
||||||
|
private MojoExecution mojo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @component
|
||||||
|
*/
|
||||||
|
private PluginDescriptor plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @component
|
||||||
|
*/
|
||||||
|
private Settings settings;
|
||||||
|
|
||||||
public void execute()
|
public void execute()
|
||||||
{
|
{
|
||||||
...
|
...
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue