[doc] Fix missing additional rulesets

Fixes #4051
This commit is contained in:
Andreas Dangel
2022-07-19 20:40:39 +02:00
parent a42913fb10
commit 84c5887f88
3 changed files with 15 additions and 4 deletions

View File

@ -43,6 +43,7 @@ Being based on a proper Antlr grammar, CPD can:
### Fixed Issues
* core
* [#4031](https://github.com/pmd/pmd/issues/4031): \[core] If report is written to stdout, stdout should not be closed
* [#4051](https://github.com/pmd/pmd/issues/4051): \[doc] Additional rulesets are not listed in documentation
* java
* [#4015](https://github.com/pmd/pmd/issues/4015): \[java] Support JDK 19
* java-bestpractices

View File

@ -47,16 +47,17 @@ public final class GenerateRuleDocsCmd {
System.out.println("Generated docs in " + (System.currentTimeMillis() - start) + " ms");
}
static final Pattern ADDITIONAL_RULESET_PATTERN = Pattern.compile("^.+" + Pattern.quote(File.separator) + "pmd-\\w+"
+ Pattern.quote(IOUtil.normalizePath(File.separator + Paths.get("src", "main", "resources", "rulesets").toString()) + File.separator)
+ "\\w+" + Pattern.quote(File.separator) + "\\w+.xml$");
public static List<String> findAdditionalRulesets(Path basePath) {
try {
List<String> additionalRulesets = new ArrayList<>();
Pattern rulesetPattern = Pattern.compile("^.+" + Pattern.quote(File.separator) + "pmd-\\w+"
+ Pattern.quote(IOUtil.normalizePath(File.separator + Paths.get("src", "main", "resources", "rulesets").toString() + File.separator))
+ "\\w+" + Pattern.quote(File.separator) + "\\w+.xml$");
Files.walkFileTree(basePath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
if (rulesetPattern.matcher(file.toString()).matches()) {
if (ADDITIONAL_RULESET_PATTERN.matcher(file.toString()).matches()) {
additionalRulesets.add(file.toString());
}

View File

@ -4,6 +4,8 @@
package net.sourceforge.pmd.docs;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.nio.file.FileSystems;
@ -34,6 +36,8 @@ public class RuleSetResolverTest {
filterRuleSets(additionalRulesets);
assertFalse(additionalRulesets.isEmpty());
RuleSetFactory ruleSetFactory = RulesetsFactoryUtils.defaultFactory();
for (String filename : additionalRulesets) {
try {
@ -44,6 +48,11 @@ public class RuleSetResolverTest {
}
}
@Test
public void testAdditionalRulesetPattern() {
assertTrue(GenerateRuleDocsCmd.ADDITIONAL_RULESET_PATTERN.matcher("/home/foo/pmd/pmd-java/src/main/resources/rulesets/java/quickstart.xml").matches());
}
private void filterRuleSets(List<String> additionalRulesets) {
Iterator<String> it = additionalRulesets.iterator();
while (it.hasNext()) {