30
30
import java .util .HashMap ;
31
31
import java .util .LinkedHashMap ;
32
32
import java .util .LinkedHashSet ;
33
+ import java .util .List ;
33
34
import java .util .Locale ;
34
35
import java .util .Map ;
35
36
import java .util .Set ;
36
37
import java .util .concurrent .ConcurrentHashMap ;
38
+ import java .util .stream .Collectors ;
37
39
38
40
import org .apache .maven .eventspy .AbstractEventSpy ;
39
41
import org .apache .maven .execution .ExecutionEvent ;
@@ -61,8 +63,12 @@ public final class DefaultPluginValidationManager extends AbstractEventSpy imple
61
63
62
64
private static final String ISSUES_KEY = DefaultPluginValidationManager .class .getName () + ".issues" ;
63
65
66
+ private static final String PLUGIN_EXCLUDES_KEY = DefaultPluginValidationManager .class .getName () + ".excludes" ;
67
+
64
68
private static final String MAVEN_PLUGIN_VALIDATION_KEY = "maven.plugin.validation" ;
65
69
70
+ private static final String MAVEN_PLUGIN_VALIDATION_EXCLUDES_KEY = "maven.plugin.validation.excludes" ;
71
+
66
72
private static final ValidationReportLevel DEFAULT_VALIDATION_LEVEL = ValidationReportLevel .INLINE ;
67
73
68
74
private static final Collection <ValidationReportLevel > INLINE_VALIDATION_LEVEL = Collections .unmodifiableCollection (
@@ -87,12 +93,28 @@ public void onEvent(Object event) {
87
93
RepositorySystemSession repositorySystemSession =
88
94
executionEvent .getSession ().getRepositorySession ();
89
95
validationReportLevel (repositorySystemSession ); // this will parse and store it in session.data
96
+ validationPluginExcludes (repositorySystemSession );
90
97
} else if (executionEvent .getType () == ExecutionEvent .Type .SessionEnded ) {
91
98
reportSessionCollectedValidationIssues (executionEvent .getSession ());
92
99
}
93
100
}
94
101
}
95
102
103
+ private List <?> validationPluginExcludes (RepositorySystemSession session ) {
104
+ return (List <?>) session .getData ().computeIfAbsent (PLUGIN_EXCLUDES_KEY , () -> parsePluginExcludes (session ));
105
+ }
106
+
107
+ private List <String > parsePluginExcludes (RepositorySystemSession session ) {
108
+ String excludes = ConfigUtils .getString (session , null , MAVEN_PLUGIN_VALIDATION_EXCLUDES_KEY );
109
+ if (excludes == null || excludes .isEmpty ()) {
110
+ return Collections .emptyList ();
111
+ }
112
+ return Arrays .stream (excludes .split ("," ))
113
+ .map (String ::trim )
114
+ .filter (s -> !s .isEmpty ())
115
+ .collect (Collectors .toList ());
116
+ }
117
+
96
118
private ValidationReportLevel validationReportLevel (RepositorySystemSession session ) {
97
119
return (ValidationReportLevel ) session .getData ()
98
120
.computeIfAbsent (ValidationReportLevel .class , () -> parseValidationReportLevel (session ));
@@ -141,6 +163,9 @@ private void mayReportInline(RepositorySystemSession session, IssueLocality loca
141
163
public void reportPluginValidationIssue (
142
164
IssueLocality locality , RepositorySystemSession session , Artifact pluginArtifact , String issue ) {
143
165
String pluginKey = pluginKey (pluginArtifact );
166
+ if (validationPluginExcludes (session ).contains (pluginKey )) {
167
+ return ;
168
+ }
144
169
PluginValidationIssues pluginIssues =
145
170
pluginIssues (session ).computeIfAbsent (pluginKey , k -> new PluginValidationIssues ());
146
171
pluginIssues .reportPluginIssue (locality , null , issue );
@@ -151,6 +176,9 @@ public void reportPluginValidationIssue(
151
176
public void reportPluginValidationIssue (
152
177
IssueLocality locality , MavenSession mavenSession , MojoDescriptor mojoDescriptor , String issue ) {
153
178
String pluginKey = pluginKey (mojoDescriptor );
179
+ if (validationPluginExcludes (mavenSession .getRepositorySession ()).contains (pluginKey )) {
180
+ return ;
181
+ }
154
182
PluginValidationIssues pluginIssues = pluginIssues (mavenSession .getRepositorySession ())
155
183
.computeIfAbsent (pluginKey , k -> new PluginValidationIssues ());
156
184
pluginIssues .reportPluginIssue (locality , pluginDeclaration (mavenSession , mojoDescriptor ), issue );
@@ -165,6 +193,9 @@ public void reportPluginMojoValidationIssue(
165
193
Class <?> mojoClass ,
166
194
String issue ) {
167
195
String pluginKey = pluginKey (mojoDescriptor );
196
+ if (validationPluginExcludes (mavenSession .getRepositorySession ()).contains (pluginKey )) {
197
+ return ;
198
+ }
168
199
PluginValidationIssues pluginIssues = pluginIssues (mavenSession .getRepositorySession ())
169
200
.computeIfAbsent (pluginKey , k -> new PluginValidationIssues ());
170
201
pluginIssues .reportPluginMojoIssue (
0 commit comments