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.

JRubyFacade.java 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. * Sonar, open source software quality management tool.
  3. * Copyright (C) 2009 SonarSource SA
  4. * mailto:contact AT sonarsource DOT com
  5. *
  6. * Sonar 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. * Sonar 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
  17. * License along with Sonar; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
  19. */
  20. package org.sonar.server.ui;
  21. import org.apache.commons.configuration.Configuration;
  22. import org.picocontainer.PicoContainer;
  23. import org.slf4j.LoggerFactory;
  24. import org.sonar.api.Plugin;
  25. import org.sonar.api.Plugins;
  26. import org.sonar.api.Property;
  27. import org.sonar.api.ServerComponent;
  28. import org.sonar.api.profiles.ProfileExporter;
  29. import org.sonar.api.profiles.ProfileImporter;
  30. import org.sonar.api.resources.Language;
  31. import org.sonar.api.rules.DefaultRulesManager;
  32. import org.sonar.api.rules.RuleRepository;
  33. import org.sonar.api.utils.ValidationMessages;
  34. import org.sonar.api.web.*;
  35. import org.sonar.jpa.dao.AsyncMeasuresService;
  36. import org.sonar.jpa.dialect.Dialect;
  37. import org.sonar.jpa.session.DatabaseConnector;
  38. import org.sonar.server.configuration.Backup;
  39. import org.sonar.server.configuration.CoreConfiguration;
  40. import org.sonar.server.configuration.ProfilesManager;
  41. import org.sonar.server.filters.Filter;
  42. import org.sonar.server.filters.FilterExecutor;
  43. import org.sonar.server.filters.FilterResult;
  44. import org.sonar.server.platform.Platform;
  45. import org.sonar.server.plugins.PluginDownloader;
  46. import org.sonar.server.plugins.UpdateFinder;
  47. import org.sonar.server.plugins.UpdateFinderFactory;
  48. import org.sonar.server.rules.ProfilesConsole;
  49. import org.sonar.server.rules.RulesConsole;
  50. import org.sonar.updatecenter.common.Version;
  51. import java.util.Collection;
  52. import java.util.List;
  53. public final class JRubyFacade implements ServerComponent {
  54. public FilterResult executeFilter(Filter filter) {
  55. return getContainer().getComponent(FilterExecutor.class).execute(filter);
  56. }
  57. /* PLUGINS */
  58. public void downloadPlugin(String pluginKey, String pluginVersion) {
  59. getContainer().getComponent(PluginDownloader.class).download(pluginKey, Version.create(pluginVersion));
  60. }
  61. public void cancelPluginDownloads() {
  62. getContainer().getComponent(PluginDownloader.class).cancelDownloads();
  63. }
  64. public List<String> getPluginDownloads() {
  65. return getContainer().getComponent(PluginDownloader.class).getDownloads();
  66. }
  67. public UpdateFinder getUpdateFinder(boolean forceReload) {
  68. return getContainer().getComponent(UpdateFinderFactory.class).getFinder(forceReload);
  69. }
  70. public String colorizeCode(String code, String language) {
  71. try {
  72. return getContainer().getComponent(CodeColorizers.class).toHtml(code, language);
  73. } catch (Exception e) {
  74. LoggerFactory.getLogger(getClass()).error("Can not highlight the code, language= " + language, e);
  75. return code;
  76. }
  77. }
  78. public List<ViewProxy<Widget>> getWidgets(String resourceScope, String resourceQualifier, String resourceLanguage) {
  79. return getContainer().getComponent(Views.class).getWidgets(resourceScope, resourceQualifier, resourceLanguage);
  80. }
  81. public List<ViewProxy<Page>> getPages(String section, String resourceScope, String resourceQualifier, String resourceLanguage) {
  82. return getContainer().getComponent(Views.class).getPages(section, resourceScope, resourceQualifier, resourceLanguage);
  83. }
  84. public List<ViewProxy<Page>> getResourceTabs() {
  85. return getContainer().getComponent(Views.class).getPages(NavigationSection.RESOURCE_TAB, null, null, null);
  86. }
  87. public ViewProxy<Page> getPage(String id) {
  88. return getContainer().getComponent(Views.class).getPage(id);
  89. }
  90. public Collection<RubyRailsWebservice> getRubyRailsWebservices() {
  91. return getContainer().getComponents(RubyRailsWebservice.class);
  92. }
  93. public Collection<Language> getLanguages() {
  94. return getContainer().getComponents(Language.class);
  95. }
  96. public Dialect getDialect() {
  97. return getContainer().getComponent(DatabaseConnector.class).getDialect();
  98. }
  99. public boolean hasPlugin(String key) {
  100. return getContainer().getComponent(Plugins.class).getPlugin(key) != null;
  101. }
  102. public Collection<Plugin> getPlugins() {
  103. return getContainer().getComponent(Plugins.class).getPlugins();
  104. }
  105. /* PROFILES CONSOLE : RULES AND METRIC THRESHOLDS */
  106. public List<RuleRepository> getRuleRepositories() {
  107. return getContainer().getComponent(RulesConsole.class).getRepositories();
  108. }
  109. public RuleRepository getRuleRepository(String repositoryKey) {
  110. return getContainer().getComponent(RulesConsole.class).getRepository(repositoryKey);
  111. }
  112. public List<RuleRepository> getRuleRepositoriesByLanguage(String languageKey) {
  113. return getContainer().getComponent(RulesConsole.class).getRepositoriesByLanguage(languageKey);
  114. }
  115. public String backupProfile(int profileId) {
  116. return getContainer().getComponent(ProfilesConsole.class).backupProfile(profileId);
  117. }
  118. public ValidationMessages restoreProfile(String xmlBackup) {
  119. return getContainer().getComponent(ProfilesConsole.class).restoreProfile(xmlBackup);
  120. }
  121. public List<ProfileExporter> getProfileExportersForLanguage(String language) {
  122. return getContainer().getComponent(ProfilesConsole.class).getProfileExportersForLanguage(language);
  123. }
  124. public List<ProfileImporter> getProfileImportersForLanguage(String language) {
  125. return getContainer().getComponent(ProfilesConsole.class).getProfileImportersForLanguage(language);
  126. }
  127. public String exportProfile(int profileId, String exporterKey) {
  128. return getContainer().getComponent(ProfilesConsole.class).exportProfile(profileId, exporterKey);
  129. }
  130. public ValidationMessages importProfile(String profileName, String language, String importerKey, String fileContent) {
  131. return getContainer().getComponent(ProfilesConsole.class).importProfile(profileName, language, importerKey, fileContent);
  132. }
  133. public String getProfileExporterMimeType(String exporterKey) {
  134. return getContainer().getComponent(ProfilesConsole.class).getProfileExporter(exporterKey).getMimeType();
  135. }
  136. public void copyProfile(long profileId, String newProfileName) {
  137. getProfilesManager().copyProfile((int) profileId, newProfileName);
  138. }
  139. public void deleteProfile(long profileId) {
  140. getProfilesManager().deleteProfile((int) profileId);
  141. }
  142. public List<Footer> getWebFooters() {
  143. return getContainer().getComponents(Footer.class);
  144. }
  145. public Backup getBackup() {
  146. return getContainer().getComponent(Backup.class);
  147. }
  148. public void registerAsyncMeasure(long asyncMeasureId) {
  149. getAsyncMeasuresService().registerMeasure(asyncMeasureId);
  150. }
  151. public void deleteAsyncMeasure(long asyncMeasureId) {
  152. getAsyncMeasuresService().deleteMeasure(asyncMeasureId);
  153. }
  154. public Property[] getPluginProperties(Plugin plugin) {
  155. return getContainer().getComponent(Plugins.class).getProperties(plugin);
  156. }
  157. private DefaultRulesManager getRulesManager() {
  158. return getContainer().getComponent(DefaultRulesManager.class);
  159. }
  160. private ProfilesManager getProfilesManager() {
  161. return getContainer().getComponent(ProfilesManager.class);
  162. }
  163. private AsyncMeasuresService getAsyncMeasuresService() {
  164. return getContainer().getComponent(AsyncMeasuresService.class);
  165. }
  166. public void reloadConfiguration() {
  167. getContainer().getComponent(CoreConfiguration.class).reload();
  168. }
  169. public String getConfigurationValue(String key) {
  170. return getContainer().getComponent(Configuration.class).getString(key, null);
  171. }
  172. public Object getComponentByClass(String className) {
  173. if (className == null) {
  174. return null;
  175. }
  176. try {
  177. Class aClass = Class.forName(className);
  178. return getContainer().getComponent(aClass);
  179. } catch (ClassNotFoundException e) {
  180. LoggerFactory.getLogger(getClass()).error("Component not found: " + className, e);
  181. return null;
  182. }
  183. }
  184. public PicoContainer getContainer() {
  185. return Platform.getInstance().getContainer();
  186. }
  187. }