+ * Set to: {@code rulesets/java/quickstart.xml}
*/
public static final String RULE_SET_DEFAULT = "rulesets/java/quickstart.xml";
private static final Logger LOGGER = Logger.getLogger(PmdOperation.class.getName());
private static final String PMD_DIR = "pmd";
+ /**
+ * The list of paths to exclude.
+ */
+ private final Collection
@@ -155,10 +298,36 @@ public class PmdOperation extends AbstractOperation
+ * The built-in rule set paths are:
+ * The valid values are the standard character sets of {@link java.nio.charset.Charset Charset}. Specifies the character set encoding of the source code files. The default is
+ * {@link StandardCharsets#UTF_8 UTF-8}. The valid values are the standard character sets of {@link java.nio.charset.Charset Charset}.
+ * Default is: {@code true}
+ *
+ * Note: If only violations are found, see {@link #failOnViolation(boolean) failOnViolation}
+ *
+ * @param failOnError whether to exit and fail the build if recoverable errors occurred
+ * @return this operation
+ * @see #failOnViolation(boolean)
+ */
+ public PmdOperation failOnError(boolean failOnError) {
+ failOnError_ = failOnError;
+ return this;
+ }
+
+ /**
+ * Sets whether the build will continue on violations.
+ *
+ * Note: If additionally recoverable errors occurred, see {@link #failOnError(boolean) failOnError}
+ *
+ * @param failOnViolation whether to exit and fail the build if violations are found
+ * @return this operation
*/
public PmdOperation failOnViolation(boolean failOnViolation) {
- this.failOnViolation = failOnViolation;
+ failOnViolation_ = failOnViolation;
return this;
}
/**
* Forces a language to be used for all input files, irrespective of file names.
+ *
+ * @param languageVersion the language version
+ * @return this operation
*/
- public PmdOperation forceVersion(LanguageVersion languageVersion) {
- this.forcedLanguageVersion = languageVersion;
+ public PmdOperation forceLanguageVersion(LanguageVersion languageVersion) {
+ forcedLanguageVersion_ = languageVersion;
return this;
}
@@ -233,21 +550,58 @@ public class PmdOperation extends AbstractOperation
+ * While clicking on the URI works in IntelliJ IDEA, Visual Studio Code, etc.; it might not in terminal emulators.
+ *
+ * Default: {@code TRUE}
+ */
+ public PmdOperation includeLineNumber(boolean includeLineNumber) {
+ includeLineNumber_ = includeLineNumber;
return this;
}
@@ -255,114 +609,290 @@ public class PmdOperation extends AbstractOperation
+ * Previous entries are disregarded.
+ *
+ * @param inputPath one or more paths
+ * @return this operation
+ * @see #addInputPaths(File...)
+ */
+ public PmdOperation inputPaths(File... inputPath) {
+ return inputPathsFiles(List.of(inputPath));
+ }
+
+ /**
+ * Sets paths to source files, or directories containing source files to analyze.
+ *
+ * Previous entries are disregarded.
+ *
+ * @param inputPath one or more paths
+ * @return this operation
+ * @see #addInputPaths(String...)
+ */
+ public PmdOperation inputPaths(String... inputPath) {
+ return inputPathsStrings(List.of(inputPath));
+ }
+
+ /**
+ * Sets paths to source files, or directories containing source files to analyze.
+ *
+ * Previous entries are disregarded.
+ *
+ * @param inputPath a collection of input paths
+ * @return this operation
+ * @see #addInputPaths(Collection)
+ */
+ public PmdOperation inputPaths(Collection
+ * Previous entries are disregarded.
+ *
+ * @param inputPath a collection of input paths
+ * @return this operation
+ * @see #addInputPathsFiles(Collection)
+ */
+ public PmdOperation inputPathsFiles(Collection
+ * Previous entries are disregarded.
+ *
+ * @param inputPath a collection of input paths
+ * @return this operation
+ * @see #addInputPathsStrings(Collection)
+ */
+ public PmdOperation inputPathsStrings(Collection
+ * If the classpath String looks like a URL to a file (i.e. starts with {@code file://}) the file will be read with
+ * each line representing an entry on the classpath.
*
- * @see #addRelativizeRoot(Path...)
+ * @param classpath one or more classpath
+ * @return this operation
+ */
+ public PmdOperation prependAuxClasspath(String... classpath) {
+ prependClasspath_ = String.join(File.pathSeparator, classpath);
+ return this;
+ }
+
+ /**
+ * Returns the prepended classpath.
+ *
+ * @return the classpath
+ */
+ public String prependAuxClasspath() {
+ return prependClasspath_;
+ }
+
+ /**
+ * Adds several paths to shorten paths that are output in the report.
+ *
+ * @param relativeRoot one or more relative root paths
+ * @return this operation
+ * @see #relativizeRoots(Collection)
*/
public PmdOperation relativizeRoots(Path... relativeRoot) {
- this.relativizeRoots.clear();
- this.relativizeRoots.addAll(List.of(relativeRoot));
+ return relativizeRoots(List.of(relativeRoot));
+ }
+
+ /**
+ * Adds several paths to shorten paths that are output in the report.
+ *
+ * @param relativeRoot one or more relative root paths
+ * @return this operation
+ * @see #relativizeRootsFiles(Collection)
+ */
+ public PmdOperation relativizeRoots(File... relativeRoot) {
+ return relativizeRootsFiles(List.of(relativeRoot));
+ }
+
+ /**
+ * Adds several paths to shorten paths that are output in the report.
+ *
+ * @param relativeRoot one or more relative root paths
+ * @return this operation
+ * @see #relativizeRootsStrings(Collection)
+ */
+ public PmdOperation relativizeRoots(String... relativeRoot) {
+ return relativizeRootsStrings(List.of(relativeRoot));
+ }
+
+ /**
+ * Adds several paths to shorten paths that are output in the report.
+ *
+ * @param relativeRoot a collection of relative root paths
+ * @return this operation
+ * @see #relativizeRoots(Path...)
+ */
+ public PmdOperation relativizeRoots(Collection
* The built-in rule set paths are:
*
+ * The built-in rule set paths are:
+ *
+ *
+ *
+ * @param ruleSet a collection of rule set paths
+ * @return this operation
+ * @see #ruleSets(Collection)
+ */
+ public PmdOperation addRuleSet(Collection
@@ -413,43 +1087,90 @@ public class PmdOperation extends AbstractOperation
*
+ * @param ruleSet one or more rule set
+ * @return this operation
* @see #addRuleSet(String...)
*/
public PmdOperation ruleSets(String... ruleSet) {
- ruleSets.clear();
- ruleSets.addAll(Arrays.asList(ruleSet));
+ return ruleSets(List.of(ruleSet));
+ }
+
+ /**
+ * Sets new rule set paths, disregarding any previous entries.
+ *
+ *
+ *
+ * @param ruleSet a collection of rule set paths
+ * @return this operation
+ * @see #addRuleSet(Collection)
+ */
+ public PmdOperation ruleSets(Collection