You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PluginReferentialMetadataConverter.java 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * SonarQube, open source software quality management tool.
  3. * Copyright (C) 2008-2014 SonarSource
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * SonarQube is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * SonarQube is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.server.plugins;
  21. import org.sonar.core.platform.PluginInfo;
  22. import org.sonar.updatecenter.common.PluginManifest;
  23. import org.sonar.updatecenter.common.PluginReferential;
  24. import org.sonar.updatecenter.common.PluginReferentialManifestConverter;
  25. import org.sonar.updatecenter.common.Version;
  26. import java.util.Collection;
  27. import java.util.List;
  28. import static com.google.common.collect.Lists.newArrayList;
  29. public class PluginReferentialMetadataConverter {
  30. private PluginReferentialMetadataConverter() {
  31. // Only static call
  32. }
  33. public static PluginReferential getInstalledPluginReferential(Collection<PluginInfo> metadata) {
  34. List<PluginManifest> pluginManifestList = getPluginManifestList(metadata);
  35. return PluginReferentialManifestConverter.fromPluginManifests(pluginManifestList);
  36. }
  37. private static List<PluginManifest> getPluginManifestList(Collection<PluginInfo> metadata) {
  38. List<PluginManifest> pluginManifestList = newArrayList();
  39. for (PluginInfo plugin : metadata) {
  40. if (!plugin.isCore()) {
  41. pluginManifestList.add(toPluginManifest(plugin));
  42. }
  43. }
  44. return pluginManifestList;
  45. }
  46. private static PluginManifest toPluginManifest(PluginInfo metadata) {
  47. PluginManifest pluginManifest = new PluginManifest();
  48. pluginManifest.setKey(metadata.getKey());
  49. pluginManifest.setName(metadata.getName());
  50. Version version = metadata.getVersion();
  51. if (version != null) {
  52. pluginManifest.setVersion(version.getName());
  53. }
  54. pluginManifest.setDescription(metadata.getDescription());
  55. pluginManifest.setMainClass(metadata.getMainClass());
  56. pluginManifest.setOrganization(metadata.getOrganizationName());
  57. pluginManifest.setOrganizationUrl(metadata.getOrganizationUrl());
  58. pluginManifest.setLicense(metadata.getLicense());
  59. pluginManifest.setHomepage(metadata.getHomepageUrl());
  60. pluginManifest.setIssueTrackerUrl(metadata.getIssueTrackerUrl());
  61. pluginManifest.setBasePlugin(metadata.getBasePlugin());
  62. pluginManifest.setRequirePlugins(metadata.getRequiredPlugins().toArray(new String[] {}));
  63. return pluginManifest;
  64. }
  65. }