1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.plugin.metadata;
20
21 import javax.inject.Inject;
22
23 import org.apache.maven.plugin.AbstractMojo;
24 import org.apache.maven.plugin.MojoExecutionException;
25 import org.apache.maven.plugin.descriptor.PluginDescriptor;
26 import org.apache.maven.plugins.annotations.LifecyclePhase;
27 import org.apache.maven.plugins.annotations.Mojo;
28 import org.apache.maven.plugins.annotations.Parameter;
29 import org.apache.maven.project.MavenProject;
30 import org.apache.maven.rtinfo.RuntimeInformation;
31 import org.eclipse.aether.util.version.GenericVersionScheme;
32 import org.eclipse.aether.version.InvalidVersionSpecificationException;
33 import org.eclipse.aether.version.VersionScheme;
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 @Mojo(name = "addPluginArtifactMetadata", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true)
52 public class AddPluginArtifactMetadataMojo extends AbstractMojo {
53
54
55
56 private final MavenProject project;
57
58
59
60
61 @Parameter
62 private String goalPrefix;
63
64
65
66
67
68
69 @Parameter(defaultValue = "false", property = "maven.plugin.skip")
70 private boolean skip;
71
72 private final RuntimeInformation runtimeInformation;
73
74 private final VersionScheme versionScheme = new GenericVersionScheme();
75
76 @Inject
77 public AddPluginArtifactMetadataMojo(MavenProject project, RuntimeInformation runtimeInformation) {
78 this.project = project;
79 this.runtimeInformation = runtimeInformation;
80 }
81
82
83 @Override
84 public void execute() throws MojoExecutionException {
85 if (skip) {
86 getLog().warn("Execution skipped");
87 return;
88 }
89
90 try {
91 if (versionScheme
92 .parseVersion("3.9.0")
93 .compareTo(versionScheme.parseVersion(runtimeInformation.getMavenVersion()))
94 < 1) {
95 getLog().info("This Mojo is not used in Maven version 3.9.0 and above");
96 return;
97 }
98 } catch (InvalidVersionSpecificationException e) {
99
100 throw new MojoExecutionException(e);
101 }
102
103 LegacySupport.execute(project, getGoalPrefix());
104 }
105
106
107
108
109 private String getGoalPrefix() {
110 if (goalPrefix == null) {
111 goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId(project.getArtifactId());
112 }
113
114 return goalPrefix;
115 }
116 }