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.

BatchPluginRepository.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.batch.bootstrap;
  21. import org.picocontainer.Startable;
  22. import org.sonar.api.Plugin;
  23. import org.sonar.core.platform.PluginInfo;
  24. import org.sonar.core.platform.PluginLoader;
  25. import org.sonar.core.platform.PluginRepository;
  26. import java.util.Collection;
  27. import java.util.Map;
  28. public class BatchPluginRepository implements PluginRepository, Startable {
  29. private final PluginInstaller installer;
  30. private final PluginLoader loader;
  31. private Map<String, Plugin> pluginInstancesByKeys;
  32. private Map<String, PluginInfo> infosByKeys;
  33. public BatchPluginRepository(PluginInstaller installer, PluginLoader loader) {
  34. this.installer = installer;
  35. this.loader = loader;
  36. }
  37. @Override
  38. public void start() {
  39. infosByKeys = installer.installRemotes();
  40. pluginInstancesByKeys = loader.load(infosByKeys);
  41. // this part is only used by tests
  42. for (Map.Entry<String, Plugin> entry : installer.installLocals().entrySet()) {
  43. String pluginKey = entry.getKey();
  44. infosByKeys.put(pluginKey, new PluginInfo(pluginKey));
  45. pluginInstancesByKeys.put(pluginKey, entry.getValue());
  46. }
  47. }
  48. @Override
  49. public void stop() {
  50. // close plugin classloaders
  51. loader.unload(pluginInstancesByKeys.values());
  52. pluginInstancesByKeys.clear();
  53. infosByKeys.clear();
  54. }
  55. @Override
  56. public Collection<PluginInfo> getPluginInfos() {
  57. return infosByKeys.values();
  58. }
  59. @Override
  60. public PluginInfo getPluginInfo(String key) {
  61. // TODO check null result
  62. return infosByKeys.get(key);
  63. }
  64. @Override
  65. public Plugin getPluginInstance(String key) {
  66. // TODO check null result
  67. return pluginInstancesByKeys.get(key);
  68. }
  69. @Override
  70. public boolean hasPlugin(String key) {
  71. return infosByKeys.containsKey(key);
  72. }
  73. }