in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java [280:375]
protected void analyzeVisitors(MojoClassVisitor mojoClassVisitor) throws ExtractionException {
final MojoAnnotatedClass mojoAnnotatedClass = mojoClassVisitor.getMojoAnnotatedClass();
try {
// @Mojo annotation
MojoAnnotationVisitor mojoAnnotationVisitor = mojoClassVisitor.getAnnotationVisitor(MOJO_V3);
if (mojoAnnotationVisitor == null) {
mojoAnnotationVisitor = mojoClassVisitor.getAnnotationVisitor(MOJO_V4);
}
if (mojoAnnotationVisitor != null) {
MojoAnnotationContent mojoAnnotationContent = new MojoAnnotationContent();
populateAnnotationContent(mojoAnnotationContent, mojoAnnotationVisitor);
if (mojoClassVisitor.getAnnotationVisitor(Deprecated.class) != null) {
mojoAnnotationContent.setDeprecated(EMPTY);
}
mojoAnnotatedClass.setMojo(mojoAnnotationContent);
}
// @Execute annotation
mojoAnnotationVisitor = mojoClassVisitor.getAnnotationVisitor(EXECUTE_V3);
if (mojoAnnotationVisitor == null) {
mojoAnnotationVisitor = mojoClassVisitor.getAnnotationVisitor(EXECUTE_V4);
}
if (mojoAnnotationVisitor != null) {
ExecuteAnnotationContent executeAnnotationContent = new ExecuteAnnotationContent();
populateAnnotationContent(executeAnnotationContent, mojoAnnotationVisitor);
mojoAnnotatedClass.setExecute(executeAnnotationContent);
}
// @Parameter annotations
List<MojoParameterVisitor> mojoParameterVisitors =
mojoClassVisitor.findParameterVisitors(new HashSet<>(Arrays.asList(PARAMETER_V3, PARAMETER_V4)));
for (MojoParameterVisitor parameterVisitor : mojoParameterVisitors) {
ParameterAnnotationContent parameterAnnotationContent = new ParameterAnnotationContent(
parameterVisitor.getFieldName(),
parameterVisitor.getClassName(),
parameterVisitor.getTypeParameters(),
parameterVisitor.isAnnotationOnMethod());
Map<String, MojoAnnotationVisitor> annotationVisitorMap = parameterVisitor.getAnnotationVisitorMap();
MojoAnnotationVisitor fieldAnnotationVisitor = annotationVisitorMap.get(PARAMETER_V3);
if (fieldAnnotationVisitor == null) {
fieldAnnotationVisitor = annotationVisitorMap.get(PARAMETER_V4);
}
if (fieldAnnotationVisitor != null) {
populateAnnotationContent(parameterAnnotationContent, fieldAnnotationVisitor);
}
if (annotationVisitorMap.containsKey(Deprecated.class.getName())) {
parameterAnnotationContent.setDeprecated(EMPTY);
}
mojoAnnotatedClass
.getParameters()
.put(parameterAnnotationContent.getFieldName(), parameterAnnotationContent);
}
// @Component annotations
List<MojoFieldVisitor> mojoComponentVisitors =
mojoClassVisitor.findFieldWithAnnotation(new HashSet<>(Arrays.asList(COMPONENT_V3)));
for (MojoFieldVisitor mojoComponentVisitor : mojoComponentVisitors) {
ComponentAnnotationContent componentAnnotationContent =
new ComponentAnnotationContent(mojoComponentVisitor.getFieldName());
Map<String, MojoAnnotationVisitor> annotationVisitorMap =
mojoComponentVisitor.getAnnotationVisitorMap();
MojoAnnotationVisitor annotationVisitor = annotationVisitorMap.get(COMPONENT_V3);
if (annotationVisitor != null) {
for (Map.Entry<String, Object> entry :
annotationVisitor.getAnnotationValues().entrySet()) {
String methodName = entry.getKey();
if ("role".equals(methodName)) {
Type type = (Type) entry.getValue();
componentAnnotationContent.setRoleClassName(type.getClassName());
} else {
reflector.invoke(
componentAnnotationContent, entry.getKey(), new Object[] {entry.getValue()});
}
}
if (StringUtils.isEmpty(componentAnnotationContent.getRoleClassName())) {
componentAnnotationContent.setRoleClassName(mojoComponentVisitor.getClassName());
}
}
mojoAnnotatedClass
.getComponents()
.put(componentAnnotationContent.getFieldName(), componentAnnotationContent);
}
} catch (ReflectorException e) {
throw new ExtractionException(e.getMessage(), e);
}
}