1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.internal;
20
21 import javax.inject.Inject;
22 import javax.inject.Named;
23 import javax.inject.Singleton;
24 import org.apache.maven.plugin.MavenPluginPrerequisitesChecker;
25 import org.apache.maven.plugin.descriptor.PluginDescriptor;
26 import org.apache.maven.rtinfo.RuntimeInformation;
27 import org.codehaus.plexus.util.StringUtils;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30
31 @Named
32 @Singleton
33 public class MavenPluginMavenPrerequisiteChecker implements MavenPluginPrerequisitesChecker {
34 private final Logger logger = LoggerFactory.getLogger(getClass());
35 private final RuntimeInformation runtimeInformation;
36
37 @Inject
38 public MavenPluginMavenPrerequisiteChecker(RuntimeInformation runtimeInformation) {
39 super();
40 this.runtimeInformation = runtimeInformation;
41 }
42
43 @Override
44 public void accept(PluginDescriptor pluginDescriptor) {
45 String requiredMavenVersion = pluginDescriptor.getRequiredMavenVersion();
46 if (StringUtils.isNotBlank(requiredMavenVersion)) {
47 boolean isRequirementMet = false;
48 try {
49 isRequirementMet = runtimeInformation.isMavenVersion(requiredMavenVersion);
50 } catch (IllegalArgumentException e) {
51 logger.warn(
52 "Could not verify plugin's Maven prerequisite as an invalid version is given in "
53 + requiredMavenVersion,
54 e);
55 return;
56 }
57 if (!isRequirementMet) {
58 throw new IllegalStateException("Required Maven version " + requiredMavenVersion
59 + " is not met by current version " + runtimeInformation.getMavenVersion());
60 }
61 }
62 }
63 }