#1402 Windows-Only: File exclusions are not case insensitive

This commit is contained in:
Andreas Dangel
2015-09-04 21:21:20 +02:00
parent 944082c53d
commit 6e300f0854
3 changed files with 20 additions and 3 deletions

View File

@ -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<File> 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;
}

View File

@ -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

View File

@ -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:**