aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-02-09 20:09:41 +0100
committerTeryk Bellahsene <teryk.bellahsene@sonarsource.com>2017-02-10 17:41:31 +0100
commiteb21235975107e58722648c204e6fe883f7808e9 (patch)
treefa9c0e8beff16f79ae2d32ac42fc0a94c89e134e
parent25732f53ecba74d8cf9762b65988eb180b672ebb (diff)
downloadsonarqube-eb21235975107e58722648c204e6fe883f7808e9.tar.gz
sonarqube-eb21235975107e58722648c204e6fe883f7808e9.zip
SONAR-8637 Display functional version of plugins when available
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/ws/UpgradesAction.java22
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java10
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/ws/UpgradesActionTest.java84
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginWSCommonsTest.java4
-rw-r--r--sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java13
5 files changed, 68 insertions, 65 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/UpgradesAction.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/UpgradesAction.java
index bba11b579b3..d90f9224950 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/UpgradesAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/UpgradesAction.java
@@ -28,6 +28,7 @@ import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.server.plugins.UpdateCenterMatrixFactory;
import org.sonar.server.plugins.ws.PluginWSCommons;
+import org.sonar.server.ui.VersionFormatter;
import org.sonar.updatecenter.common.Plugin;
import org.sonar.updatecenter.common.Release;
import org.sonar.updatecenter.common.SonarUpdate;
@@ -61,6 +62,14 @@ public class UpgradesAction implements SystemWsAction {
this.pluginWSCommons = pluginWSCommons;
}
+ private static void writeMetadata(JsonWriter jsonWriter, Release release) {
+ jsonWriter.prop(PROPERTY_VERSION, VersionFormatter.format(release.getVersion().getName()));
+ jsonWriter.prop(PROPERTY_DESCRIPTION, release.getDescription());
+ jsonWriter.propDate(PROPERTY_RELEASE_DATE, release.getDate());
+ jsonWriter.prop(PROPERTY_CHANGE_LOG_URL, release.getChangelogUrl());
+ jsonWriter.prop(PROPERTY_DOWNLOAD_URL, release.getDownloadUrl());
+ }
+
@Override
public void define(WebService.NewController controller) {
controller.createAction("upgrades")
@@ -117,16 +126,6 @@ public class UpgradesAction implements SystemWsAction {
jsonWriter.endObject();
}
- private static void writeMetadata(JsonWriter jsonWriter, Release release) {
- 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());
- jsonWriter.prop(PROPERTY_DOWNLOAD_URL, release.getDownloadUrl());
- }
-
private void writePlugins(JsonWriter jsonWriter, SonarUpdate sonarUpdate) {
jsonWriter.name(OBJECT_PLUGINS).beginObject();
@@ -143,7 +142,8 @@ public class UpgradesAction implements SystemWsAction {
jsonWriter.beginObject();
pluginWSCommons.writePlugin(jsonWriter, (Plugin) release.getArtifact());
- jsonWriter.prop(PROPERTY_VERSION, release.getVersion().toString());
+ String version = isNotBlank(release.getDisplayVersion()) ? release.getDisplayVersion() : release.getVersion().toString();
+ jsonWriter.prop(PROPERTY_VERSION, version);
jsonWriter.endObject();
}
diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java
index 213d9a17a10..d224654362c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java
@@ -46,6 +46,7 @@ import static com.google.common.collect.ImmutableSortedSet.copyOf;
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.transform;
import static java.lang.String.CASE_INSENSITIVE_ORDER;
+import static org.apache.commons.lang.StringUtils.isNotBlank;
public class PluginWSCommons {
static final String PROPERTY_KEY = "key";
@@ -76,8 +77,7 @@ public class PluginWSCommons {
public static final Comparator<Plugin> NAME_KEY_PLUGIN_ORDERING = Ordering.from(CASE_INSENSITIVE_ORDER)
.onResultOf(PluginToName.INSTANCE)
.compound(
- Ordering.from(CASE_INSENSITIVE_ORDER).onResultOf(PluginToKeyFunction.INSTANCE)
- );
+ Ordering.from(CASE_INSENSITIVE_ORDER).onResultOf(PluginToKeyFunction.INSTANCE));
public static final Comparator<PluginUpdate> NAME_KEY_PLUGIN_UPDATE_ORDERING = Ordering.from(NAME_KEY_PLUGIN_ORDERING)
.onResultOf(PluginUpdateToPlugin.INSTANCE);
@@ -89,7 +89,8 @@ public class PluginWSCommons {
json.prop(PROPERTY_DESCRIPTION, pluginInfo.getDescription());
Version version = pluginInfo.getVersion();
if (version != null) {
- json.prop(PROPERTY_VERSION, version.getName());
+ String functionalVersion = isNotBlank(pluginInfo.getDisplayVersion()) ? pluginInfo.getDisplayVersion() : version.getName();
+ json.prop(PROPERTY_VERSION, functionalVersion);
}
json.prop(PROPERTY_CATEGORY, category);
json.prop(PROPERTY_LICENSE, pluginInfo.getLicense());
@@ -138,7 +139,8 @@ public class PluginWSCommons {
public void writeRelease(JsonWriter jsonWriter, Release release) {
jsonWriter.name(OBJECT_RELEASE).beginObject();
- jsonWriter.prop(PROPERTY_VERSION, release.getVersion().toString());
+ String version = isNotBlank(release.getDisplayVersion()) ? release.getDisplayVersion() : release.getVersion().toString();
+ jsonWriter.prop(PROPERTY_VERSION, version);
jsonWriter.propDate(PROPERTY_DATE, release.getDate());
jsonWriter.prop(PROPERTY_DESCRIPTION, release.getDescription());
jsonWriter.prop(PROPERTY_CHANGE_LOG_URL, release.getChangelogUrl());
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/UpgradesActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/UpgradesActionTest.java
index 5d66052f673..39773159413 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/UpgradesActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/UpgradesActionTest.java
@@ -57,6 +57,41 @@ public class UpgradesActionTest {
private Request request = mock(Request.class);
private WsTester.TestResponse response = new WsTester.TestResponse();
+ private static SonarUpdate createSonar_51_update() {
+ Plugin brandingPlugin = Plugin.factory("branding")
+ .setCategory("Integration")
+ .setName("Branding")
+ .setDescription("Allows to add your own logo to the SonarQube UI.")
+ .setHomepageUrl("http://docs.codehaus.org/display/SONAR/Branding+Plugin")
+ .setLicense("GNU LGPL 3")
+ .setOrganization("SonarSource")
+ .setOrganizationUrl("http://www.sonarsource.com")
+ .setIssueTrackerUrl("http://jira.sonarsource.com/browse/SONARPLUGINS/component/14663")
+ .setSourcesUrl("https://github.com/SonarCommunity/sonar-branding");
+ Plugin viewsPlugin = Plugin.factory("views")
+ .setName("Views")
+ .setCategory("Governance")
+ .setDescription("Create aggregation trees to group projects. Projects can for instance be grouped by applications, applications by team, teams by department.")
+ .setHomepageUrl("https://redirect.sonarsource.com/plugins/views.html")
+ .setLicense("Commercial")
+ .setOrganization("SonarSource")
+ .setOrganizationUrl("http://www.sonarsource.com")
+ .setTermsConditionsUrl("http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf")
+ .setIssueTrackerUrl("http://jira.sonarsource.com/browse/VIEWS");
+
+ release = new Release(new Sonar(), Version.create("5.1.0.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.0.5498")).setDisplayVersion("2.8 (build 5498)"));
+
+ return sonarUpdate;
+ }
+
@Before
public void wireMocks() {
when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.of(updateCenter));
@@ -91,7 +126,7 @@ public class UpgradesActionTest {
@Test
public void empty_array_is_returned_when_update_center_is_unavailable() throws Exception {
- when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.<UpdateCenter>absent());
+ when(updateCenterFactory.getUpdateCenter(anyBoolean())).thenReturn(Optional.absent());
underTest.handle(request, response);
@@ -108,51 +143,4 @@ public class UpgradesActionTest {
assertJson(response.outputAsString()).withStrictArrayOrder()
.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")
- .setName("Branding")
- .setDescription("Allows to add your own logo to the SonarQube UI.")
- .setHomepageUrl("http://docs.codehaus.org/display/SONAR/Branding+Plugin")
- .setLicense("GNU LGPL 3")
- .setOrganization("SonarSource")
- .setOrganizationUrl("http://www.sonarsource.com")
- .setIssueTrackerUrl("http://jira.sonarsource.com/browse/SONARPLUGINS/component/14663")
- .setSourcesUrl("https://github.com/SonarCommunity/sonar-branding");
- Plugin viewsPlugin = Plugin.factory("views")
- .setName("Views")
- .setCategory("Governance")
- .setDescription("Create aggregation trees to group projects. Projects can for instance be grouped by applications, applications by team, teams by department.")
- .setHomepageUrl("https://redirect.sonarsource.com/plugins/views.html")
- .setLicense("Commercial")
- .setOrganization("SonarSource")
- .setOrganizationUrl("http://www.sonarsource.com")
- .setTermsConditionsUrl("http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf")
- .setIssueTrackerUrl("http://jira.sonarsource.com/browse/VIEWS");
-
- 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")));
-
- return sonarUpdate;
- }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginWSCommonsTest.java b/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginWSCommonsTest.java
index d4231b1c6b1..a189abcd419 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginWSCommonsTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginWSCommonsTest.java
@@ -123,13 +123,13 @@ public class PluginWSCommonsTest {
@Test
public void writeRelease() {
jsonWriter.beginObject();
- underTest.writeRelease(jsonWriter, newRelease());
+ underTest.writeRelease(jsonWriter, newRelease().setDisplayVersion("1.0 (build 42)"));
jsonWriter.endObject();
jsonWriter.close();
assertJson(response.outputAsString()).withStrictArrayOrder().isSimilarTo("{" +
" \"release\": {" +
- " \"version\": \"1.0\"," +
+ " \"version\": \"1.0 (build 42)\"," +
" \"date\": \"2015-04-16\"," +
" \"description\": \"release description\"," +
" \"changeLogUrl\": \"http://change.org/plugin\"" +
diff --git a/sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java b/sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java
index 8e489e7e725..71339ca7a37 100644
--- a/sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java
+++ b/sonar-core/src/main/java/org/sonar/core/platform/PluginInfo.java
@@ -107,6 +107,8 @@ public class PluginInfo implements Comparable<PluginInfo> {
@CheckForNull
private Version version;
+ private String displayVersion;
+
@CheckForNull
private Version minimalSqVersion;
@@ -176,6 +178,16 @@ public class PluginInfo implements Comparable<PluginInfo> {
}
@CheckForNull
+ public String getDisplayVersion() {
+ return displayVersion;
+ }
+
+ public PluginInfo setDisplayVersion(@Nullable String displayVersion) {
+ this.displayVersion = displayVersion;
+ return this;
+ }
+
+ @CheckForNull
public Version getMinimalSqVersion() {
return minimalSqVersion;
}
@@ -407,6 +419,7 @@ public class PluginInfo implements Comparable<PluginInfo> {
info.setLicense(manifest.getLicense());
info.setOrganizationName(manifest.getOrganization());
info.setOrganizationUrl(manifest.getOrganizationUrl());
+ info.setDisplayVersion(manifest.getDisplayVersion());
String minSqVersion = manifest.getSonarVersion();
if (minSqVersion != null) {
info.setMinimalSqVersion(Version.create(minSqVersion));