• 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

32.53
cli/src/main/java/com/devonfw/tools/ide/os/OperatingSystem.java
1
package com.devonfw.tools.ide.os;
2

3
import java.util.Locale;
4

5
/**
6
 * Enum with the supported operating systems.
7
 */
8
public enum OperatingSystem {
3✔
9
  /** Microsoft Windows. */
10
  WINDOWS("windows"),
7✔
11

12
  /** Apple MacOS (not iOS). */
13
  MAC("mac"),
7✔
14

15
  /** Linux (Ubunutu, Debian, SuSe, etc.) */
16
  LINUX("linux");
7✔
17

18
  private final String title;
19

20
  private OperatingSystem(String title) {
4✔
21

22
    this.title = title;
3✔
23
  }
1✔
24

25
  @Override
26
  public String toString() {
27

28
    return this.title;
3✔
29
  }
30

31
  /**
32
   * @param title the {@link #toString() string representation} of the requested {@link OperatingSystem}.
33
   * @return the according {@link OperatingSystem} or {@code null} if none matches.
34
   */
35
  public static OperatingSystem of(String title) {
36

37
    for (OperatingSystem os : values()) {
16!
38
      if (os.title.equals(title)) {
5✔
39
        return os;
2✔
40
      }
41
    }
42
    return null;
×
43
  }
44

45
  public static OperatingSystem ofName(String osName) {
46

47
    String os = osName.toLowerCase(Locale.ROOT);
4✔
48
    if (os.startsWith("windows")) {
4✔
49
      return OperatingSystem.WINDOWS;
2✔
50
    } else if (os.startsWith("mac") || os.contains("darwin")) {
8!
51
      return OperatingSystem.MAC;
2✔
52
    } else if (os.contains("linux")) {
4!
53
      return OperatingSystem.LINUX;
2✔
54
    } else if (os.contains("bsd")) {
×
55
      return OperatingSystem.LINUX;
×
56
    } else if (os.contains("ix")) {
×
57
      return OperatingSystem.LINUX;
×
58
    } else {
59
      System.err.println("ERROR: Unknown operating system '" + osName + "'");
×
60
      // be tolerant: most of our users are working on windows
61
      // in case of an odd JVM or virtualization issue let us better continue than failing
62
      return OperatingSystem.WINDOWS;
×
63
    }
64
  }
65

66
  /**
67
   * @param suffix the file extension.
68
   * @return {@code true} if the given {@code suffix} is an executable file extension of this {@link OperatingSystem}, {@code false} otherwise.
69
   */
70
  public boolean isExecutable(String suffix) {
71

72
    if (suffix == null) {
×
73
      return false;
×
74
    }
75
    if (suffix.startsWith(".")) {
×
76
      suffix = suffix.substring(1);
×
77
    }
78
    if (this == WINDOWS) {
×
79
      if (suffix.equals("exe")) {
×
80
        return true;
×
81
      } else if (suffix.equals("msi")) {
×
82
        return true;
×
83
      } else if (suffix.equals("cmd")) {
×
84
        return true;
×
85
      } else if (suffix.equals("bat")) {
×
86
        return true;
×
87
      } else if (suffix.equals("ps1")) {
×
88
        return true;
×
89
      }
90
    } else {
91
      if (suffix.equals("sh")) {
×
92
        return true;
×
93
      } else if ((this == MAC) && suffix.equals("pkg")) {
×
94
        return true;
×
95
      }
96
    }
97
    return false;
×
98
  }
99

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

© 2025 Coveralls, Inc