You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SystemInfo.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * SonarScanner CLI
  3. * Copyright (C) 2011-2021 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonarsource.scanner.cli;
  21. class SystemInfo {
  22. private static System2 system = new System2();
  23. private SystemInfo() {
  24. }
  25. static void setSystem(System2 system) {
  26. SystemInfo.system = system;
  27. }
  28. static void print(Logs logger) {
  29. logger.info("SonarScanner " + ScannerVersion.version());
  30. logger.info(java());
  31. logger.info(os());
  32. String scannerOpts = system.getenv("SONAR_SCANNER_OPTS");
  33. if (scannerOpts != null) {
  34. logger.info("SONAR_SCANNER_OPTS=" + scannerOpts);
  35. }
  36. }
  37. static String java() {
  38. StringBuilder sb = new StringBuilder();
  39. sb
  40. .append("Java ")
  41. .append(system.getProperty("java.version"))
  42. .append(" ")
  43. .append(system.getProperty("java.vendor"));
  44. String bits = system.getProperty("sun.arch.data.model");
  45. if ("32".equals(bits) || "64".equals(bits)) {
  46. sb.append(" (").append(bits).append("-bit)");
  47. }
  48. return sb.toString();
  49. }
  50. static String os() {
  51. StringBuilder sb = new StringBuilder();
  52. sb
  53. .append(system.getProperty("os.name"))
  54. .append(" ")
  55. .append(system.getProperty("os.version"))
  56. .append(" ")
  57. .append(system.getProperty("os.arch"));
  58. return sb.toString();
  59. }
  60. static class System2 {
  61. String getProperty(String key) {
  62. return System.getProperty(key);
  63. }
  64. String getenv(String key) {
  65. return System.getenv(key);
  66. }
  67. }
  68. }