Skip to content

Commit

Permalink
Update os detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jjlauer committed Nov 3, 2023
1 parent 9eb2207 commit 9d9da92
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
15 changes: 14 additions & 1 deletion src/main/java/com/fizzed/jne/OperatingSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum OperatingSystem {
LINUX("Linux", null),
FREEBSD("FreeBSD", null),
OPENBSD("OpenBSD", null),
SOLARIS("Solaris", new String[] { "sun" });
SOLARIS("Solaris", new String[] { "sun" }, new String[] { "sunos" });

private final String descriptor;
private final String[] aliases;
Expand Down Expand Up @@ -59,6 +59,18 @@ public String[] getExtraAliases() {
}

static public OperatingSystem resolve(String value) {
if (value == null) {
return null;
}

value = value.toLowerCase();

if (value.contains("windows")) {
return OperatingSystem.WINDOWS;
} else if (value.contains("mac") || value.contains("darwin")) {
return OperatingSystem.MACOS;
}

for (OperatingSystem os : OperatingSystem.values()) {
if (os.name().equalsIgnoreCase(value)) {
return os;
Expand All @@ -78,6 +90,7 @@ static public OperatingSystem resolve(String value) {
}
}
}

return null;
}

Expand Down
17 changes: 0 additions & 17 deletions src/main/java/com/fizzed/jne/PlatformInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,6 @@ static OperatingSystem doDetectOperatingSystem() {

static OperatingSystem detectOperatingSystemFromValues(String osName) {
return OperatingSystem.resolve(osName);
/*if (osName != null) {
osName = osName.toLowerCase();
if (osName.contains("windows")) {
return OperatingSystem.WINDOWS;
} else if (osName.contains("mac") || osName.contains("darwin")) {
return OperatingSystem.MACOS;
} else if (osName.contains("linux")) {
return OperatingSystem.LINUX;
} else if (osName.contains("sun") || osName.contains("solaris")) {
return OperatingSystem.SOLARIS;
} else if (osName.contains("freebsd")) {
return OperatingSystem.FREEBSD;
} else if (osName.contains("openbsd")) {
return OperatingSystem.OPENBSD;
}
}
return null;*/
}

//
Expand Down
4 changes: 4 additions & 0 deletions src/test/java/com/fizzed/jne/PlatformInfoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ public void doDetectOperatingSystem() {
@Test
public void detectOperatingSystemFromValues() {
assertThat(PlatformInfo.detectOperatingSystemFromValues("Windows"), is(OperatingSystem.WINDOWS));
assertThat(PlatformInfo.detectOperatingSystemFromValues("Windows Server 2022"), is(OperatingSystem.WINDOWS));
assertThat(PlatformInfo.detectOperatingSystemFromValues("Mac OS X"), is(OperatingSystem.MACOS));
assertThat(PlatformInfo.detectOperatingSystemFromValues("SunOS"), is(OperatingSystem.SOLARIS));
assertThat(PlatformInfo.detectOperatingSystemFromValues("blah"), is(nullValue()));
assertThat(PlatformInfo.detectOperatingSystemFromValues(null), is(nullValue()));
}

@Test
Expand Down

0 comments on commit 9d9da92

Please sign in to comment.