Compare commits
No commits in common. "03fd552702ad05279a9212f937ba60153630fd2e" and "af395dd69b52c21cda09a598cd97d6ec5836dbf7" have entirely different histories.
03fd552702
...
af395dd69b
3 changed files with 40 additions and 51 deletions
|
@ -32,7 +32,7 @@ public class PmdOperationBuild extends Project {
|
|||
public PmdOperationBuild() {
|
||||
pkg = "rife.bld.extension";
|
||||
name = "bld-pmd";
|
||||
version = version(1, 1, 1);
|
||||
version = version(1, 1, 0);
|
||||
|
||||
javaRelease = 17;
|
||||
|
||||
|
@ -48,8 +48,8 @@ public class PmdOperationBuild extends Project {
|
|||
.include(dependency("net.sourceforge.pmd", "pmd-java", pmd))
|
||||
.include(dependency("org.slf4j", "slf4j-simple", version(2, 0, 13)));
|
||||
scope(test)
|
||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 3)))
|
||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 3)))
|
||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 2)))
|
||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 2)))
|
||||
.include(dependency("org.assertj", "assertj-core", version(3, 26, 0)));
|
||||
|
||||
javadocOperation()
|
||||
|
|
|
@ -22,7 +22,6 @@ import net.sourceforge.pmd.lang.LanguageVersion;
|
|||
import net.sourceforge.pmd.lang.rule.RulePriority;
|
||||
import rife.bld.BaseProject;
|
||||
import rife.bld.operations.AbstractOperation;
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
|
@ -283,12 +282,9 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
|||
* Performs the PMD code analysis operation.
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws Exception {
|
||||
public void execute() {
|
||||
if (project_ == null) {
|
||||
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||
LOGGER.log(Level.SEVERE, "A project is required to run this operation.");
|
||||
}
|
||||
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||
throw new IllegalArgumentException("ERROR: project required.");
|
||||
}
|
||||
|
||||
var commandName = project_.getCurrentCommandName();
|
||||
|
@ -578,17 +574,17 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
|||
* @throws RuntimeException if an error occurs
|
||||
*/
|
||||
@SuppressWarnings({"PMD.CloseResource", "PMD.AvoidInstantiatingObjectsInLoops"})
|
||||
public int performPmdAnalysis(String commandName, PMDConfiguration config) throws ExitStatusException {
|
||||
public int performPmdAnalysis(String commandName, PMDConfiguration config) throws RuntimeException {
|
||||
var pmd = PmdAnalysis.create(config);
|
||||
var report = pmd.performAnalysisAndCollectReport();
|
||||
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
||||
if (LOGGER.isLoggable(Level.INFO)) {
|
||||
LOGGER.log(Level.INFO, "[{0}] inputPaths{1}", new Object[]{commandName, inputPaths_});
|
||||
LOGGER.log(Level.INFO, "[{0}] ruleSets{1}", new Object[]{commandName, ruleSets_});
|
||||
}
|
||||
var numErrors = report.getViolations().size();
|
||||
if (numErrors > 0) {
|
||||
for (var v : report.getViolations()) {
|
||||
if (LOGGER.isLoggable(Level.WARNING) && !silent()) {
|
||||
if (LOGGER.isLoggable(Level.WARNING)) {
|
||||
final String msg;
|
||||
if (includeLineNumber_) {
|
||||
msg = "[{0}] {1}:{2}\n\t{3} ({4})\n\t\t--> {5}";
|
||||
|
@ -611,12 +607,11 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
|||
"[%s] %d rule violations were found. See the report at: %s", commandName, numErrors,
|
||||
config.getReportFilePath().toUri());
|
||||
if (config.isFailOnViolation()) {
|
||||
if (LOGGER.isLoggable(Level.SEVERE) && !silent()) {
|
||||
LOGGER.log(Level.SEVERE, violations);
|
||||
}
|
||||
throw new ExitStatusException(ExitStatusException.EXIT_FAILURE);
|
||||
} else if (LOGGER.isLoggable(Level.WARNING) && !silent()) {
|
||||
throw new RuntimeException(violations); // NOPMD
|
||||
} else {
|
||||
if (LOGGER.isLoggable(Level.WARNING)) {
|
||||
LOGGER.warning(violations);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var rules = pmd.getRulesets();
|
||||
|
@ -625,7 +620,7 @@ public class PmdOperation extends AbstractOperation<PmdOperation> {
|
|||
for (var rule : rules) {
|
||||
count += rule.getRules().size();
|
||||
}
|
||||
if (LOGGER.isLoggable(Level.INFO) && !silent()) {
|
||||
if (LOGGER.isLoggable(Level.INFO)) {
|
||||
LOGGER.info(String.format("[%s] %d rules were checked.", commandName, count));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import net.sourceforge.pmd.lang.LanguageRegistry;
|
|||
import net.sourceforge.pmd.lang.rule.RulePriority;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.bld.BaseProject;
|
||||
import rife.bld.operations.exceptions.ExitStatusException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -67,7 +66,7 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testAddInputPath() throws ExitStatusException {
|
||||
void testAddInputPath() {
|
||||
var project = new BaseProject();
|
||||
var pmd = new PmdOperation().fromProject(project);
|
||||
|
||||
|
@ -94,12 +93,13 @@ class PmdOperationTest {
|
|||
project.srcMainDirectory().toPath(),
|
||||
project.srcTestDirectory().toPath());
|
||||
|
||||
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||
.isGreaterThan(0).isEqualTo(err);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddRuleSets() throws ExitStatusException {
|
||||
void testAddRuleSets() {
|
||||
var pmd = new PmdOperation().fromProject(new BaseProject());
|
||||
|
||||
assertThat(pmd.ruleSets()).containsExactly(PmdOperation.RULE_SET_DEFAULT);
|
||||
|
@ -122,7 +122,7 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testCache() throws ExitStatusException {
|
||||
void testCache() {
|
||||
var cache = Path.of("build/pmd/temp-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);
|
||||
|
@ -143,13 +143,7 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testExecuteNoProject() {
|
||||
var pmd = new PmdOperation();
|
||||
assertThatCode(pmd::execute).isInstanceOf(ExitStatusException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testExecute() throws ExitStatusException {
|
||||
void testExecute() {
|
||||
var pmd = new PmdOperation().fromProject(new BaseProject());
|
||||
|
||||
assertThat(pmd.inputPaths()).containsExactly(Paths.get("src/main").toAbsolutePath(),
|
||||
|
@ -168,11 +162,11 @@ class PmdOperationTest {
|
|||
var pmd = newPmdOperation().ruleSets(DOCUMENTATION_XML)
|
||||
.inputPaths(Path.of("src/test/resources/java/Documentation.java"));
|
||||
assertThatCode(() -> pmd.failOnViolation(true).performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||
.isInstanceOf(ExitStatusException.class);
|
||||
.isInstanceOf(RuntimeException.class).hasMessageContaining('[' + TEST + ']');
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIgnoreFile() throws ExitStatusException {
|
||||
void testIgnoreFile() {
|
||||
var pmd = newPmdOperation()
|
||||
.ruleSets(ERROR_PRONE_XML, CODE_STYLE_XML)
|
||||
.ignoreFile(Path.of("src/test/resources/ignore.txt"));
|
||||
|
@ -197,7 +191,7 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testInputPaths() throws ExitStatusException {
|
||||
void testInputPaths() {
|
||||
var pmd = newPmdOperation()
|
||||
.ruleSets(PmdOperation.RULE_SET_DEFAULT, CODE_STYLE_XML)
|
||||
.inputPaths(ERROR_PRONE_SAMPLE, CODE_STYLE_SAMPLE);
|
||||
|
@ -206,20 +200,20 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testJavaBestPractices() throws ExitStatusException {
|
||||
void testJavaBestPractices() {
|
||||
var pmd = newPmdOperation().ruleSets("category/java/bestpractices.xml")
|
||||
.inputPaths(Path.of("src/test/resources/java/BestPractices.java"));
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJavaCodeStyle() throws ExitStatusException {
|
||||
void testJavaCodeStyle() {
|
||||
var pmd = newPmdOperation().ruleSets(CODE_STYLE_XML).inputPaths(CODE_STYLE_SAMPLE);
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJavaCodeStyleAndErrorProne() throws ExitStatusException {
|
||||
void testJavaCodeStyleAndErrorProne() {
|
||||
var pmd = newPmdOperation().ruleSets(CODE_STYLE_XML).inputPaths(CODE_STYLE_SAMPLE);
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME)))
|
||||
.as("code style").isGreaterThan(0);
|
||||
|
@ -229,7 +223,7 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testJavaDesign() throws ExitStatusException {
|
||||
void testJavaDesign() {
|
||||
var pmd = newPmdOperation()
|
||||
.ruleSets(DESIGN_XML)
|
||||
.inputPaths("src/test/resources/java/Design.java")
|
||||
|
@ -238,7 +232,7 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testJavaDocumentation() throws ExitStatusException {
|
||||
void testJavaDocumentation() {
|
||||
var pmd = newPmdOperation()
|
||||
.ruleSets(DOCUMENTATION_XML)
|
||||
.inputPaths(Path.of("src/test/resources/java/Documentation.java"));
|
||||
|
@ -246,20 +240,20 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testJavaErrorProne() throws ExitStatusException {
|
||||
void testJavaErrorProne() {
|
||||
var pmd = newPmdOperation().ruleSets(ERROR_PRONE_XML).inputPaths(ERROR_PRONE_SAMPLE);
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJavaMultiThreading() throws ExitStatusException {
|
||||
void testJavaMultiThreading() {
|
||||
var pmd = newPmdOperation().ruleSets("category/java/multithreading.xml")
|
||||
.inputPaths(Path.of("src/test/resources/java/MultiThreading.java"));
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJavaPerformance() throws ExitStatusException {
|
||||
void testJavaPerformance() {
|
||||
var pmd = newPmdOperation()
|
||||
.ruleSets(PERFORMANCE_XML)
|
||||
.inputPaths(Path.of("src/test/resources/java/Performance.java"));
|
||||
|
@ -267,7 +261,7 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testJavaQuickStart() throws ExitStatusException {
|
||||
void testJavaQuickStart() {
|
||||
var pmd = newPmdOperation().ruleSets(PmdOperation.RULE_SET_DEFAULT)
|
||||
.inputPaths(new File("src/test/resources/java/"));
|
||||
assertThat(pmd.ruleSets()).containsExactly(PmdOperation.RULE_SET_DEFAULT);
|
||||
|
@ -275,14 +269,14 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testJavaSecurity() throws ExitStatusException {
|
||||
void testJavaSecurity() {
|
||||
var pmd = newPmdOperation().ruleSets(SECURITY_XML)
|
||||
.inputPaths(Path.of("src/test/resources/java/Security.java"));
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLanguageVersions() throws ExitStatusException {
|
||||
void testLanguageVersions() {
|
||||
var language = LanguageRegistry.PMD.getLanguageById("java");
|
||||
assertThat(language).isNotNull();
|
||||
|
||||
|
@ -301,14 +295,14 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testMainOperation() throws ExitStatusException {
|
||||
void testMainOperation() {
|
||||
var pmd = newPmdOperation().inputPaths(new File("src/main"))
|
||||
.performPmdAnalysis(TEST, newPmdOperation().initConfiguration(COMMAND_NAME));
|
||||
assertThat(pmd).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPriority() throws ExitStatusException {
|
||||
void testPriority() {
|
||||
var pmd = newPmdOperation().inputPaths(CODE_STYLE_SAMPLE).minimumPriority(RulePriority.HIGH);
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isEqualTo(0);
|
||||
}
|
||||
|
@ -327,7 +321,7 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testReportFile() throws FileNotFoundException, ExitStatusException {
|
||||
void testReportFile() throws FileNotFoundException {
|
||||
var report = new File("build", "pmd-report-file");
|
||||
report.deleteOnExit();
|
||||
var pmd = newPmdOperation().ruleSets(List.of(ERROR_PRONE_XML, DESIGN_XML)).reportFile(report);
|
||||
|
@ -344,7 +338,7 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testReportFormat() throws IOException, ExitStatusException {
|
||||
void testReportFormat() throws IOException {
|
||||
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 br = Files.newBufferedReader(pmd.reportFile())) {
|
||||
|
@ -353,7 +347,7 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testReportProperties() throws ExitStatusException {
|
||||
void testReportProperties() {
|
||||
var pmd = newPmdOperation().ruleSets(CODE_STYLE_XML, ERROR_PRONE_XML)
|
||||
.includeLineNumber(true)
|
||||
.reportProperties(new Properties());
|
||||
|
@ -361,14 +355,14 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testRuleSetsConfigFile() throws ExitStatusException {
|
||||
void testRuleSetsConfigFile() {
|
||||
var pmd = newPmdOperation().ruleSets("src/test/resources/pmd.xml")
|
||||
.ignoreFile("src/test/resources/ignore-all.txt");
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRuleSetsEmpty() throws ExitStatusException {
|
||||
void testRuleSetsEmpty() {
|
||||
var pmd = newPmdOperation().ruleSets("");
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isEqualTo(0);
|
||||
}
|
||||
|
@ -403,7 +397,7 @@ class PmdOperationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testXml() throws ExitStatusException {
|
||||
void testXml() {
|
||||
var pmd = newPmdOperation().addInputPaths("src/test/resources/pmd.xml")
|
||||
.ruleSets("src/test/resources/xml/basic.xml");
|
||||
assertThat(pmd.performPmdAnalysis(TEST, pmd.initConfiguration(COMMAND_NAME))).isGreaterThan(0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue