Skip to content

Commit

Permalink
[MNG-7767] Tone down plugin validator (apache#1092)
Browse files Browse the repository at this point in the history
This change reduces default output making it more compact, and also renames the "levels" to brief, default and verbose.

---

https://issues.apache.org/jira/browse/MNG-7767
  • Loading branch information
cstamas committed Apr 26, 2023
1 parent 81231b8 commit 8b8f2c3
Showing 1 changed file with 38 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public final class DefaultPluginValidationManager extends AbstractMavenLifecycle
private static final String MAVEN_PLUGIN_VALIDATION_KEY = "maven.plugin.validation";

private enum ValidationLevel {
DISABLED,
ENABLED,
BRIEF,
DEFAULT,
VERBOSE
}

Expand All @@ -67,7 +67,7 @@ public void afterSessionEnd(MavenSession session) {
private ValidationLevel validationLevel(RepositorySystemSession session) {
String level = ConfigUtils.getString(session, null, MAVEN_PLUGIN_VALIDATION_KEY);
if (level == null || level.isEmpty()) {
return ValidationLevel.ENABLED;
return ValidationLevel.DEFAULT;
}
try {
return ValidationLevel.valueOf(level.toUpperCase(Locale.ENGLISH));
Expand All @@ -77,7 +77,7 @@ private ValidationLevel validationLevel(RepositorySystemSession session) {
MAVEN_PLUGIN_VALIDATION_KEY,
level,
Arrays.toString(ValidationLevel.values()));
return ValidationLevel.ENABLED;
return ValidationLevel.DEFAULT;
}
}

Expand Down Expand Up @@ -125,53 +125,59 @@ public void reportPluginMojoValidationIssue(
}

private void reportSessionCollectedValidationIssues(MavenSession mavenSession) {
if (!logger.isWarnEnabled()) {
return; // nothing can be reported
}
ValidationLevel validationLevel = validationLevel(mavenSession.getRepositorySession());
ConcurrentHashMap<String, PluginValidationIssues> issuesMap = pluginIssues(mavenSession.getRepositorySession());
if (!issuesMap.isEmpty()) {

logger.warn("");
logger.warn("Plugin validation issues were detected in {} plugin(s)", issuesMap.size());
logger.warn("");
if (validationLevel == ValidationLevel.DISABLED || !logger.isWarnEnabled()) {
if (validationLevel == ValidationLevel.BRIEF) {
return;
}

for (Map.Entry<String, PluginValidationIssues> entry : issuesMap.entrySet()) {
logger.warn("Plugin {}", entry.getKey());
PluginValidationIssues issues = entry.getValue();
if (validationLevel == ValidationLevel.VERBOSE && !issues.pluginDeclarations.isEmpty()) {
logger.warn(" Declared at location(s):");
for (String pluginDeclaration : issues.pluginDeclarations) {
logger.warn(" * {}", pluginDeclaration);
logger.warn(" * {}", entry.getKey());
if (validationLevel == ValidationLevel.VERBOSE) {
PluginValidationIssues issues = entry.getValue();
if (!issues.pluginDeclarations.isEmpty()) {
logger.warn(" Declared at location(s):");
for (String pluginDeclaration : issues.pluginDeclarations) {
logger.warn(" * {}", pluginDeclaration);
}
}
}
if (validationLevel == ValidationLevel.VERBOSE && !issues.pluginOccurrences.isEmpty()) {
logger.warn(" Used in module(s):");
for (String pluginOccurrence : issues.pluginOccurrences) {
logger.warn(" * {}", pluginOccurrence);
if (!issues.pluginOccurrences.isEmpty()) {
logger.warn(" Used in module(s):");
for (String pluginOccurrence : issues.pluginOccurrences) {
logger.warn(" * {}", pluginOccurrence);
}
}
}
if (!issues.pluginIssues.isEmpty()) {
logger.warn(" Plugin issue(s):");
for (String pluginIssue : issues.pluginIssues) {
logger.warn(" * {}", pluginIssue);
if (!issues.pluginIssues.isEmpty()) {
logger.warn(" Plugin issue(s):");
for (String pluginIssue : issues.pluginIssues) {
logger.warn(" * {}", pluginIssue);
}
}
}
if (!issues.mojoIssues.isEmpty()) {
logger.warn(" Mojo issue(s):");
for (String mojoInfo : issues.mojoIssues.keySet()) {
logger.warn(" * Mojo {}", mojoInfo);
for (String mojoIssue : issues.mojoIssues.get(mojoInfo)) {
logger.warn(" - {}", mojoIssue);
if (!issues.mojoIssues.isEmpty()) {
logger.warn(" Mojo issue(s):");
for (String mojoInfo : issues.mojoIssues.keySet()) {
logger.warn(" * Mojo {}", mojoInfo);
for (String mojoIssue : issues.mojoIssues.get(mojoInfo)) {
logger.warn(" - {}", mojoIssue);
}
}
}
logger.warn("");
}
logger.warn("");
}
logger.warn("");
logger.warn(
"To fix these issues, please upgrade above listed plugins, or, notify their maintainers about reported issues.");
logger.warn("");
if (validationLevel == ValidationLevel.VERBOSE) {
logger.warn(
"Fix reported issues by adjusting plugin configuration or by upgrading above listed plugins. If no upgrade available, please notify plugin maintainers about reported issues.");
}
logger.warn(
"For more or less details, use 'maven.plugin.validation' property with one of the values (case insensitive): {}",
Arrays.toString(ValidationLevel.values()));
Expand Down

0 comments on commit 8b8f2c3

Please sign in to comment.