Skip to content

Commit

Permalink
[MENFORCER-454] Log warning only if the '-Drules' is actually used
Browse files Browse the repository at this point in the history
 * the method gets called with empty list if there is no configuration,
   resulting in WARNing being printed every single time
  • Loading branch information
psiroky authored and slawekjaranowski committed Dec 29, 2022
1 parent 495818f commit db7fbd2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ public void setRulesToExecute(List<String> rulesToExecute) throws MojoExecutionE
@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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ void testShouldPrintWarnWhenUsingDeprecatedRulesProperty() throws MojoExecutionE
.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());
Expand Down

0 comments on commit db7fbd2

Please sign in to comment.