Add support for the new generate checks and file suppression option

This commit is contained in:
Erik C. Thauvin 2025-05-22 09:28:46 -07:00
parent f063889778
commit def9be96f1
Signed by: erik
GPG key ID: 776702A6A2DA330E
3 changed files with 29 additions and 0 deletions

View file

@ -314,6 +314,25 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
return this;
}
/**
* Generates to output a suppression xml that will have suppress elements with {@code checks} and {@code files}
* attributes only to use to suppress all violations from user's config. Instead of printing every violation, all
* violations will be catched and single suppressions xml file will be printed out. Used only with the
* {@link #configurationFile(String) configurationFile} option. Output location can be
* specified with the {@link #outputPath(String) output} option.
*
* @param generateChecksAndFileSuppression {@code true} or {@code false}
* @return the checkstyle operation
*/
public CheckstyleOperation generateChecksAndFileSuppression(boolean generateChecksAndFileSuppression) {
if (generateChecksAndFileSuppression) {
options_.put("-G", "");
} else {
options_.remove("-G");
}
return this;
}
/**
* Generates to output a suppression xml to use to suppress all violations from user's config. Instead of printing
* every violation, all violations will be caught and single suppressions xml file will be printed out.

View file

@ -235,6 +235,7 @@ class CheckstyleOperationTest {
.executeIgnoredModules(true)
.format(OutputFormat.XML)
.generateXpathSuppression(true)
.generateChecksAndFileSuppression(true)
.javadocTree(true)
.outputPath(new File("optionPath"))
.propertiesFile(new File("properties"))
@ -279,6 +280,14 @@ class CheckstyleOperationTest {
assertThat(op.options().get("-f")).isEqualTo("xml");
}
@Test
void generateChecksAndFileSuppression() {
var op = newCheckstyleOperation().generateChecksAndFileSuppression(true);
assertThat(op.options().containsKey("-G")).as(ADD).isTrue();
op = op.generateChecksAndFileSuppression(false);
assertThat(op.options().containsKey("-G")).as(REMOVE).isFalse();
}
@Test
void generateXpathSuppression() {
var op = newCheckstyleOperation().generateXpathSuppression(true);

View file

@ -5,6 +5,7 @@
-E
-f
-g
-G
-j
-J
-o