* The built-in rule set paths are: *
* The built-in rule set paths are: *
Specifies the character set encoding of the source code files. The default is {@code UTF-8}.
* *The valid values are the standard character sets of {@link java.nio.charset.Charset Charset}.
*/ public PmdOperation encoding(String encoding) { encoding_ = Charset.forName(encoding); return this; } /** *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}.
*/ public PmdOperation encoding(Charset encoding) { encoding_ = encoding; return this; } /** * Performs the PMD code analysis operation. */ @Override public void execute() { if (project_ == null) { throw new IllegalArgumentException("ERROR: project required."); } var commandName = project_.getCurrentCommandName(); performPmdAnalysis(commandName, initConfiguration(commandName)); } /** * Sets whether the build will continue on warnings. */ public PmdOperation failOnViolation(boolean failOnViolation) { failOnViolation_ = failOnViolation; return this; } /** * Forces a language to be used for all input files, irrespective of file names. */ public PmdOperation forceVersion(LanguageVersion languageVersion) { forcedLanguageVersion_ = languageVersion; return this; } /** * Configures a PMD operation from a {@link BaseProject}. * ** The defaults are: *
* 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.
*/
public PmdOperation incrementalAnalysis(boolean incrementalAnalysis) {
incrementalAnalysis_ = incrementalAnalysis;
return this;
}
/**
* Creates a new initialized configuration.
*/
public PMDConfiguration initConfiguration(String commandName) {
PMDConfiguration config = new PMDConfiguration();
if (cache_ == null && project_ != null && incrementalAnalysis_) {
config.setAnalysisCacheLocation(
Paths.get(project_.buildDirectory().getPath(), PMD_DIR, PMD_DIR + "-cache").toFile().getAbsolutePath());
} else if (cache_ != null) {
config.setAnalysisCacheLocation(cache_.toFile().getAbsolutePath());
}
config.setFailOnViolation(failOnViolation_);
if (languageVersions_ != null) {
config.setDefaultLanguageVersions(languageVersions_);
}
if (forcedLanguageVersion_ != null) {
config.setForceLanguageVersion(forcedLanguageVersion_);
}
if (ignoreFile_ != null) {
config.setIgnoreFilePath(ignoreFile_);
}
config.setIgnoreIncrementalAnalysis(!incrementalAnalysis_);
if (inputPaths_.isEmpty()) {
throw new IllegalArgumentException(commandName + ": InputPaths required.");
} else {
config.setInputPathList(inputPaths_);
}
if (reportProperties_ != null) {
config.setReportProperties(reportProperties_);
}
if (inputUri_ != null) {
config.setInputUri(inputUri_);
}
config.setMinimumPriority(rulePriority_);
if (project_ != null) {
config.setReportFile(Objects.requireNonNullElseGet(reportFile_,
() -> Paths.get(project_.buildDirectory().getPath(),
PMD_DIR, PMD_DIR + "-report." + reportFormat_)));
} else {
config.setReportFile(reportFile_);
}
config.addRelativizeRoots(relativizeRoots_);
config.setReportFormat(reportFormat_);
config.setRuleSets(ruleSets_);
config.setShowSuppressedViolations(showSuppressed_);
config.setSourceEncoding(encoding_);
config.setSuppressMarker(suppressedMarker_);
config.setThreads(threads_);
return config;
}
/**
* Sets the to source files, or directories containing source files to analyze.
* Previously set paths will be disregarded.
*/
public PmdOperation inputPaths(Path... inputPath) {
inputPaths_.clear();
inputPaths_.addAll(List.of(inputPath));
return this;
}
/**
* Sets the to source files, or directories containing source files to analyze.
* Previously set paths will be disregarded.
*/
public PmdOperation inputPaths(Collection
* The built-in rule set paths are:
*
* The built-in rule set paths are:
*
*
*/
public PmdOperation ruleSets(String... ruleSet) {
ruleSets_.clear();
ruleSets_.addAll(Arrays.asList(ruleSet));
return this;
}
/**
* Sets the rule set path(s), disregarding any previously set paths.
*
*
*/
public PmdOperation ruleSets(Collection