[MNG-7811] Plugins verification - reporting improvements

This commit is contained in:
Slawomir Jaranowski 2023-06-15 20:31:16 +02:00
parent 804b845c4d
commit e625606588
1 changed files with 45 additions and 34 deletions

View File

@ -63,11 +63,17 @@ public final class DefaultPluginValidationManager extends AbstractEventSpy imple
private static final String MAVEN_PLUGIN_VALIDATION_KEY = "maven.plugin.validation"; private static final String MAVEN_PLUGIN_VALIDATION_KEY = "maven.plugin.validation";
private static final ValidationReportLevel DEFAULT_VALIDATION_LEVEL = ValidationReportLevel.INLINE;
private static final Collection<ValidationReportLevel> INLINE_VALIDATION_LEVEL = Collections.unmodifiableCollection(
Arrays.asList(ValidationReportLevel.INLINE, ValidationReportLevel.BRIEF));
private enum ValidationReportLevel { private enum ValidationReportLevel {
NONE, // mute validation completely (validation issue collection still happens, it is just not reported!) NONE, // mute validation completely (validation issue collection still happens, it is just not reported!)
INLINE, // inline, each "internal" problem one line next to mojo invocation INLINE, // inline, each "internal" problem one line next to mojo invocation
SUMMARY, // at end, list of plugin GAVs along with "internal" issues SUMMARY, // at end, list of plugin GAVs along with ANY validation issues
BRIEF, // synonym to SUMMARY BRIEF, // each "internal" problem one line next to mojo invocation
// and at end list of plugin GAVs along with "external" issues
VERBOSE // at end, list of plugin GAVs along with detailed report of ANY validation issues VERBOSE // at end, list of plugin GAVs along with detailed report of ANY validation issues
} }
@ -86,7 +92,7 @@ public final class DefaultPluginValidationManager extends AbstractEventSpy imple
private ValidationReportLevel validationReportLevel(RepositorySystemSession session) { private ValidationReportLevel validationReportLevel(RepositorySystemSession session) {
String level = ConfigUtils.getString(session, null, MAVEN_PLUGIN_VALIDATION_KEY); String level = ConfigUtils.getString(session, null, MAVEN_PLUGIN_VALIDATION_KEY);
if (level == null || level.isEmpty()) { if (level == null || level.isEmpty()) {
return ValidationReportLevel.INLINE; return DEFAULT_VALIDATION_LEVEL;
} }
try { try {
return ValidationReportLevel.valueOf(level.toUpperCase(Locale.ENGLISH)); return ValidationReportLevel.valueOf(level.toUpperCase(Locale.ENGLISH));
@ -96,7 +102,7 @@ public final class DefaultPluginValidationManager extends AbstractEventSpy imple
MAVEN_PLUGIN_VALIDATION_KEY, MAVEN_PLUGIN_VALIDATION_KEY,
level, level,
Arrays.toString(ValidationReportLevel.values())); Arrays.toString(ValidationReportLevel.values()));
return ValidationReportLevel.INLINE; return DEFAULT_VALIDATION_LEVEL;
} }
} }
@ -114,9 +120,11 @@ public final class DefaultPluginValidationManager extends AbstractEventSpy imple
} }
private void mayReportInline(RepositorySystemSession session, IssueLocality locality, String issue) { private void mayReportInline(RepositorySystemSession session, IssueLocality locality, String issue) {
ValidationReportLevel validationReportLevel = validationReportLevel(session); if (locality == IssueLocality.INTERNAL) {
if (locality == IssueLocality.INTERNAL && validationReportLevel == ValidationReportLevel.INLINE) { ValidationReportLevel validationReportLevel = validationReportLevel(session);
logger.warn(" {}", issue); if (INLINE_VALIDATION_LEVEL.contains(validationReportLevel)) {
logger.warn(" {}", issue);
}
} }
} }
@ -165,9 +173,10 @@ public final class DefaultPluginValidationManager extends AbstractEventSpy imple
return; // we were asked to not report anything OR reporting already happened inline return; // we were asked to not report anything OR reporting already happened inline
} }
ConcurrentHashMap<String, PluginValidationIssues> issuesMap = pluginIssues(mavenSession.getRepositorySession()); ConcurrentHashMap<String, PluginValidationIssues> issuesMap = pluginIssues(mavenSession.getRepositorySession());
EnumSet<IssueLocality> issueLocalitiesToReport = validationReportLevel == ValidationReportLevel.VERBOSE EnumSet<IssueLocality> issueLocalitiesToReport = validationReportLevel == ValidationReportLevel.SUMMARY
|| validationReportLevel == ValidationReportLevel.VERBOSE
? EnumSet.allOf(IssueLocality.class) ? EnumSet.allOf(IssueLocality.class)
: EnumSet.of(IssueLocality.INTERNAL); : EnumSet.of(IssueLocality.EXTERNAL);
if (hasAnythingToReport(issuesMap, issueLocalitiesToReport)) { if (hasAnythingToReport(issuesMap, issueLocalitiesToReport)) {
logger.warn(""); logger.warn("");
@ -179,38 +188,40 @@ public final class DefaultPluginValidationManager extends AbstractEventSpy imple
continue; continue;
} }
logger.warn(" * {}", entry.getKey()); logger.warn(" * {}", entry.getKey());
if (!issues.pluginDeclarations.isEmpty()) { if (validationReportLevel == ValidationReportLevel.VERBOSE) {
logger.warn(" Declared at location(s):"); if (!issues.pluginDeclarations.isEmpty()) {
for (String pluginDeclaration : issues.pluginDeclarations) { logger.warn(" Declared at location(s):");
logger.warn(" * {}", pluginDeclaration); for (String pluginDeclaration : issues.pluginDeclarations) {
} logger.warn(" * {}", pluginDeclaration);
}
if (!issues.pluginIssues.isEmpty()) {
for (IssueLocality issueLocality : issueLocalitiesToReport) {
Set<String> pluginIssues = issues.pluginIssues.get(issueLocality);
if (pluginIssues != null && !pluginIssues.isEmpty()) {
logger.warn(" Plugin {} issue(s):", issueLocality);
for (String pluginIssue : pluginIssues) {
logger.warn(" * {}", pluginIssue);
}
} }
} }
} if (!issues.pluginIssues.isEmpty()) {
if (!issues.mojoIssues.isEmpty()) { for (IssueLocality issueLocality : issueLocalitiesToReport) {
for (IssueLocality issueLocality : issueLocalitiesToReport) { Set<String> pluginIssues = issues.pluginIssues.get(issueLocality);
Map<String, LinkedHashSet<String>> mojoIssues = issues.mojoIssues.get(issueLocality); if (pluginIssues != null && !pluginIssues.isEmpty()) {
if (mojoIssues != null && !mojoIssues.isEmpty()) { logger.warn(" Plugin {} issue(s):", issueLocality);
logger.warn(" Mojo {} issue(s):", issueLocality); for (String pluginIssue : pluginIssues) {
for (String mojoInfo : mojoIssues.keySet()) { logger.warn(" * {}", pluginIssue);
logger.warn(" * Mojo {}", mojoInfo);
for (String mojoIssue : mojoIssues.get(mojoInfo)) {
logger.warn(" - {}", mojoIssue);
} }
} }
} }
} }
if (!issues.mojoIssues.isEmpty()) {
for (IssueLocality issueLocality : issueLocalitiesToReport) {
Map<String, LinkedHashSet<String>> mojoIssues = issues.mojoIssues.get(issueLocality);
if (mojoIssues != null && !mojoIssues.isEmpty()) {
logger.warn(" Mojo {} issue(s):", issueLocality);
for (String mojoInfo : mojoIssues.keySet()) {
logger.warn(" * Mojo {}", mojoInfo);
for (String mojoIssue : mojoIssues.get(mojoInfo)) {
logger.warn(" - {}", mojoIssue);
}
}
}
}
}
logger.warn("");
} }
logger.warn("");
} }
logger.warn(""); logger.warn("");
if (validationReportLevel == ValidationReportLevel.VERBOSE) { if (validationReportLevel == ValidationReportLevel.VERBOSE) {