Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,17 @@ public class DefaultMojoAnnotationsScanner extends AbstractLogEnabled implements
private static final Pattern SCANNABLE_CLASS = Pattern.compile("[^-]+\\.class");
private static final String EMPTY = "";

private Reflector reflector = new Reflector();
private final Reflector reflector = new Reflector();

private final HashMap<String, String> mojo3To4Translations = new HashMap<>();
private final HashMap<String, String> execute3To4Translations = new HashMap<>();
private final HashMap<String, String> parameter3To4Translations = new HashMap<>();

public DefaultMojoAnnotationsScanner() {
// Mojo V4 vs Mojo V3
mojo3To4Translations.put("projectRequired", "requiresProject");
mojo3To4Translations.put("onlineRequired", "requiresOnline");
}

@Override
public Map<String, MojoAnnotatedClass> scan(MojoAnnotationsScannerRequest request) throws ExtractionException {
Expand Down Expand Up @@ -266,7 +276,15 @@ protected void populateAnnotationContent(Object content, MojoAnnotationVisitor m
throws ReflectorException {
for (Map.Entry<String, Object> entry :
mojoAnnotationVisitor.getAnnotationValues().entrySet()) {
reflector.invoke(content, entry.getKey(), new Object[] {entry.getValue()});
String entryKey = entry.getKey();
if (MOJO_V4.equals(mojoAnnotationVisitor.getAnnotationClassName())) {
entryKey = mojo3To4Translations.getOrDefault(entryKey, entryKey);
} else if (EXECUTE_V4.equals(mojoAnnotationVisitor.getAnnotationClassName())) {
entryKey = execute3To4Translations.getOrDefault(entryKey, entryKey);
} else if (PARAMETER_V4.equals(mojoAnnotationVisitor.getAnnotationClassName())) {
entryKey = parameter3To4Translations.getOrDefault(entryKey, entryKey);
}
reflector.invoke(content, entryKey, new Object[] {entry.getValue()});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,19 @@
* @since 3.0
*/
public class MojoAnnotationVisitor extends AnnotationVisitor {
private String annotationClassName;
private final String annotationClassName;

private Map<String, Object> annotationValues = new HashMap<>();
private final Map<String, Object> annotationValues = new HashMap<>();

MojoAnnotationVisitor(String annotationClassName) {
super(Opcodes.ASM9);
this.annotationClassName = annotationClassName;
}

public String getAnnotationClassName() {
return annotationClassName;
}

public Map<String, Object> getAnnotationValues() {
return annotationValues;
}
Expand All @@ -55,12 +59,12 @@ public void visitEnum(String name, String desc, String value) {
}

@Override
public AnnotationVisitor visitAnnotation(String name, String desc) {
public MojoAnnotationVisitor visitAnnotation(String name, String desc) {
return new MojoAnnotationVisitor(this.annotationClassName);
}

@Override
public AnnotationVisitor visitArray(String s) {
public MojoAnnotationVisitor visitArray(String s) {
return new MojoAnnotationVisitor(this.annotationClassName);
}
}