This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 11d97e64e7e3fbed23d8e98abdd8c015a957ee82
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Fri May 19 17:47:03 2023 +0200

    [MNG-7787] Introduce new options for plugin validation report (#1113)
    
    Added NONE and INLINE modes.
    
    ---
    
    https://issues.apache.org/jira/browse/MNG-7787
---
 .../plugin/internal/DefaultMavenPluginManager.java |  2 +-
 .../internal/DefaultPluginValidationManager.java   | 46 +++++++++++++++-------
 2 files changed, 33 insertions(+), 15 deletions(-)

diff --git 
a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
 
b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
index aaf90b4f9..85f251240 100644
--- 
a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
+++ 
b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultMavenPluginManager.java
@@ -571,7 +571,7 @@ public class DefaultMavenPluginManager implements 
MavenPluginManager {
                         session,
                         mojoDescriptor,
                         mojo.getClass(),
-                        "Implements `Contextualizable` interface from Plexus 
Container, which is EOL.");
+                        "Mojo implements `Contextualizable` interface from 
Plexus Container, which is EOL.");
             }
 
             for (MavenPluginDependenciesValidator validator : 
dependenciesValidators) {
diff --git 
a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginValidationManager.java
 
b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginValidationManager.java
index 9cd6aec92..371abb12a 100644
--- 
a/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginValidationManager.java
+++ 
b/maven-core/src/main/java/org/apache/maven/plugin/internal/DefaultPluginValidationManager.java
@@ -51,10 +51,12 @@ public final class DefaultPluginValidationManager extends 
AbstractMavenLifecycle
 
     private static final String MAVEN_PLUGIN_VALIDATION_KEY = 
"maven.plugin.validation";
 
-    private enum ValidationLevel {
-        BRIEF,
-        DEFAULT,
-        VERBOSE
+    private enum ValidationReportLevel {
+        NONE, // mute validation completely (validation issue collection still 
happens, it is just not reported!)
+        INLINE, // inline, each problem one line next to mojo invocation, 
repeated as many times as mojo is executed
+        BRIEF, // at end, one line with count of plugins in the build having 
validation issues
+        DEFAULT, // at end, list of plugin GAVs in the build having validation 
issues
+        VERBOSE // at end, detailed report of plugins in the build having 
validation issues
     }
 
     private final Logger logger = LoggerFactory.getLogger(getClass());
@@ -64,20 +66,20 @@ public final class DefaultPluginValidationManager extends 
AbstractMavenLifecycle
         reportSessionCollectedValidationIssues(session);
     }
 
-    private ValidationLevel validationLevel(RepositorySystemSession session) {
+    private ValidationReportLevel 
validationReportLevel(RepositorySystemSession session) {
         String level = ConfigUtils.getString(session, null, 
MAVEN_PLUGIN_VALIDATION_KEY);
         if (level == null || level.isEmpty()) {
-            return ValidationLevel.DEFAULT;
+            return ValidationReportLevel.DEFAULT;
         }
         try {
-            return ValidationLevel.valueOf(level.toUpperCase(Locale.ENGLISH));
+            return 
ValidationReportLevel.valueOf(level.toUpperCase(Locale.ENGLISH));
         } catch (IllegalArgumentException e) {
             logger.warn(
                     "Invalid value specified for property {}: '{}'. Supported 
values are (case insensitive): {}",
                     MAVEN_PLUGIN_VALIDATION_KEY,
                     level,
-                    Arrays.toString(ValidationLevel.values()));
-            return ValidationLevel.DEFAULT;
+                    Arrays.toString(ValidationReportLevel.values()));
+            return ValidationReportLevel.DEFAULT;
         }
     }
 
@@ -100,6 +102,10 @@ public final class DefaultPluginValidationManager extends 
AbstractMavenLifecycle
         PluginValidationIssues pluginIssues =
                 pluginIssues(session).computeIfAbsent(pluginKey, k -> new 
PluginValidationIssues());
         pluginIssues.reportPluginIssue(null, null, issue);
+        ValidationReportLevel validationReportLevel = 
validationReportLevel(session);
+        if (validationReportLevel == ValidationReportLevel.INLINE) {
+            logger.warn(" {}", issue);
+        }
     }
 
     @Override
@@ -109,6 +115,10 @@ public final class DefaultPluginValidationManager extends 
AbstractMavenLifecycle
                 .computeIfAbsent(pluginKey, k -> new PluginValidationIssues());
         pluginIssues.reportPluginIssue(
                 pluginDeclaration(mavenSession, mojoDescriptor), 
pluginOccurrence(mavenSession), issue);
+        ValidationReportLevel validationReportLevel = 
validationReportLevel(mavenSession.getRepositorySession());
+        if (validationReportLevel == ValidationReportLevel.INLINE) {
+            logger.warn(" {}", issue);
+        }
     }
 
     @Override
@@ -122,26 +132,34 @@ public final class DefaultPluginValidationManager extends 
AbstractMavenLifecycle
                 pluginOccurrence(mavenSession),
                 mojoInfo(mojoDescriptor, mojoClass),
                 issue);
+        ValidationReportLevel validationReportLevel = 
validationReportLevel(mavenSession.getRepositorySession());
+        if (validationReportLevel == ValidationReportLevel.INLINE) {
+            logger.warn(" {}", issue);
+        }
     }
 
     private void reportSessionCollectedValidationIssues(MavenSession 
mavenSession) {
         if (!logger.isWarnEnabled()) {
             return; // nothing can be reported
         }
-        ValidationLevel validationLevel = 
validationLevel(mavenSession.getRepositorySession());
+        ValidationReportLevel validationReportLevel = 
validationReportLevel(mavenSession.getRepositorySession());
+        if (validationReportLevel == ValidationReportLevel.NONE
+                || validationReportLevel == ValidationReportLevel.INLINE) {
+            return; // we were asked to not report anything OR reporting 
already happened inline
+        }
         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.BRIEF) {
+            if (validationReportLevel == ValidationReportLevel.BRIEF) {
                 return;
             }
 
             for (Map.Entry<String, PluginValidationIssues> entry : 
issuesMap.entrySet()) {
                 logger.warn(" * {}", entry.getKey());
-                if (validationLevel == ValidationLevel.VERBOSE) {
+                if (validationReportLevel == ValidationReportLevel.VERBOSE) {
                     PluginValidationIssues issues = entry.getValue();
                     if (!issues.pluginDeclarations.isEmpty()) {
                         logger.warn("  Declared at location(s):");
@@ -174,13 +192,13 @@ public final class DefaultPluginValidationManager extends 
AbstractMavenLifecycle
                 }
             }
             logger.warn("");
-            if (validationLevel == ValidationLevel.VERBOSE) {
+            if (validationReportLevel == ValidationReportLevel.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()));
+                    Arrays.toString(ValidationReportLevel.values()));
             logger.warn("");
         }
     }

Reply via email to