• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 9907372175

12 Jul 2024 11:49AM UTC coverage: 61.142% (-0.02%) from 61.162%
9907372175

push

github

hohwille
fixed tests

1997 of 3595 branches covered (55.55%)

Branch coverage included in aggregate %.

5296 of 8333 relevant lines covered (63.55%)

2.8 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.65
cli/src/main/java/com/devonfw/tools/ide/util/FilenameUtil.java
1
package com.devonfw.tools.ide.util;
2

3
import java.util.Locale;
4

5
/**
6
 * Utility class for filenames and extensions.
7
 */
8
public final class FilenameUtil {
9

10
  private FilenameUtil() {
11

12
    // construction forbidden
13
  }
14

15
  /**
16
   * @param path the file or path name to get the extension from.
17
   * @return the file extension excluding the dot from the given {@code path} or {@code null} if no extension is present.
18
   */
19
  public static String getExtension(String path) {
20

21
    if (path == null) {
2!
22
      return null;
×
23
    }
24
    path = path.toLowerCase(Locale.ROOT).replace('\\', '/');
7✔
25
    int lastSlash = path.lastIndexOf('/');
4✔
26
    if (lastSlash < 0) {
2✔
27
      lastSlash = 0;
2✔
28
    }
29
    int lastDot = path.lastIndexOf('.');
4✔
30

31
    // workaround for sourceforge urls ending with /download like
32
    // https://sourceforge.net/projects/gcviewer/files/gcviewer-1.36.jar/download
33
    if (path.startsWith("https://") && path.contains("sourceforge") && path.endsWith("download")) {
8!
34
      return path.substring(lastDot + 1, lastSlash);
×
35
    }
36

37
    if (lastDot < lastSlash) {
3✔
38
      return null;
2✔
39
    }
40
    // include previous ".tar" for ".tar.gz" or ".tar.bz2"
41
    int rawNameLength = lastDot - lastSlash;
4✔
42
    if ((rawNameLength > 4) && path.substring(lastDot - 4, lastDot).equals(".tar")) {
12✔
43
      lastDot = lastDot - 4;
4✔
44
    }
45
    return path.substring(lastDot + 1);
6✔
46
  }
47

48
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc