From: Sébastien Lesaint Date: Wed, 29 Apr 2015 13:29:57 +0000 (+0200) Subject: SONAR-6366 SONAR-6379 remove artifact from JSON response X-Git-Tag: 5.2-RC1~2086 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=7ac1df3b6a1ad251bfd6405b4674de15b7fed02e;p=sonarqube.git SONAR-6366 SONAR-6379 remove artifact from JSON response --- 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 d10d23e87d0..a113db24883 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 @@ -97,9 +97,10 @@ public class PluginWSCommons { return; } - jsonWriter.name(OBJECT_ARTIFACT); - jsonWriter.beginObject(); + jsonWriter.name(OBJECT_ARTIFACT).beginObject(); + jsonWriter.prop(PROPERTY_NAME, pluginMetadata.getFile().getName()); + jsonWriter.endObject(); } @@ -128,21 +129,20 @@ public class PluginWSCommons { } public void writeRelease(JsonWriter jsonWriter, Release release) { - jsonWriter.name(OBJECT_RELEASE); - jsonWriter.beginObject(); + jsonWriter.name(OBJECT_RELEASE).beginObject(); + jsonWriter.prop(PROPERTY_VERSION, release.getVersion().toString()); jsonWriter.propDate(PROPERTY_DATE, release.getDate()); - writeArtifact(jsonWriter, release); - jsonWriter.endObject(); } public void writeArtifact(JsonWriter jsonWriter, Release release) { - jsonWriter.name(OBJECT_ARTIFACT); - jsonWriter.beginObject(); + jsonWriter.name(OBJECT_ARTIFACT).beginObject(); + jsonWriter.prop(PROPERTY_NAME, release.getFilename()); jsonWriter.prop(PROPERTY_URL, release.getDownloadUrl()); + jsonWriter.endObject(); } @@ -162,8 +162,7 @@ public class PluginWSCommons { * */ public void writeUpdate(JsonWriter jsonWriter, PluginUpdate pluginUpdate) { - jsonWriter.name(OBJECT_UPDATE); - jsonWriter.beginObject(); + jsonWriter.name(OBJECT_UPDATE).beginObject(); writeUpdateProperties(jsonWriter, pluginUpdate); @@ -186,8 +185,7 @@ public class PluginWSCommons { public void writeUpdateProperties(JsonWriter jsonWriter, PluginUpdate pluginUpdate) { jsonWriter.prop(PROPERTY_STATUS, toJSon(pluginUpdate.getStatus())); - jsonWriter.name(ARRAY_REQUIRES); - jsonWriter.beginArray(); + jsonWriter.name(ARRAY_REQUIRES).beginArray(); Release release = pluginUpdate.getRelease(); for (Plugin child : filter(transform(release.getOutgoingDependencies(), ReleaseToArtifact.INSTANCE), Plugin.class)) { jsonWriter.beginObject(); diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/UpdatesPluginsWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/UpdatesPluginsWsAction.java index c361ca64141..090541f3485 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/UpdatesPluginsWsAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/UpdatesPluginsWsAction.java @@ -102,7 +102,7 @@ public class UpdatesPluginsWsAction implements PluginsWsAction { private void writePlugins(JsonWriter jsonWriter, UpdateCenter updateCenter) { jsonWriter.name(ARRAY_PLUGINS); jsonWriter.beginArray(); - for (PluginUpdateAggregate aggregate : retrieveUpdatablePlugins()) { + for (PluginUpdateAggregate aggregate : retrieveUpdatablePlugins(updateCenter)) { writePluginUpdateAggregate(jsonWriter, aggregate); } jsonWriter.endArray(); @@ -130,8 +130,8 @@ public class UpdatesPluginsWsAction implements PluginsWsAction { jsonWriter.endArray(); } - private Collection retrieveUpdatablePlugins() { - List pluginUpdates = updateCenterMatrixFactory.getUpdateCenter(DO_NOT_FORCE_REFRESH).findPluginUpdates(); + private Collection retrieveUpdatablePlugins(UpdateCenter updateCenter) { + List pluginUpdates = updateCenter.findPluginUpdates(); // aggregates updates of the same plugin to a single object and sort these objects by plugin name then key return ImmutableSortedSet.copyOf( NAME_KEY_PLUGIN_UPGRADE_AGGREGATE_ORDERING, diff --git a/server/sonar-server/src/main/resources/org/sonar/server/plugins/ws/example-available_plugins.json b/server/sonar-server/src/main/resources/org/sonar/server/plugins/ws/example-available_plugins.json index b2c89f438d1..0d2077ab2e3 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/plugins/ws/example-available_plugins.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/plugins/ws/example-available_plugins.json @@ -11,11 +11,7 @@ "termsAndConditionsUrl": "http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf", "release": { "version": "3.2", - "date": "2015-03-10", - "artifact": { - "name": "sonar-abap-plugin-3.2.jar", - "url": "http://dist.sonarsource.com/abap/download/sonar-abap-plugin-3.2.jar" - } + "date": "2015-03-10" }, "update": { "status": "COMPATIBLE", @@ -32,11 +28,7 @@ "organizationUrl": "http://www.sonarsource.com", "release": { "version": "1.0", - "date": "2014-03-31", - "artifact": { - "name": "sonar-android-plugin-1.0.jar", - "url": "http://repository.codehaus.org/org/codehaus/sonar-plugins/android/sonar-android-plugin/1.0/sonar-android-plugin-1.0.jar" - } + "date": "2014-03-31" }, "update": { "status": "COMPATIBLE", diff --git a/server/sonar-server/src/main/resources/org/sonar/server/plugins/ws/example-updates_plugins.json b/server/sonar-server/src/main/resources/org/sonar/server/plugins/ws/example-updates_plugins.json index 17e592ee7c1..6693515cf08 100644 --- a/server/sonar-server/src/main/resources/org/sonar/server/plugins/ws/example-updates_plugins.json +++ b/server/sonar-server/src/main/resources/org/sonar/server/plugins/ws/example-updates_plugins.json @@ -13,11 +13,7 @@ { "release": { "version": "3.1", - "date": "2014-12-21", - "artifact": { - "name": "sonar-abap-plugin-3.1.jar", - "url": "http://dist.sonarsource.com/abap/download/sonar-abap-plugin-3.1.jar" - } + "date": "2014-12-21" }, "status": "INCOMPATIBLE", "requires": [] @@ -25,11 +21,7 @@ { "release": { "version": "3.2", - "date": "2015-03-10", - "artifact": { - "name": "sonar-abap-plugin-3.2.jar", - "url": "http://dist.sonarsource.com/abap/download/sonar-abap-plugin-3.2.jar" - } + "date": "2015-03-10" }, "status": "COMPATIBLE", "requires": [] @@ -48,11 +40,7 @@ { "release": { "version": "1.0", - "date": "2014-03-31", - "artifact": { - "name": "sonar-android-plugin-1.0.jar", - "url": "http://repository.codehaus.org/org/codehaus/sonar-plugins/android/sonar-android-plugin/1.0/sonar-android-plugin-1.0.jar" - } + "date": "2014-03-31" }, "status": "COMPATIBLE", "requires": [ 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 218316209cb..3aacdf9df32 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 @@ -19,6 +19,7 @@ */ package org.sonar.server.plugins.ws; +import java.io.File; import org.junit.Test; import org.sonar.api.utils.text.JsonWriter; import org.sonar.core.plugins.DefaultPluginMetadata; @@ -28,8 +29,6 @@ import org.sonar.updatecenter.common.PluginUpdate; import org.sonar.updatecenter.common.Release; import org.sonar.updatecenter.common.Version; -import java.io.File; - import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.api.utils.DateUtils.parseDate; import static org.sonar.core.plugins.DefaultPluginMetadata.create; @@ -42,25 +41,25 @@ import static org.sonar.updatecenter.common.PluginUpdate.Status.REQUIRE_SONAR_UP public class PluginWSCommonsTest { private static final DefaultPluginMetadata GIT_PLUGIN_METADATA = create("scmgit") - .setName("Git") - .setDescription("Git SCM Provider.") - .setVersion("1.0") - .setLicense("GNU LGPL 3") - .setOrganization("SonarSource") - .setOrganizationUrl("http://www.sonarsource.com") - .setHomepage("http://redirect.sonarsource.com/plugins/scmgit.html") - .setIssueTrackerUrl("http://jira.codehaus.org/browse/SONARSCGIT") - .setFile(new File("/home/user/sonar-scm-git-plugin-1.0.jar")); + .setName("Git") + .setDescription("Git SCM Provider.") + .setVersion("1.0") + .setLicense("GNU LGPL 3") + .setOrganization("SonarSource") + .setOrganizationUrl("http://www.sonarsource.com") + .setHomepage("http://redirect.sonarsource.com/plugins/scmgit.html") + .setIssueTrackerUrl("http://jira.codehaus.org/browse/SONARSCGIT") + .setFile(new File("/home/user/sonar-scm-git-plugin-1.0.jar")); private static final Plugin PLUGIN = new Plugin("p_key") - .setName("p_name") - .setCategory("p_category") - .setDescription("p_description") - .setLicense("p_license") - .setOrganization("p_orga_name") - .setOrganizationUrl("p_orga_url") - .setTermsConditionsUrl("p_t_and_c_url"); + .setName("p_name") + .setCategory("p_category") + .setDescription("p_description") + .setLicense("p_license") + .setOrganization("p_orga_name") + .setOrganizationUrl("p_orga_url") + .setTermsConditionsUrl("p_t_and_c_url"); private static final Release RELEASE = new Release(PLUGIN, version("1.0")).setDate(parseDate("2015-04-16")) - .setDownloadUrl("http://toto.com/file.jar"); + .setDownloadUrl("http://toto.com/file.jar"); private WsTester.TestResponse response = new WsTester.TestResponse(); private JsonWriter jsonWriter = response.newJsonWriter(); @@ -72,19 +71,19 @@ public class PluginWSCommonsTest { jsonWriter.close(); assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo("{" + - " \"key\": \"scmgit\"," + - " \"name\": \"Git\"," + - " \"description\": \"Git SCM Provider.\"," + - " \"version\": \"1.0\"," + - " \"license\": \"GNU LGPL 3\"," + - " \"organizationName\": \"SonarSource\"," + - " \"organizationUrl\": \"http://www.sonarsource.com\"," + - " \"homepage\": \"http://redirect.sonarsource.com/plugins/scmgit.html\"," + - " \"issueTrackerUrl\": \"http://jira.codehaus.org/browse/SONARSCGIT\"," + - " \"artifact\": {" + - " \"name\": \"sonar-scm-git-plugin-1.0.jar\"" + - " }" + - "}"); + " \"key\": \"scmgit\"," + + " \"name\": \"Git\"," + + " \"description\": \"Git SCM Provider.\"," + + " \"version\": \"1.0\"," + + " \"license\": \"GNU LGPL 3\"," + + " \"organizationName\": \"SonarSource\"," + + " \"organizationUrl\": \"http://www.sonarsource.com\"," + + " \"homepage\": \"http://redirect.sonarsource.com/plugins/scmgit.html\"," + + " \"issueTrackerUrl\": \"http://jira.codehaus.org/browse/SONARSCGIT\"," + + " \"artifact\": {" + + " \"name\": \"sonar-scm-git-plugin-1.0.jar\"" + + " }" + + "}"); } @Test @@ -95,16 +94,16 @@ public class PluginWSCommonsTest { jsonWriter.close(); assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo("{" + - " \"key\": \"scmgit\"," + - " \"name\": \"Git\"," + - " \"description\": \"Git SCM Provider.\"," + - " \"version\": \"1.0\"," + - " \"license\": \"GNU LGPL 3\"," + - " \"organizationName\": \"SonarSource\"," + - " \"organizationUrl\": \"http://www.sonarsource.com\"," + - " \"homepage\": \"http://redirect.sonarsource.com/plugins/scmgit.html\"," + - " \"issueTrackerUrl\": \"http://jira.codehaus.org/browse/SONARSCGIT\"," + - "}"); + " \"key\": \"scmgit\"," + + " \"name\": \"Git\"," + + " \"description\": \"Git SCM Provider.\"," + + " \"version\": \"1.0\"," + + " \"license\": \"GNU LGPL 3\"," + + " \"organizationName\": \"SonarSource\"," + + " \"organizationUrl\": \"http://www.sonarsource.com\"," + + " \"homepage\": \"http://redirect.sonarsource.com/plugins/scmgit.html\"," + + " \"issueTrackerUrl\": \"http://jira.codehaus.org/browse/SONARSCGIT\"," + + "}"); } @Test @@ -125,10 +124,10 @@ public class PluginWSCommonsTest { jsonWriter.close(); assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo("{" + - " \"artifact\": {" + - " \"name\": \"sonar-scm-git-plugin-1.0.jar\"" + - " }" + - "}"); + " \"artifact\": {" + + " \"name\": \"sonar-scm-git-plugin-1.0.jar\"" + + " }" + + "}"); } @Test @@ -137,23 +136,19 @@ public class PluginWSCommonsTest { jsonWriter.close(); assertJson(response.outputAsString()).isSimilarTo("{" + - " \"key\": \"p_key\"," + - " \"name\": \"p_name\"," + - " \"description\": \"p_description\"," + - " \"category\": \"p_category\"," + - " \"license\": \"p_license\"," + - " \"organizationName\": \"p_orga_name\"," + - " \"organizationUrl\": \"p_orga_url\"," + - " \"termsAndConditionsUrl\": \"p_t_and_c_url\"" + - " \"release\": {" + - " \"version\": \"1.0\"," + - " \"date\": \"2015-04-16\"," + - " \"artifact\": {" + - " \"name\": \"file.jar\"," + - " \"url\": \"http://toto.com/file.jar\"" + - " }" + - " }" + - "}"); + " \"key\": \"p_key\"," + + " \"name\": \"p_name\"," + + " \"description\": \"p_description\"," + + " \"category\": \"p_category\"," + + " \"license\": \"p_license\"," + + " \"organizationName\": \"p_orga_name\"," + + " \"organizationUrl\": \"p_orga_url\"," + + " \"termsAndConditionsUrl\": \"p_t_and_c_url\"" + + " \"release\": {" + + " \"version\": \"1.0\"," + + " \"date\": \"2015-04-16\"" + + " }" + + "}"); } @Test @@ -164,34 +159,30 @@ public class PluginWSCommonsTest { jsonWriter.close(); assertJson(response.outputAsString()).isSimilarTo("{" + - " \"key\": \"p_key\"," + - " \"name\": \"p_name\"," + - " \"description\": \"p_description\"," + - " \"category\": \"p_category\"," + - " \"license\": \"p_license\"," + - " \"organizationName\": \"p_orga_name\"," + - " \"organizationUrl\": \"p_orga_url\"," + - " \"termsAndConditionsUrl\": \"p_t_and_c_url\"" + - "}"); + " \"key\": \"p_key\"," + + " \"name\": \"p_name\"," + + " \"description\": \"p_description\"," + + " \"category\": \"p_category\"," + + " \"license\": \"p_license\"," + + " \"organizationName\": \"p_orga_name\"," + + " \"organizationUrl\": \"p_orga_url\"," + + " \"termsAndConditionsUrl\": \"p_t_and_c_url\"" + + "}"); } @Test - public void writeRelease_writes_artifact_object_and_file_name() { + public void writeRelease() { jsonWriter.beginObject(); underTest.writeRelease(jsonWriter, RELEASE); jsonWriter.endObject(); jsonWriter.close(); assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo("{" + - " \"release\": {" + - " \"version\": \"1.0\"," + - " \"date\": \"2015-04-16\"," + - " \"artifact\": {" + - " \"name\": \"file.jar\"," + - " \"url\": \"http://toto.com/file.jar\"" + - " }" + - " }" + - "}"); + " \"release\": {" + + " \"version\": \"1.0\"," + + " \"date\": \"2015-04-16\"" + + " }" + + "}"); } @Test @@ -202,11 +193,11 @@ public class PluginWSCommonsTest { jsonWriter.close(); assertJson(response.outputAsString()).setStrictArrayOrder(true).isSimilarTo("{" + - " \"artifact\": {" + - " \"name\": \"file.jar\"," + - " \"url\": \"http://toto.com/file.jar\"" + - " }" + - "}"); + " \"artifact\": {" + + " \"name\": \"file.jar\"," + + " \"url\": \"http://toto.com/file.jar\"" + + " }" + + "}"); } @Test @@ -233,8 +224,8 @@ public class PluginWSCommonsTest { public void writeUpdate_renders_key_name_and_description_of_outgoing_dependencies() { PluginUpdate pluginUpdate = new PluginUpdate(); pluginUpdate.setRelease( - new Release(PLUGIN, version("1.0")).addOutgoingDependency(RELEASE) - ); + new Release(PLUGIN, version("1.0")).addOutgoingDependency(RELEASE) + ); jsonWriter.beginObject(); underTest.writeUpdate(jsonWriter, pluginUpdate); @@ -242,16 +233,16 @@ public class PluginWSCommonsTest { jsonWriter.close(); assertJson(response.outputAsString()).isSimilarTo("{" + - " \"update\": {" + - " \"requires\": [" + - " {" + - " \"key\": \"p_key\"," + - " \"name\": \"p_name\"," + - " \"description\": \"p_description\"" + - " }" + - " ]" + - " }" + - "}"); + " \"update\": {" + + " \"requires\": [" + + " {" + + " \"key\": \"p_key\"," + + " \"name\": \"p_name\"," + + " \"description\": \"p_description\"" + + " }" + + " ]" + + " }" + + "}"); } private static Version version(String version) { diff --git a/server/sonar-server/src/test/resources/org/sonar/server/plugins/ws/AvailablePluginsWsActionTest/properties_per_plugin.json b/server/sonar-server/src/test/resources/org/sonar/server/plugins/ws/AvailablePluginsWsActionTest/properties_per_plugin.json index 99b5f312050..8c5ed3bf5aa 100644 --- a/server/sonar-server/src/test/resources/org/sonar/server/plugins/ws/AvailablePluginsWsActionTest/properties_per_plugin.json +++ b/server/sonar-server/src/test/resources/org/sonar/server/plugins/ws/AvailablePluginsWsActionTest/properties_per_plugin.json @@ -11,11 +11,7 @@ "termsAndConditionsUrl": "p_t_and_c_url", "release": { "version": "1.12.1", - "date": "2015-04-16", - "artifact": { - "name": "p_file.jar", - "url": "http://p_file.jar" - } + "date": "2015-04-16" }, "update": { "status": "COMPATIBLE",