27
27
import java .io .IOException ;
28
28
import java .io .InputStream ;
29
29
import java .util .Arrays ;
30
+ import java .util .Collections ;
30
31
import java .util .HashMap ;
31
32
import java .util .HashSet ;
32
33
import java .util .List ;
43
44
import org .apache .maven .plugins .annotations .Parameter ;
44
45
import org .apache .maven .tools .plugin .extractor .ExtractionException ;
45
46
import org .apache .maven .tools .plugin .extractor .annotations .datamodel .ComponentAnnotationContent ;
47
+ import org .apache .maven .tools .plugin .extractor .annotations .datamodel .DependenciesAnnotationContent ;
46
48
import org .apache .maven .tools .plugin .extractor .annotations .datamodel .ExecuteAnnotationContent ;
47
49
import org .apache .maven .tools .plugin .extractor .annotations .datamodel .MojoAnnotationContent ;
48
50
import org .apache .maven .tools .plugin .extractor .annotations .datamodel .ParameterAnnotationContent ;
@@ -71,6 +73,7 @@ public class DefaultMojoAnnotationsScanner extends AbstractLogEnabled implements
71
73
public static final String MOJO_V4 = MVN4_API + "Mojo" ;
72
74
public static final String EXECUTE_V4 = MVN4_API + "Execute" ;
73
75
public static final String PARAMETER_V4 = MVN4_API + "Parameter" ;
76
+ public static final String DEPENDENCIES_V4 = MVN4_API + "Dependencies" ;
74
77
75
78
public static final String MOJO_V3 = Mojo .class .getName ();
76
79
public static final String EXECUTE_V3 = Execute .class .getName ();
@@ -339,13 +342,14 @@ protected void analyzeVisitors(MojoClassVisitor mojoClassVisitor) throws Extract
339
342
}
340
343
341
344
// @Component annotations
342
- List <MojoFieldVisitor > mojoFieldVisitors =
345
+ List <MojoFieldVisitor > mojoComponentVisitors =
343
346
mojoClassVisitor .findFieldWithAnnotation (new HashSet <>(Arrays .asList (COMPONENT_V3 )));
344
- for (MojoFieldVisitor mojoFieldVisitor : mojoFieldVisitors ) {
347
+ for (MojoFieldVisitor mojoComponentVisitor : mojoComponentVisitors ) {
345
348
ComponentAnnotationContent componentAnnotationContent =
346
- new ComponentAnnotationContent (mojoFieldVisitor .getFieldName ());
349
+ new ComponentAnnotationContent (mojoComponentVisitor .getFieldName ());
347
350
348
- Map <String , MojoAnnotationVisitor > annotationVisitorMap = mojoFieldVisitor .getAnnotationVisitorMap ();
351
+ Map <String , MojoAnnotationVisitor > annotationVisitorMap =
352
+ mojoComponentVisitor .getAnnotationVisitorMap ();
349
353
MojoAnnotationVisitor annotationVisitor = annotationVisitorMap .get (COMPONENT_V3 );
350
354
351
355
if (annotationVisitor != null ) {
@@ -362,13 +366,44 @@ protected void analyzeVisitors(MojoClassVisitor mojoClassVisitor) throws Extract
362
366
}
363
367
364
368
if (StringUtils .isEmpty (componentAnnotationContent .getRoleClassName ())) {
365
- componentAnnotationContent .setRoleClassName (mojoFieldVisitor .getClassName ());
369
+ componentAnnotationContent .setRoleClassName (mojoComponentVisitor .getClassName ());
366
370
}
367
371
}
368
372
mojoAnnotatedClass
369
373
.getComponents ()
370
374
.put (componentAnnotationContent .getFieldName (), componentAnnotationContent );
371
375
}
376
+
377
+ // @Dependencies annotations
378
+ List <MojoFieldVisitor > mojoDependenciesVisitors =
379
+ mojoClassVisitor .findFieldWithAnnotation (Collections .singleton (DEPENDENCIES_V4 ));
380
+ for (MojoFieldVisitor mojoDependenciesVisitor : mojoDependenciesVisitors ) {
381
+ DependenciesAnnotationContent dependenciesAnnotationContent =
382
+ new DependenciesAnnotationContent (mojoDependenciesVisitor .getFieldName ());
383
+
384
+ Map <String , MojoAnnotationVisitor > annotationVisitorMap =
385
+ mojoDependenciesVisitor .getAnnotationVisitorMap ();
386
+ MojoAnnotationVisitor annotationVisitor = annotationVisitorMap .get (DEPENDENCIES_V4 );
387
+
388
+ if (annotationVisitor != null ) {
389
+ for (Map .Entry <String , Object > entry :
390
+ annotationVisitor .getAnnotationValues ().entrySet ()) {
391
+ String methodName = entry .getKey ();
392
+ if ("pathScope" .equals (methodName )) {
393
+ dependenciesAnnotationContent .setPathScope ((String ) entry .getValue ());
394
+ } else if ("requestType" .equals (methodName )) {
395
+ dependenciesAnnotationContent .setRequestType ((String ) entry .getValue ());
396
+ } else {
397
+ throw new IllegalStateException ("Unsupported method: " + methodName );
398
+ }
399
+ }
400
+ }
401
+
402
+ mojoAnnotatedClass
403
+ .getDependencies ()
404
+ .put (dependenciesAnnotationContent .getFieldName (), dependenciesAnnotationContent );
405
+ }
406
+
372
407
} catch (ReflectorException e ) {
373
408
throw new ExtractionException (e .getMessage (), e );
374
409
}
0 commit comments