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;
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";
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
"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) {
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();
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();
}
--- /dev/null
+{
+ "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"
+}
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;
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();
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() {
.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");