forked from phoedos/pmd
[doc] Further changes for windows compatibility
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
|
||||
package net.sourceforge.pmd.docs;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.FileSystems;
|
||||
import java.nio.file.FileVisitResult;
|
||||
@ -16,6 +17,8 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import net.sourceforge.pmd.RuleSet;
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
import net.sourceforge.pmd.RuleSetNotFoundException;
|
||||
@ -43,7 +46,9 @@ public class GenerateRuleDocsCmd {
|
||||
public static List<String> findAdditionalRulesets(Path basePath) {
|
||||
try {
|
||||
List<String> additionalRulesets = new ArrayList<>();
|
||||
Pattern rulesetPattern = Pattern.compile("^.+/pmd-\\w+/src/main/resources/rulesets/\\w+/\\w+.xml$");
|
||||
Pattern rulesetPattern = Pattern.compile("^.+" + Pattern.quote(File.separator) + "pmd-\\w+"
|
||||
+ Pattern.quote(FilenameUtils.normalize("/src/main/resources/rulesets/"))
|
||||
+ "\\w+" + Pattern.quote(File.separator) + "\\w+.xml$");
|
||||
Files.walkFileTree(basePath, new SimpleFileVisitor<Path>() {
|
||||
@Override
|
||||
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
||||
|
@ -109,7 +109,7 @@ public class RuleDocGenerator {
|
||||
for (String filename : additionalRulesets) {
|
||||
try {
|
||||
// do not take rulesets from pmd-test or pmd-core
|
||||
if (!filename.contains("pmd-test/") && !filename.contains("pmd-core/")) {
|
||||
if (!filename.contains("pmd-test") && !filename.contains("pmd-core")) {
|
||||
rulesets.add(ruleSetFactory.createRuleSet(filename));
|
||||
} else {
|
||||
LOG.fine("Ignoring ruleset " + filename);
|
||||
@ -539,7 +539,9 @@ public class RuleDocGenerator {
|
||||
if (!foundPathResult.isEmpty()) {
|
||||
Path foundPath = foundPathResult.get(0);
|
||||
foundPath = root.relativize(foundPath);
|
||||
return foundPath.toString();
|
||||
// Note: the path is normalized to unix path separators, so that the editme link
|
||||
// uses forward slashes
|
||||
return FilenameUtils.normalize(foundPath.toString(), true);
|
||||
}
|
||||
|
||||
return StringUtils.chomp(ruleset.getFileName());
|
||||
|
@ -51,7 +51,7 @@ public final class RuleSetUtils {
|
||||
|
||||
public static String getRuleSetClasspath(RuleSet ruleset) {
|
||||
final String RESOURCES_PATH = "/resources/";
|
||||
String filename = StringUtils.chomp(ruleset.getFileName());
|
||||
String filename = FilenameUtils.normalize(StringUtils.chomp(ruleset.getFileName()), true);
|
||||
int startIndex = filename.lastIndexOf(RESOURCES_PATH);
|
||||
if (startIndex > -1) {
|
||||
return filename.substring(startIndex + RESOURCES_PATH.length());
|
||||
|
@ -12,6 +12,7 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.RuleSetFactory;
|
||||
@ -22,7 +23,7 @@ public class RuleSetResolverTest {
|
||||
private static List<String> excludedRulesets = new ArrayList<>();
|
||||
|
||||
static {
|
||||
excludedRulesets.add("pmd-test/src/main/resources/rulesets/dummy/basic.xml");
|
||||
excludedRulesets.add(FilenameUtils.normalize("pmd-test/src/main/resources/rulesets/dummy/basic.xml"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user