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

devonfw / IDEasy / 13063267543

30 Jan 2025 11:34PM UTC coverage: 68.379% (-0.2%) from 68.557%
13063267543

push

github

web-flow
#954: improve repository support (#990)

Co-authored-by: jan-vcapgemini <59438728+jan-vcapgemini@users.noreply.github.com>
Co-authored-by: jan-vcapgemini <jan-vincent.hoelzle@capgemini.com>

2857 of 4597 branches covered (62.15%)

Branch coverage included in aggregate %.

7391 of 10390 relevant lines covered (71.14%)

3.1 hits per line

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

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

3
import java.nio.file.Path;
4
import java.util.Locale;
5

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

11
  private FilenameUtil() {
12

13
    // construction forbidden
14
  }
15

16
  /**
17
   * @param path the {@link Path} to the file or directory.
18
   * @return the filename.
19
   */
20
  public static String getFilename(Path path) {
21

22
    if (path == null) {
2!
23
      return null;
×
24
    }
25
    Path filename = path.getFileName();
3✔
26
    if (filename == null) {
2!
27
      return null;
×
28
    }
29
    return filename.toString();
3✔
30
  }
31

32
  /**
33
   * @param path the {@link Path} to the file or directory.
34
   * @return the filename excluding a potential {@link #getExtension(String) extension}.
35
   */
36
  public static String getFilenameWithoutExtension(Path path) {
37

38
    String filename = getFilename(path);
3✔
39
    if (filename == null) {
2!
40
      return null;
×
41
    }
42
    String result = filename;
2✔
43
    int lastDot = filename.lastIndexOf('.');
4✔
44
    if (lastDot > 0) {
2!
45
      result = filename.substring(0, lastDot);
5✔
46
      if (result.endsWith(".tar")) {
4✔
47
        result = result.substring(0, result.length() - 4);
8✔
48
      }
49
    }
50
    return result;
2✔
51
  }
52

53
  /**
54
   * @param path the file or path name to get the extension from.
55
   * @return the file extension excluding the dot from the given {@code path} or {@code null} if no extension is present.
56
   */
57
  public static String getExtension(String path) {
58

59
    if (path == null) {
2!
60
      return null;
×
61
    }
62
    path = path.toLowerCase(Locale.ROOT).replace('\\', '/');
7✔
63
    int lastSlash = path.lastIndexOf('/');
4✔
64
    if (lastSlash < 0) {
2✔
65
      lastSlash = 0;
2✔
66
    }
67
    int lastDot = path.lastIndexOf('.');
4✔
68

69
    // workaround for sourceforge urls ending with /download like
70
    // https://sourceforge.net/projects/gcviewer/files/gcviewer-1.36.jar/download
71
    if (path.startsWith("https://") && path.contains("sourceforge") && path.endsWith("download")) {
8!
72
      return path.substring(lastDot + 1, lastSlash);
×
73
    }
74

75
    if (lastDot < lastSlash) {
3✔
76
      return null;
2✔
77
    }
78
    // include previous ".tar" for ".tar.gz" or ".tar.bz2"
79
    int rawNameLength = lastDot - lastSlash;
4✔
80
    if ((rawNameLength > 4) && path.startsWith(".tar", lastDot - 4)) {
10✔
81
      lastDot = lastDot - 4;
4✔
82
    }
83
    return path.substring(lastDot + 1);
6✔
84
  }
85

86
}
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