* @throws InvalidPluginDescriptorException if any
*/
protected MojoDescriptor createMojoDescriptor( JavaClass javaClass )
throws InvalidPluginDescriptorException
{
ExtendedMojoDescriptor mojoDescriptor = new ExtendedMojoDescriptor();
mojoDescriptor.setLanguage( "java" );
mojoDescriptor.setImplementation( javaClass.getFullyQualifiedName() );
mojoDescriptor.setDescription( javaClass.getComment() );
// ----------------------------------------------------------------------
// Mojo annotations in alphabetical order
// ----------------------------------------------------------------------
// Aggregator flag
DocletTag aggregator = findInClassHierarchy( javaClass, JavaMojoAnnotation.AGGREGATOR );
if ( aggregator != null )
{
mojoDescriptor.setAggregator( true );
}
// Configurator hint
DocletTag configurator = findInClassHierarchy( javaClass, JavaMojoAnnotation.CONFIGURATOR );
if ( configurator != null )
{
mojoDescriptor.setComponentConfigurator( configurator.getValue() );
}
// Additional phase to execute first
DocletTag execute = findInClassHierarchy( javaClass, JavaMojoAnnotation.EXECUTE );
if ( execute != null )
{
String executePhase = execute.getNamedParameter( JavaMojoAnnotation.EXECUTE_PHASE );
String executeGoal = execute.getNamedParameter( JavaMojoAnnotation.EXECUTE_GOAL );
if ( executePhase == null && executeGoal == null )
{
throw new InvalidPluginDescriptorException( javaClass.getFullyQualifiedName()
+ ": @execute tag requires either a 'phase' or 'goal' parameter" );
}
else if ( executePhase != null && executeGoal != null )
{
throw new InvalidPluginDescriptorException( javaClass.getFullyQualifiedName()
+ ": @execute tag can have only one of a 'phase' or 'goal' parameter" );
}
mojoDescriptor.setExecutePhase( executePhase );
mojoDescriptor.setExecuteGoal( executeGoal );
String lifecycle = execute.getNamedParameter( JavaMojoAnnotation.EXECUTE_LIFECYCLE );
if ( lifecycle != null )
{
mojoDescriptor.setExecuteLifecycle( lifecycle );
if ( mojoDescriptor.getExecuteGoal() != null )
{
throw new InvalidPluginDescriptorException( javaClass.getFullyQualifiedName()
+ ": @execute lifecycle requires a phase instead of a goal" );
}
}
}
// Goal name
DocletTag goal = findInClassHierarchy( javaClass, JavaMojoAnnotation.GOAL );
if ( goal != null )
{
mojoDescriptor.setGoal( goal.getValue() );
}
// inheritByDefault flag
boolean value =
getBooleanTagValue( javaClass, JavaMojoAnnotation.INHERIT_BY_DEFAULT,
mojoDescriptor.isInheritedByDefault() );
mojoDescriptor.setInheritedByDefault( value );
// instantiationStrategy
DocletTag tag = findInClassHierarchy( javaClass, JavaMojoAnnotation.INSTANTIATION_STRATEGY );
if ( tag != null )
{
mojoDescriptor.setInstantiationStrategy( tag.getValue() );
}
// executionStrategy (and deprecated @attainAlways)
tag = findInClassHierarchy( javaClass, JavaMojoAnnotation.MULTI_EXECUTION_STRATEGY );
if ( tag != null )
{
getLogger().warn( "@" + JavaMojoAnnotation.MULTI_EXECUTION_STRATEGY + " in "
+ javaClass.getFullyQualifiedName() + " is deprecated: please use '@"
+ JavaMojoAnnotation.EXECUTION_STATEGY + " always' instead." );
mojoDescriptor.setExecutionStrategy( MojoDescriptor.MULTI_PASS_EXEC_STRATEGY );
}
else
{
mojoDescriptor.setExecutionStrategy( MojoDescriptor.SINGLE_PASS_EXEC_STRATEGY );
}
tag = findInClassHierarchy( javaClass, JavaMojoAnnotation.EXECUTION_STATEGY );
if ( tag != null )
{
mojoDescriptor.setExecutionStrategy( tag.getValue() );
}
// Phase name
DocletTag phase = findInClassHierarchy( javaClass, JavaMojoAnnotation.PHASE );
if ( phase != null )
{
mojoDescriptor.setPhase( phase.getValue() );
}
// Dependency resolution flag
DocletTag requiresDependencyResolution =
findInClassHierarchy( javaClass, JavaMojoAnnotation.REQUIRES_DEPENDENCY_RESOLUTION );
if ( requiresDependencyResolution != null )
{
String v = requiresDependencyResolution.getValue();
if ( StringUtils.isEmpty( v ) )
{
v = "runtime";
}
mojoDescriptor.setDependencyResolutionRequired( v );
}
// Dependency collection flag
DocletTag requiresDependencyCollection =
findInClassHierarchy( javaClass, JavaMojoAnnotation.REQUIRES_DEPENDENCY_COLLECTION );
if ( requiresDependencyCollection != null )
{
String v = requiresDependencyCollection.getValue();
if ( StringUtils.isEmpty( v ) )
{
v = "runtime";
}
mojoDescriptor.setDependencyCollectionRequired( v );
}
// requiresDirectInvocation flag
value =
getBooleanTagValue( javaClass, JavaMojoAnnotation.REQUIRES_DIRECT_INVOCATION,
mojoDescriptor.isDirectInvocationOnly() );
mojoDescriptor.setDirectInvocationOnly( value );
// Online flag
value =
getBooleanTagValue( javaClass, JavaMojoAnnotation.REQUIRES_ONLINE, mojoDescriptor.isOnlineRequired() );
mojoDescriptor.setOnlineRequired( value );
// Project flag
value =
getBooleanTagValue( javaClass, JavaMojoAnnotation.REQUIRES_PROJECT, mojoDescriptor.isProjectRequired() );
mojoDescriptor.setProjectRequired( value );
// requiresReports flag
value =
getBooleanTagValue( javaClass, JavaMojoAnnotation.REQUIRES_REPORTS, mojoDescriptor.isRequiresReports() );
mojoDescriptor.setRequiresReports( value );
// ----------------------------------------------------------------------
// Javadoc annotations in alphabetical order
// ----------------------------------------------------------------------
// Deprecation hint
DocletTag deprecated = javaClass.getTagByName( JavaMojoAnnotation.DEPRECATED );
if ( deprecated != null )
{
mojoDescriptor.setDeprecated( deprecated.getValue() );
}
// What version it was introduced in
DocletTag since = findInClassHierarchy( javaClass, JavaMojoAnnotation.SINCE );
if ( since != null )
{
mojoDescriptor.setSince( since.getValue() );
}
// Thread-safe mojo
value = getBooleanTagValue( javaClass, JavaMojoAnnotation.THREAD_SAFE, true, mojoDescriptor.isThreadSafe() );
mojoDescriptor.setThreadSafe( value );
extractParameters( mojoDescriptor, javaClass );
return mojoDescriptor;
}