Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

PluginsMonitor.java 2.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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.platform.monitoring;
  21. import com.google.common.base.Predicate;
  22. import com.google.common.collect.Iterables;
  23. import org.sonar.core.platform.PluginInfo;
  24. import org.sonar.core.platform.PluginRepository;
  25. import org.sonar.updatecenter.common.Version;
  26. import javax.annotation.Nonnull;
  27. import java.util.LinkedHashMap;
  28. /**
  29. * Installed plugins (excluding core plugins)
  30. */
  31. public class PluginsMonitor implements Monitor {
  32. private final PluginRepository repository;
  33. public PluginsMonitor(PluginRepository repository) {
  34. this.repository = repository;
  35. }
  36. @Override
  37. public String name() {
  38. return "Plugins";
  39. }
  40. @Override
  41. public LinkedHashMap<String, Object> attributes() {
  42. LinkedHashMap<String, Object> attributes = new LinkedHashMap<>();
  43. for (PluginInfo plugin : plugins()) {
  44. LinkedHashMap<String, Object> pluginAttributes = new LinkedHashMap<>();
  45. pluginAttributes.put("Name", plugin.getName());
  46. Version version = plugin.getVersion();
  47. if (version != null) {
  48. pluginAttributes.put("Version", version.getName());
  49. }
  50. attributes.put(plugin.getKey(), pluginAttributes);
  51. }
  52. return attributes;
  53. }
  54. private Iterable<PluginInfo> plugins() {
  55. return Iterables.filter(repository.getPluginInfos(), new Predicate<PluginInfo>() {
  56. @Override
  57. public boolean apply(@Nonnull PluginInfo info) {
  58. return !info.isCore();
  59. }
  60. });
  61. }
  62. }