public static final String INTERNAL = "internal"; | public static final String INTERNAL = "internal"; | ||||
public static final String ANALYSIS_ENDPOINT = "/analysis"; | |||||
public static final String VERSION_ENDPOINT = ANALYSIS_ENDPOINT + "/version"; | |||||
private WebApiEndpoints() { | private WebApiEndpoints() { | ||||
} | } | ||||
} | } |
/* | |||||
* 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(); | |||||
} | |||||
} |
/* | |||||
* 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(); | |||||
} |
/* | |||||
* 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; |
package org.sonar.server.v2.config; | package org.sonar.server.v2.config; | ||||
import javax.annotation.Nullable; | import javax.annotation.Nullable; | ||||
import org.sonar.api.platform.Server; | |||||
import org.sonar.api.resources.Languages; | import org.sonar.api.resources.Languages; | ||||
import org.sonar.db.DbClient; | import org.sonar.db.DbClient; | ||||
import org.sonar.server.common.gitlab.config.GitlabConfigurationService; | import org.sonar.server.common.gitlab.config.GitlabConfigurationService; | ||||
import org.sonar.server.rule.RuleDescriptionFormatter; | import org.sonar.server.rule.RuleDescriptionFormatter; | ||||
import org.sonar.server.user.SystemPasscode; | import org.sonar.server.user.SystemPasscode; | ||||
import org.sonar.server.user.UserSession; | 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.DefaultDopSettingsController; | ||||
import org.sonar.server.v2.api.dop.controller.DopSettingsController; | import org.sonar.server.v2.api.dop.controller.DopSettingsController; | ||||
import org.sonar.server.v2.api.gitlab.config.controller.DefaultGitlabConfigurationController; | import org.sonar.server.v2.api.gitlab.config.controller.DefaultGitlabConfigurationController; | ||||
return new DefaultProjectBindingsController(userSession, projectBindingsService); | return new DefaultProjectBindingsController(userSession, projectBindingsService); | ||||
} | } | ||||
@Bean | |||||
public VersionController versionController(Server server) { | |||||
return new DefaultVersionController(server); | |||||
} | |||||
} | } |
/* | |||||
* 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)); | |||||
} | |||||
} |
/* | |||||
* 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); | |||||
} | |||||
} |