From 217d5c392766572dd20b61df0117a3d8cddab46e Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Fri, 12 Jan 2024 16:23:53 +0100 Subject: [PATCH] Take care of uppercase characters on Windows. --- .../hm/hafner/analysis/FingerprintGenerator.java | 3 ++- .../analysis/FingerprintGeneratorTest.java | 16 +++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/hm/hafner/analysis/FingerprintGenerator.java b/src/main/java/edu/hm/hafner/analysis/FingerprintGenerator.java index 9f7fd23f7..d9cbbd5d2 100644 --- a/src/main/java/edu/hm/hafner/analysis/FingerprintGenerator.java +++ b/src/main/java/edu/hm/hafner/analysis/FingerprintGenerator.java @@ -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; @@ -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, diff --git a/src/test/java/edu/hm/hafner/analysis/FingerprintGeneratorTest.java b/src/test/java/edu/hm/hafner/analysis/FingerprintGeneratorTest.java index 5f8d5aa18..298d00e30 100644 --- a/src/test/java/edu/hm/hafner/analysis/FingerprintGeneratorTest.java +++ b/src/test/java/edu/hm/hafner/analysis/FingerprintGeneratorTest.java @@ -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(); @@ -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); @@ -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); @@ -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); @@ -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); }