]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6365 consistent properties for plugin in JSON response 275/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 4 May 2015 08:07:04 +0000 (10:07 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 4 May 2015 15:47:59 +0000 (17:47 +0200)
server/sonar-server/src/main/java/org/sonar/server/platform/ws/UpgradesSystemWsAction.java
server/sonar-server/src/main/resources/org/sonar/server/platform/ws/example-updates_plugins.json [deleted file]
server/sonar-server/src/main/resources/org/sonar/server/platform/ws/example-upgrades_plugins.json [new file with mode: 0644]
server/sonar-server/src/test/java/org/sonar/server/platform/ws/UpgradesSystemWsActionTest.java

index d3c9d4fea278de399080a34ac1ed540c308055c1..5e8455592012b91f8190634077d1c25675086a55 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.api.server.ws.Response;
 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.updatecenter.common.Plugin;
 import org.sonar.updatecenter.common.Release;
 import org.sonar.updatecenter.common.SonarUpdate;
@@ -39,8 +40,8 @@ import com.google.common.io.Resources;
 public class UpgradesSystemWsAction implements SystemWsAction {
 
   private static final boolean DO_NOT_FORCE_REFRESH = false;
+
   private static final String ARRAY_UPGRADES = "upgrades";
-  private static final String PROPERTY_NAME = "name";
   private static final String PROPERTY_UPDATE_CENTER_REFRESH = "updateCenterRefresh";
   private static final String PROPERTY_VERSION = "version";
   private static final String PROPERTY_DESCRIPTION = "description";
@@ -49,13 +50,14 @@ public class UpgradesSystemWsAction implements SystemWsAction {
   private static final String PROPERTY_DOWNLOAD_URL = "downloadUrl";
   private static final String OBJECT_PLUGINS = "plugins";
   private static final String ARRAY_REQUIRE_UPDATE = "requireUpdate";
-  private static final String PROPERTY_KEY = "key";
   private static final String ARRAY_INCOMPATIBLE = "incompatible";
 
   private final UpdateCenterMatrixFactory updateCenterFactory;
+  private final PluginWSCommons pluginWSCommons;
 
-  public UpgradesSystemWsAction(UpdateCenterMatrixFactory updateCenterFactory) {
+  public UpgradesSystemWsAction(UpdateCenterMatrixFactory updateCenterFactory, PluginWSCommons pluginWSCommons) {
     this.updateCenterFactory = updateCenterFactory;
+    this.pluginWSCommons = pluginWSCommons;
   }
 
   @Override
@@ -67,20 +69,26 @@ public class UpgradesSystemWsAction implements SystemWsAction {
         "Plugin information is retrieved from Update Center. Date and time at which Update Center was last refreshed " +
         "is provided in the response.")
       .setHandler(this)
-      .setResponseExample(Resources.getResource(this.getClass(), "example-updates_plugins.json"));
+      .setResponseExample(Resources.getResource(this.getClass(), "example-upgrades_plugins.json"));
   }
 
   @Override
   public void handle(Request request, Response response) throws Exception {
     JsonWriter jsonWriter = response.newJsonWriter().setSerializeEmptys(false);
 
+    writeResponse(jsonWriter);
+
+    jsonWriter.close();
+  }
+
+  private void writeResponse(JsonWriter jsonWriter) {
     jsonWriter.beginObject();
+
     UpdateCenter updateCenter = updateCenterFactory.getUpdateCenter(DO_NOT_FORCE_REFRESH);
     writeUpgrades(jsonWriter, updateCenter);
     jsonWriter.propDateTime(PROPERTY_UPDATE_CENTER_REFRESH, updateCenter.getDate());
-    jsonWriter.endObject();
 
-    jsonWriter.close();
+    jsonWriter.endObject();
   }
 
   private void writeUpgrades(JsonWriter jsonWriter, UpdateCenter updateCenter) {
@@ -126,8 +134,7 @@ public class UpgradesSystemWsAction implements SystemWsAction {
     for (Release release : pluginsToUpgrade) {
       jsonWriter.beginObject();
 
-      Plugin plugin = (Plugin) release.getArtifact();
-      writePlugin(jsonWriter, plugin);
+      pluginWSCommons.writeMetadata(jsonWriter, (Plugin) release.getArtifact());
       jsonWriter.prop(PROPERTY_VERSION, release.getVersion().toString());
 
       jsonWriter.endObject();
@@ -136,18 +143,14 @@ public class UpgradesSystemWsAction implements SystemWsAction {
     jsonWriter.endArray();
   }
 
-  private void writePlugin(JsonWriter jsonWriter, Plugin plugin) {
-    jsonWriter.prop(PROPERTY_KEY, plugin.getKey());
-    jsonWriter.prop(PROPERTY_NAME, plugin.getName());
-    jsonWriter.prop(PROPERTY_DESCRIPTION, plugin.getDescription());
-  }
-
   private void writeIncompatiblePlugins(JsonWriter jsonWriter, List<Plugin> incompatiblePlugins) {
     jsonWriter.name(ARRAY_INCOMPATIBLE).beginArray();
 
     for (Plugin incompatiblePlugin : incompatiblePlugins) {
       jsonWriter.beginObject();
-      writePlugin(jsonWriter, incompatiblePlugin);
+
+      pluginWSCommons.writeMetadata(jsonWriter, incompatiblePlugin);
+
       jsonWriter.endObject();
     }
 
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/platform/ws/example-updates_plugins.json b/server/sonar-server/src/main/resources/org/sonar/server/platform/ws/example-updates_plugins.json
deleted file mode 100644 (file)
index d943840..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-{
-  "upgrades": [
-    {
-      "version": "5.1",
-      "description": "New overall layout, merge Issues Drilldown [...]",
-      "releaseDate": "2015-04-02",
-      "changeLogUrl": "http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=11694&version=20666",
-      "downloadUrl": "http://dist.sonar.codehaus.org/sonarqube-5.1.zip",
-      "plugins": {
-        "requireUpdate": [
-          {
-            "key": "views",
-            "name": "Views",
-            "description": "Create aggregation trees to group projects. Projects can for instance be grouped by applications,   applications by team, teams by department.",
-            "version": "2.8"
-          }
-        ],
-        "incompatible": [
-          {
-            "key": "branding",
-            "name": "Branding",
-            "description": "Allows to add your own logo to the SonarQube UI."
-          }
-        ]
-      }
-    }
-  ],
-  "updateCenterRefresh": "2015-04-24T16:08:36+0200"
-}
\ No newline at end of file
diff --git a/server/sonar-server/src/main/resources/org/sonar/server/platform/ws/example-upgrades_plugins.json b/server/sonar-server/src/main/resources/org/sonar/server/platform/ws/example-upgrades_plugins.json
new file mode 100644 (file)
index 0000000..83abaa3
--- /dev/null
@@ -0,0 +1,38 @@
+{
+  "upgrades": [
+    {
+      "version": "5.1",
+      "description": "New overall layout, merge Issues Drilldown [...]",
+      "releaseDate": "2015-04-02",
+      "changeLogUrl": "http://jira.codehaus.org/secure/ReleaseNote.jspa?projectId=11694&version=20666",
+      "downloadUrl": "http://dist.sonar.codehaus.org/sonarqube-5.1.zip",
+      "plugins": {
+        "requireUpdate": [
+          {
+            "key": "views",
+            "name": "Views",
+            "category": "Governance",
+            "description": "Create aggregation trees to group projects. Projects can for instance be grouped by applications,   applications by team, teams by department.",
+            "license": "Commercial",
+            "organizationName": "SonarSource",
+            "organizationUrl": "http://www.sonarsource.com",
+            "termsAndConditionsUrl": "http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf",
+            "version": "2.8"
+          }
+        ],
+        "incompatible": [
+          {
+            "key": "branding",
+            "name": "Branding",
+            "category": "Integration",
+            "description": "Allows to add your own logo to the SonarQube UI.",
+            "license": "GNU LGPL 3",
+            "organizationName": "SonarSource",
+            "organizationUrl": "http://www.sonarsource.com"
+          }
+        ]
+      }
+    }
+  ],
+  "updateCenterRefresh": "2015-04-24T16:08:36+0200"
+}
index 73a2dd04b5e1b8577f4729a940c78593b1e3d366..f073f03d56d2bbdd395e74cb7c986c8376cfe327 100644 (file)
@@ -25,6 +25,7 @@ import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.WebService;
 import org.sonar.api.utils.DateUtils;
 import org.sonar.server.plugins.UpdateCenterMatrixFactory;
+import org.sonar.server.plugins.ws.PluginWSCommons;
 import org.sonar.server.ws.WsTester;
 import org.sonar.updatecenter.common.Plugin;
 import org.sonar.updatecenter.common.Release;
@@ -49,7 +50,7 @@ public class UpgradesSystemWsActionTest {
 
   private UpdateCenterMatrixFactory updateCenterFactory = mock(UpdateCenterMatrixFactory.class);
   private UpdateCenter updateCenter = mock(UpdateCenter.class);
-  private UpgradesSystemWsAction underTest = new UpgradesSystemWsAction(updateCenterFactory);
+  private UpgradesSystemWsAction underTest = new UpgradesSystemWsAction(updateCenterFactory, new PluginWSCommons());
 
   private Request request = mock(Request.class);
   private WsTester.TestResponse response = new WsTester.TestResponse();
@@ -94,7 +95,7 @@ public class UpgradesSystemWsActionTest {
     underTest.handle(request, response);
 
     assertJson(response.outputAsString()).setStrictArrayOrder(true)
-      .isSimilarTo(getClass().getResource("example-updates_plugins.json"));
+      .isSimilarTo(getClass().getResource("example-upgrades_plugins.json"));
   }
 
   private static SonarUpdate createSonar_51_update() {
@@ -115,7 +116,7 @@ public class UpgradesSystemWsActionTest {
       .setHomepageUrl("http://redirect.sonarsource.com/plugins/views.html")
       .setLicense("Commercial")
       .setOrganization("SonarSource")
-      .setOrganizationUrl("http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf")
+      .setOrganizationUrl("http://www.sonarsource.com")
       .setTermsConditionsUrl("http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf")
       .setIssueTrackerUrl("http://jira.sonarsource.com/browse/VIEWS");