Skip to content
Open
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 @@ -67,6 +67,7 @@
import org.apache.maven.tools.plugin.extractor.annotations.converter.JavaClassConverterContext;
import org.apache.maven.tools.plugin.extractor.annotations.converter.JavadocBlockTagsToXhtmlConverter;
import org.apache.maven.tools.plugin.extractor.annotations.converter.JavadocInlineTagsToXhtmlConverter;
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.AfterAnnotationContent;
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ComponentAnnotationContent;
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent;
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent;
Expand Down Expand Up @@ -729,6 +730,14 @@ private List<MojoDescriptor> toMojoDescriptors(
}
}

// @After annotations — collect from class hierarchy
List<AfterAnnotationContent> afterAnnotations =
getAfterAnnotationsFromHierarchy(mojoAnnotatedClass, mojoAnnotatedClasses);
for (AfterAnnotationContent after : afterAnnotations) {
mojoDescriptor.addAfterLink(
new ExtendedMojoDescriptor.AfterLink(after.phase(), after.type(), after.scope()));
}

mojoDescriptor.setExecutionStrategy(mojo.executionStrategy());
// ???
// mojoDescriptor.alwaysExecute(mojo.a)
Expand Down Expand Up @@ -819,6 +828,32 @@ protected MojoAnnotatedClass findClassWithExecuteAnnotationInParentHierarchy(
return findClassWithExecuteAnnotationInParentHierarchy(parent, mojoAnnotatedClasses);
}

/**
* Collects all {@code @After} annotations from the class hierarchy, starting from the
* most-derived class. Unlike {@code @Execute}, {@code @After} is repeatable, so
* multiple entries may exist on a single class and across the hierarchy.
*/
protected List<AfterAnnotationContent> getAfterAnnotationsFromHierarchy(
MojoAnnotatedClass mojoAnnotatedClass, Map<String, MojoAnnotatedClass> mojoAnnotatedClasses) {
List<AfterAnnotationContent> result = new ArrayList<>();
collectAfterAnnotations(mojoAnnotatedClass, mojoAnnotatedClasses, result);
return result;
}

private void collectAfterAnnotations(
MojoAnnotatedClass mojoAnnotatedClass,
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses,
List<AfterAnnotationContent> result) {
result.addAll(mojoAnnotatedClass.getAfterAnnotations());
String parentClassName = mojoAnnotatedClass.getParentClassName();
if (parentClassName != null && !parentClassName.isEmpty()) {
MojoAnnotatedClass parent = mojoAnnotatedClasses.get(parentClassName);
if (parent != null) {
collectAfterAnnotations(parent, mojoAnnotatedClasses, result);
}
}
}

protected Map<String, ParameterAnnotationContent> getParametersParentHierarchy(
MojoAnnotatedClass mojoAnnotatedClass, Map<String, MojoAnnotatedClass> mojoAnnotatedClasses) {
List<ParameterAnnotationContent> parameterAnnotationContents = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.tools.plugin.extractor.annotations.datamodel;

/**
* Holds scanned data from a {@code @After} annotation
* ({@code org.apache.maven.api.plugin.annotations.After}).
* <p>
* The {@code @After} annotation declares that the annotated mojo must run
* after another phase has completed. It carries three attributes:
* <ul>
* <li>{@code phase} &ndash; the phase this mojo must run after</li>
* <li>{@code type} &ndash; the scope type ({@code PROJECT}, {@code DEPENDENCIES}, {@code CHILDREN})</li>
* <li>{@code scope} &ndash; the dependency scope</li>
* </ul>
* <p>
* Setter method names match the annotation attribute names so that
* {@link org.apache.maven.tools.plugin.extractor.annotations.scanner.DefaultMojoAnnotationsScanner#populateAnnotationContent}
* can fill them via reflection.
*
* @since 4.0.0
*/
public class AfterAnnotationContent {
private String phase;

private String type;

private String scope;

public String phase() {
return this.phase;
}

public void phase(String phase) {
this.phase = phase;
}

public String type() {
return this.type;
}

public void type(String type) {
this.type = type;
}

public String scope() {
return this.scope;
}

public void scope(String scope) {
this.scope = scope;
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("AfterAnnotationContent");
sb.append("{phase='").append(phase).append('\'');
sb.append(", type='").append(type).append('\'');
sb.append(", scope='").append(scope).append('\'');
sb.append('}');
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -37,11 +38,12 @@
import java.util.zip.ZipInputStream;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugins.annotations.Component;

Check warning on line 41 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 41 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 41 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-8-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 41 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-8-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 41 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 4.0.0-rc-5

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 41 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 41 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 41 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 4.0.0-rc-5

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 41 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 4.0.0-rc-5

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 41 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-zulu 4.0.0-rc-5

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 41 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.tools.plugin.extractor.ExtractionException;
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.AfterAnnotationContent;
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ComponentAnnotationContent;
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent;
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent;
Expand Down Expand Up @@ -73,6 +75,8 @@
public static final String MOJO_V4 = MVN4_API + "Mojo";
public static final String EXECUTE_V4 = MVN4_API + "Execute";
public static final String PARAMETER_V4 = MVN4_API + "Parameter";
public static final String AFTER_V4 = MVN4_API + "After";
public static final String AFTERS_V4 = MVN4_API + "Afters";

public static final String MOJO_V3 = Mojo.class.getName();
public static final String EXECUTE_V3 = Execute.class.getName();
Expand Down Expand Up @@ -308,6 +312,37 @@
mojoAnnotatedClass.setExecute(executeAnnotationContent);
}

// @After annotation(s) — v4 API only
List<AfterAnnotationContent> afterAnnotations = new ArrayList<>();

// single @After
mojoAnnotationVisitor = mojoClassVisitor.getAnnotationVisitor(AFTER_V4);
if (mojoAnnotationVisitor != null) {
AfterAnnotationContent afterAnnotationContent = new AfterAnnotationContent();
populateAnnotationContent(afterAnnotationContent, mojoAnnotationVisitor);
afterAnnotations.add(afterAnnotationContent);
}

// @Afters repeatable container wraps multiple @After in its "value" array attribute
mojoAnnotationVisitor = mojoClassVisitor.getAnnotationVisitor(AFTERS_V4);
if (mojoAnnotationVisitor != null) {
// The @Afters annotation has a "value" array attribute; visitArray("value")
// creates a sub-visitor, and each nested @After is visited via visitAnnotation
// on that sub-visitor.
MojoAnnotationVisitor arrayVisitor = mojoAnnotationVisitor.getArrayVisitor("value");
if (arrayVisitor != null) {
for (MojoAnnotationVisitor nestedVisitor : arrayVisitor.getNestedAnnotationVisitors()) {
AfterAnnotationContent afterAnnotationContent = new AfterAnnotationContent();
populateAnnotationContent(afterAnnotationContent, nestedVisitor);
afterAnnotations.add(afterAnnotationContent);
}
}
}

if (!afterAnnotations.isEmpty()) {
mojoAnnotatedClass.setAfterAnnotations(afterAnnotations);
}

// @Parameter annotations
List<MojoParameterVisitor> mojoParameterVisitors =
mojoClassVisitor.findParameterVisitors(new HashSet<>(Arrays.asList(PARAMETER_V3, PARAMETER_V4)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@
*/
package org.apache.maven.tools.plugin.extractor.annotations.scanner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.AfterAnnotationContent;
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ComponentAnnotationContent;
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent;
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent;
Expand All @@ -42,6 +45,8 @@ public class MojoAnnotatedClass {

private ExecuteAnnotationContent execute;

private List<AfterAnnotationContent> afterAnnotations;

/**
* key is field name
*/
Expand Down Expand Up @@ -99,6 +104,18 @@ public MojoAnnotatedClass setExecute(ExecuteAnnotationContent execute) {
return this;
}

public List<AfterAnnotationContent> getAfterAnnotations() {
if (this.afterAnnotations == null) {
this.afterAnnotations = new ArrayList<>();
}
return afterAnnotations;
}

public MojoAnnotatedClass setAfterAnnotations(List<AfterAnnotationContent> afterAnnotations) {
this.afterAnnotations = afterAnnotations;
return this;
}

public Map<String, ParameterAnnotationContent> getParameters() {
if (this.parameters == null) {
this.parameters = new HashMap<>();
Expand Down Expand Up @@ -141,7 +158,11 @@ public void setArtifact(Artifact artifact) {
}

public boolean hasAnnotations() {
return !(getComponents().isEmpty() && getParameters().isEmpty() && execute == null && mojo == null);
return !(getComponents().isEmpty()
&& getParameters().isEmpty()
&& execute == null
&& mojo == null
&& getAfterAnnotations().isEmpty());
}

public boolean isV4Api() {
Expand All @@ -161,6 +182,7 @@ public String toString() {
sb.append(", parentClassName='").append(parentClassName).append('\'');
sb.append(", mojo=").append(mojo);
sb.append(", execute=").append(execute);
sb.append(", afterAnnotations=").append(afterAnnotations);
sb.append(", parameters=").append(parameters);
sb.append(", components=").append(components);
sb.append(", v4api=").append(v4Api);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.List;
import java.util.Map;

import org.apache.maven.plugins.annotations.Component;

Check warning on line 25 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-17-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 25 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 25 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-8-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 25 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-8-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 25 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-25-zulu 4.0.0-rc-5

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 25 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 25 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 25 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 4.0.0-rc-5

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 25 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / macos-latest jdk-21-zulu 4.0.0-rc-5

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 25 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-25-zulu 4.0.0-rc-5

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated

Check warning on line 25 in maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotationsScanner.java

View workflow job for this annotation

GitHub Actions / Verify / ubuntu-latest jdk-21-zulu 3.10.0-rc-1

org.apache.maven.plugins.annotations.Component in org.apache.maven.plugins.annotations has been deprecated
import org.apache.maven.plugins.annotations.Execute;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -44,7 +44,9 @@
Execute.class.getName(),
Deprecated.class.getName(),
V4_API_ANNOTATIONS_PACKAGE + ".Mojo",
V4_API_ANNOTATIONS_PACKAGE + ".Execute");
V4_API_ANNOTATIONS_PACKAGE + ".Execute",
V4_API_ANNOTATIONS_PACKAGE + ".After",
V4_API_ANNOTATIONS_PACKAGE + ".Afters");

List<String> FIELD_LEVEL_ANNOTATIONS = Arrays.asList(
Parameter.class.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
*/
package org.apache.maven.tools.plugin.extractor.annotations.scanner.visitors;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;

/**
* Visitor for annotations.
Expand All @@ -35,6 +39,10 @@ public class MojoAnnotationVisitor extends AnnotationVisitor {

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

private List<MojoAnnotationVisitor> nestedAnnotationVisitors;

private Map<String, MojoAnnotationVisitor> arrayVisitors;

MojoAnnotationVisitor(String annotationClassName) {
super(Opcodes.ASM9);
this.annotationClassName = annotationClassName;
Expand All @@ -56,11 +64,44 @@ public void visitEnum(String name, String desc, String value) {

@Override
public AnnotationVisitor visitAnnotation(String name, String desc) {
return new MojoAnnotationVisitor(this.annotationClassName);
String className = desc != null ? Type.getType(desc).getClassName() : this.annotationClassName;
MojoAnnotationVisitor nested = new MojoAnnotationVisitor(className);
if (nestedAnnotationVisitors == null) {
nestedAnnotationVisitors = new ArrayList<>();
}
nestedAnnotationVisitors.add(nested);
return nested;
}

@Override
public AnnotationVisitor visitArray(String s) {
return new MojoAnnotationVisitor(this.annotationClassName);
public AnnotationVisitor visitArray(String name) {
MojoAnnotationVisitor arrayVisitor = new MojoAnnotationVisitor(this.annotationClassName);
if (this.arrayVisitors == null) {
this.arrayVisitors = new HashMap<>();
}
this.arrayVisitors.put(name, arrayVisitor);
return arrayVisitor;
}

/**
* Returns the sub-visitor created by {@link #visitArray(String)} for the given array attribute.
* The sub-visitor's {@link #getNestedAnnotationVisitors()} contains the annotation elements.
*
* @param name the array attribute name
* @return the array sub-visitor, or {@code null} if not visited
*/
public MojoAnnotationVisitor getArrayVisitor(String name) {
return arrayVisitors != null ? arrayVisitors.get(name) : null;
}

/**
* Returns the nested annotation visitors collected by {@link #visitAnnotation(String, String)}
* and by array sub-visitors. Used to extract elements from repeatable annotation containers
* such as {@code @Afters}.
*
* @return list of nested annotation visitors, never {@code null}
*/
public List<MojoAnnotationVisitor> getNestedAnnotationVisitors() {
return nestedAnnotationVisitors != null ? nestedAnnotationVisitors : Collections.emptyList();
}
}
Loading
Loading