diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java index 9b25d16402..91c4564e96 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java @@ -21,6 +21,7 @@ import java.util.Set; import net.sourceforge.pmd.AbstractConfiguration; import net.sourceforge.pmd.util.FileFinder; +import net.sourceforge.pmd.util.FileUtil; import com.beust.jcommander.IStringConverter; import com.beust.jcommander.Parameter; @@ -285,10 +286,10 @@ public class CPDConfiguration extends AbstractConfiguration { if (excludedFile.isDirectory()) { List files = finder.findFilesFrom(excludedFile, languageFilter, true); for (File f : files) { - exclusions.add(f.getAbsolutePath()); + exclusions.add(FileUtil.normalizeFilename(f.getAbsolutePath())); } } else { - exclusions.add(excludedFile.getAbsolutePath()); + exclusions.add(FileUtil.normalizeFilename(excludedFile.getAbsolutePath())); } } } @@ -296,7 +297,7 @@ public class CPDConfiguration extends AbstractConfiguration { FilenameFilter filter = new FilenameFilter() { public boolean accept(File dir, String name) { File f = new File(dir, name); - if (exclusions.contains(f.getAbsolutePath())) { + if (exclusions.contains(FileUtil.normalizeFilename(f.getAbsolutePath()))) { System.err.println("Excluding " + f.getAbsolutePath()); return false; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/FileUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/FileUtil.java index 0c8093f925..c5bfd3023a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/FileUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/FileUtil.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.List; +import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.ZipEntry; @@ -46,6 +47,20 @@ public final class FileUtil { return name; } + /** + * Normalizes the filename by taking the casing into account, e.g. on Windows, + * the filename is changed to lowercase only. + * @param fileName the file name + * @return the normalized file name + */ + public static String normalizeFilename(String fileName) { + if (fileName != null && File.separatorChar == '\\') { + // windows + return fileName.toLowerCase(Locale.ROOT); + } + return fileName; + } + /** * Collects a list of DataSources using a comma separated list of input file * locations to process. If a file location is a directory, the directory diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 7900b944a9..945bbd1d36 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -70,5 +70,6 @@ **Bugfixes:** * [#1370](https://sourceforge.net/p/pmd/bugs/1370/): ConsecutiveAppendsShouldReuse not detected properly on StringBuffer +* [#1402](https://sourceforge.net/p/pmd/bugs/1402/): Windows-Only: File exclusions are not case insensitive **API Changes:**