]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6366 SONAR-6379 remove artifact from JSON response 266/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 29 Apr 2015 13:29:57 +0000 (15:29 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 30 Apr 2015 09:07:45 +0000 (11:07 +0200)
server/sonar-server/src/main/java/org/sonar/server/plugins/ws/PluginWSCommons.java
server/sonar-server/src/main/java/org/sonar/server/plugins/ws/UpdatesPluginsWsAction.java
server/sonar-server/src/main/resources/org/sonar/server/plugins/ws/example-available_plugins.json
server/sonar-server/src/main/resources/org/sonar/server/plugins/ws/example-updates_plugins.json
server/sonar-server/src/test/java/org/sonar/server/plugins/ws/PluginWSCommonsTest.java
server/sonar-server/src/test/resources/org/sonar/server/plugins/ws/AvailablePluginsWsActionTest/properties_per_plugin.json

index d10d23e87d05bbe121f4b85474003b4c270bc52d..a113db248833bbc7cb240d8b5e5e2ca5a9091327 100644 (file)
@@ -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 {
    * </pre>
    */
   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();
index c361ca64141e693547390bd51b53d7fe82250b03..090541f3485f97bc1d352ac7abc754c60bce77bc 100644 (file)
@@ -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<PluginUpdateAggregate> retrieveUpdatablePlugins() {
-    List<PluginUpdate> pluginUpdates = updateCenterMatrixFactory.getUpdateCenter(DO_NOT_FORCE_REFRESH).findPluginUpdates();
+  private Collection<PluginUpdateAggregate> retrieveUpdatablePlugins(UpdateCenter updateCenter) {
+    List<PluginUpdate> 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,
index b2c89f438d1400bbfe2f9b9fab44363201dbefbd..0d2077ab2e34fd451bd6b2cd5a28071c7f48267b 100644 (file)
       "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",
       "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",
index 17e592ee7c1f3444134ce5bba100856a7ffc98e1..6693515cf0886033eb034b15e60c4b983e81a4f7 100644 (file)
         {
           "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": []
         {
           "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": []
         {
           "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": [
index 218316209cb3f851f8fc1fb9ec82387d68773760..3aacdf9df322bd0a47a699ab54c1ba8dbdf851c5 100644 (file)
@@ -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) {
index 99b5f31205006df10e3a656607c5fe09aab55447..8c5ed3bf5aa07762312c11b107a7c9c04df85db6 100644 (file)
       "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",