/* * SonarQube, open source software quality management tool. * Copyright (C) 2008-2013 SonarSource * mailto:contact AT sonarsource DOT com * * SonarQube 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. * * SonarQube 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 this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ package org.sonar.server.ui; import org.slf4j.LoggerFactory; import org.sonar.api.CoreProperties; import org.sonar.api.config.License; import org.sonar.api.config.PropertyDefinitions; import org.sonar.api.config.Settings; import org.sonar.api.platform.ComponentContainer; import org.sonar.api.platform.NewUserHandler; 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.resources.ResourceType; import org.sonar.api.resources.ResourceTypes; import org.sonar.api.rules.RulePriority; import org.sonar.api.rules.RuleRepository; import org.sonar.api.test.MutableTestPlan; import org.sonar.api.test.MutableTestable; import org.sonar.api.test.TestPlan; import org.sonar.api.test.Testable; import org.sonar.api.utils.ValidationMessages; import org.sonar.api.web.Footer; import org.sonar.api.web.NavigationSection; import org.sonar.api.web.Page; import org.sonar.api.web.RubyRailsWebservice; import org.sonar.api.web.Widget; import org.sonar.core.component.SnapshotPerspectives; import org.sonar.core.dryrun.DryRunCache; import org.sonar.core.i18n.RuleI18nManager; import org.sonar.core.measure.MeasureFilterEngine; import org.sonar.core.measure.MeasureFilterResult; import org.sonar.core.persistence.Database; import org.sonar.core.purge.PurgeDao; import org.sonar.core.resource.ResourceIndexerDao; import org.sonar.core.resource.ResourceKeyUpdaterDao; import org.sonar.core.timemachine.Periods; import org.sonar.server.configuration.Backup; import org.sonar.server.configuration.ProfilesManager; import org.sonar.server.db.migrations.DatabaseMigrator; import org.sonar.server.platform.Platform; import org.sonar.server.platform.ServerIdGenerator; import org.sonar.server.platform.ServerSettings; import org.sonar.server.platform.SettingsChangeNotifier; import org.sonar.server.plugins.DefaultServerPluginRepository; import org.sonar.server.plugins.InstalledPluginReferentialFactory; import org.sonar.server.plugins.PluginDeployer; import org.sonar.server.plugins.PluginDownloader; import org.sonar.server.plugins.UpdateCenterMatrixFactory; import org.sonar.server.rules.ProfilesConsole; import org.sonar.server.rules.RulesConsole; import org.sonar.server.user.NewUserNotifier; import org.sonar.updatecenter.common.PluginReferential; import org.sonar.updatecenter.common.UpdateCenter; import org.sonar.updatecenter.common.Version; import javax.annotation.Nullable; import java.net.InetAddress; import java.sql.Connection; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.Map; import java.util.Set; import static com.google.common.collect.Lists.newArrayList; public final class JRubyFacade { private static final JRubyFacade SINGLETON = new JRubyFacade(); private JRubyI18n i18n; public static JRubyFacade getInstance() { return SINGLETON; } T get(Class componentType) { return getContainer().getComponentByType(componentType); } public MeasureFilterResult executeMeasureFilter(Map map, @Nullable Long userId) { return get(MeasureFilterEngine.class).execute(map, userId); } public Collection getResourceTypesForFilter() { return get(ResourceTypes.class).getAll(ResourceTypes.AVAILABLE_FOR_FILTERS); } public Collection getResourceTypes() { return get(ResourceTypes.class).getAll(); } public Collection getResourceRootTypes() { return get(ResourceTypes.class).getRoots(); } public ResourceType getResourceType(String qualifier) { return get(ResourceTypes.class).get(qualifier); } public String getResourceTypeStringProperty(String resourceTypeQualifier, String resourceTypeProperty) { ResourceType resourceType = getResourceType(resourceTypeQualifier); if (resourceType != null) { return resourceType.getStringProperty(resourceTypeProperty); } return null; } public List getQualifiersWithProperty(final String propertyKey) { List qualifiers = newArrayList(); for (ResourceType type : getResourceTypes()) { if (type.getBooleanProperty(propertyKey) == Boolean.TRUE) { qualifiers.add(type.getQualifier()); } } return qualifiers; } public Boolean getResourceTypeBooleanProperty(String resourceTypeQualifier, String resourceTypeProperty) { ResourceType resourceType = getResourceType(resourceTypeQualifier); if (resourceType != null) { return resourceType.getBooleanProperty(resourceTypeProperty); } return null; } public Collection getResourceLeavesQualifiers(String qualifier) { return get(ResourceTypes.class).getLeavesQualifiers(qualifier); } public Collection getResourceChildrenQualifiers(String qualifier) { return get(ResourceTypes.class).getChildrenQualifiers(qualifier); } // UPDATE CENTER ------------------------------------------------------------ public void downloadPlugin(String pluginKey, String pluginVersion) { get(PluginDownloader.class).download(pluginKey, Version.create(pluginVersion)); } public void cancelPluginDownloads() { get(PluginDownloader.class).cancelDownloads(); } public List getPluginDownloads() { return get(PluginDownloader.class).getDownloads(); } public void uninstallPlugin(String pluginKey) { get(PluginDeployer.class).uninstall(pluginKey); } public void cancelPluginUninstalls() { get(PluginDeployer.class).cancelUninstalls(); } public List getPluginUninstalls() { return get(PluginDeployer.class).getUninstalls(); } public UpdateCenter getUpdatePluginCenter(boolean forceReload) { return get(UpdateCenterMatrixFactory.class).getUpdateCenter(forceReload); } public PluginReferential getInstalledPluginReferential() { return get(InstalledPluginReferentialFactory.class).getInstalledPluginReferential(); } // PLUGINS ------------------------------------------------------------------ public PropertyDefinitions getPropertyDefinitions() { return get(PropertyDefinitions.class); } public boolean hasPlugin(String key) { return get(PluginRepository.class).getPlugin(key) != null; } public Collection getPluginsMetadata() { return get(PluginRepository.class).getMetadata(); } // SYNTAX HIGHLIGHTING ------------------------------------------------------ public String colorizeCode(String code, String language) { try { return get(CodeColorizers.class).toHtml(code, language); } catch (Exception e) { LoggerFactory.getLogger(getClass()).error("Can not highlight the code, language= " + language, e); return code; } } public List> getWidgets(String resourceScope, String resourceQualifier, String resourceLanguage, Object[] availableMeasures) { return get(Views.class).getWidgets(resourceScope, resourceQualifier, resourceLanguage, (String[]) availableMeasures); } public List> getWidgets() { return get(Views.class).getWidgets(); } public ViewProxy getWidget(String id) { return get(Views.class).getWidget(id); } public List> getPages(String section, String resourceScope, String resourceQualifier, String resourceLanguage, Object[] availableMeasures) { return get(Views.class).getPages(section, resourceScope, resourceQualifier, resourceLanguage, (String[]) availableMeasures); } public List> getResourceTabs() { return get(Views.class).getPages(NavigationSection.RESOURCE_TAB, null, null, null, null); } public List> getResourceTabs(String scope, String qualifier, String language, Object[] availableMeasures) { return get(Views.class).getPages(NavigationSection.RESOURCE_TAB, scope, qualifier, language, (String[]) availableMeasures); } public List> getResourceTabsForMetric(String scope, String qualifier, String language, Object[] availableMeasures, String metric) { return get(Views.class).getPagesForMetric(NavigationSection.RESOURCE_TAB, scope, qualifier, language, (String[]) availableMeasures, metric); } public ViewProxy getPage(String id) { return get(Views.class).getPage(id); } public Collection getRubyRailsWebservices() { return getContainer().getComponentsByType(RubyRailsWebservice.class); } public Collection getLanguages() { return getContainer().getComponentsByType(Language.class); } public Database getDatabase() { return get(Database.class); } public DatabaseMigrator databaseMigrator() { return get(DatabaseMigrator.class); } /* PROFILES CONSOLE : RULES AND METRIC THRESHOLDS */ public List getRuleRepositories() { return get(RulesConsole.class).getRepositories(); } public RuleRepository getRuleRepository(String repositoryKey) { return get(RulesConsole.class).getRepository(repositoryKey); } public Set getRuleRepositoriesByLanguage(String languageKey) { return get(RulesConsole.class).getRepositoriesByLanguage(languageKey); } public String backupProfile(int profileId) { return get(ProfilesConsole.class).backupProfile(profileId); } public ValidationMessages restoreProfile(String xmlBackup, boolean deleteExisting) { return get(ProfilesConsole.class).restoreProfile(xmlBackup, deleteExisting); } public List getProfileExportersForLanguage(String language) { return get(ProfilesConsole.class).getProfileExportersForLanguage(language); } public List getProfileImportersForLanguage(String language) { return get(ProfilesConsole.class).getProfileImportersForLanguage(language); } /** * @throws IllegalArgumentException if no such exporter */ public String exportProfile(int profileId, String exporterKey) { return get(ProfilesConsole.class).exportProfile(profileId, exporterKey); } public ValidationMessages importProfile(String profileName, String language, String importerKey, String fileContent) { return get(ProfilesConsole.class).importProfile(profileName, language, importerKey, fileContent); } public String getProfileExporterMimeType(String exporterKey) { return get(ProfilesConsole.class).getProfileExporter(exporterKey).getMimeType(); } public void copyProfile(long profileId, String newProfileName) { getProfilesManager().copyProfile((int) profileId, newProfileName); } 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