{
JavaField field = entry.getValue();
Type type = field.getType();
Parameter pd = new Parameter();
pd.setName( entry.getKey() );
if ( !type.isArray() )
{
pd.setType( type.getValue() );
}
else
{
StringBuilder value = new StringBuilder( type.getValue() );
int remaining = type.getDimensions();
while ( remaining-- > 0 )
{
value.append( "[]" );
}
pd.setType( value.toString() );
}
pd.setDescription( field.getComment() );
DocletTag deprecationTag = field.getTagByName( JavaMojoAnnotation.DEPRECATED );
if ( deprecationTag != null )
{
pd.setDeprecated( deprecationTag.getValue() );
}
DocletTag sinceTag = field.getTagByName( JavaMojoAnnotation.SINCE );
if ( sinceTag != null )
{
pd.setSince( sinceTag.getValue() );
}
DocletTag componentTag = field.getTagByName( JavaMojoAnnotation.COMPONENT );
if ( componentTag != null )
{
// Component tag
String role = componentTag.getNamedParameter( JavaMojoAnnotation.COMPONENT_ROLE );
if ( role == null )
{
role = field.getType().toString();
}
String roleHint = componentTag.getNamedParameter( JavaMojoAnnotation.COMPONENT_ROLEHINT );
if ( roleHint == null )
{
// support alternate syntax for better compatibility with the Plexus CDC.
roleHint = componentTag.getNamedParameter( "role-hint" );
}
// recognize Maven-injected objects as components annotations instead of parameters
String expression = PluginUtils.MAVEN_COMPONENTS.get( role );
if ( expression == null )
{
// normal component
pd.setRequirement( new Requirement( role, roleHint ) );
}
else
{
// not a component but a Maven object to be transformed into an expression/property
getLogger().warn( "Deprecated @Component for " + pd.getName() + " field in "
+ javaClass.getFullyQualifiedName() + ": replace with @Parameter( name = \""
+ expression + "\", readonly = true )" );
pd.setDefaultValue( expression );
pd.setType( role );
pd.setRequired( true );
}
pd.setEditable( false );
/* TODO: or better like this? Need @component fields be editable for the user?
pd.setEditable( field.getTagByName( READONLY ) == null );
*/
}
else
{
// Parameter tag
DocletTag parameter = field.getTagByName( JavaMojoAnnotation.PARAMETER );
pd.setRequired( field.getTagByName( JavaMojoAnnotation.REQUIRED ) != null );
pd.setEditable( field.getTagByName( JavaMojoAnnotation.READONLY ) == null );
String name = parameter.getNamedParameter( JavaMojoAnnotation.PARAMETER_NAME );
if ( !StringUtils.isEmpty( name ) )
{
pd.setName( name );
}
String alias = parameter.getNamedParameter( JavaMojoAnnotation.PARAMETER_ALIAS );
if ( !StringUtils.isEmpty( alias ) )
{
pd.setAlias( alias );
}
String expression = parameter.getNamedParameter( JavaMojoAnnotation.PARAMETER_EXPRESSION );
String property = parameter.getNamedParameter( JavaMojoAnnotation.PARAMETER_PROPERTY );
if ( StringUtils.isNotEmpty( expression ) && StringUtils.isNotEmpty( property ) )
{
getLogger().error( javaClass.getFullyQualifiedName() + "#" + field.getName() + ":" );
getLogger().error( " Cannot use both:" );
getLogger().error( " @parameter expression=\"${property}\"" );
getLogger().error( " and" );
getLogger().error( " @parameter property=\"property\"" );
getLogger().error( " Second syntax is preferred." );
throw new InvalidParameterException( javaClass.getFullyQualifiedName() + "#" + field.getName()
+ ": cannot" + " use both @parameter expression and property", null );
}
if ( StringUtils.isNotEmpty( expression ) )
{
getLogger().warn( javaClass.getFullyQualifiedName() + "#" + field.getName() + ":" );
getLogger().warn( " The syntax" );
getLogger().warn( " @parameter expression=\"${property}\"" );
getLogger().warn( " is deprecated, please use" );
getLogger().warn( " @parameter property=\"property\"" );
getLogger().warn( " instead." );
}
else if ( StringUtils.isNotEmpty( property ) )
{
expression = "${" + property + "}";
}
pd.setExpression( expression );
if ( StringUtils.isNotEmpty( expression ) && expression.startsWith( "${component." ) )
{
getLogger().warn( javaClass.getFullyQualifiedName() + "#" + field.getName() + ":" );
getLogger().warn( " The syntax" );
getLogger().warn( " @parameter expression=\"${component.<role>#<roleHint>}\"" );
getLogger().warn( " is deprecated, please use" );
getLogger().warn( " @component role=\"<role>\" roleHint=\"<roleHint>\"" );
getLogger().warn( " instead." );
}
if ( "${reports}".equals( pd.getExpression() ) )
{
mojoDescriptor.setRequiresReports( true );
}
pd.setDefaultValue( parameter.getNamedParameter( JavaMojoAnnotation.PARAMETER_DEFAULT_VALUE ) );
pd.setImplementation( parameter.getNamedParameter( JavaMojoAnnotation.PARAMETER_IMPLEMENTATION ) );
}
mojoDescriptor.addParameter( pd );
}
}