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.

DefaultServer.java 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2017 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.sonar.scanner.platform;
  21. import java.io.File;
  22. import java.util.Date;
  23. import javax.annotation.CheckForNull;
  24. import org.apache.commons.lang.StringUtils;
  25. import org.sonar.api.CoreProperties;
  26. import org.sonar.api.SonarRuntime;
  27. import org.sonar.api.batch.ScannerSide;
  28. import org.sonar.api.config.Settings;
  29. import org.sonar.api.platform.Server;
  30. import org.sonar.api.utils.DateUtils;
  31. import org.sonar.scanner.bootstrap.ScannerWsClient;
  32. import static org.apache.commons.lang.StringUtils.trimToEmpty;
  33. @ScannerSide
  34. public class DefaultServer extends Server {
  35. private final Settings settings;
  36. private final ScannerWsClient client;
  37. private final SonarRuntime runtime;
  38. public DefaultServer(Settings settings, ScannerWsClient client, SonarRuntime runtime) {
  39. this.settings = settings;
  40. this.client = client;
  41. this.runtime = runtime;
  42. }
  43. @Override
  44. public String getId() {
  45. return settings.getString(CoreProperties.SERVER_ID);
  46. }
  47. @Override
  48. public String getVersion() {
  49. return runtime.getApiVersion().toString();
  50. }
  51. @Override
  52. public Date getStartedAt() {
  53. String dateString = settings.getString(CoreProperties.SERVER_STARTTIME);
  54. return DateUtils.parseDateTime(dateString);
  55. }
  56. @Override
  57. public File getRootDir() {
  58. return null;
  59. }
  60. @Override
  61. @CheckForNull
  62. public File getDeployDir() {
  63. return null;
  64. }
  65. @Override
  66. public String getContextPath() {
  67. return null;
  68. }
  69. @Override
  70. public String getPublicRootUrl() {
  71. String baseUrl = trimToEmpty(settings.getString(CoreProperties.SERVER_BASE_URL));
  72. if (baseUrl.isEmpty()) {
  73. // If server base URL was not configured in Sonar server then is is better to take URL configured on batch side
  74. baseUrl = client.baseUrl();
  75. }
  76. return StringUtils.removeEnd(baseUrl, "/");
  77. }
  78. @Override
  79. public boolean isDev() {
  80. return false;
  81. }
  82. @Override
  83. public boolean isSecured() {
  84. return false;
  85. }
  86. @Override
  87. public String getURL() {
  88. return StringUtils.removeEnd(client.baseUrl(), "/");
  89. }
  90. @Override
  91. public String getPermanentServerId() {
  92. return settings.getString(CoreProperties.PERMANENT_SERVER_ID);
  93. }
  94. }