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.

ServerImpl.java 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-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.sonar.server.platform;
  21. import java.io.File;
  22. import java.util.Date;
  23. import javax.annotation.CheckForNull;
  24. import org.sonar.api.CoreProperties;
  25. import org.sonar.api.SonarRuntime;
  26. import org.sonar.api.ce.ComputeEngineSide;
  27. import org.sonar.api.config.Configuration;
  28. import org.sonar.api.platform.Server;
  29. import org.sonar.api.server.ServerSide;
  30. @ComputeEngineSide
  31. @ServerSide
  32. public class ServerImpl extends Server {
  33. private final Configuration config;
  34. private final StartupMetadata state;
  35. private final ServerFileSystem fs;
  36. private final UrlSettings urlSettings;
  37. private final SonarRuntime runtime;
  38. public ServerImpl(Configuration config, StartupMetadata state, ServerFileSystem fs, UrlSettings urlSettings, SonarRuntime runtime) {
  39. this.config = config;
  40. this.state = state;
  41. this.fs = fs;
  42. this.urlSettings = urlSettings;
  43. this.runtime = runtime;
  44. }
  45. /**
  46. * Can be null when server is waiting for migration
  47. */
  48. @Override
  49. @CheckForNull
  50. public String getId() {
  51. return config.get(CoreProperties.SERVER_ID).orElse(null);
  52. }
  53. @Override
  54. public String getPermanentServerId() {
  55. return getId();
  56. }
  57. @Override
  58. public String getVersion() {
  59. return runtime.getApiVersion().toString();
  60. }
  61. @Override
  62. public Date getStartedAt() {
  63. return new Date(state.getStartedAt());
  64. }
  65. @Override
  66. public String getContextPath() {
  67. return urlSettings.getContextPath();
  68. }
  69. @Override
  70. public String getPublicRootUrl() {
  71. return urlSettings.getBaseUrl();
  72. }
  73. @Override
  74. public boolean isSecured() {
  75. return urlSettings.isSecured();
  76. }
  77. }