--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.plugins.edition;
+
+import java.util.Arrays;
+import org.sonar.updatecenter.common.Plugin;
+
+public final class EditionBundledPlugins {
+
+ private static final String SONARSOURCE_ORGANIZATION = "SonarSource";
+ private static final String[] SONARSOURCE_COMMERCIAL_LICENSES = {"SonarSource", "Commercial"};
+
+ private EditionBundledPlugins() {
+ // prevents instantiation
+ }
+
+ public static boolean isEditionBundled(Plugin plugin) {
+ return SONARSOURCE_ORGANIZATION.equalsIgnoreCase(plugin.getOrganization())
+ && Arrays.stream(SONARSOURCE_COMMERCIAL_LICENSES).anyMatch(s -> s.equalsIgnoreCase(plugin.getLicense()));
+ }
+}
import static com.google.common.collect.Iterables.transform;
import static java.lang.String.CASE_INSENSITIVE_ORDER;
import static org.apache.commons.lang.StringUtils.isNotBlank;
+import static org.sonar.server.plugins.edition.EditionBundledPlugins.isEditionBundled;
public class PluginWSCommons {
- static final String PROPERTY_KEY = "key";
- static final String PROPERTY_NAME = "name";
- static final String PROPERTY_HASH = "hash";
- static final String PROPERTY_FILENAME = "filename";
- static final String PROPERTY_SONARLINT_SUPPORTED = "sonarLintSupported";
- static final String PROPERTY_DESCRIPTION = "description";
- static final String PROPERTY_LICENSE = "license";
- static final String PROPERTY_VERSION = "version";
- static final String PROPERTY_CATEGORY = "category";
- static final String PROPERTY_ORGANIZATION_NAME = "organizationName";
- static final String PROPERTY_ORGANIZATION_URL = "organizationUrl";
- static final String PROPERTY_DATE = "date";
- static final String PROPERTY_UPDATED_AT = "updatedAt";
- static final String PROPERTY_STATUS = "status";
- static final String PROPERTY_HOMEPAGE_URL = "homepageUrl";
- static final String PROPERTY_ISSUE_TRACKER_URL = "issueTrackerUrl";
- static final String OBJECT_ARTIFACT = "artifact";
- static final String PROPERTY_URL = "url";
- static final String PROPERTY_TERMS_AND_CONDITIONS_URL = "termsAndConditionsUrl";
- static final String OBJECT_UPDATE = "update";
- static final String OBJECT_RELEASE = "release";
- static final String ARRAY_REQUIRES = "requires";
- static final String PROPERTY_UPDATE_CENTER_REFRESH = "updateCenterRefresh";
- static final String PROPERTY_IMPLEMENTATION_BUILD = "implementationBuild";
- static final String PROPERTY_CHANGE_LOG_URL = "changeLogUrl";
+ private static final String PROPERTY_KEY = "key";
+ private static final String PROPERTY_NAME = "name";
+ private static final String PROPERTY_HASH = "hash";
+ private static final String PROPERTY_FILENAME = "filename";
+ private static final String PROPERTY_SONARLINT_SUPPORTED = "sonarLintSupported";
+ private static final String PROPERTY_DESCRIPTION = "description";
+ private static final String PROPERTY_LICENSE = "license";
+ private static final String PROPERTY_VERSION = "version";
+ private static final String PROPERTY_CATEGORY = "category";
+ private static final String PROPERTY_ORGANIZATION_NAME = "organizationName";
+ private static final String PROPERTY_ORGANIZATION_URL = "organizationUrl";
+ private static final String PROPERTY_DATE = "date";
+ private static final String PROPERTY_UPDATED_AT = "updatedAt";
+ private static final String PROPERTY_STATUS = "status";
+ private static final String PROPERTY_HOMEPAGE_URL = "homepageUrl";
+ private static final String PROPERTY_ISSUE_TRACKER_URL = "issueTrackerUrl";
+ private static final String PROPERTY_EDITION_BUNDLED = "editionBundled";
+ private static final String OBJECT_ARTIFACT = "artifact";
+ private static final String PROPERTY_URL = "url";
+ private static final String PROPERTY_TERMS_AND_CONDITIONS_URL = "termsAndConditionsUrl";
+ private static final String OBJECT_UPDATE = "update";
+ private static final String OBJECT_RELEASE = "release";
+ private static final String ARRAY_REQUIRES = "requires";
+ private static final String PROPERTY_UPDATE_CENTER_REFRESH = "updateCenterRefresh";
+ private static final String PROPERTY_IMPLEMENTATION_BUILD = "implementationBuild";
+ private static final String PROPERTY_CHANGE_LOG_URL = "changeLogUrl";
public static final Ordering<PluginInfo> NAME_KEY_PLUGIN_METADATA_COMPARATOR = Ordering.natural()
.onResultOf(PluginInfo::getName)
jsonWriter.prop(PROPERTY_ORGANIZATION_URL, plugin.getOrganizationUrl());
jsonWriter.prop(PROPERTY_HOMEPAGE_URL, plugin.getHomepageUrl());
jsonWriter.prop(PROPERTY_ISSUE_TRACKER_URL, plugin.getIssueTrackerUrl());
+ jsonWriter.prop(PROPERTY_EDITION_BUNDLED, isEditionBundled(plugin));
}
public void writePluginUpdate(JsonWriter json, PluginUpdate pluginUpdate) {
"license": "Commercial",
"organizationName": "SonarSource",
"organizationUrl": "http://www.sonarsource.com",
+ "editionBundled": true,
"termsAndConditionsUrl": "http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf",
"version": "2.8 (build 5498)"
}
"description": "Allows to add your own logo to the SonarQube UI.",
"license": "GNU LGPL 3",
"organizationName": "SonarSource",
- "organizationUrl": "http://www.sonarsource.com"
+ "organizationUrl": "http://www.sonarsource.com",
+ "editionBundled": false
}
]
}
"organizationName": "SonarSource",
"organizationUrl": "http://www.sonarsource.com",
"termsAndConditionsUrl": "http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf",
+ "editionBundled": true,
"release": {
"version": "3.2",
"date": "2015-03-10"
"license": "GNU LGPL 3",
"organizationName": "SonarSource and Jerome Van Der Linden, Stephane Nicolas, Florian Roncari, Thomas Bores",
"organizationUrl": "http://www.sonarsource.com",
+ "editionBundled": false,
"release": {
"version": "1.0",
"date": "2014-03-31"
}
],
"updateCenterRefresh": "2015-04-24T16:08:36+0200"
-}
\ No newline at end of file
+}
"organizationName": "SonarSource",
"organizationUrl": "http://www.sonarsource.com",
"termsAndConditionsUrl": "http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf",
+ "editionBundled": true,
"updates": [
{
"release": {
"license": "GNU LGPL 3",
"organizationName": "SonarSource and Jerome Van Der Linden, Stephane Nicolas, Florian Roncari, Thomas Bores",
"organizationUrl": "http://www.sonarsource.com",
+ "editionBundled": false,
"updates": [
{
"release": {
import org.sonar.api.utils.DateUtils;
import org.sonar.server.plugins.UpdateCenterMatrixFactory;
import org.sonar.server.plugins.ws.PluginWSCommons;
+import org.sonar.server.ws.WsActionTester;
import org.sonar.server.ws.WsTester;
import org.sonar.updatecenter.common.Plugin;
import org.sonar.updatecenter.common.Release;
public class UpgradesActionTest {
private static final String DUMMY_CONTROLLER_KEY = "dummy";
- private static final String JSON_EMPTY_UPGRADE_LIST =
- "{" +
- " \"upgrades\":" + "[]" +
- "}";
+ private static final String JSON_EMPTY_UPGRADE_LIST = "{" +
+ " \"upgrades\":" + "[]" +
+ "}";
private static Release release;
private UpdateCenterMatrixFactory updateCenterFactory = mock(UpdateCenterMatrixFactory.class);
underTest.handle(request, response);
assertJson(response.outputAsString()).withStrictArrayOrder()
- .isSimilarTo(getClass().getResource("example-upgrades_plugins.json"));
+ .isSimilarTo(new WsActionTester(underTest).getDef().responseExampleAsString());
}
}
import org.sonar.api.utils.DateUtils;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.WsActionTester;
import org.sonar.server.ws.WsTester;
import org.sonar.updatecenter.common.Plugin;
import org.sonar.updatecenter.common.PluginUpdate;
assertThat(action.responseExample()).isNotNull();
}
+ @Test
+ public void verify_example() throws Exception {
+ logInAsSystemAdministrator();
+ when(updateCenter.findAvailablePlugins()).thenReturn(of(
+ pluginUpdate(release(Plugin.factory("abap")
+ .setName("ABAP")
+ .setCategory("Languages")
+ .setDescription("Enable analysis and reporting on ABAP projects")
+ .setLicense("Commercial")
+ .setOrganization("SonarSource")
+ .setOrganizationUrl("http://www.sonarsource.com")
+ .setTermsConditionsUrl("http://dist.sonarsource.com/SonarSource_Terms_And_Conditions.pdf"),
+ "3.2")
+ .setDate(DateUtils.parseDate("2015-03-10")),
+ COMPATIBLE),
+ pluginUpdate(release(Plugin.factory("android")
+ .setName("Android")
+ .setCategory("Languages")
+ .setDescription("Import Android Lint reports.")
+ .setLicense("GNU LGPL 3")
+ .setOrganization("SonarSource and Jerome Van Der Linden, Stephane Nicolas, Florian Roncari, Thomas Bores")
+ .setOrganizationUrl("http://www.sonarsource.com"),
+ "1.0")
+ .setDate(DateUtils.parseDate("2014-03-31"))
+ .addOutgoingDependency(release(Plugin.factory("java").setName("Java").setDescription("SonarQube rule engine."), "0.3.6")),
+ COMPATIBLE)));
+
+ underTest.handle(request, response);
+
+ WsActionTester actionTester = new WsActionTester(underTest);
+ assertJson(response.outputAsString()).isSimilarTo(actionTester.getDef().responseExampleAsString());
+ }
+
@Test
public void request_fails_with_ForbiddenException_when_user_is_not_logged_in() throws Exception {
expectedException.expect(ForbiddenException.class);
underTest.handle(request, response);
- assertJson(response.outputAsString()).isSimilarTo(resource("properties_per_plugin.json"));
+ assertJson(response.outputAsString())
+ .isSimilarTo(
+ "{" +
+ " \"plugins\": [" +
+ " {" +
+ " \"key\": \"pkey\"," +
+ " \"name\": \"p_name\"," +
+ " \"category\": \"p_category\"," +
+ " \"description\": \"p_description\"," +
+ " \"license\": \"p_license\"," +
+ " \"termsAndConditionsUrl\": \"p_t_and_c_url\"," +
+ " \"organizationName\": \"p_orga_name\"," +
+ " \"organizationUrl\": \"p_orga_url\"," +
+ " \"homepageUrl\": \"p_homepage_url\"," +
+ " \"issueTrackerUrl\": \"p_issue_url\"," +
+ " \"release\": {" +
+ " \"version\": \"1.12.1\"," +
+ " \"date\": \"2015-04-16\"" +
+ " }," +
+ " \"update\": {" +
+ " \"status\": \"COMPATIBLE\"," +
+ " \"requires\": [" +
+ " {" +
+ " \"key\": \"pkey1\"," +
+ " \"name\": \"p_name_1\"" +
+ " }," +
+ " {" +
+ " \"key\": \"pkey2\"," +
+ " \"name\": \"p_name_2\"," +
+ " \"description\": \"p_desc_2\"" +
+ " }" +
+ " ]" +
+ " }" +
+ " }" +
+ " ]," +
+ " \"updateCenterRefresh\": \"2015-04-24T16:08:36+0200\"" +
+ "}");
}
@Test
import org.sonar.api.utils.DateUtils;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.tester.UserSessionRule;
+import org.sonar.server.ws.WsActionTester;
import org.sonar.server.ws.WsTester;
import org.sonar.updatecenter.common.Plugin;
import org.sonar.updatecenter.common.Release;
underTest.handle(request, response);
- assertJson(response.outputAsString()).isSimilarTo(getClass().getResource("example-updates_plugins.json"));
+ assertJson(response.outputAsString())
+ .isSimilarTo(new WsActionTester(underTest).getDef().responseExampleAsString());
}
@Test
+++ /dev/null
-{
- "plugins": [
- {
- "key": "pkey",
- "name": "p_name",
- "category": "p_category",
- "description": "p_description",
- "license": "p_license",
- "termsAndConditionsUrl": "p_t_and_c_url",
- "organizationName": "p_orga_name",
- "organizationUrl": "p_orga_url",
- "homepageUrl": "p_homepage_url",
- "issueTrackerUrl": "p_issue_url",
- "release": {
- "version": "1.12.1",
- "date": "2015-04-16"
- },
- "update": {
- "status": "COMPATIBLE",
- "requires": [
- {
- "key": "pkey1",
- "name": "p_name_1"
- },
- {
- "key": "pkey2",
- "name": "p_name_2",
- "description": "p_desc_2"
- }
- ]
- }
- }
- ],
- "updateCenterRefresh": "2015-04-24T16:08:36+0200"
-}