1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
/*
* Sonar, open source software quality management tool.
* Copyright (C) 2008-2011 SonarSource
* mailto:contact AT sonarsource DOT com
*
* Sonar is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* Sonar is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sonar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02
*/
package org.sonar.server.ui;
import org.apache.commons.configuration.Configuration;
import org.picocontainer.PicoContainer;
import org.slf4j.LoggerFactory;
import org.sonar.api.Property;
import org.sonar.api.platform.PluginMetadata;
import org.sonar.api.platform.PluginRepository;
import org.sonar.api.profiles.ProfileExporter;
import org.sonar.api.profiles.ProfileImporter;
import org.sonar.api.resources.Language;
import org.sonar.api.rules.RulePriority;
import org.sonar.api.rules.RuleRepository;
import org.sonar.api.utils.ValidationMessages;
import org.sonar.api.web.*;
import org.sonar.jpa.dialect.Dialect;
import org.sonar.jpa.session.DatabaseConnector;
import org.sonar.markdown.Markdown;
import org.sonar.server.configuration.Backup;
import org.sonar.server.configuration.CoreConfiguration;
import org.sonar.server.configuration.ProfilesManager;
import org.sonar.server.filters.Filter;
import org.sonar.server.filters.FilterExecutor;
import org.sonar.server.filters.FilterResult;
import org.sonar.server.notifications.reviews.ReviewsNotificationManager;
import org.sonar.server.platform.Platform;
import org.sonar.server.plugins.*;
import org.sonar.server.rules.ProfilesConsole;
import org.sonar.server.rules.RulesConsole;
import org.sonar.updatecenter.common.Version;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
public final class JRubyFacade {
private static final JRubyFacade SINGLETON = new JRubyFacade();
private JRubyI18n i18n;
public static JRubyFacade getInstance() {
return SINGLETON;
}
public FilterResult executeFilter(Filter filter) {
return getContainer().getComponent(FilterExecutor.class).execute(filter);
}
// UPDATE CENTER ------------------------------------------------------------
public void downloadPlugin(String pluginKey, String pluginVersion) {
getContainer().getComponent(PluginDownloader.class).download(pluginKey, Version.create(pluginVersion));
}
public void cancelPluginDownloads() {
getContainer().getComponent(PluginDownloader.class).cancelDownloads();
}
public List<String> getPluginDownloads() {
return getContainer().getComponent(PluginDownloader.class).getDownloads();
}
public void uninstallPlugin(String pluginKey) {
getContainer().getComponent(PluginDeployer.class).uninstall(pluginKey);
}
public void cancelPluginUninstalls() {
getContainer().getComponent(PluginDeployer.class).cancelUninstalls();
}
public List<String> getPluginUninstalls() {
return getContainer().getComponent(PluginDeployer.class).getUninstalls();
}
public UpdateCenterMatrix getUpdateCenterMatrix(boolean forceReload) {
return getContainer().getComponent(UpdateCenterMatrixFactory.class).getMatrix(forceReload);
}
// PLUGINS ------------------------------------------------------------------
public Property[] getPluginProperties(PluginMetadata metadata) {
PluginRepository repository = getContainer().getComponent(PluginRepository.class);
return repository.getProperties(repository.getPlugin(metadata.getKey()));
}
public boolean hasPlugin(String key) {
return getContainer().getComponent(PluginRepository.class).getPlugin(key) != null;
}
public Collection<PluginMetadata> getPluginsMetadata() {
return getContainer().getComponent(PluginRepository.class).getMetadata();
}
// SYNTAX HIGHLIGHTING ------------------------------------------------------
public String colorizeCode(String code, String language) {
try {
return getContainer().getComponent(CodeColorizers.class).toHtml(code, language);
} catch (Exception e) {
LoggerFactory.getLogger(getClass()).error("Can not highlight the code, language= " + language, e);
return code;
}
}
public static String markdownToHtml(String input) {
return Markdown.convertToHtml(input);
}
public List<ViewProxy<Widget>> getWidgets(String resourceScope, String resourceQualifier, String resourceLanguage) {
return getContainer().getComponent(Views.class).getWidgets(resourceScope, resourceQualifier, resourceLanguage);
}
public List<ViewProxy<Widget>> getWidgets() {
return getContainer().getComponent(Views.class).getWidgets();
}
public ViewProxy<Widget> getWidget(String id) {
return getContainer().getComponent(Views.class).getWidget(id);
}
public List<ViewProxy<Page>> getPages(String section, String resourceScope, String resourceQualifier, String resourceLanguage) {
return getContainer().getComponent(Views.class).getPages(section, resourceScope, resourceQualifier, resourceLanguage);
}
public List<ViewProxy<Page>> getResourceTabs() {
return getContainer().getComponent(Views.class).getPages(NavigationSection.RESOURCE_TAB, null, null, null);
}
public List<ViewProxy<Page>> getResourceTabs(String scope, String qualifier, String language) {
return getContainer().getComponent(Views.class).getPages(NavigationSection.RESOURCE_TAB, scope, qualifier, language);
}
public List<ViewProxy<Page>> getResourceTabsForMetric(String scope, String qualifier, String language, String metric) {
return getContainer().getComponent(Views.class).getPagesForMetric(NavigationSection.RESOURCE_TAB, scope, qualifier, language, metric);
}
public ViewProxy<Page> getPage(String id) {
return getContainer().getComponent(Views.class).getPage(id);
}
public Collection<RubyRailsWebservice> getRubyRailsWebservices() {
return getContainer().getComponents(RubyRailsWebservice.class);
}
public Collection<Language> getLanguages() {
return getContainer().getComponents(Language.class);
}
public Dialect getDialect() {
return getContainer().getComponent(DatabaseConnector.class).getDialect();
}
/* PROFILES CONSOLE : RULES AND METRIC THRESHOLDS */
public List<RuleRepository> getRuleRepositories() {
return getContainer().getComponent(RulesConsole.class).getRepositories();
}
public RuleRepository getRuleRepository(String repositoryKey) {
return getContainer().getComponent(RulesConsole.class).getRepository(repositoryKey);
}
public Set<RuleRepository> getRuleRepositoriesByLanguage(String languageKey) {
return getContainer().getComponent(RulesConsole.class).getRepositoriesByLanguage(languageKey);
}
public String backupProfile(int profileId) {
return getContainer().getComponent(ProfilesConsole.class).backupProfile(profileId);
}
public ValidationMessages restoreProfile(String xmlBackup) {
return getContainer().getComponent(ProfilesConsole.class).restoreProfile(xmlBackup);
}
public List<ProfileExporter> getProfileExportersForLanguage(String language) {
return getContainer().getComponent(ProfilesConsole.class).getProfileExportersForLanguage(language);
}
public List<ProfileImporter> getProfileImportersForLanguage(String language) {
return getContainer().getComponent(ProfilesConsole.class).getProfileImportersForLanguage(language);
}
public String exportProfile(int profileId, String exporterKey) {
return getContainer().getComponent(ProfilesConsole.class).exportProfile(profileId, exporterKey);
}
public ValidationMessages importProfile(String profileName, String language, String importerKey, String fileContent) {
return getContainer().getComponent(ProfilesConsole.class).importProfile(profileName, language, importerKey, fileContent);
}
public String getProfileExporterMimeType(String exporterKey) {
return getContainer().getComponent(ProfilesConsole.class).getProfileExporter(exporterKey).getMimeType();
}
public void renameProfile(int profileId, String newProfileName) {
getProfilesManager().renameProfile(profileId, newProfileName);
}
public void copyProfile(long profileId, String newProfileName) {
getProfilesManager().copyProfile((int) profileId, newProfileName);
}
public void deleteProfile(long profileId) {
getProfilesManager().deleteProfile((int) profileId);
}
public ValidationMessages changeParentProfile(int profileId, String parentName, String userName) {
return getProfilesManager().changeParentProfile(profileId, parentName, userName);
}
public void ruleActivated(int parentProfileId, int activeRuleId, String userName) {
getProfilesManager().activated(parentProfileId, activeRuleId, userName);
}
public void ruleParamChanged(int parentProfileId, int activeRuleId, String paramKey, String oldValue, String newValue, String userName) {
getProfilesManager().ruleParamChanged(parentProfileId, activeRuleId, paramKey, oldValue, newValue, userName);
}
public void ruleSeverityChanged(int parentProfileId, int activeRuleId, int oldSeverityId, int newSeverityId, String userName) {
getProfilesManager().ruleSeverityChanged(parentProfileId, activeRuleId, RulePriority.values()[oldSeverityId],
RulePriority.values()[newSeverityId], userName);
}
public void ruleDeactivated(int parentProfileId, int deactivatedRuleId, String userName) {
getProfilesManager().deactivated(parentProfileId, deactivatedRuleId, userName);
}
public void revertRule(int profileId, int activeRuleId, String userName) {
getProfilesManager().revert(profileId, activeRuleId, userName);
}
public List<Footer> getWebFooters() {
return getContainer().getComponents(Footer.class);
}
public Backup getBackup() {
return getContainer().getComponent(Backup.class);
}
private ProfilesManager getProfilesManager() {
return getContainer().getComponent(ProfilesManager.class);
}
public void reloadConfiguration() {
getContainer().getComponent(CoreConfiguration.class).reload();
}
public String getConfigurationValue(String key) {
return getContainer().getComponent(Configuration.class).getString(key, null);
}
public Connection getConnection() throws SQLException {
return getContainer().getComponent(DatabaseConnector.class).getConnection();
}
public Object getCoreComponentByClassname(String className) {
if (className == null) {
return null;
}
try {
Class aClass = Class.forName(className);
return getContainer().getComponent(aClass);
} catch (ClassNotFoundException e) {
LoggerFactory.getLogger(getClass()).error("Component not found: " + className, e);
return null;
}
}
public Object getComponentByClassname(String pluginKey, String className) {
Object component = null;
PicoContainer container = getContainer();
Class componentClass = container.getComponent(ServerPluginRepository.class).getClass(pluginKey, className);
if (componentClass != null) {
component = container.getComponent(componentClass);
}
return component;
}
public String getI18nMessage(String rubyLocale, String key, String defaultValue, Object... parameters) {
if (i18n == null) {
i18n = getContainer().getComponent(JRubyI18n.class);
}
return i18n.message(rubyLocale, key, defaultValue, parameters);
}
public ReviewsNotificationManager getReviewsNotificationManager() {
return getContainer().getComponent(ReviewsNotificationManager.class);
}
public PicoContainer getContainer() {
return Platform.getInstance().getContainer();
}
}
|