PageRenderTime 101ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/platformlabeler/src/main/java/org/jvnet/hudson/plugins/platformlabeler/PlatformDetailsTask.java

https://github.com/jfroche/hudson-plugins
Java | 88 lines | 57 code | 5 blank | 26 comment | 26 complexity | ec5b7eeb26f24e37c7796b1577aad37b MD5 | raw file
  1. /*
  2. * The MIT License
  3. *
  4. * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Stephen Connolly
  5. * Copyright (C) 2009 Robert Collins
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. */
  25. package org.jvnet.hudson.plugins.platformlabeler;
  26. import net.robertcollins.lsb.Release;
  27. import hudson.remoting.Callable;
  28. import java.io.IOException;
  29. import java.util.HashSet;
  30. class PlatformDetailsTask implements Callable<HashSet<String>, IOException> {
  31. /** Performs computation and returns the result, or throws some exception. */
  32. public HashSet<String> call() throws IOException {
  33. final String arch = System.getProperty("os.arch");
  34. String name = System.getProperty("os.name").toLowerCase();
  35. String version = System.getProperty("os.version");
  36. if (name.equals("solaris") || name.equals("SunOS")) {
  37. name = "solaris";
  38. } else if (name.startsWith("windows")) {
  39. name = "windows";
  40. if (name.startsWith("windows 9")) {
  41. if (version.startsWith("4.0")) {
  42. version = "95";
  43. } else if (version.startsWith("4.9")) {
  44. version = "me";
  45. } else {
  46. assert version.startsWith("4.1");
  47. version = "98";
  48. }
  49. } else {
  50. if (version.startsWith("4.0")) {
  51. version = "nt4";
  52. } else if (version.startsWith("5.0")) {
  53. version = "2000";
  54. } else if (version.startsWith("5.1")) {
  55. version = "xp";
  56. } else if (version.startsWith("5.2")) {
  57. version = "2003";
  58. }
  59. }
  60. } else if (name.startsWith("linux")) {
  61. String unknown_string = "unknown+check_lsb_release_installed";
  62. Release release = new Release();
  63. name = release.distributorId();
  64. if (null == name)
  65. name = unknown_string;
  66. version = release.release();
  67. if (null == version)
  68. version = unknown_string;
  69. } else if (name.startsWith("mac")) {
  70. name = "mac";
  71. } else {
  72. // Take the System.properties values verbatim.
  73. }
  74. HashSet<String> result = new HashSet<String>();
  75. result.add(arch);
  76. result.add(name);
  77. result.add(version);
  78. result.add(arch + "-" + name);
  79. result.add(name + "-" + version);
  80. result.add(arch + "-" + name + "-" + version);
  81. return result;
  82. }
  83. }