Skip to content

Commit

Permalink
Take care of uppercase characters on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Jan 12, 2024
1 parent 6ac8257 commit 217d5c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Set;

import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import edu.hm.hafner.util.FilteredLog;
Expand Down Expand Up @@ -52,7 +53,7 @@ public void run(final FullTextFingerprint algorithm, final Report report, final
}

private boolean hasAllowedExtension(final String fileName) {
return !NON_SOURCE_CODE_EXTENSIONS.contains(FilenameUtils.getExtension(fileName));
return !NON_SOURCE_CODE_EXTENSIONS.contains(StringUtils.lowerCase(FilenameUtils.getExtension(fileName)));
}

private int computeFingerprint(final Issue issue, final FullTextFingerprint algorithm, final Charset charset,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void shouldNotChangeIssuesWithFingerPrint() {

String alreadySet = "already-set";
report.add(issueBuilder.setFingerprint(alreadySet).setMessage(AFFECTED_FILE_NAME).build());
generator.run(createFullTextFingerprint("fingerprint-one.txt", "fingerprint-two.txt"),
generator.run(createFullTextFingerprint("fingerprint-two.txt"),
report, CHARSET_AFFECTED_FILE);

assertThat(report.get(0).hasFingerprint()).isTrue();
Expand All @@ -86,7 +86,7 @@ void shouldSetDefaultFingerprintIfNoFileIsGiven() {
void shouldAssignIdenticalFingerprint() {
Report report = createTwoIssues();
FingerprintGenerator generator = new FingerprintGenerator();
FullTextFingerprint fingerprint = createFullTextFingerprint("fingerprint-one.txt", "fingerprint-one.txt");
FullTextFingerprint fingerprint = createFullTextFingerprint("fingerprint-one.txt");

generator.run(fingerprint, report, CHARSET_AFFECTED_FILE);

Expand Down Expand Up @@ -119,7 +119,7 @@ private FileSystem stubFileSystem(final String firstFile, final String secondFil
void shouldAssignDifferentFingerprint() {
Report report = createTwoIssues();
FingerprintGenerator generator = new FingerprintGenerator();
FullTextFingerprint fingerprint = createFullTextFingerprint("fingerprint-one.txt", "fingerprint-two.txt");
FullTextFingerprint fingerprint = createFullTextFingerprint("fingerprint-two.txt");

generator.run(fingerprint, report, CHARSET_AFFECTED_FILE);

Expand All @@ -143,12 +143,13 @@ void shouldUseFallbackFingerprintOnError(final String fileName) {

@ParameterizedTest(name = "[{index}] Skip non source code file {0}")
@ValueSource(strings = {"library.o", "program.exe", "library.dll", "program.so", "library.a", "program.lib",
"library.jar", "library.war", "program.zip", "library.7z", "program.tar.gz", "library.tar.bz2"})
"library.jar", "library.war", "program.zip", "library.7z", "program.tar.gz", "library.tar.bz2",
"UPPER_CASE.EXE"})
void shouldUseFallbackFingerprintOnNonSourceFiles(final String fileName) {
var report = createReportWithOneIssueFor(fileName);

FingerprintGenerator generator = new FingerprintGenerator();
generator.run(createFullTextFingerprint("fingerprint-one.txt", "fingerprint-two.txt"),
generator.run(createFullTextFingerprint("fingerprint-two.txt"),
report, CHARSET_AFFECTED_FILE);

assertThatIssueHasDefaultFingerprint(report);
Expand All @@ -167,8 +168,9 @@ private void assertThatIssueHasDefaultFingerprint(final Report report) {
assertThat(report.get(0)).hasFingerprint(FingerprintGenerator.createDefaultFingerprint(report.get(0)));
}

private FullTextFingerprint createFullTextFingerprint(final String firstFile, final String secondFile) {
FileSystem fileSystem = stubFileSystem(firstFile, secondFile);
private FullTextFingerprint createFullTextFingerprint(final String secondFile) {
FileSystem fileSystem = stubFileSystem("fingerprint-one.txt", secondFile);

return new FullTextFingerprint(fileSystem);
}

Expand Down

0 comments on commit 217d5c3

Please sign in to comment.