Skip to content

Commit

Permalink
[MNG-7939] Allow to exclude plugins from validation
Browse files Browse the repository at this point in the history
(cherry picked from commit 644a15c)
  • Loading branch information
slawekjaranowski committed Nov 20, 2023
1 parent ecd59b7 commit c54baa6
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.apache.maven.eventspy.AbstractEventSpy;
import org.apache.maven.execution.ExecutionEvent;
Expand Down Expand Up @@ -61,8 +63,12 @@ public final class DefaultPluginValidationManager extends AbstractEventSpy imple

private static final String ISSUES_KEY = DefaultPluginValidationManager.class.getName() + ".issues";

private static final String PLUGIN_EXCLUDES_KEY = DefaultPluginValidationManager.class.getName() + ".excludes";

private static final String MAVEN_PLUGIN_VALIDATION_KEY = "maven.plugin.validation";

private static final String MAVEN_PLUGIN_VALIDATION_EXCLUDES_KEY = "maven.plugin.validation.excludes";

private static final ValidationReportLevel DEFAULT_VALIDATION_LEVEL = ValidationReportLevel.INLINE;

private static final Collection<ValidationReportLevel> INLINE_VALIDATION_LEVEL = Collections.unmodifiableCollection(
Expand All @@ -87,12 +93,28 @@ public void onEvent(Object event) {
RepositorySystemSession repositorySystemSession =
executionEvent.getSession().getRepositorySession();
validationReportLevel(repositorySystemSession); // this will parse and store it in session.data
validationPluginExcludes(repositorySystemSession);
} else if (executionEvent.getType() == ExecutionEvent.Type.SessionEnded) {
reportSessionCollectedValidationIssues(executionEvent.getSession());
}
}
}

private List<?> validationPluginExcludes(RepositorySystemSession session) {
return (List<?>) session.getData().computeIfAbsent(PLUGIN_EXCLUDES_KEY, () -> parsePluginExcludes(session));
}

private List<String> parsePluginExcludes(RepositorySystemSession session) {
String excludes = ConfigUtils.getString(session, null, MAVEN_PLUGIN_VALIDATION_EXCLUDES_KEY);
if (excludes == null || excludes.isEmpty()) {
return Collections.emptyList();
}
return Arrays.stream(excludes.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toList());
}

private ValidationReportLevel validationReportLevel(RepositorySystemSession session) {
return (ValidationReportLevel) session.getData()
.computeIfAbsent(ValidationReportLevel.class, () -> parseValidationReportLevel(session));
Expand Down Expand Up @@ -141,6 +163,9 @@ private void mayReportInline(RepositorySystemSession session, IssueLocality loca
public void reportPluginValidationIssue(
IssueLocality locality, RepositorySystemSession session, Artifact pluginArtifact, String issue) {
String pluginKey = pluginKey(pluginArtifact);
if (validationPluginExcludes(session).contains(pluginKey)) {
return;
}
PluginValidationIssues pluginIssues =
pluginIssues(session).computeIfAbsent(pluginKey, k -> new PluginValidationIssues());
pluginIssues.reportPluginIssue(locality, null, issue);
Expand All @@ -151,6 +176,9 @@ public void reportPluginValidationIssue(
public void reportPluginValidationIssue(
IssueLocality locality, MavenSession mavenSession, MojoDescriptor mojoDescriptor, String issue) {
String pluginKey = pluginKey(mojoDescriptor);
if (validationPluginExcludes(mavenSession.getRepositorySession()).contains(pluginKey)) {
return;
}
PluginValidationIssues pluginIssues = pluginIssues(mavenSession.getRepositorySession())
.computeIfAbsent(pluginKey, k -> new PluginValidationIssues());
pluginIssues.reportPluginIssue(locality, pluginDeclaration(mavenSession, mojoDescriptor), issue);
Expand All @@ -165,6 +193,9 @@ public void reportPluginMojoValidationIssue(
Class<?> mojoClass,
String issue) {
String pluginKey = pluginKey(mojoDescriptor);
if (validationPluginExcludes(mavenSession.getRepositorySession()).contains(pluginKey)) {
return;
}
PluginValidationIssues pluginIssues = pluginIssues(mavenSession.getRepositorySession())
.computeIfAbsent(pluginKey, k -> new PluginValidationIssues());
pluginIssues.reportPluginMojoIssue(
Expand Down

0 comments on commit c54baa6

Please sign in to comment.