}
private MojoDescriptor extractMojo(Class<?> clazz) throws InvalidPluginDescriptorException {
getLogger().debug("scanning class: " + clazz.getName());
MojoDescriptor mojoDescriptor = null;
Mojo mojo = clazz.getAnnotation(Mojo.class);
if (mojo != null) {
getLogger().info("found @Mojo in: " + clazz.getName());
mojoDescriptor = new MojoDescriptor();
mojoDescriptor.setLanguage("java");
mojoDescriptor.setImplementation(clazz.getName());
mojoDescriptor.setDescription(mojo.description().trim());
mojoDescriptor.setInstantiationStrategy(mojo.instantiationStrategy().value);
mojoDescriptor.setExecutionStrategy(mojo.executionStrategy().value);
String configurator = clazz.getAnnotation(Mojo.class).configurator();
if (configurator.trim().length() > 0) {
mojoDescriptor.setComponentConfigurator(configurator.trim());
}
mojoDescriptor.setGoal(clazz.getAnnotation(Mojo.class).goal().trim());
mojoDescriptor.setPhase(mojo.phase().value);
Execution execute = mojo.execute();
String lifecycle = execute.lifecycle().trim().length() == 0 ? null : execute.lifecycle().trim();
String goal = execute.goal().trim().length() == 0 ? null : execute.goal().trim();
Phase phase = execute.phase();
if (goal != null || phase != Phase.None) {
if (goal != null) {
if (lifecycle != null) {
throw new InvalidPluginDescriptorException("'goal' cannot be specified with 'lifecycle' in execute annotation");
}
if (phase != Phase.None) {
throw new InvalidPluginDescriptorException("execute annotation cannot specify both 'phase' and 'goal'");
}
mojoDescriptor.setExecuteGoal(goal);
} else {
mojoDescriptor.setExecutePhase(phase.value);
if (lifecycle != null) {
mojoDescriptor.setExecuteLifecycle(lifecycle);
}
}
}
mojoDescriptor.setDependencyResolutionRequired(mojo.requiresDependencyResolution().value);
mojoDescriptor.setProjectRequired(mojo.requiresProject());
mojoDescriptor.setAggregator(mojo.aggregator());
mojoDescriptor.setDirectInvocationOnly(mojo.requiresDirectInvocation());
mojoDescriptor.setOnlineRequired(mojo.requiresOnline());
mojoDescriptor.setInheritedByDefault(mojo.inheritByDefault());
if (mojo.deprecated().trim().length() > 0) {
mojoDescriptor.setDeprecated(mojo.deprecated());
}
// extract parameters working back through the inheritancce hierarchy
while (!clazz.equals(Object.class)) {
for (Field field : clazz.getDeclaredFields()) {
org.apache.maven.plugin.descriptor.Parameter parameter = extractParameter(field);