PageRenderTime 65ms CodeModel.GetById 40ms RepoModel.GetById 0ms app.codeStats 0ms

/src/org/molgenis/util/DetectOS.java

https://github.com/molgenis/molgenis-legacy
Java | 52 lines | 24 code | 9 blank | 19 comment | 4 complexity | 040ee37b51a160c1a188c0e3f5ceb2fc MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause, Apache-2.0
  1. package org.molgenis.util;
  2. public class DetectOS
  3. {
  4. // possible outcomes:
  5. /**
  6. * AIX -> unix Digital Unix -> unix FreeBSD -> unix HP UX -> unix Irix ->
  7. * unix Linux -> unix Mac OS -> mac Mac OS X -> mac MPE/iX -> unix Netware
  8. * 4.11 -> unix OS/2 -> unixlike Solaris -> unixlike Windows 2000 -> windows
  9. * Windows 7 -> windows Windows 95 -> windowslegacy Windows 98 ->
  10. * windowslegacy Windows NT -> windows Windows Vista -> windows Windows XP
  11. * -> windows
  12. */
  13. /**
  14. * Get the current OS Java is running on. Since there are many
  15. * possibilities, they are cast to five types, of which each type is
  16. * expected to behave the same way. Possible outcomes are: unix, mac,
  17. * unixlike, windows, windowslegacy. This way it is also possible to wrap
  18. * multiple types by using eg String.startsWith("windows") or
  19. * String.startsWith("unix"). See class for more details and casting
  20. * procedure.
  21. */
  22. public static String getOS()
  23. {
  24. String os = System.getProperty("os.name").toLowerCase();
  25. if (os.indexOf("windows 9") > -1)
  26. {
  27. return "windowslegacy";
  28. }
  29. else if (os.indexOf("windows") > -1)
  30. {
  31. return "windows";
  32. }
  33. if (os.indexOf("mac") > -1)
  34. {
  35. return "mac";
  36. }
  37. else
  38. {
  39. return "unix";
  40. }
  41. // throw new Exception("OS detection failed");
  42. }
  43. }