From aef2286bf00aca219862aa62ef5dcac4bb9d2e9a Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Mon, 6 Sep 2010 17:22:57 +0000 Subject: SONAR-1229 Export/Import a given Sonar quality profile --- .../server/configuration/ProfilesManager.java | 10 -- .../java/org/sonar/server/platform/Platform.java | 20 +-- .../server/rules/DeprecatedProfileExporters.java | 87 +++++++++++ .../org/sonar/server/rules/DeprecatedProfiles.java | 161 +++++++++++++++++++++ .../sonar/server/rules/DeprecatedRuleBridge.java | 100 ------------- .../sonar/server/rules/DeprecatedRuleBridges.java | 62 -------- .../server/rules/DeprecatedRuleProfileBridge.java | 161 --------------------- .../server/rules/DeprecatedRuleRepositories.java | 132 +++++++++++++++++ .../org/sonar/server/rules/ProfileBackuper.java | 51 ------- .../org/sonar/server/rules/ProfilesConsole.java | 101 +++++++++++++ .../org/sonar/server/rules/RuleRepositories.java | 53 ------- .../java/org/sonar/server/rules/RulesConsole.java | 64 ++++++++ .../server/startup/RegisterProvidedProfiles.java | 6 +- .../org/sonar/server/startup/RegisterRules.java | 12 +- .../main/java/org/sonar/server/ui/JRubyFacade.java | 32 ++-- .../WEB-INF/app/controllers/profiles_controller.rb | 8 - .../controllers/rules_configuration_controller.rb | 35 +++-- .../webapp/WEB-INF/app/helpers/profiles_helper.rb | 21 +-- .../WEB-INF/app/views/profiles/index.html.erb | 36 ++--- .../sonar/server/rules/DeprecatedProfilesTest.java | 55 +++++++ 20 files changed, 680 insertions(+), 527 deletions(-) create mode 100644 sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfileExporters.java create mode 100644 sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java delete mode 100644 sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleBridge.java delete mode 100644 sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleBridges.java delete mode 100644 sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleProfileBridge.java create mode 100644 sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java delete mode 100644 sonar-server/src/main/java/org/sonar/server/rules/ProfileBackuper.java create mode 100644 sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java delete mode 100644 sonar-server/src/main/java/org/sonar/server/rules/RuleRepositories.java create mode 100644 sonar-server/src/main/java/org/sonar/server/rules/RulesConsole.java create mode 100644 sonar-server/src/test/java/org/sonar/server/rules/DeprecatedProfilesTest.java (limited to 'sonar-server') diff --git a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java index 8ec95ce9d56..2041e4c03bd 100644 --- a/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java +++ b/sonar-server/src/main/java/org/sonar/server/configuration/ProfilesManager.java @@ -54,16 +54,6 @@ public class ProfilesManager extends BaseDao { getSession().commit(); } - public String exportProfile(String pluginKey, int profileId) { - for (RulesRepository rulesRepository : rulesManager.getRulesRepositories()) { - Plugin plugin = plugins.getPluginByExtension(rulesRepository); - if (rulesRepository instanceof ConfigurationExportable && pluginKey.equals(plugin.getKey())) { - RulesProfile profile = rulesDao.getProfileById(profileId); - return ((ConfigurationExportable) rulesRepository).exportConfiguration(profile); - } - } - return null; - } public void importProfile(String pluginKey, int profileId, String configuration) { for (RulesRepository rulesRepository : rulesManager.getRulesRepositories()) { diff --git a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java index 1d236458e31..1a5313f91c1 100644 --- a/sonar-server/src/main/java/org/sonar/server/platform/Platform.java +++ b/sonar-server/src/main/java/org/sonar/server/platform/Platform.java @@ -28,8 +28,6 @@ import org.sonar.api.Plugins; import org.sonar.api.database.configuration.DatabaseConfiguration; import org.sonar.api.platform.Environment; import org.sonar.api.platform.Server; -import org.sonar.api.profiles.XMLProfileExporter; -import org.sonar.api.profiles.XMLProfileImporter; import org.sonar.api.resources.Languages; import org.sonar.api.rules.DefaultRulesManager; import org.sonar.api.utils.HttpDownloader; @@ -51,10 +49,7 @@ import org.sonar.server.database.JndiDatabaseConnector; import org.sonar.server.filters.FilterExecutor; import org.sonar.server.mavendeployer.MavenRepository; import org.sonar.server.plugins.*; -import org.sonar.server.rules.DeprecatedRuleBridges; -import org.sonar.server.rules.DeprecatedRuleProfileBridge; -import org.sonar.server.rules.ProfileBackuper; -import org.sonar.server.rules.RuleRepositories; +import org.sonar.server.rules.*; import org.sonar.server.startup.*; import org.sonar.server.ui.AuthenticatorFactory; import org.sonar.server.ui.CodeColorizers; @@ -179,12 +174,12 @@ public final class Platform { servicesContainer.as(Characteristics.CACHE).addComponent(AuthenticatorFactory.class); servicesContainer.as(Characteristics.CACHE).addComponent(ServerLifecycleNotifier.class); servicesContainer.as(Characteristics.CACHE).addComponent(DefaultRuleProvider.class); - servicesContainer.as(Characteristics.CACHE).addComponent(DeprecatedRuleBridges.class); - servicesContainer.as(Characteristics.CACHE).addComponent(RuleRepositories.class); - servicesContainer.as(Characteristics.CACHE).addComponent(XMLProfileExporter.create()); - servicesContainer.as(Characteristics.CACHE).addComponent(XMLProfileImporter.create()); - servicesContainer.as(Characteristics.CACHE).addComponent(ProfileBackuper.class); - + servicesContainer.as(Characteristics.CACHE).addComponent(DeprecatedRuleRepositories.class); + servicesContainer.as(Characteristics.CACHE).addComponent(DeprecatedProfiles.class); + servicesContainer.as(Characteristics.CACHE).addComponent(DeprecatedProfileExporters.class); + servicesContainer.as(Characteristics.CACHE).addComponent(ProfilesConsole.class); + servicesContainer.as(Characteristics.CACHE).addComponent(RulesConsole.class); + servicesContainer.start(); } @@ -195,7 +190,6 @@ public final class Platform { startupContainer.as(Characteristics.CACHE).addComponent(GwtPublisher.class); startupContainer.as(Characteristics.CACHE).addComponent(RegisterMetrics.class); startupContainer.as(Characteristics.CACHE).addComponent(RegisterRules.class); - startupContainer.as(Characteristics.CACHE).addComponent(DeprecatedRuleProfileBridge.class); startupContainer.as(Characteristics.CACHE).addComponent(RegisterProvidedProfiles.class); startupContainer.as(Characteristics.CACHE).addComponent(ActivateDefaultProfiles.class); startupContainer.as(Characteristics.CACHE).addComponent(JdbcDriverDeployer.class); diff --git a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfileExporters.java b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfileExporters.java new file mode 100644 index 00000000000..e5fc8865416 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfileExporters.java @@ -0,0 +1,87 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2009 SonarSource SA + * 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.rules; + +import org.sonar.api.Plugin; +import org.sonar.api.Plugins; +import org.sonar.api.ServerComponent; +import org.sonar.api.profiles.ProfileExporter; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.rules.ConfigurationExportable; +import org.sonar.api.rules.RulesRepository; +import org.sonar.api.utils.SonarException; + +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + +public final class DeprecatedProfileExporters implements ServerComponent { + + private Plugins plugins; + private RulesRepository[] deprecatedRepositories; + + public DeprecatedProfileExporters(Plugins plugins, RulesRepository[] deprecatedRepositories) { + this.deprecatedRepositories = deprecatedRepositories; + this.plugins = plugins; + } + + public DeprecatedProfileExporters(Plugins plugins) { + this.deprecatedRepositories = new RulesRepository[0]; + this.plugins = plugins; + } + + public List create() { + List result = new ArrayList(); + for (RulesRepository repo : deprecatedRepositories) { + if (repo instanceof ConfigurationExportable) { + result.add(new DeprecatedProfileExporter(getPlugin(repo), (ConfigurationExportable)repo)); + } + } + return result; + } + + private Plugin getPlugin(RulesRepository repository) { + return plugins.getPluginByExtension(repository); + } +} + +class DeprecatedProfileExporter extends ProfileExporter { + private ConfigurationExportable repository; + + protected DeprecatedProfileExporter(Plugin plugin, ConfigurationExportable repository) { + super(plugin.getKey(), plugin.getName()); + this.repository = repository; + setMimeType("application/xml"); + } + + + @Override + public void exportProfile(RulesProfile profile, Writer writer) { + String xml = repository.exportConfiguration(profile); + if (xml != null) { + try { + writer.append(xml); + } catch (IOException e) { + throw new SonarException("Can not export profile", e); + } + } + } +} \ No newline at end of file diff --git a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java new file mode 100644 index 00000000000..bb3db460eff --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedProfiles.java @@ -0,0 +1,161 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2009 SonarSource SA + * 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.rules; + +import org.apache.commons.lang.StringUtils; +import org.sonar.api.Plugins; +import org.sonar.api.checks.profiles.Check; +import org.sonar.api.checks.profiles.CheckProfile; +import org.sonar.api.checks.profiles.CheckProfileProvider; +import org.sonar.api.profiles.ProfileDefinition; +import org.sonar.api.profiles.ProfilePrototype; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.rules.ActiveRule; +import org.sonar.api.rules.ActiveRuleParam; +import org.sonar.api.rules.RulePriority; +import org.sonar.api.rules.RulesRepository; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public final class DeprecatedProfiles { + + private RulesRepository[] deprecatedRepositories; + private Plugins plugins; + private CheckProfile[] deprecatedCheckProfiles; + private CheckProfileProvider[] deprecatedCheckProfileProviders; + + public DeprecatedProfiles(Plugins plugins, RulesRepository[] r, CheckProfile[] deprecatedCheckProfiles, CheckProfileProvider[] deprecatedCheckProfileProviders) { + this.deprecatedRepositories = r; + this.plugins = plugins; + this.deprecatedCheckProfiles = deprecatedCheckProfiles; + this.deprecatedCheckProfileProviders = deprecatedCheckProfileProviders; + } + + public DeprecatedProfiles(Plugins plugins, RulesRepository[] r, CheckProfile[] deprecatedCheckProfiles) { + this.deprecatedRepositories = r; + this.plugins = plugins; + this.deprecatedCheckProfiles = deprecatedCheckProfiles; + this.deprecatedCheckProfileProviders = new CheckProfileProvider[0]; + } + + public DeprecatedProfiles(Plugins plugins, RulesRepository[] r, CheckProfileProvider[] deprecatedCheckProfileProviders) { + this.deprecatedRepositories = r; + this.plugins = plugins; + this.deprecatedCheckProfiles = new CheckProfile[0]; + this.deprecatedCheckProfileProviders = deprecatedCheckProfileProviders; + } + + public DeprecatedProfiles(Plugins plugins, RulesRepository[] r) { + this.deprecatedRepositories = r; + this.plugins = plugins; + this.deprecatedCheckProfiles = new CheckProfile[0]; + this.deprecatedCheckProfileProviders = new CheckProfileProvider[0]; + } + + public List getProfiles() { + List profiles = new ArrayList(); + for (RulesRepository repository : deprecatedRepositories) { + profiles.addAll(loadFromDeprecatedRepository(repository)); + } + for (CheckProfile deprecatedCheckProfile : deprecatedCheckProfiles) { + profiles.add(loadFromDeprecatedCheckProfile(deprecatedCheckProfile)); + } + for (CheckProfileProvider provider : deprecatedCheckProfileProviders) { + for (CheckProfile deprecatedCheckProfile : provider.provide()) { + profiles.add(loadFromDeprecatedCheckProfile(deprecatedCheckProfile)); + } + } + return profiles; + } + + private List loadFromDeprecatedRepository(RulesRepository repository) { + List result = new ArrayList(); + + for (int index = 0; index < repository.getProvidedProfiles().size(); index++) { + RulesProfile deprecated = (RulesProfile) repository.getProvidedProfiles().get(index); + DefaultProfileDefinition providedProfile = DefaultProfileDefinition.create(deprecated.getName(), repository.getLanguage().getKey()); + for (ActiveRule activeRule : deprecated.getActiveRules()) { + String repositoryKey = activeRule.getRepositoryKey(); + if (StringUtils.isBlank(repositoryKey)) { + repositoryKey = getPluginKey(repository); + } + ProfilePrototype.RulePrototype rule = providedProfile.activateRule(repositoryKey, activeRule.getRuleKey(), activeRule.getPriority()); + for (ActiveRuleParam arp : activeRule.getActiveRuleParams()) { + rule.setParameter(arp.getKey(), arp.getValue()); + } + } + result.add(providedProfile); + } + return result; + } + + private ProfileDefinition loadFromDeprecatedCheckProfile(CheckProfile cp) { + DefaultProfileDefinition definition = DefaultProfileDefinition.create(cp.getName(), cp.getLanguage()); + for (Check check : cp.getChecks()) { + RulePriority priority = null; + if (check.getPriority() != null) { + priority = RulePriority.fromCheckPriority(check.getPriority()); + } + ProfilePrototype.RulePrototype rule = definition.activateRule(check.getRepositoryKey(), check.getTemplateKey(), priority); + for (Map.Entry entry : rule.getParameters().entrySet()) { + rule.setParameter(entry.getKey(), entry.getValue()); + } + } + return definition; + } + + private String getPluginKey(RulesRepository repository) { + return plugins.getPluginByExtension(repository).getKey(); + } + + public static class DefaultProfileDefinition extends ProfileDefinition { + + private ProfilePrototype prototype; + + DefaultProfileDefinition(String name, String language) { + super(name, language); + this.prototype = ProfilePrototype.create(); + } + + public static DefaultProfileDefinition create(String name, String language) { + return new DefaultProfileDefinition(name, language); + } + + @Override + public ProfilePrototype createPrototype() { + return prototype; + } + + public List getRules() { + return prototype.getRules(); + } + + public List getRulesByRepositoryKey(String repositoryKey) { + return prototype.getRulesByRepositoryKey(repositoryKey); + } + + public ProfilePrototype.RulePrototype activateRule(String repositoryKey, String key, RulePriority nullablePriority) { + return prototype.activateRule(repositoryKey, key, nullablePriority); + } + } + +} diff --git a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleBridge.java b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleBridge.java deleted file mode 100644 index d92184e9805..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleBridge.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA - * 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.rules; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.CharEncoding; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.RuleParam; -import org.sonar.api.rules.RuleRepository; -import org.sonar.api.rules.RulesRepository; -import org.sonar.api.utils.SonarException; -import org.sonar.server.platform.DefaultServerFileSystem; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** - * Bridge for the deprecated extension "org.sonar.api.rules.RulesRepository" - */ -public final class DeprecatedRuleBridge extends RuleRepository { - - private RulesRepository deprecatedRepository; - private DefaultServerFileSystem fileSystem; - - public DeprecatedRuleBridge(String repositoryKey, String repositoryName, RulesRepository deprecatedRepository, DefaultServerFileSystem fileSystem) { - super(repositoryKey, deprecatedRepository.getLanguage().getKey()); - this.deprecatedRepository = deprecatedRepository; - this.fileSystem = fileSystem; - setName(repositoryName); - } - - @Override - public List createRules() { - List rules = new ArrayList(); - registerRules(rules); - registerRuleExtensions(rules); - return rules; - } - - private void registerRules(List rules) { - List deprecatedRules = deprecatedRepository.getInitialReferential(); - if (deprecatedRules != null) { - for (Rule deprecatedRule : deprecatedRules) { - rules.add(cloneRule(deprecatedRule)); - } - } - } - - private void registerRuleExtensions(List rules) { - for (File file : fileSystem.getPluginExtensionXml(getKey())) { - try { - String fileContent = FileUtils.readFileToString(file, CharEncoding.UTF_8); - List deprecatedRules = deprecatedRepository.parseReferential(fileContent); - if (deprecatedRules != null) { - for (Rule deprecatedRule : deprecatedRules) { - rules.add(cloneRule(deprecatedRule)); - } - } - } catch (IOException e) { - throw new SonarException("Can not read the file: " + file.getPath(), e); - } - } - } - - private Rule cloneRule(Rule deprecatedRule) { - Rule rule = Rule.create(getKey(), deprecatedRule.getKey(), deprecatedRule.getName()); - rule.setRulesCategory(deprecatedRule.getRulesCategory()); - rule.setConfigKey(deprecatedRule.getConfigKey()); - rule.setPriority(deprecatedRule.getPriority()); - rule.setDescription(deprecatedRule.getDescription()); - rule.setEnabled(true); - if (deprecatedRule.getParams() != null) { - for (RuleParam deprecatedParam : deprecatedRule.getParams()) { - rule.createParameter(deprecatedParam.getKey()) - .setDescription(deprecatedParam.getDescription()) - .setType(deprecatedParam.getType()); - } - } - return rule; - } -} diff --git a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleBridges.java b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleBridges.java deleted file mode 100644 index e746abf64b7..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleBridges.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA - * 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.rules; - -import org.sonar.api.Plugin; -import org.sonar.api.Plugins; -import org.sonar.api.rules.RulesRepository; -import org.sonar.server.platform.DefaultServerFileSystem; -import org.sonar.server.rules.DeprecatedRuleBridge; - -import java.util.ArrayList; -import java.util.List; - -public final class DeprecatedRuleBridges { - - private RulesRepository[] repositories; - private DefaultServerFileSystem fileSystem; - private Plugins plugins; - - public DeprecatedRuleBridges(DefaultServerFileSystem fileSystem, Plugins plugins) { - this.fileSystem = fileSystem; - this.plugins = plugins; - this.repositories = new RulesRepository[0]; - } - - public DeprecatedRuleBridges(DefaultServerFileSystem fileSystem, Plugins plugins, RulesRepository[] repositories) { - this.fileSystem = fileSystem; - this.plugins = plugins; - this.repositories = repositories; - } - - public List createBridges() { - List bridges = new ArrayList(); - for (RulesRepository repository : repositories) { - Plugin plugin = getPlugin(repository); - bridges.add(new DeprecatedRuleBridge(plugin.getKey(), plugin.getName(), repository, fileSystem)); - } - return bridges; - } - - private Plugin getPlugin(RulesRepository repository) { - return plugins.getPluginByExtension(repository); - } - -} diff --git a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleProfileBridge.java b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleProfileBridge.java deleted file mode 100644 index 377afe2fc97..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleProfileBridge.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA - * 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.rules; - -import org.apache.commons.lang.StringUtils; -import org.sonar.api.Plugins; -import org.sonar.api.checks.profiles.Check; -import org.sonar.api.checks.profiles.CheckProfile; -import org.sonar.api.checks.profiles.CheckProfileProvider; -import org.sonar.api.profiles.ProfileDefinition; -import org.sonar.api.profiles.ProfilePrototype; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.rules.ActiveRule; -import org.sonar.api.rules.ActiveRuleParam; -import org.sonar.api.rules.RulePriority; -import org.sonar.api.rules.RulesRepository; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public final class DeprecatedRuleProfileBridge { - - private RulesRepository[] deprecatedRepositories; - private Plugins plugins; - private CheckProfile[] deprecatedCheckProfiles; - private CheckProfileProvider[] deprecatedCheckProfileProviders; - - public DeprecatedRuleProfileBridge(Plugins plugins, RulesRepository[] r, CheckProfile[] deprecatedCheckProfiles, CheckProfileProvider[] deprecatedCheckProfileProviders) { - this.deprecatedRepositories = r; - this.plugins = plugins; - this.deprecatedCheckProfiles = deprecatedCheckProfiles; - this.deprecatedCheckProfileProviders = deprecatedCheckProfileProviders; - } - - public DeprecatedRuleProfileBridge(Plugins plugins, RulesRepository[] r, CheckProfile[] deprecatedCheckProfiles) { - this.deprecatedRepositories = r; - this.plugins = plugins; - this.deprecatedCheckProfiles = deprecatedCheckProfiles; - this.deprecatedCheckProfileProviders = new CheckProfileProvider[0]; - } - - public DeprecatedRuleProfileBridge(Plugins plugins, RulesRepository[] r, CheckProfileProvider[] deprecatedCheckProfileProviders) { - this.deprecatedRepositories = r; - this.plugins = plugins; - this.deprecatedCheckProfiles = new CheckProfile[0]; - this.deprecatedCheckProfileProviders = deprecatedCheckProfileProviders; - } - - public DeprecatedRuleProfileBridge(Plugins plugins, RulesRepository[] r) { - this.deprecatedRepositories = r; - this.plugins = plugins; - this.deprecatedCheckProfiles = new CheckProfile[0]; - this.deprecatedCheckProfileProviders = new CheckProfileProvider[0]; - } - - public List getProfiles() { - List profiles = new ArrayList(); - for (RulesRepository repository : deprecatedRepositories) { - profiles.addAll(loadFromDeprecatedRepository(repository)); - } - for (CheckProfile deprecatedCheckProfile : deprecatedCheckProfiles) { - profiles.add(loadFromDeprecatedCheckProfile(deprecatedCheckProfile)); - } - for (CheckProfileProvider provider : deprecatedCheckProfileProviders) { - for (CheckProfile deprecatedCheckProfile : provider.provide()) { - profiles.add(loadFromDeprecatedCheckProfile(deprecatedCheckProfile)); - } - } - return profiles; - } - - private List loadFromDeprecatedRepository(RulesRepository repository) { - List result = new ArrayList(); - - for (int index = 0; index < repository.getProvidedProfiles().size(); index++) { - RulesProfile deprecated = (RulesProfile) repository.getProvidedProfiles().get(index); - DefaultProfileDefinition providedProfile = DefaultProfileDefinition.create(deprecated.getName(), repository.getLanguage().getKey()); - for (ActiveRule activeRule : deprecated.getActiveRules()) { - String repositoryKey = activeRule.getRepositoryKey(); - if (StringUtils.isBlank(repositoryKey)) { - repositoryKey = getPluginKey(repository); - } - ProfilePrototype.RulePrototype rule = providedProfile.activateRule(repositoryKey, activeRule.getRuleKey(), activeRule.getPriority()); - for (ActiveRuleParam arp : activeRule.getActiveRuleParams()) { - rule.setParameter(arp.getKey(), arp.getValue()); - } - } - result.add(providedProfile); - } - return result; - } - - private ProfileDefinition loadFromDeprecatedCheckProfile(CheckProfile cp) { - DefaultProfileDefinition definition = DefaultProfileDefinition.create(cp.getName(), cp.getLanguage()); - for (Check check : cp.getChecks()) { - RulePriority priority = null; - if (check.getPriority() != null) { - priority = RulePriority.fromCheckPriority(check.getPriority()); - } - ProfilePrototype.RulePrototype rule = definition.activateRule(check.getRepositoryKey(), check.getTemplateKey(), priority); - for (Map.Entry entry : rule.getParameters().entrySet()) { - rule.setParameter(entry.getKey(), entry.getValue()); - } - } - return definition; - } - - private String getPluginKey(RulesRepository repository) { - return plugins.getPluginByExtension(repository).getKey(); - } - - public static class DefaultProfileDefinition extends ProfileDefinition { - - private ProfilePrototype prototype; - - DefaultProfileDefinition(String name, String language) { - super(name, language); - this.prototype = ProfilePrototype.create(); - } - - public static DefaultProfileDefinition create(String name, String language) { - return new DefaultProfileDefinition(name, language); - } - - @Override - public ProfilePrototype createPrototype() { - return prototype; - } - - public List getRules() { - return prototype.getRules(); - } - - public List getRulesByRepositoryKey(String repositoryKey) { - return prototype.getRulesByRepositoryKey(repositoryKey); - } - - public ProfilePrototype.RulePrototype activateRule(String repositoryKey, String key, RulePriority nullablePriority) { - return prototype.activateRule(repositoryKey, key, nullablePriority); - } - } - -} diff --git a/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java new file mode 100644 index 00000000000..1794d2dfd27 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/rules/DeprecatedRuleRepositories.java @@ -0,0 +1,132 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2009 SonarSource SA + * 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.rules; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.CharEncoding; +import org.sonar.api.Plugin; +import org.sonar.api.Plugins; +import org.sonar.api.rules.Rule; +import org.sonar.api.rules.RuleParam; +import org.sonar.api.rules.RuleRepository; +import org.sonar.api.rules.RulesRepository; +import org.sonar.api.utils.SonarException; +import org.sonar.server.platform.DefaultServerFileSystem; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +public final class DeprecatedRuleRepositories { + + private RulesRepository[] repositories; + private DefaultServerFileSystem fileSystem; + private Plugins plugins; + + public DeprecatedRuleRepositories(DefaultServerFileSystem fileSystem, Plugins plugins) { + this.fileSystem = fileSystem; + this.plugins = plugins; + this.repositories = new RulesRepository[0]; + } + + public DeprecatedRuleRepositories(DefaultServerFileSystem fileSystem, Plugins plugins, RulesRepository[] repositories) { + this.fileSystem = fileSystem; + this.plugins = plugins; + this.repositories = repositories; + } + + public List create() { + List repositories = new ArrayList(); + for (RulesRepository repository : this.repositories) { + Plugin plugin = getPlugin(repository); + repositories.add(new DeprecatedRuleRepository(plugin.getKey(), plugin.getName(), repository, fileSystem)); + } + return repositories; + } + + private Plugin getPlugin(RulesRepository repository) { + return plugins.getPluginByExtension(repository); + } +} + + +class DeprecatedRuleRepository extends RuleRepository { + + private RulesRepository deprecatedRepository; + private DefaultServerFileSystem fileSystem; + + public DeprecatedRuleRepository(String repositoryKey, String repositoryName, RulesRepository deprecatedRepository, DefaultServerFileSystem fileSystem) { + super(repositoryKey, deprecatedRepository.getLanguage().getKey()); + this.deprecatedRepository = deprecatedRepository; + this.fileSystem = fileSystem; + setName(repositoryName); + } + + @Override + public List createRules() { + List rules = new ArrayList(); + registerRules(rules); + registerRuleExtensions(rules); + return rules; + } + + private void registerRules(List rules) { + List deprecatedRules = deprecatedRepository.getInitialReferential(); + if (deprecatedRules != null) { + for (Rule deprecatedRule : deprecatedRules) { + rules.add(cloneRule(deprecatedRule)); + } + } + } + + private void registerRuleExtensions(List rules) { + for (File file : fileSystem.getPluginExtensionXml(getKey())) { + try { + String fileContent = FileUtils.readFileToString(file, CharEncoding.UTF_8); + List deprecatedRules = deprecatedRepository.parseReferential(fileContent); + if (deprecatedRules != null) { + for (Rule deprecatedRule : deprecatedRules) { + rules.add(cloneRule(deprecatedRule)); + } + } + } catch (IOException e) { + throw new SonarException("Can not read the file: " + file.getPath(), e); + } + } + } + + private Rule cloneRule(Rule deprecatedRule) { + Rule rule = Rule.create(getKey(), deprecatedRule.getKey(), deprecatedRule.getName()); + rule.setRulesCategory(deprecatedRule.getRulesCategory()); + rule.setConfigKey(deprecatedRule.getConfigKey()); + rule.setPriority(deprecatedRule.getPriority()); + rule.setDescription(deprecatedRule.getDescription()); + rule.setEnabled(true); + if (deprecatedRule.getParams() != null) { + for (RuleParam deprecatedParam : deprecatedRule.getParams()) { + rule.createParameter(deprecatedParam.getKey()) + .setDescription(deprecatedParam.getDescription()) + .setType(deprecatedParam.getType()); + } + } + return rule; + } +} diff --git a/sonar-server/src/main/java/org/sonar/server/rules/ProfileBackuper.java b/sonar-server/src/main/java/org/sonar/server/rules/ProfileBackuper.java deleted file mode 100644 index ddfe6c3c681..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/rules/ProfileBackuper.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA - * 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.rules; - -import org.sonar.api.ServerComponent; -import org.sonar.api.database.DatabaseSession; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.profiles.XMLProfileExporter; -import org.sonar.jpa.session.DatabaseSessionFactory; - -import java.io.StringWriter; -import java.io.Writer; - -public final class ProfileBackuper implements ServerComponent { - - private DatabaseSessionFactory sessionFactory; - private XMLProfileExporter exporter; - - public ProfileBackuper(DatabaseSessionFactory sessionFactory, XMLProfileExporter exporter) { - this.sessionFactory = sessionFactory; - this.exporter = exporter; - } - - public String exportProfile(int profileId) { - DatabaseSession session = sessionFactory.getSession(); - RulesProfile profile = session.getSingleResult(RulesProfile.class, "id", profileId); - if (profile != null) { - Writer writer = new StringWriter(); - exporter.exportProfile(profile, writer); - return writer.toString(); - } - return null; - } -} diff --git a/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java b/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java new file mode 100644 index 00000000000..7e92a8078db --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/rules/ProfilesConsole.java @@ -0,0 +1,101 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2009 SonarSource SA + * 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.rules; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.StringUtils; +import org.sonar.api.ServerComponent; +import org.sonar.api.database.DatabaseSession; +import org.sonar.api.profiles.ProfileExporter; +import org.sonar.api.profiles.RulesProfile; +import org.sonar.api.profiles.XMLProfileExporter; +import org.sonar.jpa.session.DatabaseSessionFactory; + +import java.io.StringWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public final class ProfilesConsole implements ServerComponent { + + private DatabaseSessionFactory sessionFactory; + private List profileExporters = new ArrayList(); + + + public ProfilesConsole(DatabaseSessionFactory sessionFactory, + ProfileExporter[] exporters, DeprecatedProfileExporters deprecatedExporters) { + this.sessionFactory = sessionFactory; + initProfileExporters(exporters, deprecatedExporters); + } + + private void initProfileExporters(ProfileExporter[] exporters, DeprecatedProfileExporters deprecatedExporters) { + this.profileExporters.addAll(Arrays.asList(exporters)); + for (ProfileExporter exporter : deprecatedExporters.create()) { + this.profileExporters.add(exporter); + } + } + + public String backupProfile(int profileId) { + RulesProfile profile = loadProfile(profileId); + if (profile != null) { + Writer writer = new StringWriter(); + XMLProfileExporter.create().exportProfile(profile, writer); + return writer.toString(); + } + return null; + } + + private RulesProfile loadProfile(int profileId) { + DatabaseSession session = sessionFactory.getSession(); + RulesProfile profile = session.getSingleResult(RulesProfile.class, "id", profileId); + return profile; + } + + public List getProfileExportersForLanguage(String language) { + List result = new ArrayList(); + for (ProfileExporter exporter : profileExporters) { + if (exporter.getSupportedLanguages() == null || exporter.getSupportedLanguages().length == 0 || ArrayUtils.contains(exporter.getSupportedLanguages(), language)) { + result.add(exporter); + } + } + return result; + } + + public String exportProfile(int profileId, String exporterKey) { + RulesProfile profile = loadProfile(profileId); + if (profile != null) { + ProfileExporter exporter = getProfileExporter(exporterKey); + Writer writer = new StringWriter(); + exporter.exportProfile(profile, writer); + return writer.toString(); + } + return null; + } + + public ProfileExporter getProfileExporter(String exporterKey) { + for (ProfileExporter exporter : profileExporters) { + if (StringUtils.equals(exporterKey, exporter.getKey())) { + return exporter; + } + } + return null; + } +} diff --git a/sonar-server/src/main/java/org/sonar/server/rules/RuleRepositories.java b/sonar-server/src/main/java/org/sonar/server/rules/RuleRepositories.java deleted file mode 100644 index 30ab4e6ed87..00000000000 --- a/sonar-server/src/main/java/org/sonar/server/rules/RuleRepositories.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Sonar, open source software quality management tool. - * Copyright (C) 2009 SonarSource SA - * 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.rules; - -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.ListMultimap; -import org.sonar.api.ServerComponent; -import org.sonar.api.rules.RuleRepository; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public final class RuleRepositories implements ServerComponent { - - private List repositories = new ArrayList(); - private ListMultimap repositoriesByLanguage = ArrayListMultimap.create(); - - public RuleRepositories(RuleRepository[] repositories) { - this(repositories, null); - } - - public RuleRepositories(RuleRepository[] repositories, DeprecatedRuleBridges deprecatedBridge) { - this.repositories.addAll(Arrays.asList(repositories)); - if (deprecatedBridge != null) { - this.repositories.addAll(deprecatedBridge.createBridges()); - } - for (RuleRepository repository : this.repositories) { - repositoriesByLanguage.put(repository.getLanguage(), repository); - } - } - - public List getRepositoriesByLanguage(String language) { - return repositoriesByLanguage.get(language); - } -} diff --git a/sonar-server/src/main/java/org/sonar/server/rules/RulesConsole.java b/sonar-server/src/main/java/org/sonar/server/rules/RulesConsole.java new file mode 100644 index 00000000000..c7505386ce6 --- /dev/null +++ b/sonar-server/src/main/java/org/sonar/server/rules/RulesConsole.java @@ -0,0 +1,64 @@ +/* + * Sonar, open source software quality management tool. + * Copyright (C) 2009 SonarSource SA + * 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.rules; + +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.ListMultimap; +import org.apache.commons.lang.StringUtils; +import org.sonar.api.ServerComponent; +import org.sonar.api.rules.RuleRepository; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public final class RulesConsole implements ServerComponent { + + private List repositories = new ArrayList(); + private ListMultimap repositoriesByLanguage = ArrayListMultimap.create(); + + + public RulesConsole(RuleRepository[] repositories, DeprecatedRuleRepositories deprecatedRuleRepositories) { + initRepositories(repositories, deprecatedRuleRepositories); + } + + private void initRepositories(RuleRepository[] repositories, DeprecatedRuleRepositories deprecatedBridge) { + this.repositories.addAll(Arrays.asList(repositories)); + if (deprecatedBridge != null) { + this.repositories.addAll(deprecatedBridge.create()); + } + for (RuleRepository repository : this.repositories) { + repositoriesByLanguage.put(repository.getLanguage(), repository); + } + } + + public List getRepositoriesByLanguage(String language) { + return repositoriesByLanguage.get(language); + } + + public RuleRepository getRepository(String key) { + for (RuleRepository repository : repositories) { + if (StringUtils.equals(key, repository.getKey())) { + return repository; + } + } + return null; + } +} diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java index 6b857e7bb49..12c3aa18c1b 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterProvidedProfiles.java @@ -31,7 +31,7 @@ import org.sonar.api.rules.Rule; import org.sonar.api.rules.RuleProvider; import org.sonar.api.utils.TimeProfiler; import org.sonar.jpa.session.DatabaseSessionFactory; -import org.sonar.server.rules.DeprecatedRuleProfileBridge; +import org.sonar.server.rules.DeprecatedProfiles; import java.util.ArrayList; import java.util.Arrays; @@ -47,7 +47,7 @@ public final class RegisterProvidedProfiles { private List definitions = new ArrayList(); public RegisterProvidedProfiles(RuleProvider ruleProvider, DatabaseSessionFactory sessionFactory, - DeprecatedRuleProfileBridge deprecatedBridge, RegisterRules registerRulesBefore, + DeprecatedProfiles deprecatedBridge, RegisterRules registerRulesBefore, ProfileDefinition[] definitions) { this.ruleProvider = ruleProvider; this.sessionFactory = sessionFactory; @@ -58,7 +58,7 @@ public final class RegisterProvidedProfiles { } public RegisterProvidedProfiles(RuleProvider ruleProvider, DatabaseSessionFactory sessionFactory, - DeprecatedRuleProfileBridge deprecatedBridge, RegisterRules registerRulesBefore) { + DeprecatedProfiles deprecatedBridge, RegisterRules registerRulesBefore) { this.ruleProvider = ruleProvider; this.sessionFactory = sessionFactory; if (deprecatedBridge != null) { diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java index fba87355d79..ae9fbd01aca 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterRules.java @@ -25,7 +25,7 @@ import org.sonar.api.rules.*; import org.sonar.api.utils.Logs; import org.sonar.api.utils.TimeProfiler; import org.sonar.jpa.session.DatabaseSessionFactory; -import org.sonar.server.rules.DeprecatedRuleBridges; +import org.sonar.server.rules.DeprecatedRuleRepositories; import java.util.*; @@ -34,16 +34,16 @@ public final class RegisterRules { private DatabaseSessionFactory sessionFactory; private List repositories = new ArrayList(); - public RegisterRules(DatabaseSessionFactory sessionFactory, DeprecatedRuleBridges bridges, RuleRepository[] repos) { + public RegisterRules(DatabaseSessionFactory sessionFactory, DeprecatedRuleRepositories repositories, RuleRepository[] repos) { this.sessionFactory = sessionFactory; this.repositories.addAll(Arrays.asList(repos)); - if (bridges != null) { - this.repositories.addAll(bridges.createBridges()); + if (repositories != null) { + this.repositories.addAll(repositories.create()); } } - public RegisterRules(DatabaseSessionFactory sessionFactory, DeprecatedRuleBridges bridges) { - this(sessionFactory, bridges, new RuleRepository[0]); + public RegisterRules(DatabaseSessionFactory sessionFactory, DeprecatedRuleRepositories repositories) { + this(sessionFactory, repositories, new RuleRepository[0]); } public void start() { diff --git a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java index 07408ae83c7..9654bd04bbf 100644 --- a/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java +++ b/sonar-server/src/main/java/org/sonar/server/ui/JRubyFacade.java @@ -25,6 +25,7 @@ import org.slf4j.LoggerFactory; import org.sonar.api.Plugin; import org.sonar.api.Plugins; import org.sonar.api.Property; +import org.sonar.api.profiles.ProfileExporter; import org.sonar.api.resources.Language; import org.sonar.api.resources.Languages; import org.sonar.api.rules.DefaultRulesManager; @@ -43,8 +44,8 @@ import org.sonar.server.platform.Platform; import org.sonar.server.plugins.PluginDownloader; import org.sonar.server.plugins.UpdateFinder; import org.sonar.server.plugins.UpdateFinderFactory; -import org.sonar.server.rules.ProfileBackuper; -import org.sonar.server.rules.RuleRepositories; +import org.sonar.server.rules.ProfilesConsole; +import org.sonar.server.rules.RulesConsole; import org.sonar.updatecenter.common.Version; import java.util.Collection; @@ -122,24 +123,28 @@ public class JRubyFacade { return getContainer().getComponent(Plugins.class).getPlugins(); } - public List getPluginsWithConfigurationExportable(Language language) { - return getRulesManager().getExportablePlugins(language); - } - public List getPluginsWithConfigurationImportable(Language language) { return getRulesManager().getImportablePlugins(language); } public List getRuleRepositoriesByLanguage(String languageKey) { - return getContainer().getComponent(RuleRepositories.class).getRepositoriesByLanguage(languageKey); + return getContainer().getComponent(RulesConsole.class).getRepositoriesByLanguage(languageKey); + } + + public String backupProfile(int profileId) { + return getContainer().getComponent(ProfilesConsole.class).backupProfile(profileId); } - public String exportProfile(int profileId) { - return getContainer().getComponent(ProfileBackuper.class).exportProfile(profileId); + public List getProfileExportersForLanguage(String language) { + return getContainer().getComponent(ProfilesConsole.class).getProfileExportersForLanguage(language); } - public String exportConfiguration(String pluginKey, long profileId) { - return getProfilesManager().exportProfile(pluginKey, (int) profileId); + public String exportProfile(int profileId, String exporterKey) { + return getContainer().getComponent(ProfilesConsole.class).exportProfile(profileId, exporterKey); + } + + public String getProfileExporterMimeType(String exporterKey) { + return getContainer().getComponent(ProfilesConsole.class).getProfileExporter(exporterKey).getMimeType(); } public void importConfiguration(String pluginKey, long profileId, String configuration) { @@ -154,11 +159,6 @@ public class JRubyFacade { getProfilesManager().deleteProfile((int) profileId); } - public Map getRulesCountByCategory(String languageKey) { - Language language = getContainer().getComponent(Languages.class).get(languageKey); - return getRulesManager().countRulesByCategory(language); - } - public List