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

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


The following commit(s) were added to refs/heads/master by this push:
     new db7fbd2  [MENFORCER-454] Log warning only if the '-Drules' is actually 
used
db7fbd2 is described below

commit db7fbd2e6f433bb4ea44fa910ab13d0e0d1b427b
Author: Petr Široký <[email protected]>
AuthorDate: Thu Dec 29 22:23:00 2022 +0100

    [MENFORCER-454] Log warning only if the '-Drules' is actually used
    
     * the method gets called with empty list if there is no configuration,
       resulting in WARNing being printed every single time
---
 .../java/org/apache/maven/plugins/enforcer/EnforceMojo.java   |  5 ++++-
 .../org/apache/maven/plugins/enforcer/TestEnforceMojo.java    | 11 +++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git 
a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java
 
b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java
index 695f113..24c2545 100644
--- 
a/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java
+++ 
b/maven-enforcer-plugin/src/main/java/org/apache/maven/plugins/enforcer/EnforceMojo.java
@@ -173,7 +173,10 @@ public class EnforceMojo extends AbstractMojo {
     @Parameter(required = false, property = "rules")
     @Deprecated
     public void setCommandLineRules(List<String> rulesToExecute) throws 
MojoExecutionException {
-        getLog().warn("Detected the usage of property '-Drules' which is 
deprecated. Use '-Denforcer.rules' instead.");
+        if (rulesToExecute != null && !rulesToExecute.isEmpty()) {
+            getLog().warn(
+                            "Detected the usage of property '-Drules' which is 
deprecated. Use '-Denforcer.rules' instead.");
+        }
         setRulesToExecute(rulesToExecute);
     }
 
diff --git 
a/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java
 
b/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java
index 4be12c4..cd25b7c 100644
--- 
a/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java
+++ 
b/maven-enforcer-plugin/src/test/java/org/apache/maven/plugins/enforcer/TestEnforceMojo.java
@@ -319,6 +319,17 @@ class TestEnforceMojo {
                 .warn("Detected the usage of property '-Drules' which is 
deprecated. Use '-Denforcer.rules' instead.");
     }
 
+    @Test
+    void testShouldNotPrintWarnWhenDeprecatedRulesPropertyIsEmpty() throws 
MojoExecutionException {
+        setupBasics(false);
+
+        Log logSpy = setupLogSpy();
+
+        mojo.setCommandLineRules(Collections.emptyList());
+
+        Mockito.verifyNoInteractions(logSpy);
+    }
+
     private void setupBasics(boolean fail) {
         mojo.setFail(fail);
         mojo.setSession(EnforcerTestUtils.getMavenSession());

Reply via email to