* @throws PluginMetadataParseException if any
*/
private MojoDescriptor asDescriptor( File metadataFile, Mojo mojo )
throws PluginMetadataParseException
{
MojoDescriptor descriptor = new MojoDescriptor();
if ( mojo.getCall() != null )
{
descriptor.setImplementation( IMPL_BASE_PLACEHOLDER + ":" + mojo.getCall() );
}
else
{
descriptor.setImplementation( IMPL_BASE_PLACEHOLDER );
}
descriptor.setGoal( mojo.getGoal() );
descriptor.setPhase( mojo.getPhase() );
descriptor.setDependencyResolutionRequired( mojo.getRequiresDependencyResolution() );
descriptor.setAggregator( mojo.isAggregator() );
descriptor.setInheritedByDefault( mojo.isInheritByDefault() );
descriptor.setDirectInvocationOnly( mojo.isRequiresDirectInvocation() );
descriptor.setOnlineRequired( mojo.isRequiresOnline() );
descriptor.setProjectRequired( mojo.isRequiresProject() );
descriptor.setRequiresReports( mojo.isRequiresReports() );
descriptor.setDescription( mojo.getDescription() );
descriptor.setDeprecated( mojo.getDeprecation() );
descriptor.setSince( mojo.getSince() );
LifecycleExecution le = mojo.getExecution();
if ( le != null )
{
descriptor.setExecuteLifecycle( le.getLifecycle() );
descriptor.setExecutePhase( le.getPhase() );
descriptor.setExecuteGoal( le.getGoal() );
}
List<org.apache.maven.plugin.tools.model.Parameter> parameters = mojo.getParameters();
if ( parameters != null && !parameters.isEmpty() )
{
for ( org.apache.maven.plugin.tools.model.Parameter param : parameters )
{
Parameter dParam = new Parameter();
dParam.setAlias( param.getAlias() );
dParam.setDeprecated( param.getDeprecation() );
dParam.setDescription( param.getDescription() );
dParam.setEditable( !param.isReadonly() );
dParam.setExpression( param.getExpression() );
dParam.setDefaultValue( param.getDefaultValue() );
dParam.setSince( param.getSince() );
String property = param.getProperty();
if ( StringUtils.isNotEmpty( property ) )
{
dParam.setName( property );
}
else
{
dParam.setName( param.getName() );
}
if ( StringUtils.isEmpty( dParam.getName() ) )
{
throw new PluginMetadataParseException( metadataFile, "Mojo: \'" + mojo.getGoal()
+ "\' has a parameter without either property or name attributes. Please specify one." );
}
dParam.setRequired( param.isRequired() );
dParam.setType( param.getType() );
try
{
descriptor.addParameter( dParam );
}
catch ( DuplicateParameterException e )
{
throw new PluginMetadataParseException( metadataFile,
"Duplicate parameters detected for mojo: "
+ mojo.getGoal(), e );
}
}
}
List<Component> components = mojo.getComponents();
if ( components != null && !components.isEmpty() )
{
for ( Component component : components )
{
ComponentRequirement cr = new ComponentRequirement();
cr.setRole( component.getRole() );
cr.setRoleHint( component.getHint() );
descriptor.addRequirement( cr );
}
}
return descriptor;
}