Fixed exclude options to support multiple values

This commit is contained in:
Erik C. Thauvin 2024-04-29 03:46:25 -07:00
parent 42dd870408
commit 5d24b4060a
Signed by: erik
GPG key ID: 776702A6A2DA330E

View file

@ -32,6 +32,8 @@ import java.util.logging.Logger;
*/ */
public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOperation> { public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOperation> {
private static final Logger LOGGER = Logger.getLogger(CheckstyleOperation.class.getName()); private static final Logger LOGGER = Logger.getLogger(CheckstyleOperation.class.getName());
protected final List<String> exclude = new ArrayList<>();
protected final List<String> excludeRegex = new ArrayList<>();
/** /**
* The command line options. * The command line options.
*/ */
@ -97,7 +99,7 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
public CheckstyleOperation exclude(String... path) { public CheckstyleOperation exclude(String... path) {
for (var p : path) { for (var p : path) {
if (isNotBlank(p)) { if (isNotBlank(p)) {
options.put("-e", p); exclude.add(p);
} }
} }
return this; return this;
@ -107,29 +109,46 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
* Directory/file to exclude from CheckStyle. The path can be the full, absolute path, or relative to the current * Directory/file to exclude from CheckStyle. The path can be the full, absolute path, or relative to the current
* path. Multiple excludes are allowed. * path. Multiple excludes are allowed.
* *
* @param paths the list of paths * @param paths the paths
* @return the checkstyle operation * @return the checkstyle operation
* @see #exclude(String...) * @see #exclude(String...)
*/ */
public CheckstyleOperation exclude(Collection<String> paths) { public CheckstyleOperation exclude(Collection<String> paths) {
for (var p : paths) { for (var p : paths) {
if (isNotBlank(p)) { if (isNotBlank(p)) {
options.put("-e", p); exclude.add(p);
} }
} }
return this; return this;
} }
/** /**
* Directory/file pattern to exclude from CheckStyle. Multiple excludes are allowed. * Directory/file pattern to exclude from CheckStyle. Multiple exclude are allowed.
* *
* @param pattern the pattern * @param regex the pattern to exclude
* @return the checkstyle operation * @return the checkstyle operation
* @see #excludeRegex(Collection)
*/ */
public CheckstyleOperation excludedPathPattern(String pattern) { public CheckstyleOperation excludeRegex(String... regex) {
if (isNotBlank(pattern)) { for (var r : regex) {
options.put("-x", pattern); if (isNotBlank(r)) {
excludeRegex.add(r);
} }
return this;
/**
* Directory/file pattern to exclude from CheckStyle. Multiple exclude are allowed.
*
* @param regex the patterns to exclude
* @return the checkstyle operation
* @see #excludeRegex(String...)
*/
public CheckstyleOperation excludeRegex(Collection<String> regex) {
for (var r : regex) {
if (isNotBlank(r)) {
excludeRegex.add(r);
}
}
return this; return this;
} }
@ -162,6 +181,20 @@ public class CheckstyleOperation extends AbstractProcessOperation<CheckstyleOper
} }
}); });
if (!exclude.isEmpty()) {
for (var e : exclude) {
if (isNotBlank(e)) {
args.add("-e " + e);
}
}
}
if (!excludeRegex.isEmpty()) {
for (var e : excludeRegex) {
if (isNotBlank(e)) {
args.add("-x " + e);
}
}
}
args.addAll(sourceDirs); args.addAll(sourceDirs);
return args; return args;