- * 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";
- private final Collection 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
+ * Sets whether the build will continue on warnings.
*/
public PmdOperation failOnViolation(boolean failOnViolation) {
failOnViolation_ = failOnViolation;
@@ -476,11 +244,8 @@ 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;
- }
-
/**
* Enables or disables incremental analysis.
*/
@@ -566,27 +294,10 @@ 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.
+ * Sets several paths to shorten paths that are output in the report. Previous relative paths will be disregarded.
*
- * @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_;
- }
-
- private void printViolations(String commandName, PMDConfiguration config, Report report)
- throws ExitStatusException {
- for (var v : report.getViolations()) {
- if (LOGGER.isLoggable(Level.WARNING) && !silent()) {
- final String msg;
- if (includeLineNumber_) {
- msg = "[%s] %s:%d\n\t%s (%s)\n\t\t--> %s";
- } else {
- msg = "[%s] %s (line: %d)\n\t%s (%s)\n\t\t--> %s";
- }
- LOGGER.log(Level.WARNING,
- String.format(msg,
- commandName,
- v.getFileId().getUriString(),
- v.getBeginLine(),
- v.getRule().getName(),
- v.getRule().getExternalInfoUrl(),
- v.getDescription()));
- }
- }
-
- var violations = new StringBuilder(
- String.format("[%s] %d rule violations were found.", commandName, report.getViolations().size()));
-
- if (config.getReportFilePath() != null) {
- violations.append(" See the report at: ").append(config.getReportFilePath().toUri());
- }
-
- if (config.isFailOnViolation()) {
- if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
- LOGGER.log(Level.SEVERE, violations.toString());
- }
- throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
- } else if (LOGGER.isLoggable(Level.WARNING) && !silent()) {
- LOGGER.warning(violations.toString());
- }
- }
-
- /**
- * 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)
+ * @see #addRelativizeRoot(Path...)
*/
public PmdOperation relativizeRoots(Path... 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:
*
@@ -1084,16 +448,16 @@ public class PmdOperation extends AbstractOperation
*
- * @param ruleSet one or more rule set
- * @return this operation
* @see #addRuleSet(String...)
*/
public PmdOperation ruleSets(String... ruleSet) {
- return ruleSets(List.of(ruleSet));
+ ruleSets_.clear();
+ ruleSets_.addAll(Arrays.asList(ruleSet));
+ return this;
}
/**
- * Sets new rule set paths, disregarding any previous entries.
+ * Sets the rule set path(s), disregarding any previously set paths.
*
@@ -1108,30 +472,16 @@ public class PmdOperation extends AbstractOperation
*
- * @param ruleSet a collection of rule set paths
- * @return this operation
* @see #addRuleSet(Collection)
*/
- public PmdOperation ruleSets(Collection