/rio-lib/src/main/java/org/rioproject/impl/system/OperatingSystemType.java

https://github.com/dreedyman/Rio · Java · 130 lines · 38 code · 9 blank · 83 comment · 0 complexity · 79aaa4f95d9e499577dec4b465a7af56 MD5 · raw file

  1. /*
  2. * Copyright to the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.rioproject.impl.system;
  17. /**
  18. * Utilities to help determine operating system type
  19. *
  20. * @author Dennis Reedy
  21. */
  22. public class OperatingSystemType {
  23. /**
  24. * Linux identifier
  25. */
  26. public static final String LINUX = "linux";
  27. /**
  28. * Solaris identifier
  29. */
  30. public static final String SOLARIS = "sunos";
  31. /**
  32. * Mac identifier
  33. */
  34. public static final String MACINTOSH = "Mac";
  35. /**
  36. * Windows identifier
  37. */
  38. public static final String WINDOWS = "Windows";
  39. /**
  40. * Windows 2000 identifier
  41. */
  42. public static final String WINDOWS_2K = WINDOWS+" 2000";
  43. /**
  44. * Windows XP identifier
  45. */
  46. public static final String WINDOWS_XP = WINDOWS+" XP";
  47. /**
  48. * HP-UX identifier
  49. */
  50. public static final String HP_UX = "HP-UX";
  51. /**
  52. * Check if running on Linux
  53. *
  54. * @return If running on Linux return <code>true</code>, otherwise return
  55. * <code>false</code>
  56. */
  57. public static boolean isLinux() {
  58. String opSys = System.getProperty("os.name");
  59. return opSys.equalsIgnoreCase(LINUX);
  60. }
  61. /**
  62. * Check if running on Solaris
  63. *
  64. * @return If running on Solaris return <code>true</code>, otherwise return
  65. * <code>false</code>
  66. */
  67. public static boolean isSolaris() {
  68. String opSys = System.getProperty("os.name");
  69. return opSys.equalsIgnoreCase(SOLARIS);
  70. }
  71. /**
  72. * Check if running on Mac
  73. *
  74. * @return If running on Mac return <code>true</code>, otherwise return
  75. * <code>false</code>
  76. */
  77. public static boolean isMac() {
  78. String opSys = System.getProperty("os.name");
  79. return opSys.startsWith(MACINTOSH);
  80. }
  81. /**
  82. * Check if running on HP-UX
  83. *
  84. * @return If running on HP-UX return <code>true</code>, otherwise return
  85. * <code>false</code>
  86. */
  87. public static boolean isHP() {
  88. String opSys = System.getProperty("os.name");
  89. return opSys.equals(HP_UX);
  90. }
  91. /**
  92. * Check if running on Windows
  93. *
  94. * @return If running on Windows return <code>true</code>, otherwise return
  95. * <code>false</code>
  96. */
  97. public static boolean isWindows() {
  98. String opSys = System.getProperty("os.name");
  99. return opSys.startsWith(WINDOWS);
  100. }
  101. /**
  102. * Check if running on Windows 2000
  103. *
  104. * @return If running on Windows 2000 return <code>true</code>, otherwise
  105. * return <code>false</code>
  106. */
  107. public static boolean isWindows2K() {
  108. String opSys = System.getProperty("os.name");
  109. return opSys.startsWith(WINDOWS_2K);
  110. }
  111. /**
  112. * Check if running on Windows XP
  113. *
  114. * @return If running on Windows XP return <code>true</code>, otherwise
  115. * return <code>false</code>
  116. */
  117. public static boolean isWindowsXP() {
  118. String opSys = System.getProperty("os.name");
  119. return opSys.startsWith(WINDOWS_XP);
  120. }
  121. }