1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  package org.apache.maven.plugin;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  import org.apache.maven.artifact.Artifact;
25  import org.apache.maven.plugin.descriptor.PluginDescriptor;
26  
27  
28  
29  
30  public class MavenPluginValidator {
31      private final Artifact pluginArtifact;
32  
33      private List<String> errors = new ArrayList<>();
34  
35      private boolean firstDescriptor = true;
36  
37      public MavenPluginValidator(Artifact pluginArtifact) {
38          this.pluginArtifact = pluginArtifact;
39      }
40  
41      public void validate(PluginDescriptor pluginDescriptor) {
42          
43  
44  
45  
46          if (!firstDescriptor) {
47              return;
48          }
49          firstDescriptor = false;
50  
51          if (!pluginArtifact.getGroupId().equals(pluginDescriptor.getGroupId())) {
52              errors.add("Plugin's descriptor contains the wrong group ID: " + pluginDescriptor.getGroupId());
53          }
54  
55          if (!pluginArtifact.getArtifactId().equals(pluginDescriptor.getArtifactId())) {
56              errors.add("Plugin's descriptor contains the wrong artifact ID: " + pluginDescriptor.getArtifactId());
57          }
58  
59          if (!pluginArtifact.getBaseVersion().equals(pluginDescriptor.getVersion())) {
60              errors.add("Plugin's descriptor contains the wrong version: " + pluginDescriptor.getVersion());
61          }
62      }
63  
64      public boolean hasErrors() {
65          return !errors.isEmpty();
66      }
67  
68      public List<String> getErrors() {
69          return errors;
70      }
71  }