import org.sonar.updatecenter.common.SonarUpdate;
import org.sonar.updatecenter.common.UpdateCenter;
+import static org.apache.commons.lang.StringUtils.isNotBlank;
+
/**
* Implementation of the {@code upgrades} action for the System WebService.
*/
}
private static void writeMetadata(JsonWriter jsonWriter, Release release) {
- jsonWriter.prop(PROPERTY_VERSION, release.getVersion().getName());
+ String technicalVersion = release.getVersion().getName();
+ String functionalVersion = release.getDisplayVersion();
+ jsonWriter.prop(PROPERTY_VERSION, isNotBlank(functionalVersion) ? functionalVersion : technicalVersion);
jsonWriter.prop(PROPERTY_DESCRIPTION, release.getDescription());
jsonWriter.propDate(PROPERTY_RELEASE_DATE, release.getDate());
jsonWriter.prop(PROPERTY_CHANGE_LOG_URL, release.getChangelogUrl());
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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.ui;
+
+import com.google.common.base.Splitter;
+import java.util.List;
+
+public class VersionFormatter {
+ private static final String VERSION_SEQUENCE_SEPARATION = ".";
+
+ private VersionFormatter() {
+ // prevent instantiation
+ }
+
+ public static String format(String technicalVersion) {
+ List<String> elements = Splitter.on(VERSION_SEQUENCE_SEPARATION).splitToList(technicalVersion);
+ if (elements.size() != 4) {
+ return technicalVersion;
+ }
+
+ // version has the form 6.3.1.4563
+ StringBuilder builder = new StringBuilder();
+ builder
+ .append(elements.get(0))
+ .append(VERSION_SEQUENCE_SEPARATION)
+ .append(elements.get(1));
+ if (!"0".equals(elements.get(2))) {
+ builder.append(VERSION_SEQUENCE_SEPARATION)
+ .append(elements.get(2));
+ }
+
+ builder.append(" (build ").append(elements.get(3)).append(")");
+
+ return builder.toString();
+ }
+}
import org.sonar.db.Database;
import org.sonar.db.dialect.H2;
import org.sonar.server.ui.PageRepository;
+import org.sonar.server.ui.VersionFormatter;
import static org.sonar.api.CoreProperties.RATING_GRID;
import static org.sonar.core.config.WebConstants.SONARQUBE_DOT_COM_ENABLED;
}
private void writeVersion(JsonWriter json) {
- json.prop("version", server.getVersion());
+ String displayVersion = VersionFormatter.format(server.getVersion());
+ json.prop("version", displayVersion);
}
private void writeDatabaseProduction(JsonWriter json) {
{
"upgrades": [
{
- "version": "5.1",
+ "version": "5.1 (build 5498)",
"description": "New overall layout, merge Issues Drilldown [...]",
"releaseDate": "2015-04-02",
"changeLogUrl": "http://jira.sonarsource.com/secure/ReleaseNote.jspa?projectId=11694&version=20666",
"organizationName": "SonarSource",
"organizationUrl": "http://www.sonarsource.com",
"termsAndConditionsUrl": "http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf",
- "version": "2.8"
+ "version": "2.8 (build 5498)"
}
],
"incompatible": [
"{" +
" \"upgrades\":" + "[]" +
"}";
+ private static Release release;
private UpdateCenterMatrixFactory updateCenterFactory = mock(UpdateCenterMatrixFactory.class);
private UpdateCenter updateCenter = mock(UpdateCenter.class);
.isSimilarTo(getClass().getResource("example-upgrades_plugins.json"));
}
+ @Test
+ public void technical_version_when_functional_is_blank() throws Exception {
+ SonarUpdate sonarUpdate = createSonar_51_update();
+ when(updateCenter.findSonarUpdates()).thenReturn(of(sonarUpdate));
+ release.setDisplayVersion("");
+
+ underTest.handle(request, response);
+
+ assertThat(response.outputAsString()).contains("5.42");
+ }
+
private static SonarUpdate createSonar_51_update() {
Plugin brandingPlugin = Plugin.factory("branding")
.setCategory("Integration")
.setTermsConditionsUrl("http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf")
.setIssueTrackerUrl("http://jira.sonarsource.com/browse/VIEWS");
- SonarUpdate sonarUpdate = new SonarUpdate(
- new Release(new Sonar(), Version.create("5.1"))
- .setDate(DateUtils.parseDate("2015-04-02"))
- .setDescription("New overall layout, merge Issues Drilldown [...]")
- .setDownloadUrl("http://dist.sonar.codehaus.org/sonarqube-5.1.zip")
- .setChangelogUrl("http://jira.sonarsource.com/secure/ReleaseNote.jspa?projectId=11694&version=20666")
- );
+ release = new Release(new Sonar(), Version.create("5.42"))
+ .setDisplayVersion("5.1 (build 5498)")
+ .setDate(DateUtils.parseDate("2015-04-02"))
+ .setDescription("New overall layout, merge Issues Drilldown [...]")
+ .setDownloadUrl("http://dist.sonar.codehaus.org/sonarqube-5.1.zip")
+ .setChangelogUrl("http://jira.sonarsource.com/secure/ReleaseNote.jspa?projectId=11694&version=20666");
+ SonarUpdate sonarUpdate = new SonarUpdate(release);
sonarUpdate.addIncompatiblePlugin(brandingPlugin);
sonarUpdate.addPluginToUpgrade(new Release(viewsPlugin, Version.create("2.8")));
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.ui;
+
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class VersionFormatterTest {
+ @Test
+ public void format_technical_version() {
+ assertThat(format("6.3")).isEqualTo("6.3");
+ assertThat(format("6.3.2")).isEqualTo("6.3.2");
+ assertThat(format("6.3.2.5498")).isEqualTo("6.3.2 (build 5498)");
+ assertThat(format("6.3.0.5499")).isEqualTo("6.3 (build 5499)");
+ }
+
+ private static String format(String technicalVersion) {
+ return VersionFormatter.format(technicalVersion);
+ }
+}
import org.sonar.server.ui.PageRepository;
import org.sonar.server.ws.WsActionTester;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
executeAndVerify("version.json");
}
+ @Test
+ public void functional_version_when_4_digits() throws Exception {
+ init();
+ when(server.getVersion()).thenReturn("6.3.1.1234");
+
+ String result = call();
+
+ assertThat(result).contains("6.3.1 (build 1234)");
+ }
+
+ @Test
+ public void functional_version_when_third_digit_is_0() throws Exception {
+ init();
+ when(server.getVersion()).thenReturn("6.3.0.1234");
+
+ String result = call();
+
+ assertThat(result).contains("6.3 (build 1234)");
+ }
+
@Test
public void return_if_production_database_or_not() throws Exception {
init();
when(server.getVersion()).thenReturn("6.2");
when(database.getDialect()).thenReturn(new MySql());
- String result = ws.newRequest().execute().getInput();
+ String result = call();
assertJson(ws.getDef().responseExampleAsString()).isSimilarTo(result);
}
private void init(org.sonar.api.web.page.Page[] pages, ResourceTypeTree[] resourceTypeTrees) {
when(database.getDialect()).thenReturn(new H2());
+ when(server.getVersion()).thenReturn("6.42");
PluginRepository pluginRepository = mock(PluginRepository.class);
when(pluginRepository.hasPlugin(anyString())).thenReturn(true);
PageRepository pageRepository = new PageRepository(pluginRepository, new PageDefinition[] {context -> {
}
private void executeAndVerify(String json) {
- assertJson(ws.newRequest().execute().getInput()).isSimilarTo(getClass().getResource(GlobalActionTest.class.getSimpleName() + "/" + json));
+ assertJson(call()).isSimilarTo(getClass().getResource(GlobalActionTest.class.getSimpleName() + "/" + json));
+ }
+
+ private String call() {
+ return ws.newRequest().execute().getInput();
}
private Page[] createPages() {