Skip to content

Commit 1f7ba86

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

File tree

12 files changed

+291
-28
lines changed

12 files changed

+291
-28
lines changed

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 11 additions & 13 deletions
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;
3130
import org.apache.maven.api.plugin.annotations.Mojo;
3231
import org.apache.maven.api.plugin.annotations.Parameter;
33-
import org.apache.maven.api.services.ArtifactInstaller;
34-
import org.apache.maven.api.settings.Settings;
32+
import org.apache.maven.api.plugin.annotations.Resolution;
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+
@Resolution(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

Lines changed: 8 additions & 3 deletions
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.resolutions.resolution.size() == 1
80+
81+
resolution = mojo.resolutions.resolution[0]
82+
assert resolution.field.text() == 'classPath'
83+
assert resolution.pathScope.text() == 'main-runtime'
84+
assert resolution.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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
import org.apache.maven.project.MavenProject;
6161
import org.apache.maven.tools.plugin.ExtendedMojoDescriptor;
6262
import org.apache.maven.tools.plugin.PluginToolsRequest;
63+
import org.apache.maven.tools.plugin.Resolution;
6364
import org.apache.maven.tools.plugin.extractor.ExtractionException;
6465
import org.apache.maven.tools.plugin.extractor.GroupKey;
6566
import org.apache.maven.tools.plugin.extractor.MojoDescriptorExtractor;
@@ -71,6 +72,7 @@
7172
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent;
7273
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent;
7374
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ParameterAnnotationContent;
75+
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ResolutionAnnotationContent;
7476
import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotatedClass;
7577
import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScanner;
7678
import org.apache.maven.tools.plugin.extractor.annotations.scanner.MojoAnnotationsScannerRequest;
@@ -791,6 +793,18 @@ private List<MojoDescriptor> toMojoDescriptors(
791793
mojoDescriptor.addParameter(parameter);
792794
}
793795

796+
// Dependencies annotations
797+
Map<String, ResolutionAnnotationContent> resolutions =
798+
getResolutionsParentHierarchy(mojoAnnotatedClass, mojoAnnotatedClasses);
799+
800+
for (ResolutionAnnotationContent resolutionAnnotationContent : new TreeSet<>(resolutions.values())) {
801+
Resolution resolution = new Resolution();
802+
resolution.setField(resolutionAnnotationContent.getFieldName());
803+
resolution.setPathScope(resolutionAnnotationContent.getPathScope());
804+
resolution.setRequestType(resolutionAnnotationContent.getRequestType());
805+
mojoDescriptor.addResolution(resolution);
806+
}
807+
794808
mojoDescriptor.setPluginDescriptor(pluginDescriptor);
795809

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

864+
protected Map<String, ResolutionAnnotationContent> getResolutionsParentHierarchy(
865+
MojoAnnotatedClass mojoAnnotatedClass, Map<String, MojoAnnotatedClass> mojoAnnotatedClasses) {
866+
List<ResolutionAnnotationContent> resolutionAnnotationContents = new ArrayList<>();
867+
868+
resolutionAnnotationContents =
869+
getResolutionsParent(mojoAnnotatedClass, resolutionAnnotationContents, mojoAnnotatedClasses);
870+
871+
// move to parent first to build the Map
872+
Collections.reverse(resolutionAnnotationContents);
873+
874+
Map<String, ResolutionAnnotationContent> map = new HashMap<>(resolutionAnnotationContents.size());
875+
876+
for (ResolutionAnnotationContent resolutionAnnotationContent : resolutionAnnotationContents) {
877+
map.put(resolutionAnnotationContent.getFieldName(), resolutionAnnotationContent);
878+
}
879+
return map;
880+
}
881+
882+
protected List<ResolutionAnnotationContent> getResolutionsParent(
883+
MojoAnnotatedClass mojoAnnotatedClass,
884+
List<ResolutionAnnotationContent> resolutionAnnotationContents,
885+
Map<String, MojoAnnotatedClass> mojoAnnotatedClasses) {
886+
resolutionAnnotationContents.addAll(mojoAnnotatedClass.getResolutions().values());
887+
String parentClassName = mojoAnnotatedClass.getParentClassName();
888+
if (parentClassName != null) {
889+
MojoAnnotatedClass parent = mojoAnnotatedClasses.get(parentClassName);
890+
if (parent != null) {
891+
return getResolutionsParent(parent, resolutionAnnotationContents, mojoAnnotatedClasses);
892+
}
893+
}
894+
return resolutionAnnotationContents;
895+
}
896+
850897
protected Map<String, ComponentAnnotationContent> getComponentsParentHierarchy(
851898
MojoAnnotatedClass mojoAnnotatedClass, Map<String, MojoAnnotatedClass> mojoAnnotatedClasses) {
852899
List<ComponentAnnotationContent> componentAnnotationContents = new ArrayList<>();
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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 Guillaume Nodet
25+
* @since 4.0
26+
*/
27+
public class ResolutionAnnotationContent extends AnnotatedField {
28+
private String pathScope;
29+
30+
private String requestType;
31+
32+
public ResolutionAnnotationContent(String fieldName) {
33+
super(fieldName);
34+
}
35+
36+
public ResolutionAnnotationContent(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+
return super.toString() + "ResolutionAnnotationContent"
65+
+ "{pathScope='"
66+
+ pathScope + '\'' + ", requestType='"
67+
+ requestType + '\'' + '}';
68+
}
69+
}

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

Lines changed: 40 additions & 5 deletions
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;
@@ -46,6 +47,7 @@
4647
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent;
4748
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent;
4849
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ParameterAnnotationContent;
50+
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ResolutionAnnotationContent;
4951
import org.apache.maven.tools.plugin.extractor.annotations.scanner.visitors.MojoAnnotationVisitor;
5052
import org.apache.maven.tools.plugin.extractor.annotations.scanner.visitors.MojoClassVisitor;
5153
import org.apache.maven.tools.plugin.extractor.annotations.scanner.visitors.MojoFieldVisitor;
@@ -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 RESOLUTION_V4 = MVN4_API + "Resolution";
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+
// @Resolution annotations
378+
List<MojoFieldVisitor> mojoResolutionVisitors =
379+
mojoClassVisitor.findFieldWithAnnotation(Collections.singleton(RESOLUTION_V4));
380+
for (MojoFieldVisitor mojoResolutionVisitor : mojoResolutionVisitors) {
381+
ResolutionAnnotationContent dependenciesAnnotationContent =
382+
new ResolutionAnnotationContent(mojoResolutionVisitor.getFieldName());
383+
384+
Map<String, MojoAnnotationVisitor> annotationVisitorMap =
385+
mojoResolutionVisitor.getAnnotationVisitorMap();
386+
MojoAnnotationVisitor annotationVisitor = annotationVisitorMap.get(RESOLUTION_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+
.getResolutions()
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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ExecuteAnnotationContent;
2727
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.MojoAnnotationContent;
2828
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ParameterAnnotationContent;
29+
import org.apache.maven.tools.plugin.extractor.annotations.datamodel.ResolutionAnnotationContent;
2930

3031
/**
3132
* @author Olivier Lamy
@@ -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, ResolutionAnnotationContent> resolutions;
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, ResolutionAnnotationContent> getResolutions() {
133+
if (this.resolutions == null) {
134+
this.resolutions = new HashMap<>();
135+
}
136+
return resolutions;
137+
}
138+
139+
public MojoAnnotatedClass setResolutions(Map<String, ResolutionAnnotationContent> resolutions) {
140+
this.resolutions = resolutions;
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(resolutions);
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

Lines changed: 2 additions & 1 deletion
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 + ".Resolution");
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)