Skip to content

Commit 728b097

Browse files
committed
Upgrade to beta-4-SNAPSHOT
1 parent 3a4d654 commit 728b097

File tree

12 files changed

+295
-28
lines changed

12 files changed

+295
-28
lines changed

maven-plugin-plugin/src/it/v4api/invoker.properties

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717

1818
invoker.java.version = 17+
1919
invoker.goals.1 = clean install
20+
invoker.goals.2 = org.apache.maven.its:v4api:1.0-SNAPSHOT:first

maven-plugin-plugin/src/it/v4api/src/main/java/org/apache/maven/its/v4api/FirstMojo.java

+11-13
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,17 @@
1919
package org.apache.maven.its.v4api;
2020

2121
import java.nio.file.Path;
22+
import java.util.List;
2223

2324
import org.apache.maven.api.MojoExecution;
2425
import org.apache.maven.api.Project;
2526
import org.apache.maven.api.Session;
2627
import org.apache.maven.api.di.Inject;
27-
import org.apache.maven.api.di.Named;
2828
import org.apache.maven.api.plugin.Log;
2929
import org.apache.maven.api.plugin.MojoException;
30-
import org.apache.maven.api.plugin.annotations.Execute;
30+
import org.apache.maven.api.plugin.annotations.Dependencies;
3131
import org.apache.maven.api.plugin.annotations.Mojo;
3232
import org.apache.maven.api.plugin.annotations.Parameter;
33-
import org.apache.maven.api.services.ArtifactInstaller;
34-
import org.apache.maven.api.settings.Settings;
3533

3634
/**
3735
* Test mojo for the v4 api plugin descriptor generation.
@@ -42,7 +40,6 @@
4240
* @since 1.2
4341
*/
4442
@Mojo(name = "first", defaultPhase = "integration-test")
45-
@Execute(phase = "generate-sources", lifecycle = "cobertura")
4643
public class FirstMojo implements org.apache.maven.api.plugin.Mojo {
4744

4845
/**
@@ -62,6 +59,9 @@ public class FirstMojo implements org.apache.maven.api.plugin.Mojo {
6259
@Parameter(name = "namedParam", alias = "alias")
6360
private String aliasedParam;
6461

62+
@Dependencies(pathScope = "main-runtime")
63+
private List<Path> classPath;
64+
6565
@Inject
6666
private Session session;
6767

@@ -71,15 +71,13 @@ public class FirstMojo implements org.apache.maven.api.plugin.Mojo {
7171
@Inject
7272
private MojoExecution mojo;
7373

74-
@Inject
75-
private Settings settings;
76-
7774
@Inject
7875
private Log log;
7976

80-
@Inject
81-
@Named("test")
82-
private ArtifactInstaller custom;
83-
84-
public void execute() throws MojoException {}
77+
public void execute() throws MojoException {
78+
log.info("Executing first");
79+
for (Path path : classPath) {
80+
log.info(path.toString());
81+
}
82+
}
8583
}

maven-plugin-plugin/src/it/v4api/verify.groovy

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ assert descriptorFile.isFile()
2525
def pluginDescriptor = new XmlParser().parse( descriptorFile );
2626

2727
assert pluginDescriptor.requiredJavaVersion.text() == '17'
28-
assert pluginDescriptor.requiredMavenVersion.text() == '4.0.0-beta-3'
28+
assert pluginDescriptor.requiredMavenVersion.text() == '4.0.0-beta-4-SNAPSHOT'
2929

3030
def mojo = pluginDescriptor.mojos.mojo.findAll{ it.goal.text() == "first" }[0]
3131

@@ -37,8 +37,6 @@ assert mojo.projectRequired.text() == 'true'
3737
assert mojo.onlineRequired.text() == 'false'
3838
assert mojo.aggregator.text() == 'false'
3939
assert mojo.phase.text() == 'integration-test'
40-
assert mojo.executePhase.text() == 'generate-sources'
41-
assert mojo.executeLifecycle.text() == 'cobertura'
4240

4341
assert mojo.parameters.parameter.size() == 3
4442

@@ -78,6 +76,13 @@ assert parameter.description.text() == ''
7876
assert parameter.defaultValue.isEmpty()
7977
assert parameter.expression.isEmpty()
8078

79+
assert mojo.dependencies.dependency.size() == 1
80+
81+
dependency = mojo.dependencies.dependency[0]
82+
assert dependency.field.text() == 'classPath'
83+
assert dependency.pathScope.text() == 'main-runtime'
84+
assert dependency.requestType.text() == ''
85+
8186
// check help mojo source and class
8287
assert new File( basedir, "target/classes/org/apache/maven/its/v4api/HelpMojo.class" ).isFile()
8388
assert new File( basedir, "target/generated-sources/plugin/org/apache/maven/its/v4api/HelpMojo.java" ).isFile()

maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/JavaAnnotationsMojoDescriptorExtractor.java

+48
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.apache.maven.plugin.descriptor.PluginDescriptor;
5959
import org.apache.maven.plugin.descriptor.Requirement;
6060
import org.apache.maven.project.MavenProject;
61+
import org.apache.maven.tools.plugin.Dependencies;
6162
import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
6263
import org.apache.maven.tools.plugin.PluginToolsRequest;
6364
import org.apache.maven.tools.plugin.extractor.ExtractionException;
@@ -68,6 +69,7 @@
6869
import org.apache.maven.tools.plugin.extractor.annotations.converter.JavadocBlockTagsToXhtmlConverter;
6970
import org.apache.maven.tools.plugin.extractor.annotations.converter.JavadocInlineTagsToXhtmlConverter;
7071
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ComponentAnnotationContent;
72+
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.DependenciesAnnotationContent;
7173
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent;
7274
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent;
7375
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ParameterAnnotationContent;
@@ -791,6 +793,18 @@ private List<MojoDescriptor> toMojoDescriptors(
791793
mojoDescriptor.addParameter(parameter);
792794
}
793795

796+
// Dependencies annotations
797+
Map<String, DependenciesAnnotationContent> dependenciess =
798+
getDependenciesParentHierarchy(mojoAnnotatedClass, mojoAnnotatedClasses);
799+
800+
for (DependenciesAnnotationContent dependenciesAnnotationContent : new TreeSet<>(dependenciess.values())) {
801+
Dependencies dependencies = new Dependencies();
802+
dependencies.setField(dependenciesAnnotationContent.getFieldName());
803+
dependencies.setPathScope(dependenciesAnnotationContent.getPathScope());
804+
dependencies.setRequestType(dependenciesAnnotationContent.getRequestType());
805+
mojoDescriptor.addDependencies(dependencies);
806+
}
807+
794808
mojoDescriptor.setPluginDescriptor(pluginDescriptor);
795809

796810
mojoDescriptors.add(mojoDescriptor);
@@ -847,6 +861,40 @@ protected List<ParameterAnnotationContent> getParametersParent(
847861
return parameterAnnotationContents;
848862
}
849863

864+
protected Map<String, DependenciesAnnotationContent> getDependenciesParentHierarchy(
865+
MojoAnnotatedClass mojoAnnotatedClass, Map<String, MojoAnnotatedClass> mojoAnnotatedClasses) {
866+
List<DependenciesAnnotationContent> dependenciesAnnotationContents = new ArrayList<>();
867+
868+
dependenciesAnnotationContents =
869+
getDependenciesParent(mojoAnnotatedClass, dependenciesAnnotationContents, mojoAnnotatedClasses);
870+
871+
// move to parent first to build the Map
872+
Collections.reverse(dependenciesAnnotationContents);
873+
874+
Map<String, DependenciesAnnotationContent> map = new HashMap<>(dependenciesAnnotationContents.size());
875+
876+
for (DependenciesAnnotationContent dependenciesAnnotationContent : dependenciesAnnotationContents) {
877+
map.put(dependenciesAnnotationContent.getFieldName(), dependenciesAnnotationContent);
878+
}
879+
return map;
880+
}
881+
882+
protected List<DependenciesAnnotationContent> getDependenciesParent(
883+
MojoAnnotatedClass mojoAnnotatedClass,
884+
List<DependenciesAnnotationContent> dependenciesAnnotationContents,
885+
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses) {
886+
dependenciesAnnotationContents.addAll(
887+
mojoAnnotatedClass.getDependencies().values());
888+
String parentClassName = mojoAnnotatedClass.getParentClassName();
889+
if (parentClassName != null) {
890+
MojoAnnotatedClass parent = mojoAnnotatedClasses.get(parentClassName);
891+
if (parent != null) {
892+
return getDependenciesParent(parent, dependenciesAnnotationContents, mojoAnnotatedClasses);
893+
}
894+
}
895+
return dependenciesAnnotationContents;
896+
}
897+
850898
protected Map<String, ComponentAnnotationContent> getComponentsParentHierarchy(
851899
MojoAnnotatedClass mojoAnnotatedClass, Map<String, MojoAnnotatedClass> mojoAnnotatedClasses) {
852900
List<ComponentAnnotationContent> componentAnnotationContents = new ArrayList<>();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.tools.plugin.extractor.annotations.datamodel;
20+
21+
import java.lang.annotation.Annotation;
22+
23+
/**
24+
* @author Olivier Lamy
25+
* @since 3.0
26+
*/
27+
public class DependenciesAnnotationContent extends AnnotatedField {
28+
private String pathScope;
29+
30+
private String requestType;
31+
32+
public DependenciesAnnotationContent(String fieldName) {
33+
super(fieldName);
34+
}
35+
36+
public DependenciesAnnotationContent(String fieldName, String pathScope, String requestType) {
37+
this(fieldName);
38+
this.pathScope = pathScope;
39+
this.requestType = requestType;
40+
}
41+
42+
public String getPathScope() {
43+
return pathScope;
44+
}
45+
46+
public void setPathScope(String pathScope) {
47+
this.pathScope = pathScope;
48+
}
49+
50+
public String getRequestType() {
51+
return requestType;
52+
}
53+
54+
public void setRequestType(String requestType) {
55+
this.requestType = requestType;
56+
}
57+
58+
public Class<? extends Annotation> annotationType() {
59+
return null;
60+
}
61+
62+
@Override
63+
public String toString() {
64+
final StringBuilder sb = new StringBuilder();
65+
sb.append(super.toString());
66+
sb.append("DependenciesAnnotationContent");
67+
sb.append("{pathScope='").append(pathScope).append('\'');
68+
sb.append(", requestType='").append(requestType).append('\'');
69+
sb.append('}');
70+
return sb.toString();
71+
}
72+
}

maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/DefaultMojoAnnotationsScanner.java

+40-5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.io.IOException;
2828
import java.io.InputStream;
2929
import java.util.Arrays;
30+
import java.util.Collections;
3031
import java.util.HashMap;
3132
import java.util.HashSet;
3233
import java.util.List;
@@ -43,6 +44,7 @@
4344
import org.apache.maven.plugins.annotations.Parameter;
4445
import org.apache.maven.tools.plugin.extractor.ExtractionException;
4546
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ComponentAnnotationContent;
47+
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.DependenciesAnnotationContent;
4648
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent;
4749
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent;
4850
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ParameterAnnotationContent;
@@ -71,6 +73,7 @@ public class DefaultMojoAnnotationsScanner extends AbstractLogEnabled implements
7173
public static final String MOJO_V4 = MVN4_API + "Mojo";
7274
public static final String EXECUTE_V4 = MVN4_API + "Execute";
7375
public static final String PARAMETER_V4 = MVN4_API + "Parameter";
76+
public static final String DEPENDENCIES_V4 = MVN4_API + "Dependencies";
7477

7578
public static final String MOJO_V3 = Mojo.class.getName();
7679
public static final String EXECUTE_V3 = Execute.class.getName();
@@ -339,13 +342,14 @@ protected void analyzeVisitors(MojoClassVisitor mojoClassVisitor) throws Extract
339342
}
340343

341344
// @Component annotations
342-
List<MojoFieldVisitor> mojoFieldVisitors =
345+
List<MojoFieldVisitor> mojoComponentVisitors =
343346
mojoClassVisitor.findFieldWithAnnotation(new HashSet<>(Arrays.asList(COMPONENT_V3)));
344-
for (MojoFieldVisitor mojoFieldVisitor : mojoFieldVisitors) {
347+
for (MojoFieldVisitor mojoComponentVisitor : mojoComponentVisitors) {
345348
ComponentAnnotationContent componentAnnotationContent =
346-
new ComponentAnnotationContent(mojoFieldVisitor.getFieldName());
349+
new ComponentAnnotationContent(mojoComponentVisitor.getFieldName());
347350

348-
Map<String, MojoAnnotationVisitor> annotationVisitorMap = mojoFieldVisitor.getAnnotationVisitorMap();
351+
Map<String, MojoAnnotationVisitor> annotationVisitorMap =
352+
mojoComponentVisitor.getAnnotationVisitorMap();
349353
MojoAnnotationVisitor annotationVisitor = annotationVisitorMap.get(COMPONENT_V3);
350354

351355
if (annotationVisitor != null) {
@@ -362,13 +366,44 @@ protected void analyzeVisitors(MojoClassVisitor mojoClassVisitor) throws Extract
362366
}
363367

364368
if (StringUtils.isEmpty(componentAnnotationContent.getRoleClassName())) {
365-
componentAnnotationContent.setRoleClassName(mojoFieldVisitor.getClassName());
369+
componentAnnotationContent.setRoleClassName(mojoComponentVisitor.getClassName());
366370
}
367371
}
368372
mojoAnnotatedClass
369373
.getComponents()
370374
.put(componentAnnotationContent.getFieldName(), componentAnnotationContent);
371375
}
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+
372407
} catch (ReflectorException e) {
373408
throw new ExtractionException(e.getMessage(), e);
374409
}

maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotatedClass.java

+19
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import org.apache.maven.artifact.Artifact;
2525
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ComponentAnnotationContent;
26+
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.DependenciesAnnotationContent;
2627
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent;
2728
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent;
2829
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ParameterAnnotationContent;
@@ -52,6 +53,11 @@ public class MojoAnnotatedClass {
5253
*/
5354
private Map<String, ComponentAnnotationContent> components;
5455

56+
/**
57+
* key is field name
58+
*/
59+
private Map<String, DependenciesAnnotationContent> dependencies;
60+
5561
/**
5662
* artifact which contains this annotation
5763
*/
@@ -123,6 +129,18 @@ public MojoAnnotatedClass setComponents(Map<String, ComponentAnnotationContent>
123129
return this;
124130
}
125131

132+
public Map<String, DependenciesAnnotationContent> getDependencies() {
133+
if (this.dependencies == null) {
134+
this.dependencies = new HashMap<>();
135+
}
136+
return dependencies;
137+
}
138+
139+
public MojoAnnotatedClass setDependencies(Map<String, DependenciesAnnotationContent> dependencies) {
140+
this.dependencies = dependencies;
141+
return this;
142+
}
143+
126144
public String getParentClassName() {
127145
return parentClassName;
128146
}
@@ -163,6 +181,7 @@ public String toString() {
163181
sb.append(", execute=").append(execute);
164182
sb.append(", parameters=").append(parameters);
165183
sb.append(", components=").append(components);
184+
sb.append(", dependencies=").append(dependencies);
166185
sb.append(", v4api=").append(v4Api);
167186
sb.append('}');
168187
return sb.toString();

maven-plugin-tools-annotations/src/main/java/org/apache/maven/tools/plugin/extractor/annotations/scanner/MojoAnnotationsScanner.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ public interface MojoAnnotationsScanner {
5151
Component.class.getName(),
5252
Deprecated.class.getName(),
5353
V4_API_ANNOTATIONS_PACKAGE + ".Parameter",
54-
V4_API_ANNOTATIONS_PACKAGE + ".Component");
54+
V4_API_ANNOTATIONS_PACKAGE + ".Component",
55+
V4_API_ANNOTATIONS_PACKAGE + ".Dependencies");
5556

5657
List<String> METHOD_LEVEL_ANNOTATIONS = Arrays.asList(
5758
Parameter.class.getName(), Deprecated.class.getName(), V4_API_ANNOTATIONS_PACKAGE + ".Parameter");

0 commit comments

Comments
 (0)