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 org.apache.maven.plugin.AbstractMojo;
22 import org.apache.maven.plugin.MojoExecutionException;
23 import org.apache.maven.plugin.descriptor.PluginDescriptor;
24 import org.apache.maven.plugins.annotations.Component;
25 import org.apache.maven.plugins.annotations.LifecyclePhase;
26 import org.apache.maven.plugins.annotations.Mojo;
27 import org.apache.maven.plugins.annotations.Parameter;
28 import org.apache.maven.project.MavenProject;
29 import org.apache.maven.rtinfo.RuntimeInformation;
30 import org.eclipse.aether.util.version.GenericVersionScheme;
31 import org.eclipse.aether.version.InvalidVersionSpecificationException;
32 import org.eclipse.aether.version.VersionScheme;
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 @Mojo(name = "addPluginArtifactMetadata", defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true)
51 public class AddPluginArtifactMetadataMojo extends AbstractMojo {
52
53
54
55 @Component
56 private 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 @Component
73 private RuntimeInformation runtimeInformation;
74
75 private final VersionScheme versionScheme = new GenericVersionScheme();
76
77
78 @Override
79 public void execute() throws MojoExecutionException {
80 if (skip) {
81 getLog().warn("Execution skipped");
82 return;
83 }
84
85 try {
86 if (versionScheme
87 .parseVersion("3.9.0")
88 .compareTo(versionScheme.parseVersion(runtimeInformation.getMavenVersion()))
89 < 1) {
90 getLog().info("This Mojo is not used in Maven version 3.9.0 and above");
91 return;
92 }
93 } catch (InvalidVersionSpecificationException e) {
94
95 throw new MojoExecutionException(e);
96 }
97
98 LegacySupport.execute(project, getGoalPrefix());
99 }
100
101
102
103
104 private String getGoalPrefix() {
105 if (goalPrefix == null) {
106 goalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId(project.getArtifactId());
107 }
108
109 return goalPrefix;
110 }
111 }