@@ -46,6 +46,9 @@ public class WebApiEndpoints { | |||
public static final String INTERNAL = "internal"; | |||
public static final String ANALYSIS_ENDPOINT = "/analysis"; | |||
public static final String VERSION_ENDPOINT = ANALYSIS_ENDPOINT + "/version"; | |||
private WebApiEndpoints() { | |||
} | |||
} |
@@ -0,0 +1,37 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2024 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.v2.api.analysis.controller; | |||
import org.sonar.api.platform.Server; | |||
public class DefaultVersionController implements VersionController { | |||
private final Server server; | |||
public DefaultVersionController(Server server) { | |||
this.server = server; | |||
} | |||
@Override | |||
public String getVersion() { | |||
return server.getVersion(); | |||
} | |||
} |
@@ -0,0 +1,40 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2024 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.v2.api.analysis.controller; | |||
import io.swagger.v3.oas.annotations.Operation; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
import org.springframework.web.bind.annotation.ResponseStatus; | |||
import org.springframework.web.bind.annotation.RestController; | |||
import static org.sonar.server.v2.WebApiEndpoints.VERSION_ENDPOINT; | |||
import static org.springframework.http.HttpStatus.OK; | |||
import static org.springframework.http.MediaType.TEXT_PLAIN_VALUE; | |||
@RequestMapping(VERSION_ENDPOINT) | |||
@RestController | |||
public interface VersionController { | |||
@GetMapping(produces = TEXT_PLAIN_VALUE) | |||
@ResponseStatus(OK) | |||
@Operation(summary = "Server version", description = "Get the version of the Scanner Engine") | |||
String getVersion(); | |||
} |
@@ -0,0 +1,23 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2024 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
@ParametersAreNonnullByDefault | |||
package org.sonar.server.v2.api.analysis.controller; | |||
import javax.annotation.ParametersAreNonnullByDefault; |
@@ -20,6 +20,7 @@ | |||
package org.sonar.server.v2.config; | |||
import javax.annotation.Nullable; | |||
import org.sonar.api.platform.Server; | |||
import org.sonar.api.resources.Languages; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.server.common.gitlab.config.GitlabConfigurationService; | |||
@@ -42,6 +43,8 @@ import org.sonar.server.platform.NodeInformation; | |||
import org.sonar.server.rule.RuleDescriptionFormatter; | |||
import org.sonar.server.user.SystemPasscode; | |||
import org.sonar.server.user.UserSession; | |||
import org.sonar.server.v2.api.analysis.controller.DefaultVersionController; | |||
import org.sonar.server.v2.api.analysis.controller.VersionController; | |||
import org.sonar.server.v2.api.dop.controller.DefaultDopSettingsController; | |||
import org.sonar.server.v2.api.dop.controller.DopSettingsController; | |||
import org.sonar.server.v2.api.gitlab.config.controller.DefaultGitlabConfigurationController; | |||
@@ -151,4 +154,9 @@ public class PlatformLevel4WebConfig { | |||
return new DefaultProjectBindingsController(userSession, projectBindingsService); | |||
} | |||
@Bean | |||
public VersionController versionController(Server server) { | |||
return new DefaultVersionController(server); | |||
} | |||
} |
@@ -0,0 +1,50 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2024 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.v2.api.analysis.controller; | |||
import org.junit.Test; | |||
import org.sonar.api.platform.Server; | |||
import org.springframework.test.web.servlet.MockMvc; | |||
import static org.mockito.Mockito.mock; | |||
import static org.mockito.Mockito.when; | |||
import static org.sonar.server.v2.WebApiEndpoints.VERSION_ENDPOINT; | |||
import static org.sonar.server.v2.api.ControllerTester.getMockMvc; | |||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | |||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |||
public class DefaultVersionControllerTest { | |||
private final Server server = mock(Server.class); | |||
private final MockMvc mockMvc = getMockMvc(new DefaultVersionController(server)); | |||
@Test | |||
public void getVersion_shouldReturnServerVersion() throws Exception { | |||
String serverVersion = "10.6"; | |||
when(server.getVersion()).thenReturn(serverVersion); | |||
mockMvc.perform(get(VERSION_ENDPOINT)) | |||
.andExpect(status().isOk()) | |||
.andExpect(content().string(serverVersion)); | |||
} | |||
} |
@@ -0,0 +1,38 @@ | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2024 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.v2.config; | |||
import org.junit.Test; | |||
import org.sonar.api.platform.Server; | |||
import org.sonar.server.v2.api.analysis.controller.DefaultVersionController; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.mockito.Mockito.mock; | |||
public class PlatformLevel4WebConfigTest { | |||
private final PlatformLevel4WebConfig platformLevel4WebConfig = new PlatformLevel4WebConfig(); | |||
@Test | |||
public void versionController() { | |||
assertThat(platformLevel4WebConfig.versionController(mock(Server.class))).isNotNull() | |||
.isInstanceOf(DefaultVersionController.class); | |||
} | |||
} |