BREAKING: reworked excludes methods and added addExcludes methods

This commit is contained in:
Erik C. Thauvin 2025-02-01 12:47:55 -08:00
parent 25bce33323
commit af25b2f507
Signed by: erik
GPG key ID: 776702A6A2DA330E
2 changed files with 226 additions and 27 deletions

View file

@ -52,7 +52,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
/**
* The list of paths to exclude.
*/
private final List<Path> excludes_ = new ArrayList<>();
private final Collection<Path> excludes_ = new ArrayList<>();
/**
* The input paths (source) list.
*/
@ -142,6 +142,79 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
*/
private int threads_ = 1;
/**
* Adds paths to exclude from the analysis.
*
* @param excludes one or more paths to exclude
* @return this operation
* @see #excludes(Path...)
* @since 1.2.0
*/
public PmdOperation addExcludes(Path... excludes) {
return addExcludes(List.of(excludes));
}
/**
* Adds paths to exclude from the analysis.
*
* @param excludes paths to exclude
* @return this operation
* @see #excludes(Collection)
* @since 1.2.0
*/
public PmdOperation addExcludes(Collection<Path> excludes) {
excludes_.addAll(excludes);
return this;
}
/**
* Adds paths to exclude from the analysis.
*
* @param excludes one or more paths to exclude
* @return this operation
* @see #excludesFiles(Collection)
* @since 1.2.0
*/
public PmdOperation addExcludesFiles(Collection<File> excludes) {
return addExcludes(excludes.stream().map(File::toPath).toList());
}
/**
* Adds paths to exclude from the analysis.
*
* @param excludes one or more paths to exclude
* @return this operation
* @see #excludesFiles(File...)
* @since 1.2.0
*/
public PmdOperation addExcludesFiles(File... excludes) {
return addExcludesFiles(List.of(excludes));
}
/**
* Adds paths to exclude from the analysis.
*
* @param excludes one or more paths to exclude
* @return this operation
* @see #excludesStrings(Collection)
* @since 1.2.0
*/
public PmdOperation addExcludesStrings(Collection<String> excludes) {
return addExcludes(excludes.stream().map(Paths::get).toList());
}
/**
* Adds paths to exclude from the analysis.
*
* @param excludes one or more paths to exclude
* @return this operation
* @see #excludesStrings(String...)
* @since 1.2.0
*/
public PmdOperation addExcludesStrings(String... excludes) {
return addExcludesStrings(List.of(excludes));
}
/**
* Adds paths to source files, or directories containing source files to analyze.\
*
@ -322,23 +395,26 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
}
/**
* Adds paths to exclude from the analysis.
* Sets paths to exclude from the analysis.
*
* @param excludes one or more paths to exclude
* @return this operation
* @see #addExcludes(Path...)
*/
public PmdOperation excludes(Path... excludes) {
excludes_.addAll(List.of(excludes));
excludes(List.of(excludes));
return this;
}
/**
* Adds paths to exclude from the analysis.
* Sets paths to exclude from the analysis.
*
* @param excludes paths to exclude
* @return this operation
* @see #addExcludes(Collection)
*/
public PmdOperation excludes(Collection<Path> excludes) {
excludes_.clear();
excludes_.addAll(excludes);
return this;
}
@ -348,10 +424,60 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
*
* @return the exclude paths
*/
public List<Path> excludes() {
public Collection<Path> excludes() {
return excludes_;
}
/**
* Sets paths to exclude from the analysis.
*
* @param excludes one or more paths to exclude
* @return this operation
* @see #excludesFiles(Collection)
* @since 1.2.0
*/
public PmdOperation excludesFiles(Collection<File> excludes) {
excludes(excludes.stream().map(File::toPath).toList());
return this;
}
/**
* Sets paths to exclude from the analysis.
*
* @param excludes one or more paths to exclude
* @return this operation
* @see #excludesFiles(File...)
* @since 1.2.0
*/
public PmdOperation excludesFiles(File... excludes) {
return excludesFiles(List.of(excludes));
}
/**
* Sets paths to exclude from the analysis.
*
* @param excludes one or more paths to exclude
* @return this operation
* @see #excludesStrings(Collection)
* @since 1.2.0
*/
public PmdOperation excludesStrings(Collection<String> excludes) {
excludes(excludes.stream().map(Paths::get).toList());
return this;
}
/**
* Sets paths to exclude from the analysis.
*
* @param excludes one or more paths to exclude
* @return this operation
* @see #excludesStrings(String...)
* @since 1.2.0
*/
public PmdOperation excludesStrings(String... excludes) {
return excludesStrings(List.of(excludes));
}
/**
* Performs the PMD code analysis operation.
*/
@ -519,7 +645,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
// setExcludes
if (!excludes_.isEmpty()) {
config.setExcludes(excludes_);
config.setExcludes(excludes_.stream().toList());
}
// setFailOnError
@ -656,7 +782,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
*
* @param inputPath a collection of input paths
* @return this operation
* @see #addInputPathsFiles(Collection) )
* @see #addInputPathsFiles(Collection)
*/
public PmdOperation inputPathsFiles(Collection<File> inputPath) {
return inputPaths(inputPath.stream().map(File::toPath).toList());