Map<String, JavaField> rawParams = extractFieldParameterTags( javaClass );
for ( Map.Entry<String, JavaField> entry : rawParams.entrySet() )
{
JavaField field = entry.getValue();
Type type = field.getType();
Parameter pd = new Parameter();
if ( !type.isArray() )
{
pd.setType( type.getValue() );
}
else
{
StringBuffer value = new StringBuffer( type.getValue() );
int remaining = type.getDimensions();
while ( remaining-- > 0 )
{
value.append( "[]" );
}
pd.setType( value.toString() );
}
pd.setDescription( field.getComment() );
DocletTag componentTag = field.getTagByName( JavaMojoAnnotation.COMPONENT );
if ( componentTag != null )
{
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" );
}
pd.setRequirement( new Requirement( role, roleHint ) );
pd.setName( entry.getKey() );
pd.setEditable( false );
/* TODO: or better like this? Need @component fields be editable for the user?
pd.setEditable( field.getTagByName( READONLY ) == null );
*/
}
else
{
DocletTag parameter = field.getTagByName( JavaMojoAnnotation.PARAMETER );
// ----------------------------------------------------------------------
// We will look for a property name here first and use that if present
// i.e:
//
// @parameter property="project"
//
// Which will become the name used for the configuration element which
// will in turn will allow plexus to use the corresponding setter.
// ----------------------------------------------------------------------
String property = parameter.getNamedParameter( JavaMojoAnnotation.PARAMETER_PROPERTY );
if ( !StringUtils.isEmpty( property ) )
{
pd.setName( property );
}
else
{
pd.setName( entry.getKey() );
}
pd.setRequired( field.getTagByName( JavaMojoAnnotation.REQUIRED ) != null );
pd.setEditable( field.getTagByName( JavaMojoAnnotation.READONLY ) == null );
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() );
}
String alias = parameter.getNamedParameter( JavaMojoAnnotation.PARAMETER_ALIAS );
if ( !StringUtils.isEmpty( alias ) )
{
pd.setAlias( alias );
}
String expression = parameter.getNamedParameter( JavaMojoAnnotation.PARAMETER_EXPRESSION );
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." );