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.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program 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. * This program 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 com.google.common.base.Function;
  22. import com.google.common.collect.Collections2;
  23. import org.sonar.core.platform.PluginInfo;
  24. import org.sonar.updatecenter.common.PluginManifest;
  25. import org.sonar.updatecenter.common.PluginReferential;
  26. import org.sonar.updatecenter.common.PluginReferentialManifestConverter;
  27. import org.sonar.updatecenter.common.Version;
  28. import javax.annotation.Nonnull;
  29. import java.util.Collection;
  30. import java.util.List;
  31. import static com.google.common.collect.Lists.newArrayList;
  32. public class PluginReferentialMetadataConverter {
  33. private PluginReferentialMetadataConverter() {
  34. // Only static call
  35. }
  36. public static PluginReferential getInstalledPluginReferential(Collection<PluginInfo> infos) {
  37. List<PluginManifest> pluginManifestList = getPluginManifestList(infos);
  38. return PluginReferentialManifestConverter.fromPluginManifests(pluginManifestList);
  39. }
  40. private static List<PluginManifest> getPluginManifestList(Collection<PluginInfo> metadata) {
  41. List<PluginManifest> pluginManifestList = newArrayList();
  42. for (PluginInfo plugin : metadata) {
  43. pluginManifestList.add(toPluginManifest(plugin));
  44. }
  45. return pluginManifestList;
  46. }
  47. private static PluginManifest toPluginManifest(PluginInfo metadata) {
  48. PluginManifest pluginManifest = new PluginManifest();
  49. pluginManifest.setKey(metadata.getKey());
  50. pluginManifest.setName(metadata.getName());
  51. Version version = metadata.getVersion();
  52. if (version != null) {
  53. pluginManifest.setVersion(version.getName());
  54. }
  55. pluginManifest.setDescription(metadata.getDescription());
  56. pluginManifest.setMainClass(metadata.getMainClass());
  57. pluginManifest.setOrganization(metadata.getOrganizationName());
  58. pluginManifest.setOrganizationUrl(metadata.getOrganizationUrl());
  59. pluginManifest.setLicense(metadata.getLicense());
  60. pluginManifest.setHomepage(metadata.getHomepageUrl());
  61. pluginManifest.setIssueTrackerUrl(metadata.getIssueTrackerUrl());
  62. pluginManifest.setBasePlugin(metadata.getBasePlugin());
  63. pluginManifest.setRequirePlugins(Collections2.transform(metadata.getRequiredPlugins(), RequiredPluginToString.INSTANCE).toArray(
  64. new String[metadata.getRequiredPlugins().size()]));
  65. return pluginManifest;
  66. }
  67. private enum RequiredPluginToString implements Function<PluginInfo.RequiredPlugin, String> {
  68. INSTANCE;
  69. @Override
  70. public String apply(@Nonnull PluginInfo.RequiredPlugin requiredPlugin) {
  71. return requiredPlugin.toString();
  72. }
  73. }
  74. }