inputPath) {
- return addInputPaths(inputPath.stream().map(Paths::get).toList());
- }
-
/**
* Adds new rule set paths.
*
@@ -303,7 +203,8 @@ public class PmdOperation extends AbstractOperation {
* @see #ruleSets(String...)
*/
public PmdOperation addRuleSet(String... ruleSet) {
- return addRuleSet(List.of(ruleSet));
+ ruleSets_.addAll(List.of(ruleSet));
+ return this;
}
/**
@@ -324,7 +225,7 @@ public class PmdOperation extends AbstractOperation {
*
* @param ruleSet a collection of rule set paths
* @return this operation
- * @see #ruleSets(Collection)
+ * @see #ruleSets(Collection
*/
public PmdOperation addRuleSet(Collection ruleSet) {
ruleSets_.addAll(ruleSet);
@@ -339,20 +240,6 @@ public class PmdOperation extends AbstractOperation {
return this;
}
- /**
- * Sets the location of the cache file for incremental analysis.
- */
- public PmdOperation cache(File cache) {
- return cache(cache.toPath());
- }
-
- /**
- * Sets the location of the cache file for incremental analysis.
- */
- public PmdOperation cache(String cache) {
- return cache(Path.of(cache));
- }
-
/**
* Sets the default language version to be used for all input files.
*
@@ -360,7 +247,8 @@ public class PmdOperation extends AbstractOperation {
* @return this operation
*/
public PmdOperation defaultLanguageVersions(LanguageVersion... languageVersion) {
- return languageVersions(List.of(languageVersion));
+ languageVersions_.addAll(List.of(languageVersion));
+ return this;
}
/**
@@ -380,7 +268,8 @@ public class PmdOperation extends AbstractOperation {
* The valid values are the standard character sets of {@link java.nio.charset.Charset Charset}.
*/
public PmdOperation encoding(String encoding) {
- return encoding(Charset.forName(encoding));
+ encoding_ = Charset.forName(encoding);
+ return this;
}
/**
@@ -394,90 +283,6 @@ public class PmdOperation extends AbstractOperation {
return this;
}
- /**
- * 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(List.of(excludes));
- return this;
- }
-
- /**
- * Sets paths to exclude from the analysis.
- *
- * @param excludes paths to exclude
- * @return this operation
- * @see #addExcludes(Collection)
- */
- public PmdOperation excludes(Collection excludes) {
- excludes_.clear();
- excludes_.addAll(excludes);
- return this;
- }
-
- /**
- * Returns the paths to exclude from the analysis.
- *
- * @return the exclude paths
- */
- public Collection 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 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 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.
*/
@@ -580,7 +385,8 @@ public class PmdOperation extends AbstractOperation {
* @return this operation
*/
public PmdOperation ignoreFile(File ignoreFile) {
- return ignoreFile(ignoreFile.toPath());
+ ignoreFile_ = ignoreFile.toPath();
+ return this;
}
/**
@@ -590,7 +396,8 @@ public class PmdOperation extends AbstractOperation {
* @return this operation
*/
public PmdOperation ignoreFile(String ignoreFile) {
- return ignoreFile(Path.of(ignoreFile));
+ ignoreFile_ = Paths.get(ignoreFile);
+ return this;
}
/**
@@ -620,17 +427,8 @@ public class PmdOperation extends AbstractOperation {
* @return this operation
*/
public PMDConfiguration initConfiguration(String commandName) {
- var config = new PMDConfiguration();
+ PMDConfiguration config = new PMDConfiguration();
- // addRelativizeRoots
- config.addRelativizeRoots(relativizeRoots_.stream().toList());
-
- // prependAuxClasspath
- if (prependClasspath_ != null) {
- config.prependAuxClasspath(prependClasspath_);
- }
-
- // setAnalysisCacheLocation
if (cache_ == null && project_ != null && incrementalAnalysis_) {
config.setAnalysisCacheLocation(
Paths.get(project_.buildDirectory().getPath(), PMD_DIR, PMD_DIR + "-cache").toFile().getAbsolutePath());
@@ -638,50 +436,38 @@ public class PmdOperation extends AbstractOperation {
config.setAnalysisCacheLocation(cache_.toFile().getAbsolutePath());
}
- // setDefaultLanguageVersions
+ config.setFailOnError(failOnError_);
+ config.setFailOnViolation(failOnViolation_);
+
if (languageVersions_ != null) {
config.setDefaultLanguageVersions(languageVersions_.stream().toList());
}
- // setExcludes
- if (!excludes_.isEmpty()) {
- config.setExcludes(excludes_.stream().toList());
- }
-
- // setFailOnError
- config.setFailOnError(failOnError_);
- // setFailOnViolation
- config.setFailOnViolation(failOnViolation_);
-
- // setForceLanguageVersion
if (forcedLanguageVersion_ != null) {
config.setForceLanguageVersion(forcedLanguageVersion_);
}
- // setIgnoreFilePath
if (ignoreFile_ != null) {
config.setIgnoreFilePath(ignoreFile_);
}
- // setIgnoreIncrementalAnalysis
config.setIgnoreIncrementalAnalysis(!incrementalAnalysis_);
- // setInputPathList
if (inputPaths_.isEmpty()) {
throw new IllegalArgumentException(commandName + ": InputPaths required.");
} else {
config.setInputPathList(inputPaths_.stream().toList());
}
+ if (reportProperties_ != null) {
+ config.setReportProperties(reportProperties_);
+ }
- // setInputUri
if (inputUri_ != null) {
config.setInputUri(inputUri_);
}
- // setMinimumPriority
config.setMinimumPriority(rulePriority_);
- // setReportFile
if (project_ != null) {
config.setReportFile(Objects.requireNonNullElseGet(reportFile_,
() -> Paths.get(project_.buildDirectory().getPath(),
@@ -690,25 +476,12 @@ public class PmdOperation extends AbstractOperation {
config.setReportFile(reportFile_);
}
- // setReportFormat
+ config.addRelativizeRoots(relativizeRoots_.stream().toList());
config.setReportFormat(reportFormat_);
-
- // setReportProperties
- if (reportProperties_ != null) {
- config.setReportProperties(reportProperties_);
- }
-
- // setRuleSets
config.setRuleSets(ruleSets_.stream().toList());
-
- // setShowSuppressedViolations
config.setShowSuppressedViolations(showSuppressed_);
- // setSourceEncoding
config.setSourceEncoding(encoding_);
- // setSuppressMarker
config.setSuppressMarker(suppressedMarker_);
-
- // setThreads
config.setThreads(threads_);
return config;
@@ -722,7 +495,9 @@ public class PmdOperation extends AbstractOperation {
* @see #addInputPaths(Path...)
*/
public PmdOperation inputPaths(Path... inputPath) {
- return inputPaths(List.of(inputPath));
+ inputPaths_.clear();
+ inputPaths_.addAll(List.of(inputPath));
+ return this;
}
/**
@@ -735,7 +510,9 @@ public class PmdOperation extends AbstractOperation {
* @see #addInputPaths(File...)
*/
public PmdOperation inputPaths(File... inputPath) {
- return inputPathsFiles(List.of(inputPath));
+ inputPaths_.clear();
+ inputPaths_.addAll(Arrays.stream(inputPath).map(File::toPath).toList());
+ return this;
}
/**
@@ -748,7 +525,9 @@ public class PmdOperation extends AbstractOperation {
* @see #addInputPaths(String...)
*/
public PmdOperation inputPaths(String... inputPath) {
- return inputPathsStrings(List.of(inputPath));
+ inputPaths_.clear();
+ inputPaths_.addAll(Arrays.stream(inputPath).map(Paths::get).toList());
+ return this;
}
/**
@@ -775,32 +554,6 @@ public class PmdOperation extends AbstractOperation {
return inputPaths_;
}
- /**
- * 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 #addInputPathsFiles(Collection)
- */
- public PmdOperation inputPathsFiles(Collection inputPath) {
- return inputPaths(inputPath.stream().map(File::toPath).toList());
- }
-
- /**
- * 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 #addInputPathsStrings(Collection)
- */
- public PmdOperation inputPathsStrings(Collection inputPath) {
- return inputPaths(inputPath.stream().map(Paths::get).toList());
- }
-
/**
* Sets the default language versions.
*
@@ -808,7 +561,8 @@ public class PmdOperation extends AbstractOperation {
* @return this operation
*/
public PmdOperation languageVersions(LanguageVersion... languageVersion) {
- return languageVersions(List.of(languageVersion));
+ languageVersions_.addAll(List.of(languageVersion));
+ return this;
}
/**
@@ -909,69 +663,43 @@ public class PmdOperation extends AbstractOperation {
}
/**
- * Prepend the specified classpath like string to the current ClassLoader of the configuration. If no ClassLoader
- * is currently configured, the ClassLoader used to load the PMDConfiguration class will be used as the parent
- * ClassLoader of the created ClassLoader.
- *
- * 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.
+ * Adds several paths to shorten paths that are output in the report.
*
- * @param classpath one or more classpath
- * @return this operation
+ * @param relativeRoot one or more relative root paths
+ * @return this operations
*/
- public PmdOperation prependAuxClasspath(String... classpath) {
- prependClasspath_ = String.join(File.pathSeparator, classpath);
+ public PmdOperation relativizeRoots(Path... relativeRoot) {
+ relativizeRoots_.addAll(List.of(relativeRoot));
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) {
- 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)
+ * @return this operations
*/
public PmdOperation relativizeRoots(File... relativeRoot) {
- return relativizeRootsFiles(List.of(relativeRoot));
+ relativizeRoots_.addAll(Arrays.stream(relativeRoot).map(File::toPath).toList());
+ return this;
}
/**
* 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)
+ * @return this operations
*/
public PmdOperation relativizeRoots(String... relativeRoot) {
- return relativizeRootsStrings(List.of(relativeRoot));
+ relativizeRoots_.addAll(Arrays.stream(relativeRoot).map(Paths::get).toList());
+ return this;
}
/**
* 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...)
+ * @return this operations
*/
public PmdOperation relativizeRoots(Collection relativeRoot) {
relativizeRoots_.addAll(relativeRoot);
@@ -987,28 +715,6 @@ public class PmdOperation extends AbstractOperation {
return relativizeRoots_;
}
- /**
- * 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(File...)
- */
- public PmdOperation relativizeRootsFiles(Collection relativeRoot) {
- return relativizeRoots(relativeRoot.stream().map(File::toPath).toList());
- }
-
- /**
- * 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(String...)
- */
- public PmdOperation relativizeRootsStrings(Collection relativeRoot) {
- return relativizeRoots(relativeRoot.stream().map(Paths::get).toList());
- }
-
/**
* Sets the path to the report page.
*
@@ -1027,7 +733,8 @@ public class PmdOperation extends AbstractOperation {
* @return this operation
*/
public PmdOperation reportFile(File reportFile) {
- return reportFile(reportFile.toPath());
+ reportFile_ = reportFile.toPath();
+ return this;
}
/**
@@ -1037,7 +744,8 @@ public class PmdOperation extends AbstractOperation {
* @return this operation
*/
public PmdOperation reportFile(String reportFile) {
- return reportFile(Paths.get(reportFile));
+ reportFile_ = Paths.get(reportFile);
+ return this;
}
/**
@@ -1092,7 +800,9 @@ public class PmdOperation extends AbstractOperation {
* @see #addRuleSet(String...)
*/
public PmdOperation ruleSets(String... ruleSet) {
- return ruleSets(List.of(ruleSet));
+ ruleSets_.clear();
+ ruleSets_.addAll(List.of(ruleSet));
+ return this;
}
/**
diff --git a/src/test/java/rife/bld/extension/PmdOperationTest.java b/src/test/java/rife/bld/extension/PmdOperationTest.java
index 77321d6..6d042a7 100644
--- a/src/test/java/rife/bld/extension/PmdOperationTest.java
+++ b/src/test/java/rife/bld/extension/PmdOperationTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2023-2025 the original author or authors.
+ * Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,7 +19,6 @@ package rife.bld.extension;
import net.sourceforge.pmd.PMDConfiguration;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.rule.RulePriority;
-import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.junit.jupiter.api.Test;
import rife.bld.BaseProject;
import rife.bld.operations.exceptions.ExitStatusException;
@@ -47,7 +46,6 @@ import static org.assertj.core.api.Assertions.assertThatCode;
* @since 1.0
*/
class PmdOperationTest {
- static final String BAR = "bar";
static final String CATEGORY_FOO = "category/foo.xml";
static final Path CODE_STYLE_SAMPLE = Path.of("src/test/resources/java/CodeStyle.java");
static final String CODE_STYLE_XML = "category/java/codestyle.xml";
@@ -56,11 +54,6 @@ class PmdOperationTest {
static final String DOCUMENTATION_XML = "category/java/documentation.xml";
static final Path ERROR_PRONE_SAMPLE = Path.of("src/test/resources/java/ErrorProne.java");
static final String ERROR_PRONE_XML = "category/java/errorprone.xml";
- static final File FILE_BAR = new File(BAR);
- static final String FOO = "foo";
- static final File FILE_FOO = new File(FOO);
- static final Path PATH_BAR = Path.of(BAR);
- static final Path PATH_FOO = Path.of(FOO);
static final String PERFORMANCE_XML = "category/java/performance.xml";
static final String SECURITY_XML = "category/java/security.xml";
static final String TEST = "test";
@@ -68,46 +61,13 @@ class PmdOperationTest {
PmdOperation newPmdOperation() {
return new PmdOperation()
.inputPaths(Path.of("src/main"), Path.of("src/test"))
- .cache("build/" + COMMAND_NAME + "/pmd-cache")
+ .cache(Paths.get("build", COMMAND_NAME, "pmd-cache"))
.failOnViolation(false)
.reportFile(Paths.get("build", COMMAND_NAME, "pmd-test-report.txt"));
}
@Test
- void testAddExcludes() {
- var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).addExcludes(PATH_FOO);
- var config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getExcludes()).containsExactly(PATH_FOO);
-
- pmd = pmd.addExcludes(PATH_BAR);
- config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getExcludes()).containsExactly(PATH_FOO, PATH_BAR);
- }
-
- @Test
- void testAddExcludesFiles() {
- var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).addExcludesFiles(FILE_FOO);
- var config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getExcludes()).containsExactly(FILE_FOO.toPath());
-
- pmd = pmd.addExcludesFiles(FILE_BAR);
- config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getExcludes()).containsExactly(FILE_FOO.toPath(), FILE_BAR.toPath());
- }
-
- @Test
- void testAddExcludesStrings() {
- var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).addExcludesStrings(FOO);
- var config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getExcludes()).containsExactly(PATH_FOO);
-
- pmd = pmd.addExcludesStrings(BAR);
- config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getExcludes()).containsExactly(PATH_FOO, PATH_BAR);
- }
-
- @Test
- void testAddInputPaths() throws ExitStatusException {
+ void testAddInputPath() throws ExitStatusException {
var project = new BaseProject();
var pmd = new PmdOperation().fromProject(project);
@@ -117,42 +77,22 @@ class PmdOperationTest {
var err = pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME));
pmd.inputPaths().clear();
- pmd = pmd.addInputPaths(project.srcMainDirectory(), project.srcTestDirectory());
+ pmd.addInputPaths(project.srcMainDirectory());
- assertThat(pmd.inputPaths()).as("File...").containsExactly(project.srcMainDirectory().toPath(),
+ assertThat(pmd.inputPaths()).as("main").containsExactly(project.srcMainDirectory().toPath());
+
+ pmd.inputPaths().clear();
+ pmd.addInputPaths(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
+
+ assertThat(pmd.inputPaths()).as("toPath(main, test)").containsExactly(project.srcMainDirectory().toPath(),
project.srcTestDirectory().toPath());
pmd.inputPaths().clear();
- pmd = pmd.addInputPathsFiles(List.of(project.srcMainDirectory(), project.srcTestDirectory()));
+ pmd.addInputPaths(List.of(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath()));
- assertThat(pmd.inputPaths()).as("List(File...)")
- .containsExactly(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
-
- pmd.inputPaths().clear();
- pmd = pmd.addInputPaths(project.srcMainDirectory().getAbsolutePath(),
- project.srcTestDirectory().getAbsolutePath());
-
- assertThat(pmd.inputPaths()).as("String...")
- .containsExactly(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
-
- pmd.inputPaths().clear();
- pmd = pmd.addInputPathsStrings(
- List.of(project.srcMainDirectory().getAbsolutePath(), project.srcTestDirectory().getAbsolutePath()));
-
- assertThat(pmd.inputPaths()).as("List(String...)")
- .containsExactly(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
-
- pmd.inputPaths().clear();
- pmd = pmd.addInputPaths(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
-
- assertThat(pmd.inputPaths()).as("Path...")
- .containsExactly(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
-
- pmd.inputPaths().clear();
- pmd = pmd.addInputPaths(List.of(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath()));
-
- assertThat(pmd.inputPaths()).as("List(Path)")
- .containsExactly(project.srcMainDirectory().toPath(), project.srcTestDirectory().toPath());
+ assertThat(pmd.inputPaths()).as("List(main, test)").containsExactly(
+ project.srcMainDirectory().toPath(),
+ project.srcTestDirectory().toPath());
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
.isGreaterThan(0).isEqualTo(err);
@@ -184,10 +124,7 @@ class PmdOperationTest {
@Test
void testCache() throws ExitStatusException {
var cache = Path.of("build/pmd/temp-cache");
- var pmd = newPmdOperation()
- .ruleSets(CODE_STYLE_XML)
- .inputPaths(List.of(CODE_STYLE_SAMPLE))
- .cache(cache);
+ var pmd = newPmdOperation().ruleSets(CODE_STYLE_XML).inputPaths(List.of(CODE_STYLE_SAMPLE)).cache(cache);
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
var f = cache.toFile();
assertThat(f.exists()).as("file exits").isTrue();
@@ -205,59 +142,6 @@ class PmdOperationTest {
assertThat(config.getSourceEncoding()).as("ISO_8859").isEqualTo(StandardCharsets.ISO_8859_1);
}
- @Test
- void testExcludes() {
- var foz = Path.of("foz/baz");
- var baz = Path.of("baz/foz");
-
- var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludes(PATH_FOO, PATH_BAR);
- var config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(pmd.excludes()).containsExactly(List.of(PATH_FOO, PATH_BAR).toArray(new Path[0]));
- assertThat(config.getExcludes()).containsExactly(List.of(PATH_FOO, PATH_BAR).toArray(new Path[0]));
-
- var excludes = List.of(List.of(PATH_FOO, PATH_BAR), List.of(foz, baz));
- for (var exclude : excludes) {
- pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludes(exclude);
- config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getExcludes()).containsExactly(exclude.toArray(new Path[0]));
- }
- }
-
- @Test
- void testExcludesFiles() {
- var foz = new File("foz");
- var baz = new File("baz");
-
- var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludesFiles(FILE_FOO, FILE_BAR);
- var config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getExcludes()).containsExactly(FILE_FOO.toPath(), FILE_BAR.toPath());
-
- var excludes = List.of(List.of(FILE_FOO, FILE_BAR), List.of(foz, baz));
- for (var exclude : excludes) {
- pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludesFiles(exclude);
- config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getExcludes()).containsExactly(exclude.stream().map(File::toPath).toArray(Path[]::new));
- }
- }
-
- @Test
- void testExcludesStrings() {
- var foz = "foz";
- var baz = "baz";
-
- var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludesStrings(FOO, BAR);
- var config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(pmd.excludes()).containsExactly(PATH_FOO, PATH_BAR);
- assertThat(config.getExcludes()).containsExactly(PATH_FOO, PATH_BAR);
-
- var excludes = List.of(List.of(FOO, BAR), List.of(foz, baz));
- for (var exclude : excludes) {
- pmd = newPmdOperation().ruleSets(CATEGORY_FOO).excludesStrings(exclude);
- config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getExcludes()).containsExactly(exclude.stream().map(Paths::get).toArray(Path[]::new));
- }
- }
-
@Test
void testExecute() throws ExitStatusException {
var pmd = new PmdOperation().fromProject(new BaseProject());
@@ -329,31 +213,7 @@ class PmdOperationTest {
var pmd = newPmdOperation()
.ruleSets(PmdOperation.RULE_SET_DEFAULT, CODE_STYLE_XML)
.inputPaths(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
- assertThat(pmd.inputPaths()).as("Path....").containsExactly(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
- assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
-
- pmd = newPmdOperation()
- .ruleSets(PmdOperation.RULE_SET_DEFAULT, CODE_STYLE_XML)
- .inputPaths(ERROR_PRONE_SAMPLE.toFile(), CODE_STYLE_SAMPLE.toFile());
- assertThat(pmd.inputPaths()).as("File...").containsExactly(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
- assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
-
- pmd = newPmdOperation()
- .ruleSets(PmdOperation.RULE_SET_DEFAULT, CODE_STYLE_XML)
- .inputPaths(ERROR_PRONE_SAMPLE.toString(), CODE_STYLE_SAMPLE.toString());
- assertThat(pmd.inputPaths()).as("String...").containsExactly(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
- assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
-
- pmd = newPmdOperation()
- .ruleSets(PmdOperation.RULE_SET_DEFAULT, CODE_STYLE_XML)
- .inputPathsFiles(List.of(ERROR_PRONE_SAMPLE.toFile(), CODE_STYLE_SAMPLE.toFile()));
- assertThat(pmd.inputPaths()).as("List(Path...)").containsExactly(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
- assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
-
- pmd = newPmdOperation()
- .ruleSets(PmdOperation.RULE_SET_DEFAULT, CODE_STYLE_XML)
- .inputPathsStrings(List.of(ERROR_PRONE_SAMPLE.toString(), CODE_STYLE_SAMPLE.toString()));
- assertThat(pmd.inputPaths()).as("List(String...)").containsExactly(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
+ assertThat(pmd.inputPaths()).contains(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
}
@@ -375,7 +235,6 @@ class PmdOperationTest {
var pmd = newPmdOperation().ruleSets(CODE_STYLE_XML).inputPaths(CODE_STYLE_SAMPLE);
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
.as("code style").isGreaterThan(0);
-
pmd = pmd.ruleSets(ERROR_PRONE_XML).inputPaths(ERROR_PRONE_SAMPLE);
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
.as("code style + error prone").isGreaterThan(0);
@@ -386,7 +245,7 @@ class PmdOperationTest {
var pmd = newPmdOperation()
.ruleSets(DESIGN_XML)
.inputPaths("src/test/resources/java/Design.java")
- .cache(new File("build/pmd/design-cache"));
+ .cache(Path.of("build/pmd/design-cache"));
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
}
@@ -442,7 +301,7 @@ class PmdOperationTest {
var pmd = newPmdOperation()
.forceLanguageVersion(language.getLatestVersion())
.defaultLanguageVersions(language.getVersions())
- .languageVersions(language.getDefaultVersion())
+ .languageVersions(language.getVersion("22"))
.ruleSets(PmdOperation.RULE_SET_DEFAULT);
assertThat(pmd.languageVersions()).contains(language.getDefaultVersion());
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
@@ -460,12 +319,6 @@ class PmdOperationTest {
assertThat(pmd).isEqualTo(0);
}
- @Test
- void testPrependAuxClasspath() {
- var pmd = newPmdOperation().ruleSets(CATEGORY_FOO).prependAuxClasspath(FOO, BAR);
- assertThat(pmd.prependAuxClasspath()).isEqualTo(FOO + File.pathSeparator + BAR);
- }
-
@Test
void testPriority() throws ExitStatusException {
var pmd = newPmdOperation().inputPaths(CODE_STYLE_SAMPLE).minimumPriority(RulePriority.HIGH);
@@ -474,26 +327,15 @@ class PmdOperationTest {
@Test
void testRelativizeRoots() {
+ var foo = Path.of("foo/bar");
+ var bar = Path.of("bar/foo");
var baz = Path.of("baz/foz");
- var pmd = newPmdOperation().ruleSets(List.of(CATEGORY_FOO)).relativizeRoots(PATH_FOO).
- relativizeRoots(PATH_BAR.toFile()).relativizeRoots(baz.toString())
- .relativizeRoots(List.of(PATH_FOO, PATH_BAR, baz));
+ var pmd = newPmdOperation().ruleSets(List.of(CATEGORY_FOO)).relativizeRoots(foo).relativizeRoots(bar.toFile())
+ .relativizeRoots(baz.toString()).relativizeRoots(List.of(foo, bar, baz));
var config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getRelativizeRoots()).isEqualTo(pmd.relativizeRoots())
- .containsExactly(PATH_FOO, PATH_BAR, baz, PATH_FOO, PATH_BAR, baz);
-
- pmd = newPmdOperation().ruleSets(List.of(CATEGORY_FOO))
- .relativizeRootsFiles(List.of(PATH_FOO.toFile(), PATH_BAR.toFile(), baz.toFile()));
- config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getRelativizeRoots()).as("List(File...)").isEqualTo(pmd.relativizeRoots())
- .containsExactly(PATH_FOO, PATH_BAR, baz);
-
- pmd = newPmdOperation().ruleSets(List.of(CATEGORY_FOO))
- .relativizeRootsStrings(List.of(PATH_FOO.toString(), PATH_BAR.toString(), baz.toString()));
- config = pmd.initConfiguration(COMMAND_NAME);
- assertThat(config.getRelativizeRoots()).as("List(String....)").isEqualTo(pmd.relativizeRoots())
- .containsExactly(PATH_FOO, PATH_BAR, baz);
+ assertThat(config.getRelativizeRoots()).isEqualTo(pmd.relativizeRoots());
+ assertThat(config.getRelativizeRoots()).containsExactly(foo, bar, baz, foo, bar, baz);
}
@Test
@@ -517,11 +359,8 @@ class PmdOperationTest {
void testReportFormat() throws IOException, ExitStatusException {
var pmd = newPmdOperation().ruleSets(ERROR_PRONE_XML).reportFormat("xml").inputPaths(ERROR_PRONE_SAMPLE);
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
- try (var softly = new AutoCloseableSoftAssertions()) {
- try (var br = Files.newBufferedReader(pmd.reportFile())) {
- softly.assertThat(br.readLine()).as("xml report")
- .startsWith("");
- }
+ try (var br = Files.newBufferedReader(pmd.reportFile())) {
+ assertThat(br.readLine()).as("xml report").startsWith("");
}
}