PageRenderTime 72ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/core/src/main/java/hudson/tasks/labelers/OSLabeler.java

https://github.com/fujibee/hudson
Java | 100 lines | 60 code | 4 blank | 36 comment | 22 complexity | 0a8eddfc068d6fea5a08cd7590d0ebb2 MD5 | raw file
  1. /*
  2. * The MIT License
  3. *
  4. * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Stephen Connolly
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy
  7. * of this software and associated documentation files (the "Software"), to deal
  8. * in the Software without restriction, including without limitation the rights
  9. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. * copies of the Software, and to permit persons to whom the Software is
  11. * furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in
  14. * all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. * THE SOFTWARE.
  23. */
  24. package hudson.tasks.labelers;
  25. import hudson.remoting.Callable;
  26. import hudson.remoting.VirtualChannel;
  27. import hudson.tasks.DynamicLabeler;
  28. import java.util.Collections;
  29. import java.util.HashSet;
  30. import java.util.Set;
  31. /**
  32. * Created by IntelliJ IDEA.
  33. *
  34. * @author connollys
  35. * @since 25-May-2007 15:25:03
  36. */
  37. // @Extension --- not live yet
  38. public class OSLabeler extends DynamicLabeler {
  39. public Set<String> findLabels(VirtualChannel channel) {
  40. try {
  41. return channel.call(new OSLabelFinder());
  42. } catch (Exception e) {
  43. return Collections.emptySet();
  44. }
  45. }
  46. private static class OSLabelFinder implements Callable<Set<String>, Exception> {
  47. /** Performs computation and returns the result, or throws some exception. */
  48. public Set<String> call() throws Exception {
  49. Set<String> result = new HashSet<String>();
  50. final String os = System.getProperty("os.name").toLowerCase();
  51. final String version = System.getProperty("os.version");
  52. final String arch = System.getProperty("os.arch");
  53. if (os.equals("solaris") || os.equals("SunOS")) {
  54. result.add("solaris");
  55. result.add("solaris_" + arch);
  56. result.add("solaris_" + arch + "_" + version);
  57. } else if (os.startsWith("windows")) {
  58. result.add("windows");
  59. if (os.startsWith("windows 9")) {
  60. // ugh! windows 9x
  61. // I have not tested these values
  62. result.add("windows_9x_family");
  63. if (version.startsWith("4.0")) {
  64. result.add("windows_95");
  65. } else if (version.startsWith("4.9")) {
  66. result.add("windows_ME"); // but could be Windows ME
  67. } else {
  68. assert version.startsWith("4.1");
  69. result.add("windows_98");
  70. }
  71. } else {
  72. // older Java Runtimes can mis-report newer versions of windows NT
  73. result.add("windows_nt_family");
  74. if (version.startsWith("4.0")) {
  75. // Windows NT 4
  76. result.add("windows_nt4");
  77. } else if (version.startsWith("5.0")) {
  78. result.add("windows_2000");
  79. } else if (version.startsWith("5.1")) {
  80. result.add("windows_xp");
  81. } else if (version.startsWith("5.2")) {
  82. result.add("windows_2003");
  83. }
  84. }
  85. } else if (os.startsWith("linux")) {
  86. result.add("linux");
  87. } else if (os.startsWith("mac")) {
  88. result.add("mac");
  89. } else {
  90. // I give up!
  91. result.add(os);
  92. }
  93. return result;
  94. }
  95. }
  96. }